123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #include "http_callrouter.h"
- #include "strutil.h"
- void HttpsLogCallBack(const char* logtxt) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI("HttpsLogCallBack")("HttpsLogCallBack: %s.", logtxt);
- }
- static int get_http_callnodeinfo(node_info_t* pnode, const char* pcaller_num, const char* paccess_num, const char* pvoiceaddr, const char* pmediaaddr)
- {
- int iret = -1;
- if (NULL == pnode || NULL == pcaller_num || NULL == pvoiceaddr || NULL == pmediaaddr || NULL == paccess_num) {
- return iret;
- }
- char strinterip[RVC_DATALEN] = { 0 };
- char strvoiceip[RVC_DATALEN] = { 0 };
- char strvoiceport[RVC_DATALEN] = { 0 };
-
- char* pindex = NULL;
- if (pindex = (char*)strstr(pvoiceaddr, ":")){
- snprintf(strvoiceip, RVC_DATALEN,"%s", pvoiceaddr);
- snprintf(strvoiceport, RVC_DATALEN, "%s", pindex+1);
- if (pindex = (char*)strstr(strvoiceip, ":")) {
- *pindex = '\0';
- }
- }
-
- pindex = NULL;
- if (pindex = (char*)strstr(pmediaaddr, ":")) {
- snprintf(pnode->strassistip, RVC_DATALEN, "%s", pmediaaddr);
- snprintf(pnode->strport, RVC_DATALEN, "%s", pindex+1);
- if (pindex = (char*)strstr(pnode->strassistip, ":")) {
- *pindex = '\0';
- }
- }
-
- //to url Ç°Ãæ+8
- if ('8' == *paccess_num) {
- snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s@%s", "sip:", paccess_num, strvoiceip);
- }
- else {
- snprintf(pnode->strcallurl, RVC_DATALEN, "%s%s%s@%s", "sip:", "8", paccess_num, strvoiceip);
- }
- //new new_caller_id_number=callernum#assist_int_ip
- get_interger_netaddr(strinterip, RVC_DATALEN, pnode->strassistip);
- snprintf(pnode->strcallernum, RVC_DATALEN, "%s%s%s", pcaller_num, "#", strinterip);
- iret = 0;
- return iret;
- }
- node_list_head_t* get_http_callroute_list(http_call_info_t* pinfo)
- {
- node_list_head_t* phead = NULL;
- IHttpFunc* client = create_http(HttpsLogCallBack);
- if (NULL == pinfo) {
- return NULL;
- }
- CallRouteHTTPReq req;
- req.m_timeOut = 5;
-
- const char* pData = pinfo->strServerURL.GetData();
- if (pData) {
- req.m_url = pData;
- }
- pData = pinfo->strAPI.GetData();
- if (pData) {
- req.m_url.append(pData);
- }
-
- pData = pinfo->strQueueName.GetData();
- if (pData) {
- req.queueName = pData;
- }
-
- pData = pinfo->strAddClientLevel.GetData();
- if (pData) {
- req.addClientLevel = pData;
- }
-
- pData = pinfo->strTerminalNo.GetData();
- if (pData) {
- req.terminalNo = pData;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin http get request.");
- CallRouteHTTPRet ret;
- if (client->Get(req, ret)) {
- 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.",
- 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(),
- 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(),
- 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);
- phead = create_node_list_head(pinfo->strTerminalNo.GetData());
- node_info_t tnode = {0};
- 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())) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new http_callroute node: new_caller_number:%s new_touri:%s, assist_ip:%s, assist_port:%s!",
- tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
- add_node_to_list(phead, tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
- memset(&tnode, 0, sizeof(node_info_t));
- 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())) {
- 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!",
- tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
- add_node_to_list(phead, tnode.strcallernum, tnode.strcallurl, tnode.strassistip, tnode.strport);
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("http get call node info failed!");
- }
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("http get request failed!");
- }
-
- return phead;
- }
|