#include "IM_ClientProtocol.h" #define LOG( X ) m_pLog->Log( "NCP", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ char _tBfrErrMSG234[256];\ sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ m_pLog->Log( "NCP", this, _LOG_ERROR, _tBfrErrMSG234 );\ } #else #define LOG_ERROR( X ) m_pLog->Log( "NCP", this, _LOG_ERROR, X ); #endif // Constructor implementation IM_ClientProtocol::IM_ClientProtocol() : protocolParser(){ }; // Destructor implementation IM_ClientProtocol::~IM_ClientProtocol(){ }; int IM_ClientProtocol::packetChecker(U8 *Buffer, size_t BufferSize){ // double enter -> finish package if( BufferSize > 2 ){ if( ( Buffer[BufferSize-2] == 13 ) && ( Buffer[BufferSize-1] == 13 ) ) return 0; }; if( BufferSize > 3 ){ if( ( Buffer[BufferSize-4] == 13 ) && ( Buffer[BufferSize-3] == 10 ) && ( Buffer[BufferSize-2] == 13 ) && ( Buffer[BufferSize-1] == 10 ) ) return 0; }; return 1; }; protocolPackage *IM_ClientProtocol::packetExtractor(U8 *Buffer, size_t BufferSize){ protocolPackage *tVal = NULL; tVal = (protocolPackage *) malloc( sizeof(protocolPackage)); if(tVal) { tVal->m_pData = (U8*)malloc( BufferSize+1 ); if( tVal->m_pData ) { tVal->m_nCode = 200; tVal->m_nSize = BufferSize; memcpy( tVal->m_pData, Buffer, BufferSize ); tVal->m_pData[BufferSize]=0; } else { free( tVal ); tVal = NULL; }; }; return tVal; }; #undef LOG #undef LOG_ERROR