You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "IM_ClientProtocol.h"
  2. #define LOG( X ) m_pLog->Log( "NCP", this, X )
  3. #ifdef DEBUG
  4. #define LOG_ERROR( X ) {\
  5. char _tBfrErrMSG234[256];\
  6. sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  7. m_pLog->Log( "NCP", this, _LOG_ERROR, _tBfrErrMSG234 );\
  8. }
  9. #else
  10. #define LOG_ERROR( X ) m_pLog->Log( "NCP", this, _LOG_ERROR, X );
  11. #endif
  12. // Constructor implementation
  13. IM_ClientProtocol::IM_ClientProtocol() : protocolParser(){
  14. };
  15. // Destructor implementation
  16. IM_ClientProtocol::~IM_ClientProtocol(){
  17. };
  18. int IM_ClientProtocol::packetChecker(U8 *Buffer, size_t BufferSize){
  19. // double enter -> finish package
  20. if( BufferSize > 2 ){
  21. if( ( Buffer[BufferSize-2] == 13 ) && ( Buffer[BufferSize-1] == 13 ) ) return 0;
  22. };
  23. if( BufferSize > 3 ){
  24. if( ( Buffer[BufferSize-4] == 13 ) && ( Buffer[BufferSize-3] == 10 ) && ( Buffer[BufferSize-2] == 13 ) && ( Buffer[BufferSize-1] == 10 ) ) return 0;
  25. };
  26. return 1;
  27. };
  28. protocolPackage *IM_ClientProtocol::packetExtractor(U8 *Buffer, size_t BufferSize){
  29. protocolPackage *tVal = NULL;
  30. tVal = (protocolPackage *) malloc( sizeof(protocolPackage));
  31. if(tVal) {
  32. tVal->m_pData = (U8*)malloc( BufferSize+1 );
  33. if( tVal->m_pData ) {
  34. tVal->m_nCode = 200;
  35. tVal->m_nSize = BufferSize;
  36. memcpy( tVal->m_pData, Buffer, BufferSize );
  37. tVal->m_pData[BufferSize]=0;
  38. } else {
  39. free( tVal );
  40. tVal = NULL;
  41. };
  42. };
  43. return tVal;
  44. };
  45. #undef LOG
  46. #undef LOG_ERROR