*
程序名称:recordresend.c
程序内容:话单预警机制话单重发模块
程序作者:周继国
版权所有:上海新动信息有限公司
cc recordresend.c -I/usr/local/include/mysql -lmysqlclient -L/usr/local/lib/mysql -o recordresend
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <mysql.h>
#include <mysqld_error.h>
#include <my_config.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <unistd.h>
#include <time.h>
#include <md5.h>
#include <stdarg.h>
//#include <signal.h>
//定义配置数据类型
struct INITDATA
{
char sLogHostName[256];
char sLogDBName[256];
char sLogDBUserName[256];
char sLogDBPassWord[256];
char sLogTableName[256];
char sResendHostName[256];
char sResendDBName[256];
char sResendDBUserName[256];
char sResendDBPassword[256];
char sResendTable[256];
char sServiceCode[256];
char sProvider[256];
char sSender[256];
char sState[256];
};
int GetMonthAndDay(MYSQL mysql,char *mobile_date)
{
MYSQL_RES *result;
char query_string[1024];
MYSQL_ROW row;
int num_row;
strcpy(query_string,"select DATE_FORMAT(now(),'%Y-%m')");
mysql_real_query(&mysql,query_string,strlen(query_string));
result = mysql_store_result(&mysql);
row = mysql_fetch_row(result);
strcpy(mobile_date,row[0]);
mysql_free_result(result);
return 0;
}
void CurTimeF(char* sTime)
{
time_t t;
struct tm* tm_buf;
t = time(0);
tm_buf = localtime(&t);
sprintf(sTime, "%02d:%02d:%02d",tm_buf->tm_hour,tm_buf->tm_min,tm_buf->tm_sec);
}
/************
Name : PubAlltrimStr()
Paras : char *str
Usage : delete the character that you not see.
Return : char *
************/
char* PubAlltrimStr( char *str )
{
int len;
int i;
char *s;
char filterchars[8];
bzero(filterchars, sizeof(filterchars));
strcpy(filterchars, " \t\r\n");
len = strlen(str);
for(i = len-1; i >= 0; i--)
{
if( strchr((char*)filterchars, str[i]) == NULL )
{
str[i+1] = '';
break;
}
}
s = str;
for(i = 0; i < len; i++)
{
if( strchr((char*)filterchars, *s) != NULL )
{
s++;
}
else
{
break;
}
}
if(s != str)
memmove(str, s, strlen(s) + 1);
return str;
}
/************
Name : PubReadCfg()
Paras : char *filename,char *option,int flag, flag > 0;
Usage : get the option from the config file
Return : int . 0 successfully,1 have the option in the config file but no configured ,
-100 can not open configure file, -1 not found
***********/
int PubReadCfg(char *filename, char *option, int flag)
{
char str[255+1];
char *fret;
int i=0;
int ret=-1;
int isequl=0;
int count=0;
char head[254];
char tail[254];
FILE *fp;
int len_str;
fp = fopen(filename, "r");
if (fp == NULL)
{
printf("\nCan not open %s!\n", filename);
return -100;
}
while(1)
{
memset(str, '', sizeof(str));
memset(head, '', sizeof(head));
memset(tail, '', sizeof(tail));
fret = fgets(str, 255, fp);
if(fret == NULL)
break;
if( strlen(str) >= 255 )
{
printf(" %s: fromat error!\n",filename);
break;
}
len_str = strlen(str);
for(i=0; i<len_str; i++)
{
if (str[i] == '=')
break;
}
if(i >= len_str - 1)
{
continue;
}
strncpy(tail, str+i+1, strlen(str)-i-1);
if(strlen(tail) != 0)
{
memset(&str[i], '', strlen(tail));
}
else
{
memset(&str[i], '', 1);
}
PubAlltrimStr(&str[0]);
strcpy(head, &str[0]);
PubAlltrimStr(option);
isequl=strcmp(option, head);
if (isequl != 0)