http_callrouter.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "http_callrouter.h"
  2. #include "strutil.h"
  3. #include "Event.h"
  4. void HttpsLogCallBack(const char* logtxt) {
  5. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI("HttpsLogCallBack")("HttpsLogCallBack: %s.", logtxt);
  6. }
  7. static int get_http_callnodeinfo(node_info_t* pnode, const char* pcaller_num, const char* paccess_num, const char* pvoiceaddr, const char* pmediaaddr)
  8. {
  9. int iret = -1;
  10. if (NULL == pnode || NULL == pcaller_num || NULL == pvoiceaddr || NULL == pmediaaddr || NULL == paccess_num) {
  11. return iret;
  12. }
  13. char strinterip[RVC_DATALEN] = { 0 };
  14. char strvoiceip[RVC_DATALEN] = { 0 };
  15. char strvoiceport[RVC_DATALEN] = { 0 };
  16. char* pindex = NULL;
  17. if (pindex = (char*)strstr(pvoiceaddr, ":")){
  18. snprintf(strvoiceip, RVC_DATALEN,"%s", pvoiceaddr);
  19. snprintf(strvoiceport, RVC_DATALEN, "%s", pindex+1);
  20. if (pindex = (char*)strstr(strvoiceip, ":")) {
  21. *pindex = '\0';
  22. }
  23. }
  24. pindex = NULL;
  25. if (pindex = (char*)strstr(pmediaaddr, ":")) {
  26. snprintf(pnode->strassistip, RVC_DATALEN, "%s", pmediaaddr);
  27. snprintf(pnode->strport, RVC_DATALEN, "%s", pindex+1);
  28. if (pindex = (char*)strstr(pnode->strassistip, ":")) {
  29. *pindex = '\0';
  30. }
  31. }
  32. //to url 前面+8
  33. if ('8' == *paccess_num) {
  34. snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s@%s", "sip:", paccess_num, strvoiceip);
  35. }
  36. else {
  37. snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s%s@%s", "sip:", "8", paccess_num, strvoiceip);
  38. }
  39. //new new_caller_id_number=callernum#assist_int_ip
  40. get_interger_netaddr(strinterip, RVC_DATALEN, pnode->strassistip);
  41. snprintf(pnode->strcallernum, RVC_DATALEN, "%s%s%s", pcaller_num, "#", strinterip);
  42. iret = 0;
  43. return iret;
  44. }
  45. node_list_head_t* get_http_callroute_list(http_call_info_t* pinfo, int itimeout, bool bprintdbg)
  46. {
  47. node_list_head_t* phead = NULL;
  48. IHttpFunc* client = create_http(HttpsLogCallBack);
  49. if (NULL == pinfo) {
  50. return NULL;
  51. }
  52. CallRouteHTTPReq req;
  53. req.m_timeOut = itimeout;
  54. if (bprintdbg) {
  55. req.m_printDbg = true;
  56. }
  57. const char* pData = pinfo->strServerURL.GetData();
  58. if (pData) {
  59. req.m_url = pData;
  60. }
  61. pData = pinfo->strAPI.GetData();
  62. if (pData) {
  63. req.m_url.append(pData);
  64. }
  65. pData = pinfo->strQueueName.GetData();
  66. if (pData) {
  67. req.queueName = pData;
  68. }
  69. pData = pinfo->strAddClientLevel.GetData();
  70. if (pData) {
  71. req.addClientLevel = pData;
  72. }
  73. pData = pinfo->strTerminalNo.GetData();
  74. if (pData) {
  75. req.terminalNo = pData;
  76. }
  77. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin http get request, timeout is %d, printdbg flag is %s.", req.m_timeOut, req.m_printDbg ? "true":"false");
  78. CallRouteHTTPRet ret;
  79. PROCESS_LINK_CONTEXT("LR0402304CallRoute")
  80. if (client->Get(req, ret, &nextLink)) {
  81. //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.",
  82. // 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(),
  83. // 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(),
  84. // 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);
  85. phead = create_node_list_head(pinfo->strTerminalNo.GetData());
  86. node_info_t tnode = {0};
  87. 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())) {
  88. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("new 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. memset(&tnode, 0, sizeof(node_info_t));
  92. 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())) {
  93. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("new backup http_callroute node: new_caller_number:%s new_touri:%s, assist_ip:%s, assist_port:%s!",
  94. tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
  95. add_node_to_list(phead, tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
  96. }
  97. }
  98. else {
  99. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("http get call node info failed!");
  100. }
  101. }
  102. else {
  103. LogWarn(Severity_Middle, Error_Exception, LOG_WARN_COUNTERCONNECT_CALLROUTE_INTERACTIVE_FAILED, CSimpleStringA::Format("CallRoute http req fail,url=%s, syscode=%d, usercode=%s, errmsg=%s", req.m_url.c_str(), ret.m_sysCode, ret.m_userCode.c_str(), ret.m_errMsg.c_str()).GetData());
  104. }
  105. return phead;
  106. }