📄 cngp.c
字号:
getdatetime(resq[i].rq_response_time);
resq[i].rq_response_status = -3;
resq[i].intime = time(NULL);
n++;
}
}
}
#endif
return n;
}
int Insertresq(RES_Q *resq, RES_Q tmp)
{
int k=0;
for(k =0 ; k< memsend ; k++)
if(strlen(resq[k].rq_submit_id) ==0)
{
memcpy(&resq[k], &tmp, sizeof(RES_Q));
return 0;
}
return -1; // buffer full
}
int checkresqnum(RES_Q *resq)
{
int k =0 , i=0;
for(k=0; k< memsend ; k++)
if(strlen(resq[k].rq_submit_id) ==0)
i++;
return i;
}
int CheckTimeout(SEND_Q *sendq)
{
int i=0, count =0;
for( i=0; i<memsend; i++)
if( ( sendq[i].intime + timeout_no_submit_resp< time(NULL) ) && (strcmp(sendq[i].sq_submit_stat ,"sub") ==0) )
{
if(sendq[i].sq_pri <= retry_max)
{
// insert into send_log , failed
InsertSendLog(&fsql_main, send_q_db,&sendq[i], -1);
sendq[i].sq_id = 0;
memset(&sendq[i], 0, sizeof(SEND_Q));
continue;
}
sendq[i].intime = time(NULL);
strcpy(sendq[i].sq_submit_stat, "");
sendq[i].sq_pri--;
count++;
}
return count;
}
int Countsendq(SEND_Q *sendq, int size )
{
int i =0;
int count =0;
for(i=0; i<size; i++)
{
if(sendq[i].sq_id<=0)
count++;
}
return count;
}
int Countresq(RES_Q *resq, int size )
{
int i =0;
int count =0;
for(i=0; i<size; i++)
{
if( strlen(resq[i].rq_submit_id) ==0)
count++;
}
return count;
}
int Countunsend(SEND_Q *sendq)
{
int i =0;
int count =0;
for(i=0; i<memsend; i++)
{
if(sendq[i].sq_id>0 && (strlen(sendq[i].sq_submit_stat) ==0) )
count++;
}
return count;
}
/*把待发数据放入buffer*/
int CopyToBuffer(SEND_Q *map, int num, SEND_Q temp)
{
int k = 0;
k = FindPlace(map, memsend);
if(k >= 0) //有位置可以放
{
pthread_mutex_lock(&sendq_lock[num]);
memcpy(&map[k], &temp, sizeof(SEND_Q));
map[k].intime = time(NULL);
pthread_mutex_unlock(&sendq_lock[num]);
}
if(k < 0) //MAP队列满
{
INFO("[FUNCTION-CopyToBuffer] send buffer[%d] full \n", num);
return -1;
}
return 0;
}
int AllocateData( MYSQL_RES *result, char *deleteids)
{
MYSQL_ROW row;
SEND_Q send_tmp;
int num =0, allrow=0;
int ii =0,ret=0;
allrow = mysql_num_rows(result);
while( ( row = mysql_fetch_row(result) )!=NULL)
{
send_tmp.length_pi = atoi(row[34]);
send_tmp.length_mi = atoi(row[35]);
send_tmp.sq_sms_length = atoi(row[36]);
copy_send_q(&send_tmp, row);
strncpy(send_tmp.sq_reg_gateway,send_tmp.sq_send, sizeof(send_tmp.sq_reg_gateway) );
send_tmp.sq_reg_gateway[sizeof(send_tmp.sq_reg_gateway) -1] ='\0';
ret = CopyToBuffer(SENDQ[ii],ii, send_tmp);
while(ret == -1)
{
if(ii == connections-1)
ii =0;
else
ii++;
ret = CopyToBuffer(SENDQ[ii],ii, send_tmp);
}
ii++;
if( ii== connections)
ii =0;
if(num ==0)
strcpy(deleteids,row[0]);
else
strcat(deleteids,row[0]);
if(num < allrow-1)
{
strcat(deleteids, ",");
}
num ++;
}
INFO("[INFO-MAIN]: Deleteid [%s]\n", deleteids);
return 0;
}
static int config(unsigned char *file)
{
char cfgfile[256];
sprintf(cfgfile, "%s", file);
if (init_conf(cfgfile) != 0) {
INFO("[-ERR]: init_conf: failed\n");
return (-1);
}
if (get_value_uchar(CNGP_IP, sizeof(CNGP_IP)-1, "CNGP_IP") != 0) goto CFGERR;
if (get_value_uchar(LOGIN_NAME, sizeof(LOGIN_NAME)-1, "LOGIN_NAME") != 0) goto CFGERR;
if (get_value_uchar(LOGIN_PASSWORD, sizeof(LOGIN_PASSWORD)-1, "LOGIN_PASSWORD") != 0) goto CFGERR;
if (get_value_uint32(&CNGP_FLAG, "CNGP_FLAG") != 0) goto CFGERR;
get_value_uint32(&RECV_DEL106_FLAG, "RECV_DEL106_FLAG");
if( get_value_uchar(province, sizeof(province)-1,"PROVINCE") !=0) goto CFGERR;
if(get_value_uint32(&connecttype, "CONNECTTYPE") !=0) goto CFGERR;
if( connecttype == 0)// mt、mo 公用socket链接
{
if(get_value_int32(&port,"PORT") !=0) goto CFGERR;
if(get_value_int32(&send_version, "SEND_VERSION")!=0) goto CFGERR;
if(get_value_int32(&login_mode, "LOGIN_MODE")!=0) goto CFGERR;
if(get_value_int32(&connnum, "CONNNUM")!=0) goto CFGERR;
if(connnum > MAXCNN)
goto CFGERR;
}
else if(connecttype == 1)// mt、mo分别建立链接
{
if(get_value_int32(&mtnum, "MTNUM")!=0) goto CFGERR;
if(get_value_int32(&mtport, "MTPORT")!=0) goto CFGERR;
if(get_value_int32(&mtmode,"MTMODE")!=0) goto CFGERR;
if(get_value_int32(&mtversion, "MTVERSION")!=0) goto CFGERR;
if(get_value_int32(&monum, "MONUM")!=0) goto CFGERR;
if(get_value_int32(&moport, "MOPORT")!=0) goto CFGERR;
if(get_value_int32(&momode,"MOMODE")!=0) goto CFGERR;
if(get_value_int32(&moversion, "MOVERSION")!=0) goto CFGERR;
if(mtnum>MAXCNN ||monum >MAXCNN)
goto CFGERR;
}
else
goto CFGERR;
// database config
if (get_value_uchar(send_q_db, sizeof(send_q_db)-1, "SEND_Q_DB") != 0) goto CFGERR;
if (get_value_uchar(send_q_host, sizeof(send_q_host)-1, "SEND_Q_HOST") != 0) goto CFGERR;
if (get_value_uchar(send_q_user, sizeof(send_q_user)-1, "SEND_Q_USER") != 0) goto CFGERR;
if (get_value_uchar(send_q_pass, sizeof(send_q_pass)-1, "SEND_Q_PASS") != 0) goto CFGERR;
if (get_value_int32(&send_q_port, "SEND_Q_PORT") != 0) goto CFGERR;
// 2SP
if (get_value_uchar(media_db, sizeof(media_db)-1, "MEDIA_DB") != 0) goto CFGERR;
if (get_value_uchar(media_host, sizeof(media_host)-1, "MEDIA_HOST") != 0) goto CFGERR;
if (get_value_uchar(media_user, sizeof(media_user)-1, "MEDIA_USER") != 0) goto CFGERR;
if (get_value_uchar(media_pass, sizeof(media_pass)-1, "MEDIA_PASS") != 0) goto CFGERR;
if (get_value_int32(&media_port, "MEDIA_PORT") != 0) goto CFGERR;
// For gateway argument
if (get_value_uchar(servicemedia_db, sizeof(servicemedia_db)-1, "SERVICEMEDIA_DB") != 0) goto CFGERR;
if (get_value_uchar(servicemedia_host, sizeof(servicemedia_host)-1, "SERVICEMEDIA_HOST") != 0) goto CFGERR;
if (get_value_uchar(servicemedia_user, sizeof(servicemedia_user)-1, "SERVICEMEDIA_USER") != 0) goto CFGERR;
if (get_value_uchar(servicemedia_pass, sizeof(servicemedia_pass)-1, "SERVICEMEDIA_PASS") != 0) goto CFGERR;
if (get_value_int32(&servicemedia_port, "SERVICEMEDIA_PORT") != 0) goto CFGERR;
if (get_value_uint32(&retry_num, "RETRY_NUM") != 0) goto CFGERR;
if (get_value_uint32(&MAX_MSG_LEN, "MAX_MSG_LEN") != 0) goto CFGERR;
if(get_value_uint32(&altq_num, "FLOW_NUM")!=0) goto CFGERR;
if(get_value_uint32(&active_time, "ACTIVE_TIME")!=0) goto CFGERR;
if(get_value_uint32(&resnum, "RESNUM")!=0) goto CFGERR;
if(get_value_uint32(&memsend, "MEMSEND")!=0) goto CFGERR;
if(get_value_uint32(&reportnum, "REPORTNUM")!=0) goto CFGERR;
if(get_value_uint32(&socketbuffersize, "SOCKETBUFFER") !=0) goto CFGERR;
if(get_value_uint32(&reporttime, "REPORTTIME")!=0) goto CFGERR;
if(get_value_uchar(logfile, sizeof(logfile) -1 , "LOG_FILE")!=0) goto CFGERR;
if(get_value_uint32(&timeoutu, "TIMEOUTSOCKET")!=0) goto CFGERR;
if (get_value_uint32(&timeout_no_submit_resp, "TIMEOUT_NO_SUBMIT_RESP") != 0) goto CFGERR;
if (get_value_uchar(gateway_name, sizeof(gateway_name)-1, "GATEWAY_NAME") != 0) goto CFGERR;
if (get_value_int32(&feecode_flag, "FEECODE_FLAG") != 0) goto CFGERR;
if (get_value_int32(&report_flag, "REPORT_FLAG") != 0) goto CFGERR;
if (get_value_uchar(ISMP_SERVICE_CODE, sizeof(ISMP_SERVICE_CODE)-1, "ISMP_SERVICE_CODE") != 0) goto CFGERR;
if(get_value_uchar(SSMP_SERVICE_CODE, sizeof(SSMP_SERVICE_CODE)-1 , "SSMP")!=0) goto CFGERR;
if (get_value_uint32(&Priority,"PRIORITY") !=0) goto CFGERR;
if (get_value_uint32(&S_MFXX.SubType, "MFXX.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_MFXX.FeeType, sizeof(S_MFXX.FeeType)-1, "MFXX.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_MFXX.FeeUserType, "MFXX.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_DBXF.SubType, "DBXF.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_DBXF.FeeType, sizeof(S_DBXF.FeeType)-1, "DBXF.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_DBXF.FeeUserType, "DBXF.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_DYJG.SubType, "DYJG.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_DYJG.FeeType, sizeof(S_DYJG.FeeType)-1, "DYJG.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_DYJG.FeeUserType, "DYJG.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_QXDY.SubType, "QXDY.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_QXDY.FeeType, sizeof(S_QXDY.FeeType)-1, "QXDY.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_QXDY.FeeUserType, "QXDY.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_BYHD.SubType, "BYHD.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_BYHD.FeeType, sizeof(S_BYHD.FeeType)-1, "BYHD.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_BYHD.FeeUserType, "BYHD.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_BYXX.SubType, "BYXX.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_BYXX.FeeType, sizeof(S_BYXX.FeeType)-1, "BYXX.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_BYXX.FeeUserType, "BYXX.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_ATXF.SubType, "ATXF.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_ATXF.FeeType, sizeof(S_ATXF.FeeType)-1, "ATXF.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_ATXF.FeeUserType, "ATXF.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_ZXDX.SubType, "ZXDX.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_ZXDX.FeeType, sizeof(S_ZXDX.FeeType)-1, "ZXDX.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_ZXDX.FeeUserType, "ZXDX.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_QBTD.SubType, "QBTD.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_QBTD.FeeType, sizeof(S_QBTD.FeeType)-1, "QBTD.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_QBTD.FeeUserType, "QBTD.FEEUSERTYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_ECQR.SubType, "ECQR.SUBTYPE") != 0) goto CFGERR;
if (get_value_uchar(S_ECQR.FeeType, sizeof(S_ECQR.FeeType)-1, "ECQR.FEETYPE") != 0) goto CFGERR;
if (get_value_uint32(&S_ECQR.FeeUserType, "ECQR.FEEUSERTYPE") != 0) goto CFGERR;
close_conf();
return (0);
CFGERR:
close_conf();
return (-1);
}
static int ConnectISMG(char *host, int port, char *name, char *password, unsigned long seqnum, int loginmode, int sendversion, pthread_t threadnums)
{
int res = 1;
int socket_fd =0;
INFO("[INFO-RECV:%u]:Trying Server ( %s : %d)\n", threadnums, host, port);
res = ISMG_Connect(&socket_fd, host, port);
INFO("[INFO-RECV:%u]: res:%d socket_fd:%d\n", threadnums, res, socket_fd );
if (res != 0)
{
close(socket_fd);
return -1;
}
if (CNGP_Login(socket_fd, name, password, loginmode, sendversion,seqnum)!= 0)
{
close(socket_fd);
return -1;
}
return socket_fd;
}
int Dumptosendsmc(MYSQL_RES *Result, char *deletequery, char *deleteids)
{
MYSQL_ROW row;
int allrow =0;
char content[1024]="";
char query_string[1024]="";
char send_smc[128];
time_t t;
struct tm *time_buf;
char now_date[32];
int n=0;
t = time(NULL);
time_buf = localtime(&t);
memset(now_date, 0, sizeof(now_date));
sprintf(now_date, "%04d%02d%02d", time_buf->tm_year+1900, time_buf->tm_mon+1, time_buf->tm_mday);
memset(send_smc, 0, sizeof(send_smc));
sprintf(send_smc, "send_smc_%s", now_date);
strcat(deletequery, send_smc);
strcat(deletequery, " values ");
allrow = mysql_num_rows(Result);
while( ( row = mysql_fetch_row(Result) )!=NULL)
{
mysql_escape_string(content, row[7], strlen(row[7]) ) ;
sprintf(query_string, " ('", send_q_db, send_smc);
strcat(query_string, row[1]); // ss_service_code
strcat(query_string, "','");
strcat(query_string, row[11]); // ss_mobile
strcat(query_string, "',now(),'"); // ss_date
strcat(query_string, row[17]); // ss_provider
strcat(query_string, "','");
strcat(query_string, row[5]); // ss_fee_code
strcat(query_string,"','");
strcat(query_string,row[23]);//ss_submit_time
strcat(query_string,"',");
strcat(query_string,row[2]);//ss_num
strcat(query_string,",'");
strcat(query_string,"fail");
strcat(query_string,"','");
strcat(query_string,row[25]); //ss_jf_code
strcat(query_string,"', '0', '");
strcat(query_string,row[26]); //ss_product_name
strcat(query_string,"','");
strcat(query_string,row[27]); //ss_zone_province
strcat(query_string,"','");
strcat(query_string,row[28]); //ss_zone_city
strcat(query_string,"','");
strcat(query_string,row[29]); //ss_from
strcat(query_string,"','");
strcat(query_string,row[31]); //ss_reg_cmd
strcat(query_string,"','");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -