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

手机短信编程

开发平台:

Visual C++

  1. // EsmeTransceiver.cpp: implementation of the CEsmeTransceiver class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. //#include "SMPPAPI.h"
  6. #include "EsmeTransceiver.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. #ifdef SMPPAPI_EVALUATION
  16. uint32 CEsmeTransceiver::m_eval_counter = 1;
  17. #endif
  18. CEsmeTransceiver::CEsmeTransceiver()
  19. {
  20. }
  21. CEsmeTransceiver::~CEsmeTransceiver()
  22. {
  23. }
  24. int CEsmeTransceiver::bind(CString sysid, CString passwd, CString systype, CSmppAddress &addrrange)
  25. {
  26. bool ret = 1;
  27. m_system_id = sysid;
  28. m_password = passwd;
  29. m_system_type = systype;
  30. m_address_range = addrrange;
  31. if (open())
  32. {
  33. CBindTransceiver pak;
  34. pak.setSystemId(sysid);
  35. pak.setPassword(passwd);
  36. pak.setSystemType(systype);
  37. pak.setSourceRange(addrrange);
  38. if (sendPacket(pak))
  39. ret = 0;
  40. }
  41. return ret;
  42. }
  43. int CEsmeTransceiver::submitMessage(CSubmitSM &pak)
  44. {
  45. #ifdef SMPPAPI_EVALUATION
  46. m_eval_counter++;
  47. if (m_eval_counter > 200)
  48. return 1;
  49. #endif
  50. sendPacket(pak);
  51. return 0;
  52. }
  53. int CEsmeTransceiver::submitMessage(CString msg, CString dst, uint32 ton, uint32 npi)
  54. {
  55. CSmppAddress dst_addr(ton, npi, dst);
  56. return submitMessage(msg, dst_addr);
  57. }
  58. int CEsmeTransceiver::submitMessage(CString msg, CSmppAddress &dst)
  59. {
  60. CSubmitSM s;
  61. s.setMessage( (PBYTE) msg.GetBuffer(0), msg.GetLength());
  62. msg.ReleaseBuffer();
  63. s.setDestination(dst);
  64. s.setSource(m_address_range);
  65. return submitMessage(s);
  66. }
  67. int CEsmeTransceiver::submitMessage(PBYTE msg, uint32 msglen, uint32 enc, CSmppAddress &dst, uint32 esm)
  68. {
  69. CSubmitSM s;
  70. s.setMessage(msg, msglen);
  71. s.setDestination(dst);
  72. s.setSource(m_address_range);
  73. s.setDataCoding(enc);
  74. s.setEsmClass(esm);
  75. return submitMessage(s);
  76. }
  77. void CEsmeTransceiver::parse_packet(PBYTE pby, int nsz)
  78. {
  79. #ifdef SMPPAPI_EVALUATION
  80. m_eval_counter++;
  81. if (m_eval_counter > 200)
  82. return;
  83. #endif
  84. if (nsz < 16)
  85. return;
  86. uint32 cmdId = readInt(pby);
  87. #ifdef _DEBUG
  88. TCHAR buff[100];
  89. sprintf(buff, "CommandId is %x", cmdId);
  90. TRACE(buff);
  91. #endif
  92. int cmdStatus = readInt(pby+4);
  93. int seqNum = readInt(pby+8);
  94. switch (cmdId)
  95. {
  96. case SMPP_GENERIC_NACK:
  97. {
  98. CGenericNack* ppak;
  99. ppak = new CGenericNack();
  100. ppak->loadPacket(pby, nsz);
  101. //call back
  102. if (m_pProcessPacket != NULL)
  103. {
  104. m_pProcessPacket(ppak, m_Param);
  105. }
  106. delete ppak;
  107. }
  108. break;
  109. case SMPP_SPECIAL_LINKCLOSE:
  110. {
  111. CLinkClose* ppak;
  112. ppak = new CLinkClose();
  113. ppak->loadPacket(pby, nsz);
  114. //call back
  115. if (m_pProcessPacket != NULL)
  116. {
  117. m_pProcessPacket(ppak, m_Param);
  118. }
  119. delete ppak;
  120. }
  121. break;
  122. case SMPP_BIND_TRANSCEIVER_RESP:
  123. {
  124. CBindTransceiverResp* ppak;
  125. ppak = new CBindTransceiverResp();
  126. ppak->loadPacket(pby, nsz);
  127. //call back
  128. if (m_pProcessPacket != NULL)
  129. {
  130. m_pProcessPacket(ppak, m_Param);
  131. }
  132. delete ppak;
  133. }
  134. break;
  135. case SMPP_SUBMIT_SM_RESP:
  136. {
  137. CSubmitSMResp* ppak;
  138. ppak = new CSubmitSMResp();
  139. ppak->loadPacket(pby, nsz);
  140. //call back
  141. if (m_pProcessPacket != NULL)
  142. {
  143. m_pProcessPacket(ppak, m_Param);
  144. }
  145. delete ppak;
  146. }
  147. break;
  148. case SMPP_QUERY_SM_RESP:
  149. {
  150. CQuerySMResp* ppak;
  151. ppak = new CQuerySMResp();
  152. ppak->loadPacket(pby, nsz);
  153. //call back
  154. if (m_pProcessPacket != NULL)
  155. {
  156. m_pProcessPacket(ppak, m_Param);
  157. }
  158. delete ppak;
  159. }
  160. break;
  161. case SMPP_UNBIND_RESP:
  162. {
  163. CUnbindResp* ppak;
  164. ppak = new CUnbindResp();
  165. ppak->loadPacket(pby, nsz);
  166. //call back
  167. if (m_pProcessPacket != NULL)
  168. {
  169. m_pProcessPacket(ppak, m_Param);
  170. }
  171. delete ppak;
  172. }
  173. break;
  174. case SMPP_DELIVER_SM:
  175. {
  176. CDeliverSM* ppak;
  177. ppak = new CDeliverSM();
  178. ppak->loadPacket(pby, nsz);
  179. //call back
  180. if (m_pProcessPacket != NULL)
  181. {
  182. m_pProcessPacket(ppak, m_Param);
  183. }
  184. delete ppak;
  185. }
  186. break;
  187. case SMPP_ENQUIRE_LINK:
  188. {
  189. CEnquireLink* ppak;
  190. ppak = new CEnquireLink();
  191. ppak->loadPacket(pby, nsz);
  192. //call back
  193. if (m_pProcessPacket != NULL)
  194. {
  195. m_pProcessPacket(ppak, m_Param);
  196. }
  197. delete ppak;
  198. }
  199. break;
  200. case SMPP_ENQUIRE_LINK_RESP:
  201. {
  202. CEnquireLinkResp* ppak;
  203. ppak = new CEnquireLinkResp();
  204. ppak->loadPacket(pby, nsz);
  205. //call back
  206. if (m_pProcessPacket != NULL)
  207. {
  208. m_pProcessPacket(ppak, m_Param);
  209. }
  210. delete ppak;
  211. }
  212. break;
  213. default:
  214. break;
  215. }
  216. }