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

手机短信编程

开发平台:

Visual C++

  1. // SmppTransmitter.cpp: implementation of the CSmppTransmitter class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. //#include "SMPPAPI.h"
  6. #include "EsmeTransmitter.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 CEsmeTransmitter::m_eval_counter = 1;
  18. #endif
  19. CEsmeTransmitter::CEsmeTransmitter()
  20. {
  21. }
  22. CEsmeTransmitter::~CEsmeTransmitter()
  23. {
  24. }
  25. int CEsmeTransmitter::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. CBindTransmitter 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. int CEsmeTransmitter::submitMessage(CSubmitSM &pak)
  45. {
  46. #ifdef SMPPAPI_EVALUATION
  47. m_eval_counter++;
  48. if (m_eval_counter > 200)
  49. return 1;
  50. #endif
  51. sendPacket(pak);
  52. return 0;
  53. }
  54. int CEsmeTransmitter::submitMessage(CString msg, CString dst, uint32 ton, uint32 npi)
  55. {
  56. CSmppAddress dst_addr(ton, npi, dst);
  57. return submitMessage(msg, dst_addr);
  58. }
  59. int CEsmeTransmitter::submitMessage(CString msg, CSmppAddress &dst)
  60. {
  61. CSubmitSM s;
  62. s.setMessage( (PBYTE) msg.GetBuffer(0), msg.GetLength());
  63. msg.ReleaseBuffer();
  64. s.setDestination(dst);
  65. s.setSource(m_address_range);
  66. return submitMessage(s);
  67. }
  68. int CEsmeTransmitter::submitMessage(PBYTE msg, uint32 msglen, uint32 enc, CSmppAddress &dst, uint32 esm)
  69. {
  70. CSubmitSM s;
  71. s.setMessage(msg, msglen);
  72. s.setDestination(dst);
  73. s.setSource(m_address_range);
  74. s.setDataCoding(enc);
  75. s.setEsmClass(esm);
  76. return submitMessage(s);
  77. }
  78. void CEsmeTransmitter::parse_packet(PBYTE pby, int nsz)
  79. {
  80. if (nsz < 16)
  81. return;
  82. uint32 cmdId = readInt(pby);
  83. TRACE1("CommandId is %x", cmdId);
  84. int cmdStatus = readInt(pby+4);
  85. int seqNum = readInt(pby+8);
  86. switch (cmdId)
  87. {
  88. case SMPP_GENERIC_NACK:
  89. {
  90. CGenericNack* ppak;
  91. ppak = new CGenericNack();
  92. ppak->loadPacket(pby, nsz);
  93. //call back
  94. if (m_pProcessPacket != NULL)
  95. {
  96. m_pProcessPacket(ppak, m_Param);
  97. }
  98. delete ppak;
  99. }
  100. break;
  101. case SMPP_SPECIAL_LINKCLOSE:
  102. {
  103. CLinkClose* ppak;
  104. ppak = new CLinkClose();
  105. ppak->loadPacket(pby, nsz);
  106. //call back
  107. if (m_pProcessPacket != NULL)
  108. {
  109. m_pProcessPacket(ppak, m_Param);
  110. }
  111. delete ppak;
  112. }
  113. break;
  114. case SMPP_BIND_TRANSMITTER_RESP:
  115. {
  116. CBindTransmitterResp* ppak;
  117. ppak = new CBindTransmitterResp();
  118. ppak->loadPacket(pby, nsz);
  119. //call back
  120. if (m_pProcessPacket != NULL)
  121. {
  122. m_pProcessPacket(ppak, m_Param);
  123. }
  124. delete ppak;
  125. }
  126. break;
  127. case SMPP_SUBMIT_SM_RESP:
  128. {
  129. CSubmitSMResp* ppak;
  130. ppak = new CSubmitSMResp();
  131. ppak->loadPacket(pby, nsz);
  132. //call back
  133. if (m_pProcessPacket != NULL)
  134. {
  135. m_pProcessPacket(ppak, m_Param);
  136. }
  137. delete ppak;
  138. }
  139. break;
  140. case SMPP_QUERY_SM_RESP:
  141. {
  142. CQuerySMResp* ppak;
  143. ppak = new CQuerySMResp();
  144. ppak->loadPacket(pby, nsz);
  145. //call back
  146. if (m_pProcessPacket != NULL)
  147. {
  148. m_pProcessPacket(ppak, m_Param);
  149. }
  150. delete ppak;
  151. }
  152. break;
  153. case SMPP_ENQUIRE_LINK:
  154. {
  155. CEnquireLink* ppak;
  156. ppak = new CEnquireLink();
  157. ppak->loadPacket(pby, nsz);
  158. //call back
  159. if (m_pProcessPacket != NULL)
  160. {
  161. m_pProcessPacket(ppak, m_Param);
  162. }
  163. delete ppak;
  164. }
  165. break;
  166. case SMPP_ENQUIRE_LINK_RESP:
  167. {
  168. CEnquireLinkResp* ppak;
  169. ppak = new CEnquireLinkResp();
  170. ppak->loadPacket(pby, nsz);
  171. //call back
  172. if (m_pProcessPacket != NULL)
  173. {
  174. m_pProcessPacket(ppak, m_Param);
  175. }
  176. delete ppak;
  177. }
  178. break;
  179. case SMPP_UNBIND_RESP:
  180. {
  181. CUnbindResp* ppak;
  182. ppak = new CUnbindResp();
  183. ppak->loadPacket(pby, nsz);
  184. //call back
  185. if (m_pProcessPacket != NULL)
  186. {
  187. m_pProcessPacket(ppak, m_Param);
  188. }
  189. delete ppak;
  190. }
  191. break;
  192. default:
  193. break;
  194. }
  195. }