コード例 #1
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief Initializes the dump file by placing the proper tags at its beginning.

	\param DumpFileHandle: pointer to the (open) file in which we have to write.

	\return nbSUCCESS if everything is fine, nbFAILURE in case of errors.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::InitializeDumpFile(FILE *DumpFileHandle)
{
char TempString[NETPDL_MAX_STRING];
unsigned int BytesToWrite;

	BytesToWrite= ssnprintf(TempString, sizeof(TempString), XML_FILE_HEADER  "<%s %s %s date=\"%s\">\n", m_rootXMLTag, 
		PxML_VERSION, PxML_CREATOR, NetPDLDatabase->CreationDate);

	// Initialize the temp file
	if ( fwrite(TempString, sizeof (char), BytesToWrite, DumpFileHandle) != BytesToWrite)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__,  m_errbuf, sizeof(m_errbuf),
			"Error writing data in the temp file");

		return nbFAILURE;
	}

	// Dump the summary (if present)
	if (m_initText[0])
	{
		BytesToWrite= (int) strlen(m_initText);

		// initialize the temp file
		if ( fwrite(m_initText, sizeof (char), BytesToWrite, DumpFileHandle) != BytesToWrite)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__,  m_errbuf, sizeof(m_errbuf),
				"Error writing data in the temp file");

			return nbFAILURE;
		}
	}

	return nbSUCCESS;
}
コード例 #2
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
// Documented in the base class
int CPDMLReader::GetPDMLField(char *ProtoName, char *FieldName, struct _nbPDMLField *FirstField, struct _nbPDMLField **ExtractedField)
{
struct _nbPDMLPacket *PDMLPacket;

	if (!m_NetPDLDecodingEngine)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"This method cannot be used to return a field when the PDML source is a file.");

		return nbFAILURE;
	}

	// If our source is the Decoding Engine, we can access to some internal structures of the PDMLMaker
	PDMLPacket= &( ((CNetPDLDecoder *)m_NetPDLDecodingEngine)->m_PDMLMaker->m_packetSummary);

	if (PDMLPacket == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"No packets have been decoded so far. You must first decode a packet, then look for a specific field in it.");

		return nbFAILURE;
	}

	// Let's jump to the common code
	return GetPDMLFieldInternal(PDMLPacket, ProtoName, FieldName, FirstField, ExtractedField);
}
コード例 #3
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief Initializes the variables contained into this class.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::Initialize()
{
	// Instantiate the DOM parser.
    m_DOMParser = new XercesDOMParser;

	if (m_DOMParser == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"Allocation of the Xerces DOM parser internal object failed.");

		return nbFAILURE;
	}

    m_DOMParser->setValidationScheme(XercesDOMParser::Val_Never);
    m_DOMParser->setDoNamespaces(false);
    m_DOMParser->setDoSchema(false);
    m_DOMParser->setValidationSchemaFullChecking(false);

	// Allocates a new vector for containing the packet list
	m_packetList= new unsigned long [m_maxNumPackets];
	if (m_packetList == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__,  m_errbuf, sizeof(m_errbuf),
			"Not enough memory to allocate the packetlist buffer.");

		return nbFAILURE;
	}

	// Initialize first item
	m_packetList[0]= 0;

	return nbSUCCESS;
}
コード例 #4
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief Initializes the variables contained into this class.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	The error message will be returned in the ErrBuf parameter.
*/
int CPDMLReader::Initialize()
{
unsigned int i;

	// Allocate various ascii buffers
	if (m_asciiBuffer.Initialize() == nbFAILURE)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_asciiBuffer.GetLastError() );
		return nbFAILURE;
	}

	// Allocates a new vector for containing the pointers to the protocol list
	m_protoList= new _nbPDMLProto* [m_maxNumProto];
	if (m_protoList == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Not enough memory to allocate the protolist buffer.");
		return nbFAILURE;
	}
	// Allocate items in the protocol list
	for (i= 0; i< m_maxNumProto; i++)
	{
		m_protoList[i]= new _nbPDMLProto;
		if (m_protoList[i] == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Not enough memory to allocate a protolist item.");
			return nbFAILURE;
		}
	}

	// Allocates a new vector for containing the pointers to the Fields list
	m_fieldsList= new _nbPDMLField* [m_maxNumFields];
	if (m_fieldsList == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Not enough memory to allocate the fieldlist buffer.");
		return nbFAILURE;
	}
	// Allocate items in the field list
	for (i= 0; i< m_maxNumFields; i++)
	{
		m_fieldsList[i]= new _nbPDMLField;
		if (m_fieldsList[i] == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Not enough memory to allocate a fieldlist item.");
			return nbFAILURE;
		}
	}

	return CPxMLReader::Initialize();
}
コード例 #5
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It returns the XML ascii dump of the requested element.

	This method is provided in order to allow random access to the list of decoded packets.

	\param PacketNumber: the ordinal number of the packet (starting from '1') that has to
	be returned.

	\param Buffer: pointer to a char buffer that will keep the packet (in ascii) that we 
	want to retrieve. The packet will be returned as a string of characters in XML 
	format (i.e. PDML/PSML).

	\param BufferSize: the size of the 'Buffer'.

	\param ValidData: upon return, it contains the number of valid data within 'Buffer',
	not counting the string terminator at the end.

	\return nbSUCCESS if the function is successful, nbFAILURE if some error occurred,
	nbWARNING if the user asked for a packet that is out of range.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::GetXMLPacketFromDump(unsigned long PacketNumber, char *Buffer, unsigned int BufferSize, unsigned int &ValidData)
{
unsigned long BytesToRead, BytesRead;
FILE *SourceFileHandle;

	if (m_NetPDLDecodingEngine)
		SourceFileHandle= m_tempDumpFileHandle;
	else
		SourceFileHandle= m_sourceOnDiskFileHandle;

	// Check that the requested packet is not out of range
	if (PacketNumber > m_currNumPackets)
	{
		// Please beware that this is not a 'real' error; it must be considered a warning instead
		// This is the reason why we do not use the errorsnprintf here
		return nbWARNING;
	}

	fseek(SourceFileHandle, m_packetList[PacketNumber-1], SEEK_SET);

	BytesToRead= m_packetList[PacketNumber] - m_packetList[PacketNumber-1];

	if (BufferSize < BytesToRead)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__,  m_errbuf, sizeof(m_errbuf),
			"The temporary buffer is too small for a decoded packet");

		return nbFAILURE;
	}

	BytesRead= (int) fread(Buffer, sizeof(char), BytesToRead, SourceFileHandle);

	if (BytesRead != BytesToRead)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__,  m_errbuf, sizeof(m_errbuf),
			"Error reading the PxML file: got a number of bytes smaller than the expected.");

		return nbFAILURE;
	}

	// Put a '0' to terminate the string
	Buffer[BytesRead - 1]= 0;
	ValidData= BytesRead - 1;

	// Move the pointer of the file at the end
	fseek(SourceFileHandle, 0, SEEK_END);

	return nbSUCCESS;
}
コード例 #6
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It gets an DOMDocument containing the PDML fragment related to a single packet and formats the packet header.

	This function parses the DOMDocument that contains a PDML fragment related to a single packet
	and it fills the proper members of the m_packetSummary structure.

	\param PDMLDocument The DOMDocument associated to the current PDML packet.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	In case of errors, the error message is stored in the m_errbuf internal buffer.
*/
int CPDMLReader::FormatPacketSummary(DOMDocument *PDMLDocument)
{
char TempAsciiBuffer[NETPDL_MAX_STRING + 1];
XMLCh TempXMLBuffer[NETPDL_MAX_STRING + 1];
const XMLCh *TempPtr;
DOMNodeList *PacketList;
DOMNode *PacketNode;


	// Let's get the pointer to a 'packet' node
	XMLString::transcode(PDML_PACKET, TempXMLBuffer, NETPDL_MAX_STRING);
	PacketList= PDMLDocument->getElementsByTagName(TempXMLBuffer);
	PacketNode= PacketList->item(0);

	if (PacketNode == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"The PDML dump does not contain the '%s' element.", PDML_PACKET);

		return nbFAILURE;
	}

	// Ok, now we can extract attributes
	XMLString::transcode(PDML_FIELD_ATTR_NAME_NUM, TempXMLBuffer, NETPDL_MAX_STRING);

	TempPtr= ((DOMElement *) PacketNode)->getAttribute(TempXMLBuffer);

	// If the XML element contains that attribute, transform it in ascii and return it to the caller
	if (TempPtr)
	{
		XMLString::transcode(TempPtr, TempAsciiBuffer, NETPDL_MAX_STRING);
		m_packetSummary.Number= atoi(TempAsciiBuffer);
	}

	XMLString::transcode(PDML_FIELD_ATTR_NAME_LENGTH, TempXMLBuffer, NETPDL_MAX_STRING);
	TempPtr= ((DOMElement *) PacketNode)->getAttribute(TempXMLBuffer);
	if (TempPtr)
	{
		XMLString::transcode(TempPtr, TempAsciiBuffer, NETPDL_MAX_STRING);
		m_packetSummary.Length= atoi(TempAsciiBuffer);
	}

	XMLString::transcode(PDML_FIELD_ATTR_NAME_CAPLENGTH, TempXMLBuffer, NETPDL_MAX_STRING);
	TempPtr= ((DOMElement *) PacketNode)->getAttribute(TempXMLBuffer);
	if (TempPtr)
	{
		XMLString::transcode(TempPtr, TempAsciiBuffer, NETPDL_MAX_STRING);
		m_packetSummary.CapturedLength= atoi(TempAsciiBuffer);
	}

	XMLString::transcode(PDML_FIELD_ATTR_NAME_TIMESTAMP, TempXMLBuffer, NETPDL_MAX_STRING);
	TempPtr= ((DOMElement *) PacketNode)->getAttribute(TempXMLBuffer);
	if (TempPtr)
	{
		XMLString::transcode(TempPtr, TempAsciiBuffer, NETPDL_MAX_STRING);
		sscanf(TempAsciiBuffer, "%ld.%ld", &m_packetSummary.TimestampSec, &m_packetSummary.TimestampUSec);
	}

	return nbSUCCESS;
}
コード例 #7
0
int nbPacketCapture::RegisterCallbackFunction(nbDataDstCallbackFunction *DataDstCallbackFunction, void *CustomPtr)
{
	nbNetVmPortApplication * NetVmPortApplication;

	if (m_dstNetDevice)
		{
			ssnprintf(m_errbuf, sizeof(m_errbuf), "Only one receiver is allowed. Currently, the target receiver is a network device.");
			return nbFAILURE;
		}

	NetVmPortApplication= new nbNetVmPortApplication;
	if (NetVmPortApplication == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), ERROR_ALLOC_FAILED);
			return nbFAILURE;
		}

	if (NetVmPortApplication->RegisterCallbackFunction(DataDstCallbackFunction, CustomPtr) == nbFAILURE)
		{
			ssnprintf(m_errbuf, sizeof(m_errbuf), NetVmPortApplication->GetLastError() );
			return nbFAILURE;
		}

	m_dstNetDevice=  NetVmPortApplication;

	return nbSUCCESS;
}
コード例 #8
0
// Documented in the base class
nbPSMLReader *CNetPDLDecoder::GetPSMLReader()
{
	if (m_PSMLReader == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "The current instance of packet decoder has not been configured to generate PSML packets.");
		return NULL;
	}

	if (m_PSMLReader->InitializeDecoder( (nbPacketDecoder *) this) == nbFAILURE)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_PSMLReader->GetLastError() );
		return NULL;
	}

	return (nbPSMLReader *) m_PSMLReader;
}
コード例 #9
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It extracts a given attribute from the current element and fills the appropriate field in the _nbPDMLField/Proto structure.

	This function replace a very annoying task. It extracts a given attribute from the current DOM element,
	transform it into a number, and updates the appropriate member in the _nbPDMLField/_nbPDMLProto structure.

	\param SourceNode: pointer to the node containing the attribute that has to be extracted.
	\param TagToLookFor: name of the attribute that has to be extracted.
	\param AppendAt: pointer to the member of the _nbPDMLField/_nbPDMLProto that has to keep the attribute 
	extracted from the XML element.

	\param ErrBuf: user-allocated buffer (of length 'ErrBufSize') that will keep an error message (if one).
	This buffer will always be NULL terminated.

	\param ErrBufSize: size of the previous buffer.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	The error message will be returned in the ErrBuf parameter.

	\note This function has been declared as 'static' because it is called also from other contexts.
*/
int CPDMLReader::AppendItemLong(DOMNode *SourceNode, char *TagToLookFor, unsigned long *AppendAt, char *ErrBuf, int ErrBufSize)
{
const XMLCh *TempPtr;
XMLCh XMLTagToLookFor[NETPDL_MAX_STRING + 1];

	XMLString::transcode(TagToLookFor, XMLTagToLookFor, NETPDL_MAX_STRING);

	TempPtr= ((DOMElement *) SourceNode)->getAttribute(XMLTagToLookFor);

	// If the XML element contains that attribute, transform it in ascii and return it to the caller
	if (TempPtr)
	{
	char TmpBufAscii[NETPDL_MAX_STRING + 1];

		XMLString::transcode(TempPtr, TmpBufAscii, NETPDL_MAX_STRING);

		sscanf(TmpBufAscii, "%lu", AppendAt);
		return nbSUCCESS;
	}

	(*AppendAt)= 0;
	
	errorsnprintf(__FILE__, __FUNCTION__, __LINE__, ErrBuf, ErrBufSize, "This function was called with a wrong parameter");
	return nbFAILURE;
}
コード例 #10
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief Checks the number of packets in 'm_packetList'; it enlarges this vector if needed.

	\return nbSUCCESS if everything is fine, nbFAILURE if something goes wrong.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::CheckPacketListSize()
{
	// The vector is not enough; Please allocate a new one, and let's hope it is enough
	if (m_currNumPackets == (m_maxNumPackets - 1))
	{
		long newsize= m_maxNumPackets * 10;

		unsigned long *newVector= new unsigned long [newsize];
		if (newVector == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
				"Not enough memory to allocate the new packetlist buffer.");

			return nbFAILURE;
		}

		for (unsigned long i=0; i < m_maxNumPackets; i++)
			newVector[i]= m_packetList[i];

		delete m_packetList;

		m_maxNumPackets= newsize;
		m_packetList= newVector;
	}

	return nbSUCCESS;
}
コード例 #11
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It extracts a given attribute from the current element and stores it in the appropriate ascii buffer.

	This function replaces a very annoying task. It extracts a given attribute from the current DOM element,
	transform it into an ascii buffer (appropriately located into the m_asciiBuffer buffer), and updates the
	appropriate pointer to it.

	This function updates also the pointer into the m_asciiBuffer buffer in order to point to the first free location
	in this buffer.

	\param SourceNode: pointer to the node containing the attribute that has to be extracted.
	\param TagToLookFor: name of the attribute that has to be extracted.
	\param AppendAt: pointer to the member of the _nbPDMLField/_nbPDMLProto that has to keep the attribute 
	extracted from the XML element.
	\param TmpBuffer: pointer to the CAsciiBuffer class, which manages an ascii temporary buffer in which 
	the content of the XML attribute has to be stored. The XML attribute will be stored in ASCII.
	\param ErrBuf: user-allocated buffer (of length 'ErrBufSize') that will keep an error message (if one).
	This buffer will always be NULL terminated.
	\param ErrBufSize: size of the previous buffer.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	The error message will be returned in the ErrBuf parameter.

	\note This function has been declared as 'static' because it is called also from other contexts.
*/
int CPDMLReader::AppendItemString(DOMNode *SourceNode, char *TagToLookFor, char **AppendAt, CAsciiBuffer *TmpBuffer, char *ErrBuf, int ErrBufSize)
{
const XMLCh *TempPtr;
XMLCh XMLTagToLookFor[NETPDL_MAX_STRING + 1];

	XMLString::transcode(TagToLookFor, XMLTagToLookFor, NETPDL_MAX_STRING);

	TempPtr= ((DOMElement *) SourceNode)->getAttribute(XMLTagToLookFor);

	// If the XML element contains that attribute, transform it in ascii and return it to the caller
	if (TempPtr && (*TempPtr) )
	{
		(*AppendAt)= TmpBuffer->TranscodeAndStore( (wchar_t *)(XMLCh *) TempPtr);

		if ((*AppendAt) == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, ErrBuf, ErrBufSize, "%s", TmpBuffer->GetLastError() );
			return nbFAILURE;
		}
	}
	else	// otherwise, append 'NULL'
		(*AppendAt)= NULL;

	return nbSUCCESS;
}
コード例 #12
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief In case the fields list is not enough, it allocates a new fields list which is 10 times bigger.

	\param CurrentNumFields: pointer to a variable that keeps the current size of the CurrentFieldsList vector.
	When the function returns, the value of this pointer will contain the new number of items in the new vector.

	\param CurrentFieldsList: pointer to the current Fields List vector.
	When the function returns, the value of this pointer will point to the new vector. The old one will be deallocated 
	by this function.

	\param ErrBuf: user-allocated buffer (of length 'ErrBufSize') that will keep an error message (if one).
	This buffer will always be NULL terminated.

	\param ErrBufSize: size of the previous buffer.

	\return nbSUCCESS if everything is fine, nbFAILURE if something goes wrong.
	The error message will be returned in the 'ErrBuf' buffer.

	\note This function has been declared as 'static' because it is called also from other contexts.
*/
int CPDMLReader::UpdateFieldsList(unsigned long *CurrentNumFields, _nbPDMLField ***CurrentFieldsList, char *ErrBuf, int ErrBufSize)
{
unsigned long NewSize;

	NewSize= *CurrentNumFields * 10;

	_nbPDMLField **newVector= new _nbPDMLField* [NewSize];
	// Check if something goes wrong
	if (newVector == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, ErrBuf, ErrBufSize, "Not enough memory to allocate the new fieldslist buffer.");
		return nbFAILURE;
	}

	unsigned long i;
	for (i=0; i < *CurrentNumFields; i++)
		newVector[i]= (*CurrentFieldsList)[i];

	// Delete old buffer
	delete (*CurrentFieldsList);

	// Update the pointer to the fields list
	(*CurrentFieldsList)= newVector;

	// Allocate items in the protocol list
	for(i= *CurrentNumFields; i < NewSize; i++)
	{
		newVector[i]= new _nbPDMLField;
		if (newVector[i] == NULL)
		{
			// Update the number of fields (taking into account the right number of allocations)
			*CurrentNumFields= i - 1;

			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, ErrBuf, ErrBufSize,
				"Not enough memory to allocate a fieldslist item.");

			return nbFAILURE;
		}
	}

	// Update the number of fields
	*CurrentNumFields= NewSize;

	return nbSUCCESS;
}
コード例 #13
0
// Documented in the base class
nbPDMLReader *CNetPDLDecoder::GetPDMLReader()
{
	if (m_PDMLReader->InitializeDecoder( (nbPacketDecoder *) this) == nbFAILURE)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_PDMLReader->GetLastError() );
		return NULL;
	}

	return (nbPDMLReader *) m_PDMLReader;
}
コード例 #14
0
/*!
	\brief This function converts the packet summary data from the PSMLMaker internal format to the PSMLReader one.

	\param Buffer: pointer to an ascii buffer that contains the list of &lt;section&gt; nodes that belong to the current packet.
	\param BufferLen: number of chars in the previous buffer.
	\param PacketPtr: pointer to a 'char *' in which PSMLReader will put the will put the formatted data.

	\return The number of '&lt;sections&gt;' that have been copied in the returned buffer,
	or nbFAILURE if some error occurred.
	In case of error, the error message can be retrieved by the GetLastError() method.

	\note This function is used only when the PSML fragment has to be read from file. This happens either
	when our source is a nbDecodingEngine but we want to return previously decoded packets, or when our source
	is a file.
*/
int CPSMLReader::FormatItem(char *Buffer, int BufferLen, char **PacketPtr)
{
unsigned int ItemNumber;

	// Parse the XML string and return a pointer to the list of '<section>' contained into it
	DOMNodeList *ItemList= ParseMemBuf(Buffer, BufferLen);

	if (ItemList == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "The file does not appear to be a valid PSML structure.");
		return nbFAILURE;
	}

	m_asciiBuffer.ClearBuffer(true /* resizing permitted */);

	for (ItemNumber= 0; ItemNumber < ItemList->getLength(); ItemNumber++)
	{
		DOMText *TextNode= (DOMText *) (ItemList->item(ItemNumber))->getFirstChild();

		// In case we have <section></section>, the TextNode is NULL, so we have to avoid following code.
		if (TextNode)
		{
			if (m_asciiBuffer.TranscodeAndStore( (wchar_t *)(XMLCh *) TextNode->getNodeValue()) == NULL)
			{
				errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_asciiBuffer.GetLastError() );
				(*PacketPtr)= m_asciiBuffer.GetStartBufferPtr();
				return nbFAILURE;
			}
		}
		else
		{
			if (m_asciiBuffer.Store("") == NULL)
			{
				errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_asciiBuffer.GetLastError() );
				(*PacketPtr)= m_asciiBuffer.GetStartBufferPtr();
				return nbFAILURE;
			}
		}
	}

	(*PacketPtr)= m_asciiBuffer.GetStartBufferPtr();
	return (int) ItemNumber;
}
コード例 #15
0
/*!
	\brief Initializes the variables contained into this class.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPSMLReader::Initialize()
{
	// Allocate various ascii buffers
	if (m_asciiBuffer.Initialize() == nbFAILURE)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_asciiBuffer.GetLastError() );
		return nbFAILURE;
	}

	return CPxMLReader::Initialize();
}
コード例 #16
0
/*
	\brief It accepts a XML (ascii) buffer and it parses it.

	This function is used when we have a char buffer containing an XML fragment, and we have to parse it.
	This function returns the list of PSML items (&lt;section&gt;) contained in the XML buffer.

	\param Buffer: pointer to a buffer that contains the XML fragment (in ascii).
	\param BufSize: number of valid bytes in the previous buffer; not NULL terminated buffers are supported as well.

	\return A pointer to the list of &lt;section&gt; nodes contained into the XML fragment if everything
	is fine, NULL otherwise.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
DOMNodeList *CPSMLReader::ParseMemBuf(char *Buffer, int BytesToParse)
{
DOMDocument *Document;
XMLCh TempBuffer[NETPDL_MAX_STRING + 1];
MemBufInputSource MemBuf( (const XMLByte *) Buffer, BytesToParse, "", false);

	try
	{
		// Reset any other document previously created
		m_DOMParser->resetDocumentPool();

		// Load the description in memory and get document root
		m_DOMParser->parse(MemBuf);

		Document= m_DOMParser->getDocument();

		if ( (Document->getDocumentElement()) == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
				"Fatal error: cannot parse PSML file. Possible errors: "
				"wrong file location, or not well-formed XML file.");
			return NULL;
		}
	}
	catch (...)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Unexpected exception during PSML buffer parsing.");
		return NULL;
	}

	if (Document == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Unexpected exception during PSML buffer parsing.");
		return NULL;
	}

	XMLString::transcode(PSML_SECTION, TempBuffer, NETPDL_MAX_STRING);

	// After parsing the '<packet>' fragment, let's list the <section> contained into it
	return Document->getElementsByTagName(TempBuffer);
}
コード例 #17
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It copies a given string into an ascii buffer and it modifies a pointer in order to point to it.

	This function is very similar to the other AppendItemString().

	This function updates also the pointer into the m_asciiBuffer buffer in order to point to the first free location
	in this buffer.

	\param SourceString: pointer to the ASCII string that has to be converted into a char *
	\param AppendAt: pointer to the member of the _nbPDMLField/_nbPDMLProto that has to keep the attribute 
	extracted from the XML element.
	\param TmpBuffer: pointer to the CAsciiBuffer class, which manages an ascii temporary buffer in which 
	the content of the XML attribute has to be stored. The XML attribute will be stored in ASCII.
	\param ErrBuf: user-allocated buffer (of length 'ErrBufSize') that will keep an error message (if one).
	This buffer will always be NULL terminated.
	\param ErrBufSize: size of the previous buffer.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	The error message will be returned in the ErrBuf parameter.

	\note This function has been declared as 'static' because it is called also from other contexts.
*/
int CPDMLReader::AppendItemString(char *SourceString, char **AppendAt, CAsciiBuffer *TmpBuffer, char *ErrBuf, int ErrBufSize)
{
	(*AppendAt)= TmpBuffer->Store(SourceString);

	if ((*AppendAt) == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, ErrBuf, ErrBufSize, "%s", TmpBuffer->GetLastError() );
		return nbFAILURE;
	}

	return nbSUCCESS;
}
コード例 #18
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It fills the member of the _nbPDMLPacket structure that is in charge of the packet dump.

	This function extracts the value of the given node, it transforms it into an ascii buffer (appropriately 
	located into the m_asciiBuffer buffer), and updates the appropriate pointer to it.

	This function updates also the pointer into the m_asciiBuffer buffer in order to point to the first
	free location in this buffer.

	\param PDMLDocument The DOMDocument associated to the current PDML packet.
	\param TmpBuffer: pointer to the CAsciiBuffer class, which manages an ascii temporary buffer in which 
	the content of the XML node has to be stored. The XML content will be stored in binary.
	\param ErrBuf: user-allocated buffer (of length 'ErrBufSize') that will keep an error message (if one).
	This buffer will always be NULL terminated.
	\param ErrBufSize: size of the previous buffer.

	\return nbSUCCESS if everything is fine, nbFAILURE if some error occurred.
	In case of errors, the  error message will be returned in the ErrBuf parameter.
*/
int CPDMLReader::FormatDumpItem(DOMDocument *PDMLDocument, CAsciiBuffer *TmpBuffer, char *ErrBuf, int ErrBufSize)
{
XMLCh TempBuffer[NETPDL_MAX_STRING + 1];
const XMLCh *TempPtr;
char* AsciiBufPtr;
DOMNodeList *DumpList;
DOMNode *DumpItem;
DOMNode *DumpValue;

	// Let's initialize this member, just in case
	m_packetSummary.PacketDump= NULL;

	XMLString::transcode(PDML_DUMP, TempBuffer, NETPDL_MAX_STRING);

	// Now, let's get the raw packet dump
	DumpList= PDMLDocument->getElementsByTagName(TempBuffer);
	if (DumpList == NULL)
		return nbSUCCESS;

	// Let's check if the PDML fragment contains also the packet dump. If not, let's return.
	DumpItem= DumpList->item(0);
	if (DumpItem == NULL)
		return nbSUCCESS;

	DumpValue= DumpItem->getFirstChild();
	if (DumpValue == NULL)
		return nbSUCCESS;

	TempPtr= DumpValue->getNodeValue();

	// If the XML element contains that attribute, transform it in ascii and return it to the caller
	if (TempPtr && (*TempPtr) )
	{
		AsciiBufPtr= TmpBuffer->TranscodeAndStore( (wchar_t *)(XMLCh *) TempPtr);

		if (AsciiBufPtr == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, ErrBuf, ErrBufSize, "%s", TmpBuffer->GetLastError() );
			return nbFAILURE;
		}

		// Since we're tranforming an ascii buffer into a bin buffer (which is half the previous one)
		//  there's no problem of buffer overflow.
		ConvertHexDumpAsciiToHexDumpBin(AsciiBufPtr, (unsigned char *) AsciiBufPtr, strlen(AsciiBufPtr) + 1);

		m_packetSummary.PacketDump= (unsigned char *) AsciiBufPtr;
	}
	else	// otherwise, append 'NULL'
		m_packetSummary.PacketDump= NULL;

	return nbSUCCESS;
}
コード例 #19
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It tells the PxMLReader that the source of PSML items is a nbPacketDecoded class which is currently
	decoding network packets.

	This function is called internally from the PacketDecoder class; it is not exported to the user.

	\param NetBeePacketDecoder: pointer to the Packet Decoder class which is currently decoding network packets.

	\return nbSUCCESS if everything is fine, nbFAILURE otherwise.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::InitializeDecoder(nbPacketDecoder *NetBeePacketDecoder)
{
	if (NetBeePacketDecoder == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"Invalid pointer to the Packet Decoder class.");

		return nbFAILURE;
	}

	// Save a reference to the decoder for future use
	m_NetPDLDecodingEngine= NetBeePacketDecoder;
	return nbSUCCESS;
}
コード例 #20
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*
	\brief It accepts a XML (ascii) buffer and it parses it.

	This function is used when we have a char buffer containing an XML fragment, and we have to parse it.
	This function returns the list of PDML items (&lt;section&gt;) contained in the XML buffer.

	\param Buffer: pointer to a buffer that contains the XML fragment (in ascii).
	\param BytesToParse: number of valid bytes in the previous buffer; not NULL terminated buffers are supported as well.

	\return A pointer to the DOM document associated to the XML fragment if
	everything is fine, NULL otherwise.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
DOMDocument* CPDMLReader::ParseMemBuf(char *Buffer, int BytesToParse)
{
DOMDocument *Document;
MemBufInputSource MemBuf( (const XMLByte *) Buffer, BytesToParse, "", false);

	try
	{
		// Reset any other document previously created
		m_DOMParser->resetDocumentPool();

		// Load the description in memory and get document root
		m_DOMParser->parse(MemBuf);

		Document= m_DOMParser->getDocument();

		if ( (Document->getDocumentElement()) == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
				"Fatal error: cannot parse PDML file. Possible errors: "
				"wrong file location, or not well-formed XML file.");
			return NULL;
		}
	}
	catch (...)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Unexpected exception during PDML buffer parsing.");
		return NULL;
	}

	if (Document == NULL)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "Unexpected exception during PDML buffer parsing.");
		return NULL;
	}

	return Document;
}
コード例 #21
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
// Documented in the base class
int CPDMLReader::GetCurrentPacket(_nbPDMLPacket **PDMLPacket)
{
	if (m_NetPDLDecodingEngine)
	{
		// If our source is the Decoding Engine, we can access to some internal structures of the PDMLMaker
		*PDMLPacket= &( ((CNetPDLDecoder *)m_NetPDLDecodingEngine)->m_PDMLMaker->m_packetSummary);

		return nbSUCCESS;
	}

	errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
		"The current PDML item cannot be returned when the PDML source is a file.");

	return nbFAILURE;
}
コード例 #22
0
// Documented in the base class
int CPSMLReader::GetCurrentPacketXML(char* &PacketPtr, unsigned int &PacketLength)
{
	if (m_NetPDLDecodingEngine)
	{
		m_asciiBuffer.ClearBuffer(true /* resizing permitted */);

		PacketPtr= m_asciiBuffer.GetStartBufferPtr();
		((CNetPDLDecoder *) m_NetPDLDecodingEngine)->m_PSMLMaker->GetCurrentPacketAscii(PacketPtr, m_asciiBuffer.GetBufferTotSize() );
		PacketLength= m_asciiBuffer.GetBufferCurrentSize();

		return nbSUCCESS;
	}

	errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "The current PSML item cannot be returned when the PSML source is a file.");
	return nbFAILURE;
}
コード例 #23
0
// Documented in the base class
int CPSMLReader::GetCurrentPacket(char **PacketPtr)
{
char **ItemData;

	if (m_NetPDLDecodingEngine)
	{
		// If our source is the Decoding Engine, we can access to some internal structures of the PSMLMaker
		ItemData= ((CNetPDLDecoder *) m_NetPDLDecodingEngine)->m_PSMLMaker->m_summaryItemsData;

		// Convert PSMLMaker internal data to a '\0' delimited ascii buffer
		return FormatItem(ItemData, PacketPtr);
	}

	errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "The current PSML item cannot be returned when the PSML source is a file.");
	return nbFAILURE;
}
コード例 #24
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
//!Documented in the base class
int CPxMLReader::RemovePacket(unsigned long PacketNumber)
{
	if (PacketNumber > m_currNumPackets)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"The requested element is out of range.");

		return nbFAILURE;
	}

	for (unsigned long i= (PacketNumber-1); i < m_currNumPackets; i++)
		m_packetList[i] = m_packetList[i+1];

	m_currNumPackets--;

	return nbSUCCESS;
}
コード例 #25
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief It adds an new packet to the list of packets.

	This function is called only from within the derived classes in case we want to keep all packets.

	\param Buffer: pointer to a char buffer that keeps the entire packet (in ascii) that we want
	to dump on file.

	\param BytesToWrite: the number of bytes (in 'Buffer') that needs to be written on file.

	\return nbSUCCESS if the function is successful, nbFAILURE if something goes wrong.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::StorePacket(char *Buffer, unsigned int BytesToWrite)
{
	if ( fwrite(Buffer, sizeof (char), BytesToWrite, m_tempDumpFileHandle) != BytesToWrite)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"Error writing data in the temp file");

		return nbFAILURE;
	}

	m_currNumPackets++;
	m_packetList[m_currNumPackets]= ftell(m_tempDumpFileHandle);

	// Check if the vector is enough; if not, let's allocate a new one, and let's hope it is enough
	if (CheckPacketListSize() == nbFAILURE)
		return nbFAILURE;
	
	return nbSUCCESS;
}
コード例 #26
0
/*!
	\brief This function converts the packet summary from the PSMLMaker internal format to the PSMLReader one.

	\param ItemData: pointer to the variable (inside the PSMLReader) that keeps the PSML data.
	\param PacketPtr: pointer to a 'char *' in which PSMLReader will put the will put the formatted data.

	\return The number of '&lt;sections&gt;' that have been copied in the returned buffer,
	or nbFAILURE if some errors occurred.
	In case of error, the error message can be retrieved by the GetLastError() method.

	\note This function is used only when the PSML fragment has to be generated from the current decoding engine
	(i.e. the source is a nbDecodingEngine).
*/
int CPSMLReader::FormatItem(char **ItemData, char **PacketPtr)
{
unsigned int ItemNumber;

	m_asciiBuffer.ClearBuffer(true /* resizing permitted */);

	// Loop through the <section> and put them into the same ascii buffer
	for (ItemNumber= 0; ItemNumber < NetPDLDatabase->ShowSumStructureNItems; ItemNumber++)
	{
		if (m_asciiBuffer.Store(ItemData[ItemNumber]) == NULL)
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "%s", m_asciiBuffer.GetLastError() );
			(*PacketPtr)= m_asciiBuffer.GetStartBufferPtr();
			return nbFAILURE;
		}
	}

	(*PacketPtr)= m_asciiBuffer.GetStartBufferPtr();
	return (int) ItemNumber;
}
コード例 #27
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
// Documented in the base class
int CPDMLReader::GetPDMLField(unsigned long PacketNumber, char *ProtoName, char *FieldName, struct _nbPDMLField *FirstField, struct _nbPDMLField **ExtractedField)
{
struct _nbPDMLPacket *PDMLPacket;
int Res;

	Res= GetPacket(PacketNumber, &PDMLPacket);

	if (Res == nbFAILURE)
		return nbFAILURE;

	if (Res == nbWARNING)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"The packet you are looking for is probably out of range.");
		return nbFAILURE;
	}

	// Let's jump to the common code
	return GetPDMLFieldInternal(PDMLPacket, ProtoName, FieldName, FirstField, ExtractedField);
}
コード例 #28
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief This function formats the summary data from the PDMLMaker internal format to the PDMLReader one.

	\param ItemList: pointer to the list of &lt;proto&gt; nodes that belong to the current packet.
	\param Buffer: pointer to a user-allocated buffer in which PDMLReader will put the returned ascii data.
	\param BufSize: size of previous buffer. There is no guarantee that the buffer will be NULL terminated.

	\return The number of '&lt;sections&gt;' that have been copied in the returned buffer, 
	or nbFAILURE if some error occurred.
	In case of error, the error message can be retrieved by the GetLastError() method.

	\note This function is used only when the PDML fragment has to be read from file. This happens either
	when our source is a nbDecodingEngine but we want to return previously decoded packets, or when our source
	is a file.
*/
int CPDMLReader::FormatItem(DOMNodeList *ItemList, char *Buffer, int BufSize)
{
int CopiedChars;
unsigned int ItemNumber;

	CopiedChars= 0;
	for (ItemNumber= 0; ItemNumber < ItemList->getLength(); ItemNumber++)
	{
	char TempBuffer[NETPDL_MAX_STRING + 1];
	int TempChars;

		DOMText *TextNode= (DOMText *) (ItemList->item(ItemNumber))->getFirstChild();

		// In case we have <section></section>, the TextNode is NULL, so we have to avoid following code.
		if (TextNode)
		{
			XMLString::transcode(TextNode->getNodeValue(), TempBuffer, NETPDL_MAX_STRING);
			TempChars= ssnprintf(&Buffer[CopiedChars], BufSize - CopiedChars, "%s", TempBuffer);
		}
		else
		{
			Buffer[CopiedChars]= 0;

			// Check to avoid a buffer overrun
			if (CopiedChars >= (BufSize - 1) )
				TempChars= -1;
			else
				TempChars= 0;
		}

		if (TempChars >= 0)
			CopiedChars+= (TempChars + 1); // ssnprintf does not count the terminating null character
		else
		{
			errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf), "The buffer is not big enough to contain summary items.");
			return nbFAILURE;
		}
	}

	return (int) ItemNumber;
}
コード例 #29
0
ファイル: pxmlreader.cpp プロジェクト: gerpe/fresdwn
/*!
	\brief Initialize the parameters needed for dumping packets to file.
	
	Basically, this is needed to open a temp file in case we want to store PDML/PSML packets to disk.
    This function is called only when a CPSMLMaker/CPDMLMaker is using this class to dump its content on disk
	(and the user wants want to keep all packets).

	\param RootXMLTag: string that keeps the root tag (e.g. 'pdml') in the resulting file.

	\param InitText: string that keeps any text that must be placed at the beginning of the file
	(such as the summary index for the PSML file).

	\return nbSUCCESS function is successful, nbFAILURE if something goes wrong.
	In case of error, the error message can be retrieved by the GetLastError() method.
*/
int CPxMLReader::InitializeParsForDump(char *RootXMLTag, char *InitText)
{
	strncpy(m_rootXMLTag, RootXMLTag, sizeof(m_rootXMLTag) );
	if (InitText)
		strncpy(m_initText, InitText, sizeof(m_initText) );

	// Get temp file name
	m_tempDumpFileHandle= tmpfile();
	if (m_tempDumpFileHandle == 0)
	{
		errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
			"Fatal error: cannot open a temp file to store PDML/PSML data.");

		return nbFAILURE;
	}

	if (InitializeDumpFile(m_tempDumpFileHandle) == nbFAILURE)
		return nbFAILURE;

	// Initialize first item (we have to skip the '<pdml>' tag and such)
	m_packetList[0]= ftell(m_tempDumpFileHandle);

	return nbSUCCESS;
}
コード例 #30
0
ファイル: pdmlreader.cpp プロジェクト: gerpe/fresdwn
// Documented in the base class
int CPDMLReader::GetCurrentPacketXML(char* &PacketPtr, unsigned int &PacketLength)
{
	if (m_NetPDLDecodingEngine)
	{
		m_asciiBuffer.ClearBuffer(true /* resizing permitted */);

		// If our source is the Decoding Engine, we can access to some internal structures of the PDMLMaker
		if (CPDMLMaker::DumpPDMLPacket( &( ((CNetPDLDecoder *)m_NetPDLDecodingEngine)->m_PDMLMaker->m_packetSummary),
			((CNetPDLDecoder *)m_NetPDLDecodingEngine)->m_PDMLMaker->m_isVisExtRequired,
			((CNetPDLDecoder *)m_NetPDLDecodingEngine)->m_PDMLMaker->m_generateRawDump,
				&m_asciiBuffer, m_errbuf, sizeof(m_errbuf)) == nbFAILURE)
			return nbFAILURE;

		PacketPtr= m_asciiBuffer.GetStartBufferPtr();
		PacketLength= m_asciiBuffer.GetBufferCurrentSize();

		return nbSUCCESS;
	}

	errorsnprintf(__FILE__, __FUNCTION__, __LINE__, m_errbuf, sizeof(m_errbuf),
		"The current PDML item cannot be returned when the PDML source is a file.");

	return nbFAILURE;
}