http_callrouter.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "http_callrouter.h"
  2. #include "strutil.h"
  3. void HttpsLogCallBack(const char* logtxt) {
  4. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI("HttpsLogCallBack")("HttpsLogCallBack: %s.", logtxt);
  5. }
  6. static int get_http_callnodeinfo(node_info_t* pnode, const char* pcaller_num, const char* paccess_num, const char* pvoiceaddr, const char* pmediaaddr)
  7. {
  8. int iret = -1;
  9. if (NULL == pnode || NULL == pcaller_num || NULL == pvoiceaddr || NULL == pmediaaddr || NULL == paccess_num) {
  10. return iret;
  11. }
  12. char strinterip[RVC_DATALEN] = { 0 };
  13. char strvoiceip[RVC_DATALEN] = { 0 };
  14. char strvoiceport[RVC_DATALEN] = { 0 };
  15. char* pindex = NULL;
  16. if (pindex = (char*)strstr(pvoiceaddr, ":")){
  17. snprintf(strvoiceip, RVC_DATALEN,"%s", pvoiceaddr);
  18. snprintf(strvoiceport, RVC_DATALEN, "%s", pindex+1);
  19. if (pindex = (char*)strstr(strvoiceip, ":")) {
  20. *pindex = '\0';
  21. }
  22. }
  23. pindex = NULL;
  24. if (pindex = (char*)strstr(pmediaaddr, ":")) {
  25. snprintf(pnode->strassistip, RVC_DATALEN, "%s", pmediaaddr);
  26. snprintf(pnode->strport, RVC_DATALEN, "%s", pindex+1);
  27. if (pindex = (char*)strstr(pnode->strassistip, ":")) {
  28. *pindex = '\0';
  29. }
  30. }
  31. //to url Ç°Ãæ+8
  32. if ('8' == *paccess_num) {
  33. snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s@%s", "sip:", paccess_num, strvoiceip);
  34. }
  35. else {
  36. snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s%s@%s", "sip:", "8", paccess_num, strvoiceip);
  37. }
  38. //new new_caller_id_number=callernum#assist_int_ip
  39. get_interger_netaddr(strinterip, RVC_DATALEN, pnode->strassistip);
  40. snprintf(pnode->strcallernum, RVC_DATALEN, "%s%s%s", pcaller_num, "#", strinterip);
  41. iret = 0;
  42. return iret;
  43. }
  44. node_list_head_t* get_http_callroute_list(http_call_info_t* pinfo)
  45. {
  46. node_list_head_t* phead = NULL;
  47. IHttpFunc* client = create_http(HttpsLogCallBack);
  48. if (NULL == pinfo) {
  49. return NULL;
  50. }
  51. CallRouteHTTPReq req;
  52. req.m_timeOut = 5;
  53. const char* pData = pinfo->strServerURL.GetData();
  54. if (pData) {
  55. req.m_url = pData;
  56. }
  57. pData = pinfo->strAPI.GetData();
  58. if (pData) {
  59. req.m_url.append(pData);
  60. }
  61. pData = pinfo->strQueueName.GetData();
  62. if (pData) {
  63. req.queueName = pData;
  64. }
  65. pData = pinfo->strAddClientLevel.GetData();
  66. if (pData) {
  67. req.addClientLevel = pData;
  68. }
  69. pData = pinfo->strTerminalNo.GetData();
  70. if (pData) {
  71. req.terminalNo = pData;
  72. }
  73. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin http get request.");
  74. CallRouteHTTPRet ret;
  75. if (client->Get(req, ret)) {
  76. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get result is %s, returnCode:%s, code:%s, errorMsg:%s, message:%s, terminalNo:%s, branchNo:%s, accessNum:%s, voiceGateAddress:%s, mediaGateAddress:%s, voiceGateAddressBackUp:%s, mediaGateAddressBackUp:%s, queueName:%s, clientLevel:%d.",
  77. ret.m_success?"success":"failed", ret.m_returnCode.c_str(), ret.m_code.c_str(), ret.m_errorMsg.c_str(), ret.m_message.c_str(),
  78. ret.m_call_route.m_terminalNo.c_str(), ret.m_call_route.m_branchNo.c_str(), ret.m_call_route.m_accessNum.c_str(),ret.m_call_route.m_voiceGateAddress.c_str(),
  79. ret.m_call_route.m_mediaGateAddress.c_str(), ret.m_call_route.m_voiceGateAddressBackUp.c_str(), ret.m_call_route.m_mediaGateAddressBackUp.c_str(), ret.m_call_route.m_queueName.c_str(), ret.m_call_route.m_clientLevel);
  80. phead = create_node_list_head(pinfo->strTerminalNo.GetData());
  81. node_info_t tnode = {0};
  82. if (0 == get_http_callnodeinfo(&tnode, pinfo->strTerminalNo.GetData(), ret.m_call_route.m_accessNum.c_str(), ret.m_call_route.m_voiceGateAddress.c_str(), ret.m_call_route.m_mediaGateAddress.c_str())) {
  83. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new http_callroute node: new_caller_number:%s new_touri:%s, assist_ip:%s, assist_port:%s!",
  84. tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
  85. add_node_to_list(phead, tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
  86. memset(&tnode, 0, sizeof(node_info_t));
  87. if (0 == get_http_callnodeinfo(&tnode, pinfo->strTerminalNo.GetData(), ret.m_call_route.m_accessNum.c_str(), ret.m_call_route.m_voiceGateAddressBackUp.c_str(), ret.m_call_route.m_mediaGateAddressBackUp.c_str())) {
  88. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new backup http_callroute node: new_caller_number:%s new_touri:%s, assist_ip:%s, assist_port:%s!",
  89. tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
  90. add_node_to_list(phead, tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
  91. }
  92. }
  93. else {
  94. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("http get call node info failed!");
  95. }
  96. }
  97. else {
  98. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("http get request failed!");
  99. }
  100. return phead;
  101. }