selfcare init
This commit is contained in:
199
proxy_c/pstn_cli/src/include/pstn_client.h
Normal file
199
proxy_c/pstn_cli/src/include/pstn_client.h
Normal file
@@ -0,0 +1,199 @@
|
||||
#ifndef _PSTN_CLIENT_H
|
||||
#define _PSTN_CLIENT_H
|
||||
|
||||
#define MAX_COMMAND_LEN 2048
|
||||
#define MAX_PSTN_PROCS 8
|
||||
#define MSG_TIMER 6000
|
||||
#define MSG_WAIT_TIMER 400
|
||||
#define MSG_WAIT_LTIMER 1600
|
||||
|
||||
#define MAX_SLOTS 100
|
||||
|
||||
|
||||
typedef struct msan_param_t
|
||||
{
|
||||
u_char server_enable;
|
||||
char server_ip[16];
|
||||
u_short server_port;
|
||||
char user_name[16];
|
||||
char password[16];
|
||||
}_msan_param_t;
|
||||
|
||||
typedef struct pair_2_slot_param_t
|
||||
{
|
||||
int used;
|
||||
int pair_group; /* every 64 pairs is a group */
|
||||
int msan_id; /*1/2 */
|
||||
int slot_id; /* paris are mapped to : slot+port */
|
||||
}_pair_2_slot_param_t;
|
||||
|
||||
typedef struct pstn_server_param_t
|
||||
{
|
||||
char local_ip[16];
|
||||
u_short local_port;
|
||||
u_char server_enable;
|
||||
char server_ip[16];
|
||||
u_short server_port;
|
||||
char user_name[16];
|
||||
char password[16];
|
||||
|
||||
int krone_pair_id_in_crm;
|
||||
int ss_entry_id_in_crm;
|
||||
|
||||
_msan_param_t msan[2];
|
||||
_pair_2_slot_param_t pair_slot_info[MAX_SLOTS];
|
||||
|
||||
}_pstn_server_param_t;
|
||||
|
||||
typedef enum PORT_STATE
|
||||
{
|
||||
PS_NULL,
|
||||
PS_CREATE,
|
||||
PS_UPDATE,
|
||||
PS_DELETE,
|
||||
PS_BAR_OUT,
|
||||
PS_UNBAR_OUT,
|
||||
PS_BAR_IN,
|
||||
PS_UNBAR_IN,
|
||||
PS_CREATE_MSAN,
|
||||
PS_DELETE_MSAN,
|
||||
PS_RELEASE,
|
||||
}_PORT_STATE;
|
||||
|
||||
typedef enum PORT_CRT_STATE
|
||||
{
|
||||
PCS_NULL,
|
||||
PCS_INIT,
|
||||
PCS_ECHO,
|
||||
PCS_LOGIN,
|
||||
PCS_PSSWD,
|
||||
PCS_NOGUI,
|
||||
PCS_QUERY_DSTN,
|
||||
PCS_ENTRY,
|
||||
PCS_STATION,
|
||||
PCS_DSTN,
|
||||
PCS_NAME,
|
||||
PCS_SIGNAL,
|
||||
PCS_SIP_USER,
|
||||
PCS_VOIP_GRP,
|
||||
PCS_TOLL,
|
||||
PCS_EXTI,
|
||||
PCS_ACTIVE,
|
||||
PCS_LOGOUT,
|
||||
PCS_LOGOUT_AGAIN,
|
||||
PCS_TRANS_TO_MSAN,
|
||||
// PCS_ENTRY,
|
||||
// PCS_VOIP_GRP,
|
||||
|
||||
PCS_MAX,
|
||||
}_PORT_CRT_STATE;
|
||||
|
||||
typedef enum PORT_UPDATE_STATE
|
||||
{
|
||||
PUS_NULL,
|
||||
PUS_INIT,
|
||||
PUS_LOGIN,
|
||||
PUS_PSSWD,
|
||||
PUS_NOGUI,
|
||||
PUS_DSTN,
|
||||
PUS_TOLL,
|
||||
PUS_LOCKI,
|
||||
PUS_EXTI,
|
||||
PUS_ACTIVATE,
|
||||
PUS_LOGOUT,
|
||||
PUS_MAX,
|
||||
}_PORT_UPDATE_STATE;
|
||||
|
||||
typedef enum PORT_DEL_STATE
|
||||
{
|
||||
PDS_NULL,
|
||||
PDS_INIT,
|
||||
PDS_LOGIN,
|
||||
PDS_PSSWD,
|
||||
PDS_NOGUI,
|
||||
PDS_DSTN,
|
||||
PDS_ENTRY,
|
||||
PDS_DEL,
|
||||
PDS_EXTI,
|
||||
PDS_LOGOUT,
|
||||
PDS_LOGOUT_AGAIN,
|
||||
PDS_MAX,
|
||||
}_PORT_DEL_STATE;
|
||||
|
||||
|
||||
typedef enum MSAN_CRT_STATE
|
||||
{
|
||||
MCS_NULL,
|
||||
MCS_INIT,
|
||||
MCS_ECHO,
|
||||
MCS_LOGIN,
|
||||
MCS_PSSWD,
|
||||
MCS_CREATE,
|
||||
MCS_BRING_UP,
|
||||
MCS_SAVE,
|
||||
MCS_EXIT,
|
||||
MCS_WAIT_EXIT,
|
||||
MCS_MAX,
|
||||
}_MSAN_CRT_STATE;
|
||||
|
||||
typedef enum MSAN_DEL_STATE
|
||||
{
|
||||
MDS_NULL,
|
||||
MDS_INIT,
|
||||
MDS_LOGIN,
|
||||
MDS_PSSWD,
|
||||
MDS_DELETE,
|
||||
MDS_BRING_DOWN,
|
||||
MDS_SAVE,
|
||||
MDS_LOGOUT,
|
||||
MDS_MAX,
|
||||
}_MSAN_DEL_STATE;
|
||||
|
||||
|
||||
|
||||
typedef enum PSTN_PROV_CMD
|
||||
{
|
||||
PC_NULL,
|
||||
PC_CREATE,
|
||||
PC_UPDATE,
|
||||
PC_DELETE,
|
||||
PC_BAR,
|
||||
PC_UNBAR,
|
||||
}_PSTN_PROV_CMD;
|
||||
|
||||
typedef struct pstn_prov_t
|
||||
{
|
||||
int command;
|
||||
long pre_id;
|
||||
char isdn_number[16];
|
||||
char user_name[64];
|
||||
int ss_entry;
|
||||
int krone_pair_id;
|
||||
int msan_id;
|
||||
int msan_slot_id;
|
||||
int msan_slot_port_id;
|
||||
int update_status;
|
||||
}_pstn_prov_t;
|
||||
|
||||
typedef struct pstn_proc_t
|
||||
{
|
||||
char flag;
|
||||
int id;
|
||||
int tcp_port_id;
|
||||
int state;
|
||||
int sub_state;
|
||||
int timer;
|
||||
int dstn_entry;
|
||||
int recv_msg_flag;
|
||||
int msg_len;
|
||||
char recv_msg[MAX_COMMAND_LEN];
|
||||
_pstn_prov_t prov;
|
||||
}_pstn_proc_t;
|
||||
|
||||
|
||||
typedef struct pstn_procs_t
|
||||
{
|
||||
_pstn_proc_t procs[MAX_PSTN_PROCS];
|
||||
}_pstn_procs_t;
|
||||
|
||||
#endif
|
||||
1174
proxy_c/pstn_cli/src/pstn_client.c
Normal file
1174
proxy_c/pstn_cli/src/pstn_client.c
Normal file
File diff suppressed because it is too large
Load Diff
133
proxy_c/pstn_cli/src/tcp_client.c
Normal file
133
proxy_c/pstn_cli/src/tcp_client.c
Normal file
@@ -0,0 +1,133 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
|
||||
#define RES_LENGTH 10240
|
||||
|
||||
static int client_fd=0;
|
||||
static int client_connect_flag = -1;
|
||||
static char server_ip[16];
|
||||
static short server_port;
|
||||
|
||||
int connect_socket(char * server,int serverPort);
|
||||
int send_msg(int sockfd,char * sendBuff);
|
||||
char * recv_msg(int sockfd);
|
||||
int close_socket(int sockfd);
|
||||
|
||||
int init_socketfd()
|
||||
{
|
||||
int sockfd = -1;
|
||||
|
||||
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){
|
||||
herror("Init socket error!");
|
||||
}
|
||||
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
void tcp_init_client_fd()
|
||||
{
|
||||
client_fd = init_socketfd();
|
||||
|
||||
}
|
||||
|
||||
void tcp_connect_server(char *ip, u_short port)
|
||||
{
|
||||
tcp_init_client_fd();
|
||||
|
||||
strcpy(server_ip, ip);
|
||||
server_port = port;
|
||||
client_connect_flag = connect_socket(ip, port);
|
||||
}
|
||||
|
||||
int is_tcp_connected()
|
||||
{
|
||||
return client_connect_flag;
|
||||
}
|
||||
|
||||
/* * ********************************************************/
|
||||
int connect_socket(char * server,int serverPort)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
struct hostent * phost;
|
||||
|
||||
bzero(&addr,sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(serverPort);
|
||||
addr.sin_addr.s_addr = inet_addr(server);
|
||||
|
||||
if(addr.sin_addr.s_addr == INADDR_NONE){
|
||||
phost = (struct hostent*)gethostbyname(server);
|
||||
if(phost==NULL){
|
||||
herror("Init socket s_addr error!");
|
||||
return -1;
|
||||
}
|
||||
addr.sin_addr.s_addr =((struct in_addr*)phost->h_addr)->s_addr;
|
||||
}
|
||||
if(connect(client_fd,(struct sockaddr*)&addr, sizeof(addr))<0)
|
||||
{
|
||||
// perror("Connect server fail!");
|
||||
return -1; //0<><30>ʾ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>-1<><31>ʾʧ<CABE><CAA7>
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int tcp_send_msg( u_char *sendbuf, short len)
|
||||
{
|
||||
int sendSize=0;
|
||||
|
||||
if((sendSize=send(client_fd,sendbuf,len,MSG_NOSIGNAL))<=0){
|
||||
close_socket(client_fd);
|
||||
herror("Send msg error!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sendSize;
|
||||
}
|
||||
|
||||
int tcp_recv_msg(u_char *recvbuf)
|
||||
{
|
||||
int recLenth=0;
|
||||
|
||||
if(( recLenth=recv(client_fd,recvbuf, BUF_SIZE,0))==-1 )
|
||||
{
|
||||
close_socket(client_fd);
|
||||
return -1;
|
||||
}
|
||||
if( recLenth>0)
|
||||
recvbuf[recLenth] = 0;
|
||||
return recLenth;
|
||||
}
|
||||
|
||||
int tcp_check_connection()
|
||||
{
|
||||
//if(client_connect_flag == -1)
|
||||
// connect_socket(server_ip, server_port);
|
||||
|
||||
return client_connect_flag;
|
||||
}
|
||||
|
||||
/**************************************************
|
||||
*<2A>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD>
|
||||
* **********************************************/
|
||||
int close_socket(int sockfd)
|
||||
{
|
||||
client_connect_flag = -1;
|
||||
close(sockfd);
|
||||
|
||||
smcli_connection_is_broken();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user