Exemple #1
0
void Parser::ParseBinary()
	{
	using namespace ZUtil_Strim;

	sSkip_WSAndCPlusPlusComments(*fStrimU);

	if (sTryRead_CP(*fStrimU, '{'))
		{
		fParseHandler.ParsedBinary(ZStreamR_HexStrim(true, *fStrimU));

		sSkip_WSAndCPlusPlusComments(*fStrimU);

		if (!sTryRead_CP(*fStrimU, '}'))
			throw ParseException("Expected '}'");
		}
	else
		{
		string fileName;
		if (!sTryRead_EscapedString(*fStrimU, '"', fileName))
			throw ParseException("Expected a quoted file name");

		ZFileSpec fileSpecUsed;
		ZRef<ZStreamerR> theStreamer = fStreamProvider.ProvideStreamBinary(fFileSpec, fileName, true, fileSpecUsed);
		if (!theStreamer)
			throw ParseException(string("Could not open file \"") + fileName + string("\" to read binary data"));

		if (fIncludeHandler)
			fIncludeHandler->NotifyInclude(fileSpecUsed);

		fParseHandler.ParsedBinary(theStreamer->GetStreamR());
		}
	}
Exemple #2
0
ZStreamerR_ZLibDecode::ZStreamerR_ZLibDecode(
	ZStream_ZLib::EFormatR iFormatR, size_t iBufferSize,
	ZRef<ZStreamerR> iStreamer)
:	fStreamer(iStreamer),
	fStream(iFormatR, iBufferSize, iStreamer->GetStreamR())
	{}
Exemple #3
0
ZStreamerR_DynamicBuffered::ZStreamerR_DynamicBuffered(
	ZRef<ZStreamerR> iStreamerSource, ZRef<ZStreamerRWPos> iStreamerBuffer)
:	fStreamerSource(iStreamerSource),
	fStreamerBuffer(iStreamerBuffer),
	fStream(iStreamerSource->GetStreamR(), iStreamerBuffer->GetStreamRWPos())
	{}
Exemple #4
0
ZStreamerR_ZLibDecode::ZStreamerR_ZLibDecode(ZRef<ZStreamerR> iStreamer)
:	fStreamer(iStreamer),
	fStream(iStreamer->GetStreamR())
	{}
Exemple #5
0
ZStreamerR_Boundary::ZStreamerR_Boundary(const void* iBoundary, size_t iBoundarySize,
	ZRef<ZStreamerR> iStreamerSource)
:	fStreamerSource(iStreamerSource),
	fStream(iBoundary, iBoundarySize, iStreamerSource->GetStreamR())
	{}
Exemple #6
0
ZStreamerR_Boundary::ZStreamerR_Boundary(const string& iBoundary, ZRef<ZStreamerR> iStreamerSource)
:	fStreamerSource(iStreamerSource),
	fStream(iBoundary, iStreamerSource->GetStreamR())
	{}
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);
		}
	}
Exemple #8
0
ZStreamerRPos_StreamR::ZStreamerRPos_StreamR(
	ZRef<ZStreamerR> iStreamerR, ZRef<ZStreamerRWPos> iStreamerRWPos)
:	fStreamerR(iStreamerR),
	fStreamerRWPos(iStreamerRWPos),
	fStreamRPos_StreamR(iStreamerR->GetStreamR(), iStreamerRWPos->GetStreamRWPos())
	{}