EsmeReceiver.cpp
上传用户:hkcoast
上传日期:2007-01-12
资源大小:979k
文件大小:3k
源码类别:

手机短信编程

开发平台:

Visual C++

  1. // EsmeReceiver.cpp: implementation of the CEsmeReceiver class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. //#include "SMPPAPI.h"
  6. #include "EsmeReceiver.h"
  7. #include "smpppacket.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. #ifdef SMPPAPI_EVALUATION
  17. uint32 CEsmeReceiver::m_eval_counter = 1;
  18. #endif
  19. CEsmeReceiver::CEsmeReceiver()
  20. {
  21. }
  22. CEsmeReceiver::~CEsmeReceiver()
  23. {
  24. }
  25. int CEsmeReceiver::bind(CString sysid, CString passwd, CString systype, CSmppAddress &addrrange)
  26. {
  27. bool ret = 1;
  28. m_system_id = sysid;
  29. m_password = passwd;
  30. m_system_type = systype;
  31. m_address_range = addrrange;
  32. if (open())
  33. {
  34. CBindReceiver pak;
  35. pak.setSystemId(sysid);
  36. pak.setPassword(passwd);
  37. pak.setSystemType(systype);
  38. pak.setSourceRange(addrrange);
  39. if (sendPacket(pak))
  40. ret = 0;
  41. }
  42. return ret;
  43. }
  44. void CEsmeReceiver::parse_packet(PBYTE pby, int nsz)
  45. {
  46. #ifdef SMPPAPI_EVALUATION
  47. m_eval_counter++;
  48. if (m_eval_counter > 200)
  49. return;
  50. #endif
  51. if (nsz < 16)
  52. return;
  53. uint32 cmdId = readInt(pby);
  54. TRACE1("CommandId is %x", cmdId);
  55. int cmdStatus = readInt(pby+4);
  56. int seqNum = readInt(pby+8);
  57. switch (cmdId)
  58. {
  59. case SMPP_GENERIC_NACK:
  60. {
  61. CGenericNack* ppak;
  62. ppak = new CGenericNack();
  63. ppak->loadPacket(pby, nsz);
  64. //call back
  65. if (m_pProcessPacket != NULL)
  66. {
  67. m_pProcessPacket(ppak, m_Param);
  68. }
  69. delete ppak;
  70. }
  71. break;
  72. case SMPP_SPECIAL_LINKCLOSE:
  73. {
  74. CLinkClose* ppak;
  75. ppak = new CLinkClose();
  76. ppak->loadPacket(pby, nsz);
  77. //call back
  78. if (m_pProcessPacket != NULL)
  79. {
  80. m_pProcessPacket(ppak, m_Param);
  81. }
  82. delete ppak;
  83. }
  84. break;
  85. case SMPP_BIND_RECEIVER_RESP:
  86. {
  87. CBindReceiverResp* ppak;
  88. ppak = new CBindReceiverResp();
  89. ppak->loadPacket(pby, nsz);
  90. //call back
  91. if (m_pProcessPacket != NULL)
  92. {
  93. m_pProcessPacket(ppak, m_Param);
  94. }
  95. delete ppak;
  96. }
  97. break;
  98. case SMPP_ENQUIRE_LINK:
  99. {
  100. CEnquireLink* ppak;
  101. ppak = new CEnquireLink();
  102. ppak->loadPacket(pby, nsz);
  103. //call back
  104. if (m_pProcessPacket != NULL)
  105. {
  106. m_pProcessPacket(ppak, m_Param);
  107. }
  108. delete ppak;
  109. }
  110. break;
  111. case SMPP_ENQUIRE_LINK_RESP:
  112. {
  113. CEnquireLinkResp* ppak;
  114. ppak = new CEnquireLinkResp();
  115. ppak->loadPacket(pby, nsz);
  116. //call back
  117. if (m_pProcessPacket != NULL)
  118. {
  119. m_pProcessPacket(ppak, m_Param);
  120. }
  121. delete ppak;
  122. }
  123. break;
  124. case SMPP_UNBIND_RESP:
  125. {
  126. CUnbindResp* ppak;
  127. ppak = new CUnbindResp();
  128. ppak->loadPacket(pby, nsz);
  129. //call back
  130. if (m_pProcessPacket != NULL)
  131. {
  132. m_pProcessPacket(ppak, m_Param);
  133. }
  134. delete ppak;
  135. }
  136. break;
  137. case SMPP_DELIVER_SM:
  138. {
  139. CDeliverSM* ppak;
  140. ppak = new CDeliverSM();
  141. ppak->loadPacket(pby, nsz);
  142. //call back
  143. if (m_pProcessPacket != NULL)
  144. {
  145. m_pProcessPacket(ppak, m_Param);
  146. }
  147. delete ppak;
  148. }
  149. break;
  150. default:
  151. break;
  152. }
  153. }