Example #1
0
bool ZWebDAV::sHandle_PUT(const ZTrail& iPrefix, ZNode iRoot, const ZStreamR& iStreamR, const ZStreamW& iStreamW, const ZTuple& iHeader, const ZTrail& iTrail, const ZTuple& iParam)
	{
	ZHTTP::Response r;
	r.Set("date", sAsString_WebDAV(ZTime::sNow()));
	r.Set("Content-Length", 0);

	ZNode theNode = iRoot.Trail(iTrail);

	ZRef<ZStreamerWPos> theStreamerWPos = theNode.CreateWPos(true);
	if (!theStreamerWPos)
		{
		r.SetResult(409);
		}
	else
		{
		theStreamerWPos->GetStreamW().CopyAllFrom(iStreamR);
		theStreamerWPos->GetStreamWPos().Truncate();

		r.SetResult(204);
		}

	r.Send(iStreamW);
	return true;
	}
Example #2
0
ZStreamerW_DynamicBuffered::ZStreamerW_DynamicBuffered(
	ZRef<ZStreamerW> iStreamerSink, ZRef<ZStreamerRWPos> iStreamerBuffer)
:	fStreamerSink(iStreamerSink),
	fStreamerBuffer(iStreamerBuffer),
	fStream(iStreamerSink->GetStreamW(), iStreamerBuffer->GetStreamRWPos())
	{}
Example #3
0
ZStreamerW_ZLibEncode::ZStreamerW_ZLibEncode(ZRef<ZStreamerW> iStreamer)
:	fStreamer(iStreamer),
	fStream(iStreamer->GetStreamW())
	{}
Example #4
0
ZStreamerW_ZLibEncode::ZStreamerW_ZLibEncode(
	ZStream_ZLib::EFormatW iFormatW, int iCompressionLevel, size_t iBufferSize,
	ZRef<ZStreamerW> iStreamer)
:	fStreamer(iStreamer),
	fStream(iFormatW, iCompressionLevel, iBufferSize, iStreamer->GetStreamW())
	{}
Example #5
0
void ZBlackBerryServer::HandleRequest(ZRef<ZStreamerRWCon> iSRWCon)
	{
	const ZStreamR& r = iSRWCon->GetStreamR();
	const ZStreamW& w = iSRWCon->GetStreamW();

	const int req = r.ReadUInt8();
	if (req == 0)
		{
		// Async changed notifications
		ZGuardRMtxR locker(fMutex);
		ZRef<Handler_ManagerChanged> theHandler = new Handler_ManagerChanged(iSRWCon, iSRWCon, this);
		fHandlers_ManagerChanged.push_back(theHandler);
		locker.Release();

		sStartCommerRunners(theHandler);
		}
	else if (req == 1)
		{
		// Synchronous get device IDs
		ZGuardRMtxR locker(fMutex);

		vector<uint64> theIDs;
		for (vector<Entry_t>::iterator i = fEntries.begin(); i != fEntries.end(); ++i)
			{
			if (i->fLive)
				theIDs.push_back(i->fID);
			}
		locker.Release();

		w.WriteCount(theIDs.size());
		for (vector<uint64>::iterator i = theIDs.begin(); i != theIDs.end(); ++i)
			w.WriteUInt64(*i);
		}
	else if (req == 2)
		{
		// Async device finished notifications
		const uint64 deviceID = r.ReadUInt64();

		ZGuardRMtxR locker(fMutex);

		bool gotIt = false;
		for (vector<Entry_t>::iterator i = fEntries.begin(); !gotIt && i != fEntries.end(); ++i)
			{
			if (i->fLive && i->fID == deviceID)
				{
				ZRef<Handler_DeviceFinished> theHandler =
					new Handler_DeviceFinished(iSRWCon, iSRWCon, this);
				i->fHandlers.push_back(theHandler);
				locker.Release();

				w.WriteBool(true);
				sStartCommerRunners(theHandler);
				gotIt = true;
				}
			}

		if (!gotIt)
			{
			locker.Release();
			w.WriteBool(false);
			}
		}
	else if (req == 4)
		{
		// Synchronous get attribute
		const uint64 deviceID = r.ReadUInt64();
		const uint16 object = r.ReadUInt16();
		const uint16 attribute = r.ReadUInt16();
		if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID))
			{
			if (ZQ<ZBlackBerry::Data> theQ = theDevice->GetAttribute(object, attribute))
				{
				ZBlackBerry::Data theMB = theQ.Get();
				w.WriteBool(true);
				w.WriteCount(theMB.GetSize());
				w.Write(theMB.GetPtr(), theMB.GetSize());
				return;
				}
			}
		w.WriteBool(false);
		}
	else if (req == 5)
		{
		// Synchronous get PIN
		const uint64 deviceID = r.ReadUInt64();
		if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID))
			{
			uint32 thePIN = theDevice->GetPIN();
			w.WriteBool(true);
			w.WriteUInt32(thePIN);
			}
		else
			{
			w.WriteBool(false);
			}
		}
	else if (req == 6)
		{
		// Open channel
		const uint64 deviceID = r.ReadUInt64();

		const bool preserveBoundaries = r.ReadBool();

		const bool gotHash = r.ReadBool();
		ZBlackBerry::PasswordHash thePasswordHash;
		if (gotHash)
			r.Read(&thePasswordHash, sizeof(thePasswordHash));

		const string channelName = spReadString(r);

		ZBlackBerry::Device::Error theError = ZBlackBerry::Device::error_DeviceClosed;

		if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID))
			{
			if (ZRef<ZBlackBerry::Channel> deviceCon = theDevice->Open(preserveBoundaries,
				channelName, gotHash ? &thePasswordHash : nullptr, &theError))
				{
				const size_t readSize = deviceCon->GetIdealSize_Read();
				const size_t writeSize = deviceCon->GetIdealSize_Write();
				w.WriteUInt32(ZBlackBerry::Device::error_None);
				w.WriteUInt32(readSize);
				w.WriteUInt32(writeSize);
				w.Flush();

				// Use a standard copier for the device-->client direction
				sCallOnNewThread(
					sBindR(sCallable(&spCopyAllCon), deviceCon, iSRWCon, readSize));

				// And our specialized copier for the client-->device direction.
				sCallOnNewThread(
					sBindR(sCallable(&spCopyChunked), iSRWCon, deviceCon));
				return;
				}
			}

		if (theError == ZBlackBerry::Device::error_None)
			{
			if (ZLOG(s, eDebug + 1, "ZBlackBerryServer::HandleRequest"))
				{
				s << "Open failed, but got error_None";
				}
			theError = ZBlackBerry::Device::error_Generic;
			}
		w.WriteUInt32(theError);
		}
	}