|
@@ -1,13 +1,36 @@
|
|
|
-#include "stdafx.h"
|
|
|
+
|
|
|
#include "callrouter.h"
|
|
|
#include "strutil.h"
|
|
|
#include "callroute_request.h"
|
|
|
#include "callroute_nodelist.h"
|
|
|
#include "SpBase.h"
|
|
|
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
#include <process.h>
|
|
|
#include <DbgHelp.h>
|
|
|
#pragma comment(lib, "dbghelp.lib")
|
|
|
+#else
|
|
|
+#include <sys/socket.h>
|
|
|
+#include <fcntl.h>
|
|
|
+#include <errno.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <pthread.h>
|
|
|
+#include <netinet/in.h>
|
|
|
+#include <string.h>
|
|
|
+#include <arpa/inet.h>
|
|
|
+#include <sys/ioctl.h>
|
|
|
+
|
|
|
+typedef int SOCKET;
|
|
|
+
|
|
|
+#ifndef INVALID_SOCKET
|
|
|
+#define INVALID_SOCKET (SOCKET)(~0)
|
|
|
+#endif
|
|
|
+#ifndef SOCKET_ERROR
|
|
|
+#define SOCKET_ERROR (-1)
|
|
|
+#endif
|
|
|
+
|
|
|
+#endif // RVC_WIN32
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -31,12 +54,20 @@ static int set_socket_attribute(SOCKET client_socket, int timeout)
|
|
|
int ret = -1;
|
|
|
|
|
|
if(setsockopt(client_socket,SOL_SOCKET,SO_SNDTIMEO,(char *)&timeout,sizeof(timeout))==SOCKET_ERROR){
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
closesocket(client_socket);
|
|
|
+#else
|
|
|
+ close(client_socket);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
if(setsockopt(client_socket,SOL_SOCKET,SO_RCVTIMEO,(char *)&timeout,sizeof(timeout))==SOCKET_ERROR){
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
closesocket(client_socket);
|
|
|
+#else
|
|
|
+ close(client_socket);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -59,18 +90,22 @@ static int request_voipgateway_address(call_info_t *call_info, proxy_rsp_packet_
|
|
|
|
|
|
SOCKET client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
if (set_socket_attribute(client_socket, 2000)){
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("request_voipgateway_address set_socket_attribute failed.");
|
|
|
+ Dbg("request_voipgateway_address set_socket_attribute failed.");
|
|
|
return ret;
|
|
|
}
|
|
|
if (INVALID_SOCKET != client_socket){
|
|
|
struct sockaddr_in sa;
|
|
|
sa.sin_family = AF_INET;
|
|
|
- sa.sin_addr.S_un.S_addr = inet_addr(call_info->callroute_server_ip);
|
|
|
+ sa.sin_addr.s_addr = inet_addr(call_info->callroute_server_ip);
|
|
|
sa.sin_port = htons(call_info->callroute_server_port);
|
|
|
memset(sa.sin_zero, 0, sizeof(sa.sin_zero));
|
|
|
|
|
|
//控制为非阻塞方式
|
|
|
- ioctlsocket(client_socket,FIONBIO,&mode);
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ ioctlsocket(client_socket, FIONBIO, &mode);
|
|
|
+#else
|
|
|
+ ioctl(client_socket, FIONBIO, &mode);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
ret = connect(client_socket, (struct sockaddr *)&sa, sizeof(struct sockaddr));
|
|
|
if (0 == ret){
|
|
|
bconnected = TRUE;
|
|
@@ -88,10 +123,18 @@ static int request_voipgateway_address(call_info_t *call_info, proxy_rsp_packet_
|
|
|
}
|
|
|
//控制为阻塞方式
|
|
|
mode = 0;
|
|
|
- ioctlsocket(client_socket, FIONBIO, &mode);
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ ioctlsocket(client_socket, FIONBIO, &mode);
|
|
|
+#else
|
|
|
+ ioctl(client_socket, FIONBIO, &mode);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
if (!bconnected){ //连接失败
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
closesocket(client_socket);
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("request_voipgateway_address connect callroute server timeout.");
|
|
|
+#else
|
|
|
+ close(client_socket);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+ Dbg("request_voipgateway_address connect callroute server timeout.");
|
|
|
return ret; //超时
|
|
|
}
|
|
|
|
|
@@ -104,16 +147,24 @@ static int request_voipgateway_address(call_info_t *call_info, proxy_rsp_packet_
|
|
|
ret = send(client_socket, (const char*)(&req_info), len, 0);
|
|
|
|
|
|
if (ret <= 0){
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
closesocket(client_socket);
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("request_voipgateway_address send to callroute server failed.");
|
|
|
+#else
|
|
|
+ close(client_socket);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+ Dbg("request_voipgateway_address send to callroute server failed.");
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
ret = recv(client_socket, (char*)rsp_packet, rsp_len, 0);
|
|
|
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
closesocket(client_socket);
|
|
|
+#else
|
|
|
+ close(client_socket);
|
|
|
+#endif // RVC_OS_WIN
|
|
|
if (ret <= 0){
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("request_voipgateway_address recv from callroute server failed.");
|
|
|
+ Dbg("request_voipgateway_address recv from callroute server failed.");
|
|
|
return ret;
|
|
|
}
|
|
|
}
|
|
@@ -134,7 +185,7 @@ static bool is_response_packet_valid(proxy_rsp_packet_t* packet_info)
|
|
|
memcpy(packgelen, packet_info->req_hdr.packgelen, 4);
|
|
|
memcpy(tradefrom, packet_info->req_hdr.tradefrom, 3);
|
|
|
memcpy(requestcode, packet_info->req_hdr.requestcode, 16);
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get mediaserver address from callroute server failed, rsp packgelen:%s, tradefrom:%s, requestcode:%s!",
|
|
|
+ Dbg("get mediaserver address from callroute server failed, rsp packgelen:%s, tradefrom:%s, requestcode:%s!",
|
|
|
packgelen,tradefrom, requestcode);
|
|
|
}else{
|
|
|
bret = true;
|
|
@@ -213,14 +264,14 @@ static node_list_head_t *create_node_list_by_callernum(call_info_t *call_info, p
|
|
|
_snprintf(new_caller_number, RVC_DATALEN, "%s%s%s",
|
|
|
call_info->szcaller_num.GetData(), "#", strinterip);
|
|
|
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new callroute node: new_caller_number:%s new_touri:%s, assist_ip:%s, assist_port:%s!",
|
|
|
+ Dbg("new callroute node: new_caller_number:%s new_touri:%s, assist_ip:%s, assist_port:%s!",
|
|
|
new_caller_number, new_touri, packet_info->rsp_body.video_content_ip, packet_info->rsp_body.video_content_port);
|
|
|
add_node_to_list(phead, new_caller_number, new_touri, packet_info->rsp_body.video_content_ip, packet_info->rsp_body.video_content_port);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}else{
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create_node_list_by_callernum failed. szbranchno:%s, szcaller_num:%s, szdest_num:%s.", call_info->szbranchno.GetData(), call_info->szcaller_num.GetData(), call_info->szdest_num.GetData());
|
|
|
+ Dbg("create_node_list_by_callernum failed. szbranchno:%s, szcaller_num:%s, szdest_num:%s.", call_info->szbranchno.GetData(), call_info->szcaller_num.GetData(), call_info->szdest_num.GetData());
|
|
|
}
|
|
|
|
|
|
return phead;
|
|
@@ -237,14 +288,14 @@ node_list_head_t *get_callroute_list(call_info_t *call_info)
|
|
|
call_info->szdest_num.GetLength() == 0 ||
|
|
|
call_info->szcaller_num.GetLength() == 0 ||
|
|
|
call_info->szbranchno.GetLength() == 0) {
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get_callroute_list failed call_info param is null.");
|
|
|
+ Dbg("get_callroute_list failed call_info param is null.");
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
reset_buffer(&rsp_info, 0x20, sizeof(proxy_rsp_packet_t));
|
|
|
ret = request_voipgateway_address(call_info, &rsp_info, recvlen);
|
|
|
if (ret <= 0){
|
|
|
- Dbg(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get_callroute_list failed szbranchno:%s, szcaller_num:%s, szdest_num:%s.", call_info->szbranchno.GetData(), call_info->szcaller_num.GetData(), call_info->szdest_num.GetData());
|
|
|
+ Dbg("get_callroute_list failed szbranchno:%s, szcaller_num:%s, szdest_num:%s.", call_info->szbranchno.GetData(), call_info->szcaller_num.GetData(), call_info->szdest_num.GetData());
|
|
|
return NULL;
|
|
|
}
|
|
|
|