init ems server code

This commit is contained in:
2024-09-27 15:39:34 +08:00
parent 9d4009aaca
commit 9930e4e58f
1551 changed files with 110216 additions and 102864 deletions

View File

@@ -0,0 +1,90 @@
#/bin/sh
# Makefile for CDR Module.
CC = gcc
CFLAGS=-g -Wall -I/usr/local/mysql/include
CFLAGS.ES=-g -Wall -I/usr/include/mariadb
COMPILE.c=$(CC) $(CFLAGS)
COMPILE.c.ES=$(CC) $(CFLAGS.ES)
LINK.c=$(CC) $(CFLAGS)
LINK.c.ES=$(CC) $(CFLAGS.ES)
LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L../../../../wxc2plat/snmp -lsnmp \
-L../../../../wxc2plat/debug -ldebug \
-L../../../../wxc2plat/iptrans -liptrans \
-L../../../../wxc2plat/public -lpublic \
-L/usr/local/mysql/lib -lmariadbclient -lz
LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lz
PROGS=cdrCollector
CDR_OBJ = cdr.o cdrdb.o
CDR_OBJ.ES = cdr.o.ES cdrdb.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files(*.o, *.a)"
@echo "make linux72 -- Generate target files for Redhat Linux 7.2"
@echo "make linuxES -- Generate target files for Redhat ES 4.0"
linux72: $(CDR_OBJ) cdrmain.o
@cd ../../../omcLib/c_program/ftp; make linux72; cd ..
@cd ../../../accountMgr/c_program/cdrCollector;
@echo Linking $(PROGS)
@$(LINK.c) -o $(PROGS) cdrmain.o $(CDR_OBJ) $(LINKFLAG) -lm
ar r libcdr.a $(CDR_OBJ)
rm -rf *.o
rm -rf *bak
rm -rf *~
cp -f $(PROGS) ../../../bin
cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(CDR_OBJ.ES) cdrmain.o.ES
@cd ../../../omcLib/c_program/ftp; make linuxES; cd ..
@cd ../../../accountMgr/c_program/cdrCollector;
@echo Linking $(PROGS)
@$(LINK.c.ES) -o $(PROGS) cdrmain.o $(CDR_OBJ) $(LINKFLAG.ES) -lm
ar r libcdr.a $(CDR_OBJ)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
cdrmain.o: cdrmain.c
$(COMPILE.c) -c cdrmain.c
cdr.o: cdr.c cdr.h
$(COMPILE.c) -c cdr.c
cdrmain.o.ES: cdrmain.c
$(COMPILE.c.ES) -c cdrmain.c
cdr.o.ES: cdr.c cdr.h
$(COMPILE.c.ES) -c cdr.c
cdrdb.o.ES: cdrdb.c
$(COMPILE.c.ES) -c cdrdb.c
clean:
rm -f *.o *.a $(PROGS)
@cd ../../../omcLib/c_program/ftp; rm -f *.o *.a; cd ..
@cd ../../../accountMgr/c_program/cdrCollector;rm -f *.o *.a; cd ..

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,145 @@
#ifndef __CDR_HEAD_FILE
#define __CDR_HEAD_FILE
#include "mysql.h"
#include "errmsg.h"
#include <dirent.h>
#include "../../../../plat/public/src/include/asn1.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned int DWORD;
#endif
/* Added for show version by Simon
* --Begin
*/
#define CDRCOLLECTOR_VERSION "1.2311.15"
/* --End
*
*/
#define CDR_DEBUG 0
#define MAX_CDR_PTR 0x7FFFFFFF
#define CDR_PORT 4968
#define MAX_TAG_VALUE 32
#define MAX_FLD_NUM 128
#define MAX_PROCESS_CDR_NUM 256
#define MAX_SNMP_MSG_NUM 64
#define MAX_BIND_VAR_NUM 16
#define MAX_SRC_NUM 32
#define MAX_SYS_NUM 128
#define MAX_SQL_COMM_NUM 256
#define MAX_RETRY 300
#define MAX_MSG_TIMEOUT 20
#define MAX_IDLE_TIMEOUT 5
#define INSTANT_TIMEOUT -1
#define HOST_NAME "localhost"
#define CDRDB_NAME "CDR_DB"
#define CSV_PATH "/usr/local/cdr"
#define CDR_LOG_PATH "../log"
#define CDR_LOG_FILE "cdrlog"
#define OMC_SINGLE 7
#define OMC_MASTER 5
#define STATE_IDLE 0
#define STATE_INFO_GET 1
#define STATE_INFO_RESPONSE 2
#define STATE_CDR_GET 3
#define STATE_CDR_RESPONSE 4
#define STATE_TAIL_SET 5
#define STATE_TAIL_RESPONSE 6
#define STATE_RESET_SET 7
#define STATE_RESET_RESPONSE 8
void cdr_timer();
void cdr_init();
typedef struct field_def
{
char fieldName[64];
char type;
char optional;
int width;
char tags[MAX_TAG_VALUE][24];
char tagFlag[MAX_TAG_VALUE];
}field_def;
typedef struct cdr_def
{
char tags[MAX_TAG_VALUE];
char allFieldList[8192];
char outFieldList[8192];
int fieldCount;
field_def fields[MAX_FLD_NUM];
}cdr_def;
typedef struct cdr_src
{
char dataPotOid[128];
char headPotOid[128];
char tailPotOid[128];
DWORD dataOid[32];
DWORD headOid[32];
DWORD tailOid[32];
BYTE dataOidLen;
BYTE headOidLen;
BYTE tailOidLen;
int bufferSize;
int sysTypeNo;
int port;
char recordTable[64];
char defineTable[64];
char csvPath[128];
int version;
cdr_def define;
}cdr_src;
typedef struct cdr_sys
{
int cdrSrcNo;
int sysTypeNo;
int sysNo;
int subSysNo;
char ip[24];
snmp_addr addr;
DWORD requestId;
int timeout;
int retry;
DWORD head;
DWORD tail;
DWORD tmptail;
int prepareSetTail;
int isVarTooBig;
int maxVarNum;
int state;
int processNum;
int error;
}cdr_sys;
typedef struct msg
{
snmp_pdu pdu;
unsigned char use;
int timeout;
}msg;
typedef struct sql_comm_buf
{
char sqlstr[MAX_SQL_COMM_NUM][8192];
int commNum;
}sql_comm_buf;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,132 @@
/*************************************************
File name: cdr.c
Author:
Version: 9:00:00
Date: 2002-5-7
Description:cdrCollectorģ<72><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>snmp<6D><70>iptransģ<73><EFBFBD><E9A3AC><EFBFBD><EFBFBD>cdr.c<><63><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
<09><><EFBFBD>嶨ʱ<E5B6A8><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>ʱ
<09><><EFBFBD><EFBFBD><EFBFBD>ⲿģ<E2B2BF><C4A3><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
void snmp_init(WORD nport);
void iptrans_init();
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include "cdr.h"
static struct itimerval itimer, old_itimer;
static void On_Timer();
static void SetTimer();
/*************************************************
Function: // main
Description: // <20><>ʼ<EFBFBD><CABC>snmp<6D><70>iptransģ<73><C4A3>,<2C><>ʼ<EFBFBD><CABC><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // iptrans_init; snmp_init;
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
int main(int argc, char *argv[])
{
pid_t pid;
/* Added to show version by Simon
* --Begin
*/
if (argc == 2 && strstr(argv[1], "-v")) {
fprintf(stdout, "%s version: %s \n", argv[0], CDRCOLLECTOR_VERSION);
exit(0);
}
/* --End
*
*/
debug_init();
fprintf(stderr, "\n Calling iptrans_init()");
iptrans_init();
fprintf(stderr, "\n Calling snmp_init()");
snmp_init(CDR_PORT);
if (argc == 2 && strstr(argv[1], "-d")) {
if ((pid = fork()) != 0)
exit(0);
setsid();
//umask(0);
}
cdr_init();
//cdr_start();
SetTimer();
while (1) {
//cdr_loop();
usleep(50);
}
return 1;
}
/*************************************************
Function: // On_Timer
Description: // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // cdr_timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void On_Timer()
{
//debug_rt();
//snmp_timer();
cdr_timer();
}
/*************************************************
Function: // SetTimer
Description: // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // On_Timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void SetTimer()
{
struct sigaction act;
act.sa_handler = On_Timer;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGALRM, &act, NULL) < 0) {
perror("Produce Sigaction");
exitLog("cdrCollector:SetTimer, sigaction function error");
exit(1);
}
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 10 * 1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 10 * 1000;
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
printf("Setting Timer error! \n");
exitLog("cdrCollector:SetTimer, setitimer function error");
exit(1);
}
}

View File

@@ -0,0 +1,29 @@
CREATE TABLE IF NOT EXISTS CDR_DB.cdrFromPPS_18 (
key_sys_id tinyint(2) DEFAULT '0' NOT NULL,
instance int(4) DEFAULT '0' NOT NULL,
recordType int(2),
callType int(2),
servedIMSI varchar(20),
servedMSISDN varchar(20),
callingNumber varchar(20),
calledNumber varchar(20),
recordingEntity varchar(20),
mscIncomingTKGP varchar(20),
mscOutgoingTKGP varchar(20),
locationAreaCode int(4),
cellId varchar(4),
seizureTime datetime,
answerTime datetime,
releaseTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
callDuration int(4),
causeForTerm int(4),
callReference int(4),
charge int(4),
balance int(4),
gprs_sgsn_ip varchar(16),
gprs_ggsn_ip varchar(16),
gprs_dest_ip varchar(16),
gprs_volume int(10),
srcCode text,
PRIMARY KEY (key_sys_id, instance, releaseTime)
);

View File

@@ -0,0 +1,77 @@
#/bin/sh
CC = gcc
CFLAGS=-g -Wall -I/usr/local/mysql/include
CFLAGS.ES=-g -Wall -I/usr/include/mariadb
COMPILE.c=$(CC) $(CFLAGS)
COMPILE.c.ES=$(CC) $(CFLAGS.ES)
LINK.c=$(CC) $(CFLAGS)
LINK.c.ES=$(CC) $(CFLAGS.ES)
LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L/usr/local/mysql/lib -lmariadbclient -lz
LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lz \
PROGS=ftpSend
FTPSEND_OBJ = ftpsend.o
FTPSEND_OBJ.ES = ftpsend.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files"
@echo "make linux72 -- Generate target files for Redhat Linux 72"
@echo "make linuxES -- Generate target files for Redhat Linux ES"
linux72: $(FTPSEND_OBJ)
@cd ../../../omcLib/c_program/ftp; make linux72; cd ..
@cd ../../../accountMgr/c_program/ftpsend;
@echo Linking $(PROGS)
@$(LINK.c) -o $(PROGS) $(FTPSEND_OBJ) $(LINKFLAG) -lm
ar r libftpsend.a $(FTPSEND_OBJ)
# rm -rf *.o
# rm -rf *bak
# rm -rf *~
# cp -f $(PROGS) ../../../bin
# cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(FTPSEND_OBJ.ES)
@cd ../../../omcLib/c_program/ftp; make linuxES; cd ..
@cd ../../../accountMgr/c_program/ftpsend;
@echo Linking $(PROGS)
@$(LINK.c.ES) -o $(PROGS) $(FTPSEND_OBJ) $(LINKFLAG.ES) -lm
ar r libftpsend.a $(FTPSEND_OBJ)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
ftpsend.o:ftpsend.c
$(COMPILE.c) -c ftpsend.c
ftpsend.o.ES:ftpsend.c
$(COMPILE.c.ES) -c ftpsend.c
clean:
rm -f *.o *.a $(PROGS)
@cd ../../../omcLib/c_program/ftp; rm -f *.o *.a; cd ..
@cd ../../../accountMgr/c_program/ftpsend; rm -f *.o *.a; cd ..

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
#ifndef ftpsend_H_
#define ftpsend_H_
#include <sys/time.h>
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#define MAX_FILE_TRANSFER_NUM 32
#define WAIT_TIME 60
#define INFO_UPDATE_TIME 60
/* The information of the file transfer object */
typedef struct FileTransfer
{
char srcDir[128];
char dstDir[128];
char dstIP[16];
char filter[16];
char logName[32];
char logPass[32];
int curFileIndex;
int waitTime;
}FileTransfer;
#endif

View File

@@ -0,0 +1,8 @@
#!/bin/bash
make clean
sleep 1
make linuxES
sleep 1
./ftpSend

View File

@@ -0,0 +1,54 @@
#/bin/bash
CC=gcc
CFLAGS=-g -Wall -I/usr/include/mariadb
PROGS=nrtrde
LINK.c=$(CC) $(CFLAGS)
LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lz \
NRTRDE_OBJ=nrtrde.o decodeASN.o encodeASN.o conv_prefix.o seq_num_mng.o
default: linuxES
all:
@echo "make clean -- Delete the target files"
@echo "make linuxES -- Generate target files for Redhat Linux ES"
linuxES: $(NRTRDE_OBJ)
@$(LINK.c) -o $(PROGS) $(NRTRDE_OBJ) $(LINKFLAG) -lm
ar r libnrtrde.a nrtrde.o decodeASN.o encodeASN.o conv_prefix.o seq_num_mng.o
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
nrtrde.o: nrtrde.c
$(LINK.c) -c nrtrde.c
decodeASN.o: decodeASN.c
$(LINK.c) -c decodeASN.c
encodeASN.o: encodeASN.c
${LINK.c} -c encodeASN.c
conv_prefix.o: conv_prefix.c
${LINK.c} -c conv_prefix.c
seq_num_mng.o: seq_num_mng.c
${LINK.c} -c seq_num_mng.c
clean:
rm -rf *.o *.a $(PROGS)

View File

@@ -0,0 +1,45 @@
# NR.conf
# The local mcc
MCC=262
# The local mnc
MNC=09
# The local tag
LOCAL_TADIG=FEAKE
# The time to make NRTRDE Delivery Report and Error Report
MAKE_REPORT_TIME=23
# The max value of CallEventDuration of a CDR
CallEventDurationMax=6000
# The version of the NRTRDE Delivery report
ND_VERSION=1.0
# The version of the NRTRDE Error report
NE_VERSION=1.0
# The specificationVersionNumber of the NRTRDE file
NR_SVN=2
# The ReleaseVersionNumber of the NRTRDE file
NR_RVN=1
# The backup directory
NR_RECV_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NR_RECV_BAK/
NR_SEND_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NR_SEND_BAK/
ND_RECV_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/ND_RECV_BAK/
ND_SEND_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/ND_SEND_BAK/
NE_RECV_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NE_RECV_BAK/
NE_SEND_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NE_SEND_BAK/
LOCAL_CSV_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/LOCAL_CSV/
# The source directory to send the file
SEND_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/SEND/
# The directory to receive the file
RECV_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/RECV/

View File

@@ -0,0 +1,148 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "conv_prefix.h"
_conv_prefix conv_prefix;
/*------------------------------------------------------------------*/
int readConvPrefixConf()
{
char filename[]="./conf/conv_prefix.conf";
FILE *fpConf = NULL;
int i;
fpConf = fopen(filename,"r");
if(fpConf == NULL) return 0;
fread(&conv_prefix,sizeof(_conv_prefix),1,fpConf);
fclose(fpConf);
for(i=0;i<MAX_CONV_PREFIX;i++)
{
if(strlen(conv_prefix.conv_prefix[i].prefix))
conv_prefix.conv_prefix[i].used_flag = 1;
else
conv_prefix.conv_prefix[i].used_flag = 0;
if(strlen(conv_prefix.group_conv_prefix[i].startNumber))
conv_prefix.group_conv_prefix[i].used_flag = 1;
else
conv_prefix.group_conv_prefix[i].used_flag = 0;
}
for(i=0;i<MAX_CLI_PREFIX;i++)
{
if(strlen(conv_prefix.cli_prefix[i].prefix))
conv_prefix.cli_prefix[i].used_flag = 1;
else
conv_prefix.cli_prefix[i].used_flag = 0;
}
return 1;
}
int xappSearchGroupTable(char *msisdn_unk)
{
int loop=0;
for(loop=0;loop<MAX_CONV_PREFIX;loop++)
{
if(conv_prefix.group_conv_prefix[loop].used_flag)
{
if((strcmp(msisdn_unk,conv_prefix.group_conv_prefix[loop].startNumber))>=0 &&
(strcmp(conv_prefix.group_conv_prefix[loop].endNumber,msisdn_unk))>=0)
return loop;
}
}
return -1;
}
int msisdnUnkToInt(char *msisdn_unk, char *msisdn_int)
/* return value:
-1 = error length;
0 = cannn't find appropriate prefix;
1 = conv. succeed
*/
{
int retval = 0, index = -1;
int loop,len=0,max_len=0,old_len;
int delete_len,add_len;
strcpy(msisdn_int,msisdn_unk);
index = xappSearchGroupTable(msisdn_unk);
if(index>=0)
{
char tmpStart[17],tmpEnd[17];
strcpy(tmpStart,msisdn_unk);
tmpStart[conv_prefix.group_conv_prefix[index].repStartDigit] = 0;
strcpy(tmpEnd,&msisdn_unk[conv_prefix.group_conv_prefix[index].repEndDigit]);
sprintf(msisdn_int,"%s%s%s",
tmpStart,
conv_prefix.group_conv_prefix[index].repDigitWith,
tmpEnd);
return 1;
}
for(loop=0;loop<MAX_CONV_PREFIX;loop++)
{
if(conv_prefix.conv_prefix[loop].used_flag)
{
len = strlen(conv_prefix.conv_prefix[loop].prefix);
if(len>0)
{
if(len>max_len)
if(strncasecmp(msisdn_unk,
conv_prefix.conv_prefix[loop].prefix,
len)==0)
{
max_len = len;
index = loop;
}//cmp
}//len>0
}//used
}
if(index>=0 && index<MAX_CONV_PREFIX)
{
len = strlen(msisdn_unk);
if(len>24) len = 24;
old_len = len;
if(conv_prefix.conv_prefix[index].valid_length>0)
{
if(len != conv_prefix.conv_prefix[index].valid_length)
{
strcpy(msisdn_int,msisdn_unk);
return -1;
}
}
delete_len = conv_prefix.conv_prefix[index].delete_length;
if(delete_len>len)
{
strcpy(msisdn_int,msisdn_unk);
return -1;
}
add_len = conv_prefix.conv_prefix[index].add_length;
if(add_len != strlen(conv_prefix.conv_prefix[index].add_digits))
{
strcpy(msisdn_int,msisdn_unk);
return -1;
}
strcpy(msisdn_int,
conv_prefix.conv_prefix[index].add_digits);
strcat(msisdn_int,
&msisdn_unk[delete_len]);
msisdn_int[add_len+old_len-delete_len] = 0;
retval = 1;
}
return retval;
}

View File

@@ -0,0 +1,66 @@
#ifndef _CONV_PREFIX_H
#define _CONV_PREFIX_H
#include <sys/types.h>
#define MAX_CONV_PREFIX 128
#define MAX_CLI_PREFIX 64
#define MAX_PREFIX_LEN 16
#define MAX_NAME_LEN 8
#define MAX_PLAT_NAME_LEN 24
#define MAX_PLAT_NAME_INSTANCE 256
typedef struct conv_prefix_record
{
u_char used_flag;
char prefix[MAX_PREFIX_LEN];
char delete_length;
char add_length;
char add_digits[MAX_PREFIX_LEN];
u_char valid_length;
}_conv_prefix_record;
typedef struct cli_prefix
{
u_char in_property;
char prefix[MAX_PREFIX_LEN];
char delete_length;
u_char out_property;
char add_length;
char add_digits[MAX_PREFIX_LEN-1];
u_char used_flag;
u_char valid_length;
}_cli_prefix;
typedef struct xapp_group_prefix
{
char startNumber[MAX_PREFIX_LEN+1];
char endNumber[MAX_PREFIX_LEN+1];
u_char repStartDigit;
u_char repEndDigit;
char repDigitWith[MAX_PREFIX_LEN+1];
u_char status; /* 0=unlock, 1=lock */
u_char used_flag;
char cReserved[MAX_PREFIX_LEN-1];
}_xapp_group_prefix;
typedef struct conv_prefix
{
_conv_prefix_record conv_prefix[MAX_CONV_PREFIX];
_cli_prefix cli_prefix[MAX_CLI_PREFIX];
char conv_name[MAX_CONV_PREFIX][MAX_NAME_LEN];
char cli_name[MAX_CLI_PREFIX][MAX_NAME_LEN];
char plat_name[MAX_PLAT_NAME_INSTANCE][MAX_PLAT_NAME_LEN];
_xapp_group_prefix group_conv_prefix[MAX_CONV_PREFIX];
}_conv_prefix;
int msisdnUnkToInt(char *msisdn_unk, char *msisdn_int);
/* return value:
-1 = error length;
0 = cannn't find appropriate prefix;
1 = conv. succeed
*/
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
#!/bin/bash
rm -rf *.log
rm -rf *.txt
rm -rf ./NR_SEND_BAK/
rm -rf ./NR_RECV_BAK/
rm -rf ./ND_SEND_BAK/
rm -rf ./ND_RECV_BAK/
rm -rf ./NE_SEND_BAK/
rm -rf ./NE_RECV_BAK/
rm -rf ./LOCAL_CSV/
rm -rf ./SEND/
rm -rf ./RECV/

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,130 @@
#ifndef nrtrde__H
#define nrtrde__H
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "./conv_prefix.h"
#include <sys/types.h>
#include <dirent.h>
#ifndef MYSQL_H
#include "mysql.h"
#endif
#ifndef NRTRDE_DEBUG
#define NRTRDE_DEBUG 0
#endif
/********************************************************/
/****** Constant Define ******/
/********************************************************/
/* The hpmn servers info update timeslot (Second) */
#define HPMN_INFO_UPDATE_TIME 60
/* The hpmn servers count which this version to support */
#define HPMN_SERVER_COUNT 100
/* The max time of the file backup (day) */
#define MAX_BAK_DAY 7
#define SEQ_NUM_CONF "./conf/nrtrde_seq.conf"
/* The return value of the function */
#define SUCCESSFUL 1
#define FAIL 0
#define NO_FIND 0x7FFFFFFF
/********************************************************/
/****** Struct Define ******/
/********************************************************/
/* The information of the hpmn servers */
typedef struct HpmnServer
{
char mcc[8]; //The mcc of the HPMN server
char mnc[8]; //The mnc of the HPMN server
char tadig[8]; //The tadig of the HPMN server, length=5
char serverIP[16]; //The remote IP address of the HPMN server, xxx.xxx.xxx.xxx
char loginName[64]; //The user name to login the remote HPMN server
char loginPass[64]; //The user password to login the remote HPMN server
int timeSlot; //The timeslot to send the nrtrde to the remote HPMN server
char reportDir[256]; //The directory to send the report files to the HPMN server
char nrtrdeDir[256]; //The directory to send the nrtrde files to the HPMN server
int sendFileTimeout; //When the value<0, then send the nrtrde file to remote HPMN server
}HpmnServer;
/* The config of the tag */
typedef struct TagNode
{
char fieldName[32]; //The field name of the tag
int tagValue; //The value of the tag, the tag is application
int isStructed; //Whether the tag is structed or not
int code; //How to code the field, 0-no code; 1-Integer; 2-Ascii; 3-HexString; 4-NumberString; 5-BCDString;
int minSize; //The min size of the field
int maxSize; //The max size of the field
}TagNode;
/* Use for link struct */
typedef struct DataNode
{
struct DataNode* next; //The next data link to the data
unsigned char data; //The data in the node
}DataNode;
/* Use for store the record of the NRTRDE Delivery report */
typedef struct NDRepNode
{
char tadig[8]; //The tadig of this record
char fileName[32]; //The fileName of this record
char recvTime[32]; //The time when to receive the file
struct NDRepNode* next; //The next node in the link
}NDRepNode;
/* Use for store the record of the NRTRDE Error report */
typedef struct NERepNode
{
char tadig[8]; //The tadig of this record
char fileName[32]; //The fileName of the received NRTRDE file which is parsed
int type; //The type of this record, 1-NRTRDE file error, 2-MOC error, 3-MTC error
int recordNumber; //The number of this record in the NRTRDE file
char errorCode[8]; //The error code of this record
struct NERepNode* next; //The next node in the link
}NERepNode;
/* Use for store the information of every CallEvents */
typedef struct CallEvent
{
int type; //1-MOC, 2-MTC, 3-GPRS
char imsi[32]; //Imsi
char imei[32]; //Imei
char startTime[32]; //CallEventStartTime
char utcTimeOff[32]; //utcTimeOffsef
long callDuration; //CallEventDuration
int causeForTerm; //CauseForTermination
char teleServCode[32]; //TeleServiceCode
char bearerServCode[32]; //BearerServCode
char supplServCode[32]; //SupplementaryServiceCode
char dialledDigits[32]; //DialledDigits
char connectedNumber[32]; //ConnectedNumber
char thirdPartyNumber[32]; //ThirdPartyNumber
char callingNumber[32]; //CallingNumber
char recEntityId[32]; //RecEntityId
long callReference; //CallReference
long chargeAmount; //ChargeAmount
}CallEvent;
typedef struct seq_object
{
char tadig[8];
unsigned long nr_seq_num;
unsigned long nd_seq_num;
unsigned long ne_seq_num;
}seq_object;
typedef struct seq_buffer
{
int count;
seq_object seq_obj[HPMN_SERVER_COUNT];
}seq_buffer;
#endif

View File

@@ -0,0 +1,204 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "nrtrde.h"
seq_buffer seq_buf;
int add_seq_obj(seq_buffer *seq_buf,seq_object *add_obj);
unsigned long find_seq_obj(seq_buffer *seq_buf,char *keyvalue);
int get_seq_num(char *tadig,int type,char *out_seq);
int init_seq();
int store_seq();
int add_seq_obj(seq_buffer *seq_buf,seq_object *add_obj)
{
int unitlen;
int low,high,mid,last;
char tmpvalue[24];
char keyfield[24];
seq_object tmp_seq_obj_list[HPMN_SERVER_COUNT];
if(seq_buf->count >= HPMN_SERVER_COUNT)
return 0;
unitlen=sizeof(seq_object);
mid=0;
low=0;
high=seq_buf->count-1;
memset(keyfield,0,sizeof(keyfield));
sprintf(keyfield,"%s",add_obj->tadig);
memset(tmpvalue,0,sizeof(tmpvalue));
memcpy(tmpvalue,seq_buf->seq_obj[high].tadig,8);
if(strcmp(keyfield,tmpvalue) == 0)
{
return 0;
}
else if(strcmp(keyfield,tmpvalue) > 0)
{
sprintf(seq_buf->seq_obj[seq_buf->count].tadig,"%s",keyfield);
seq_buf->seq_obj[seq_buf->count].nr_seq_num=add_obj->nr_seq_num;
seq_buf->seq_obj[seq_buf->count].nd_seq_num=add_obj->nd_seq_num;
seq_buf->seq_obj[seq_buf->count].ne_seq_num=add_obj->ne_seq_num;
}
else
{
while(low <= high)
{
mid=(low+high)/2;
memset(tmpvalue,0,sizeof(tmpvalue));
memcpy(tmpvalue,seq_buf->seq_obj[mid].tadig,8);
if(strcmp(keyfield,tmpvalue) == 0)
return 0;
else if(strcmp(keyfield,tmpvalue) < 0)
high=mid-1;
else
low=mid+1;
}
if(low > high)
last=low;
else
last=mid;
memcpy(tmp_seq_obj_list,seq_buf->seq_obj,sizeof(tmp_seq_obj_list));
memcpy(&seq_buf->seq_obj[last+1],&tmp_seq_obj_list[last],(HPMN_SERVER_COUNT-last-1)*unitlen);
sprintf(seq_buf->seq_obj[last].tadig,"%s",keyfield);
seq_buf->seq_obj[last].nr_seq_num=add_obj->nr_seq_num;
seq_buf->seq_obj[last].nd_seq_num=add_obj->nd_seq_num;
seq_buf->seq_obj[last].ne_seq_num=add_obj->ne_seq_num;
}
seq_buf->count++;
return 1;
}
/*
return NO_FIND:can not find
*/
unsigned long find_seq_obj(seq_buffer *seq_buf,char *keyvalue)
{
char tmpvalue[24];
char keyfield[24];
int low,high,mid;
mid=0;
low=0;
high=seq_buf->count-1;
memset(keyfield,0,sizeof(keyfield));
sprintf(keyfield,"%s",keyvalue);
memset(tmpvalue,0,sizeof(tmpvalue));
memcpy(tmpvalue,seq_buf->seq_obj[high].tadig,8);
if(strcmp(keyfield,tmpvalue) == 0)
return high;
else if(strcmp(keyfield,tmpvalue) > 0)
return NO_FIND;
else
{
while(low <= high)
{
mid=(low+high)/2;
memset(tmpvalue,0,sizeof(tmpvalue));
memcpy(tmpvalue,seq_buf->seq_obj[mid].tadig,8);
if(strcmp(keyfield,tmpvalue) == 0)
return mid;
else if(strcmp(keyfield,tmpvalue) < 0)
high=mid-1;
else
low=mid+1;
}
}
return NO_FIND;
}
int init_seq()
{
FILE *handle=NULL;
memset(&seq_buf,0,sizeof(seq_buf));
handle=fopen(SEQ_NUM_CONF,"r+");
if(handle == NULL)
{
FILE *tmpf;
tmpf=fopen(SEQ_NUM_CONF,"w+");
if(tmpf == NULL)
{
printf("Can not create the %s\n",SEQ_NUM_CONF);
exit(0);
}
fwrite(&seq_buf,sizeof(seq_buf),1,tmpf);
fclose(tmpf);
handle=fopen(SEQ_NUM_CONF,"r+");
}
fread(&seq_buf,sizeof(seq_buf),1,handle);
printf("Load sequence number conf from %s\n",SEQ_NUM_CONF);
fclose(handle);
return 1;
}
int store_seq()
{
FILE *handle=NULL;
handle=fopen(SEQ_NUM_CONF,"w+");
if(handle == NULL)
{
printf("Can not write the %s\n",SEQ_NUM_CONF);
exit(0);
}
fwrite(&seq_buf,sizeof(seq_buf),1,handle);
fclose(handle);
return 1;
}
//type:0-NR, 1-ND, 2-NE;
int get_seq_num(char *tadig,int type,char *out_seq)
{
unsigned long find_index;
find_index=find_seq_obj(&seq_buf,tadig);
if(find_index == NO_FIND)
{
if(type == 0)
sprintf(out_seq,"0000001");
else
sprintf(out_seq,"00001");
return 0;
}
if(type == 0)
{
if(seq_buf.seq_obj[find_index].nr_seq_num == 0)
seq_buf.seq_obj[find_index].nr_seq_num++;
sprintf(out_seq,"%07ld",seq_buf.seq_obj[find_index].nr_seq_num);
seq_buf.seq_obj[find_index].nr_seq_num++;
seq_buf.seq_obj[find_index].nr_seq_num%=10000000;
}
else if(type == 1)
{
if(seq_buf.seq_obj[find_index].nd_seq_num == 0)
seq_buf.seq_obj[find_index].nd_seq_num++;
sprintf(out_seq,"%05ld",seq_buf.seq_obj[find_index].nd_seq_num);
seq_buf.seq_obj[find_index].nd_seq_num++;
seq_buf.seq_obj[find_index].nd_seq_num%=100000;
}
else
{
if(seq_buf.seq_obj[find_index].ne_seq_num == 0)
seq_buf.seq_obj[find_index].ne_seq_num++;
sprintf(out_seq,"%05ld",seq_buf.seq_obj[find_index].ne_seq_num);
seq_buf.seq_obj[find_index].ne_seq_num++;
seq_buf.seq_obj[find_index].ne_seq_num%=100000;
}
store_seq();
return 1;
}

View File

@@ -0,0 +1,52 @@
#/bin/bash
CC=gcc
CFLAGS=-g -Wall -I/usr/include/mariadb
PROGS=sftpSend
LINK.c=$(CC) $(CFLAGS)
LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lz \
-L/usr/lib -lpthread -lz \
SFTPSEND_OBJ=sftpSend.o sftp.o
default: linuxES
all:
@echo "make clean -- Delete the target files"
@echo "make linuxES -- Generate target files for Redhat Linux ES"
linuxES: $(SFTPSEND_OBJ)
@$(LINK.c) -o $(PROGS) $(SFTPSEND_OBJ) $(LINKFLAG) -lm
ar r libsftpSend.a sftpSend.o sftp.o
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
cp -f parseResult ../../../../bin/
cp -f initKeys ../../../../bin/
cp -f sendfile ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
cp -f parseResult /usr/local/omc/bin/
cp -f initKeys /usr/local/omc/bin/
cp -f sendfile /usr/local/omc/bin/
installall: installbin installomc
sftpSend.o: sftpSend.c
$(LINK.c) -c sftpSend.c
sftp.o: sftp.c
$(LINK.c) -c sftp.c
clean:
rm -rf *.o *.a $(PROGS)

View File

@@ -0,0 +1,45 @@
# NR.conf
# The local mcc
MCC=262
# The local mnc
MNC=09
# The local tag
LOCAL_TADIG=FEAKE
# The time to make NRTRDE Delivery Report and Error Report
MAKE_REPORT_TIME=23
# The max value of CallEventDuration of a CDR
CallEventDurationMax=6000
# The version of the NRTRDE Delivery report
ND_VERSION=1.0
# The version of the NRTRDE Error report
NE_VERSION=1.0
# The specificationVersionNumber of the NRTRDE file
NR_SVN=2
# The ReleaseVersionNumber of the NRTRDE file
NR_RVN=1
# The backup directory
NR_RECV_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NR_RECV_BAK/
NR_SEND_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NR_SEND_BAK/
ND_RECV_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/ND_RECV_BAK/
ND_SEND_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/ND_SEND_BAK/
NE_RECV_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NE_RECV_BAK/
NE_SEND_BAK_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/NE_SEND_BAK/
LOCAL_CSV_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/LOCAL_CSV/
# The source directory to send the file
SEND_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/SEND/
# The directory to receive the file
RECV_DIR=/usr/local/omc/src/accountMgr/c_program/nrtrde/RECV/

View File

@@ -0,0 +1,4 @@
#!/bin/bash
rm -rf *.txt
rm -rf *.log

View File

@@ -0,0 +1,32 @@
#!/usr/bin/expect
#This script use to init the server keys, it rewrite the known_hosts config file
#This script have 3 parameters
#remoteip: the ip of the remote server
#username: the name for logging in
#userpass: the password for logging in
set remoteip [lindex $argv 0]
set username [lindex $argv 1]
set userpass [lindex $argv 2]
set timeout 5
spawn sftp $username@$remoteip
expect "*(yes/no)?*"
send "yes\n"
expect "*password*"
send "$userpass\n"
expect "*sftp>*"
send "quit\n"
expect eof
exit

View File

@@ -0,0 +1,31 @@
#!/bin/sh
#This script parse the result.txt file
#to judge whether the operation of sending file is successful
#The local do not have the Permission to access the remote directory
if [ `grep -c "handle" /tmp/result$1.txt` -gt 0 ] ; then
`echo 4 >/tmp/temp$1.txt`
#echo "The local do not have the Permission to access the remote directory"
exit
fi
#The name or the password is not fit
if [ `grep -c "Permission denied" /tmp/result$1.txt` -gt 0 ] ; then
`echo 2 >/tmp/temp$1.txt`
#echo "The name or the password is not fit"
exit
fi
#Successful
if [ `grep -c "100%" /tmp/result$1.txt` -gt 0 ] ; then
`echo 0 >/tmp/temp$1.txt`
#echo "Send the file successfully"
exit
fi
#The remote server is unavailable
`echo 1 >/tmp/temp$1.txt`
#echo "The remote server is unavailable"
exit

View File

@@ -0,0 +1,34 @@
#!/usr/bin/expect
#This script interative with the remote server, and send the file to it
#This script have 6 parameters
#remoteip: the ip of the remote server
#username: the name for logining in
#userpass: the password for logining in
#resdir: the directory to store the files
#sendfile: the file to send to the remote server
#desdir: the directory to send the files
set remoteip [lindex $argv 0]
set username [lindex $argv 1]
set userpass [lindex $argv 2]
set resdir [lindex $argv 3]
set sendfile [lindex $argv 4]
set desdir [lindex $argv 5]
set timeout 120
spawn sftp $username@$remoteip
expect "yes/no" {send "yes\n"; expect "*assword: "} "*assword: "
send "$userpass\n"
expect "*sftp>*"
send "cd $desdir\n"
send "lcd $resdir\n"
send "put $sendfile\n"
expect "*100%*"
exit

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,127 @@
/*************************************************
File name:sftp.h
Author: JianHui Zheng
Version: 9:00:00
Date: 2007-10-9
Description:sftp.c<><63>ͷ<EFBFBD>ļ<EFBFBD>
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#ifndef _SFTP_SEND_H_
#define _SFTP_SEND_H_
#include <pthread.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <memory.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/time.h>
#include <time.h>
#include <net/if.h>
#include <syslog.h>
#include <termio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <syslog.h>
#include <sys/io.h>
#include <error.h>
#include <dirent.h>
#include <sys/types.h>
#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned int DWORD;
#endif
#include "mysql.h"
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/snmp/src/include/snmp.h"
/********************************************************/
/****** Constant Define ******/
/********************************************************/
/* The hpmn servers info update timeslot (Second) */
#define HPMN_INFO_UPDATE_TIME 60
/* The hpmn servers count which this version to support */
#define HPMN_SERVER_COUNT 100
/* Wait time when the server send file fail */
#define WAIT_TIME 10
/* The max number of thread */
#define MAX_THREAD_NUM 8
#define MAX_FAIL_TIMEOUT 300
/* The max number of File Transfer object */
#define MAX_FILE_TRANSFER_NUM 32
/* The return value of the function */
#define SUCCESSFUL 1
#define FAIL 0
#ifndef SFTP_DEBUG
#define SFTP_DEBUG 0
#endif
/********************************************************/
/****** Struct Define ******/
/********************************************************/
/* The information of the hpmn servers */
typedef struct HpmnServer
{
char mcc[8]; //The mcc of the HPMN server
char mnc[8]; //The mnc of the HPMN server
char tadig[8]; //The tadig of the HPMN server, length=5
char serverIP[16]; //The remote IP address of the HPMN server, xxx.xxx.xxx.xxx
char loginName[64]; //The user name to login the remote HPMN server
char loginPass[64]; //The user password to login the remote HPMN server
int timeSlot; //The timeslot to send the nrtrde to the remote HPMN server
char reportDir[256]; //The directory to send the report files to the HPMN server
char nrtrdeDir[256]; //The directory to send the nrtrde files to the HPMN server
int sendFileTimeout; //When the value<0, then send the nrtrde file to remote HPMN server
}HpmnServer;
/* The information of the file transfer object */
typedef struct FileTransfer
{
char srcDir[128];
char dstDir[128];
char dstIP[16];
char filter[16];
char logName[32];
char logPass[32];
int curFileIndex;
int waitTime;
int failTimeout;
}FileTransfer;
#endif

View File

@@ -0,0 +1,126 @@
/*************************************************
File name:sftpSend.c
Author:
Version: 9:00:00
Date: 2007-10-9
Description:<3A><><EFBFBD><EFBFBD>sftpģ<70><C4A3><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><CAB1>
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include "sftp.h"
extern void sftpsend_timer();
extern void sftp_init();
static struct itimerval itimer, old_itimer;
static void On_Timer();
static void SetTimer();
/*************************************************
Function: // main
Description: //
Calls: //
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
int main(int argc, char *argv[])
{
pid_t pid;
if (argc == 2 && strstr(argv[1], "-d")) {
if ((pid = fork()) != 0)
exit(0);
setsid();
}
sftp_init();
SetTimer();
while (1) {
usleep(50);
}
return 1;
}
/*************************************************
Function: // On_Timer
Description: // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // sftpsend_timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void On_Timer()
{
//long l_time;
//struct tm *t;
//l_time = time(NULL);
//t = localtime(&l_time);
sftpsend_timer();
/*****test************/
//printf("timer-%02d\n",t->tm_sec);
}
/*************************************************
Function: // SetTimer
Description: // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // On_Timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void SetTimer()
{
struct sigaction act;
act.sa_handler = On_Timer;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGALRM, &act, NULL) < 0) {
perror("Produce Sigaction");
exitLog("sftpSend:SetTimer, sigaction function error");
exit(1);
}
// itimer.it_interval.tv_sec = 0;
// itimer.it_interval.tv_usec = 1000 * 1000;
// itimer.it_value.tv_sec = 0;
// itimer.it_value.tv_usec = 20 * 1000;
itimer.it_interval.tv_sec = 1;
itimer.it_interval.tv_usec = 0;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 20 * 1000;
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
printf("Setting Timer error! \n");
exitLog("sftpSend:SetTimer, setitimer function error");
exit(1);
}
}

View File

@@ -0,0 +1,92 @@
#!/bin/sh
# Makefile for smcli module.
CC = gcc
CFLAGS=-D_REENTRANT -g -Wall
dbINCLUDE_FLAGS = -I/usr/local/mysql/include
dbINCLUDE_FLAGS.ES = -I/usr/include/mariadb
dbLib = -L/usr/local/mysql/lib -lmariadbclient -lz
dbLib.ES = -L/usr/lib/mysql -lmariadbclient -lm
omcLib = -L../../../omcLib/c_program/omcLib -lomcLib
LIB_FLAGS = $(omcLib) $(dbLib)
LIB_FLAGS.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lm
CHECK_INDENT=indent -kr -ts4 *.c *.h
LINK_SUFFIX = $(LIB_FLAGS)
LINK_SUFFIX.ES = $(LIB_FLAGS.ES)
PROGS = smcli
PROGS_OBJ = commands.o smcli.o pmcli.o
PROGS_OBJ.ES = commands.o.ES smcli.o.ES pmcli.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files"
@echo "make linux72 -- Generate target files for Redhat Linux 72"
@echo "make linuxES -- Generate target files for Redhat Linux ES"
linux72: $(PROGS_OBJ)
@cd ../../../omcLib/c_program/omcLib; make clean; make linux72; cd -
@cd ../../../accountMgr/c_program/smcli;
@echo Linking $(PROGS)
#$(CHECK_INDENT)
@$(CC) $(CFLAGS) -o $(PROGS) $(PROGS_OBJ) $(LINK_SUFFIX)
rm -f *.o core *~
cp -f $(PROGS) ../../../bin
cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(PROGS_OBJ.ES)
@cd ../../../omcLib/c_program/omcLib; make linuxES; cd -
@cd ../../../accountMgr/c_program/smcli;
@echo Linking $(PROGS)
#$(CHECK_INDENT)
@$(CC) $(CFLAGS) -o $(PROGS) $(PROGS_OBJ) $(LINK_SUFFIX.ES)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
commands.o: commands.c smcli.h
$(CC) $(CFLAGS) -c commands.c $(dbINCLUDE_FLAGS)
smcli.o: smcli.c
$(CC) $(CFLAGS) -c smcli.c $(dbINCLUDE_FLAGS)
#added for the configuration of parameters
pmcli.o: pmcli.c
$(CC) $(CFLAGS) -c pmcli.c $(dbINCLUDE_FLAGS)
commands.o.ES: commands.c smcli.h
$(CC) $(CFLAGS) -c commands.c $(dbINCLUDE_FLAGS.ES)
smcli.o.ES: smcli.c
$(CC) $(CFLAGS) -c smcli.c $(dbINCLUDE_FLAGS.ES)
pmcli.o.ES: pmcli.c
$(CC) $(CFLAGS) -c pmcli.c $(dbINCLUDE_FLAGS.ES)
clean:
rm -f *.o *.a $(PROGS)
@cd ../../../accountMgr/c_program/smcli; rm -f *.o *.a; cd ..

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,300 @@
/*************************************************
File name: smcli.h
Author:
Version: 9:00:00
Date: 2007-8-4
Description:smcli.c的头文件定义了unitOptDef,CmdBuf,PORT_STATUS等结构
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#ifndef _SMCLI_H_
#define _SMCLI_H_
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <memory.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/time.h>
#include <time.h>
#include <net/if.h>
#include <syslog.h>
#include <termio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <syslog.h>
#include <sys/io.h>
#include <error.h>
#include "mysql.h"
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#define SMCLI_VERSION "R9V0_1"
#define MAX_CLIENTS 48
#define SMCLI_PORT 4999
#define MaxCmdTypeNum 9
#define delayTime 500
#define CmdBufSize 12
//Command TypeNo define
#define CMD_READ 1
#define CMD_MODIFY 2
#define CMD_CREATE 3
#define CMD_DELETE 4
#define CMD_CONNECT 5
#define CMD_EXPORT 6
#define CMD_IMPORT 7
#define CMD_DISCONNECT 8
#define CMD_RECHARGE 9 //20041010
#define CMD_ALIVE 90
#define CMD_HELP 91
//Database table define
#define CommandTable "OMC_PUB.subscriberComm"
#define paramCommandTable "OMC_PUB.parameterComm"
#define sysInfoTable "OMC_PUB.sysInfo"
#define sysSubsConfTable "OMC_PUB.sysSubsConf" //20041101
#define sysUserTable "OMC_PUB.sysUser" //operator table
#define sysOperLogTable "OMC_PUB.sysOperLog"
#define smcliIndexTable "OMC_PUB.smcliIndex" //20041119
#define SMCLI_DEFAULT_VALUE_FILE "/usr/local/apache/htdocs/smcliDefaultValue.txt"
//Error display define
#define ERR_0000 "0000:Command successful"
#define ERR_0001 "0001:Unknown command"
#define ERR_0002 "0002:Invalid syntax"
#define ERR_0003 "0003:Invalid command"
#define ERR_0004 "0004:Incomplete command"
#define ERR_0005 "0005:No privilege command"
#define ERR_0010 "0010:Unknown parameter"
#define ERR_0011 "0011:Duplicate parameter"
#define ERR_0012 "0012:No privilege parameter"
#define ERR_0200 "0200:Command failed(General failed)"
#define ERR_0201 "0201:The value is too big"
#define ERR_0202 "0202:No such field"
#define ERR_0203 "0203:Error field value"
#define ERR_0204 "0204:The field is read only"
#define ERR_0205 "0205:General error (not defined error)"
#define ERR_0206 "0206:No access to the field"
#define ERR_0207 "0207:Wrong value type"
#define ERR_0208 "0208:Wrong value length"
#define ERR_0209 "0209:Wrong encoding of the value"
#define ERR_0210 "0210:Wrong value of the field"
#define ERR_0211 "0211:Cannot create the record"
#define ERR_0212 "0212:The value is incosistent"
#define ERR_0213 "0213:Resource unavailable"
#define ERR_0214 "0214:Commit failed(try again)"
#define ERR_0215 "0215:Undo failed"
#define ERR_0216 "0216:Error authorization info"
#define ERR_0217 "0217:The field is not writable"
#define ERR_0218 "0218:Inconsistent field name"
#define ERR_0251 "0251:Unknown error"
#define ERR_0252 "0252:Cannot send command to one object at same time"
#define ERR_0254 "0254:You must connect the server firstly"
#define ERR_0255 "0255:Execute time out"
#define ERR_0256 "0256:Cannot find this server"
#define ERR_0257 "0257:Password error"
#define ERR_0258 "0258:Cannot open the file"
#define ERR_0259 "0259:The subscriber status is invalid"
#define ERR_0260 "0260:Connection failure to"
#define ERR_0261 "0261:You have connected a server,please disconnect the server firstly"
#define ERR_0300 "0300:Time out,please login again"
//commState define (define in subsComm.h)
#define nProcFail 0
#define nWaitProc 1
#define nInProc 2
#define nOutProc 3
#define InputBufSize 8192
#define OutputBufSize 8192
#define MaxOptNum 512
typedef struct unitOptDef {
unsigned char optFlag[MaxCmdTypeNum + 1];
//[0]:usedFlag;0=no use,1=used
//[1-8]:match to command type no;0=mandatory,1~8=privilege1..........privilege8,9=nouse
char optName[64]; //参数名称
long int exMode; //参数值的转换存储模式
//const
char fieldName[64]; //参数在数据库里的名称
char initFieldValue[256]; //参数的默认值
char optValue[256]; //参数值
char fieldValue[256]; //参数在数据库里存储的值
} unitOptDef;
typedef struct CmdBuf {
unsigned char isConnected;
//const
char serverStr[64]; //设备服务器名称
//const
char objectStr[64]; //操作对象名称
char ip[16]; //设备服务器IP地址
//const
int sysTypeNo; //设备号
int sysNo; //系统号
int subSysNo; //子系统号
//const
int dataTypeNo; //用户数据类型号
char srcTable[64]; //
char tmpTable[64]; //20041101
char paramStr[64];
char paramTable[64];
//const
char cmdFlag[MaxCmdTypeNum];//八种操作的权限
//match to CmdList's sort,0=no support 1~8=privilege1............privilege8
unsigned int optDefNum; //命令可以操作的命令对象个数
unitOptDef optDef[MaxOptNum]; //命令可以操作的所有参数对象
} CmdBuf;
/* by simon at 23/9/26 */
// CmdBuf defCmdBuf[CmdBufSize];
// struct sockaddr_in cliaddr;
typedef struct PORT_STATUS {
int connfd;
DWORD peerip;
int peerport;
char username[64];
char passwd[64];
int failNo;
unsigned char loginFlag;
unsigned char usernameFlag;
unsigned char isConnected[CmdBufSize];
char serverStr[CmdBufSize][64];
char ip[CmdBufSize][16];
int sysNo[CmdBufSize];
int subSysNo[CmdBufSize];
int cmdBufNum;
unsigned char fieldNameFlag;
char fieldNameList[2048];
char exportFieldsStr[1024];
FILE *expFile;
FILE *impFile;
FILE *impLogFile;
long int exportedNum;
long int exportNum;
long int exportMaxNum;
long int importedNum;
long int importNum;
BOOL expDoingFlag;
BOOL impDoingFlag;
char tmpInputBuf[InputBufSize];
unsigned char privilege;
long time;
int paramOperationCount;
int multiPacketFlag;
char secondPacket[InputBufSize];
} _PORT_STATUS;
/* by simon at 23/9/26*/
// _PORT_STATUS port_status[MAX_CLIENTS];
// CmdBuf *cmdBuf;
//option Flag value define
#define Op_N 0 //no use
#define Op_M 1 //mandatory
#define Op_O 2 //optional
#define Op_S 3 //subjoin
//default option define,Everyone CmdBuf must have those option
#define OptNo_ipaddress 0
#define OptNo_passwd 1
#define OptNo_expfile 2
#define OptNo_query 3
#define OptNo_fields 4
#define OptNo_max 5
#define OptNo_impfile 6
#define OptNo_srvip 7
//#define OptNo_index 8 //index field
//#define OptNo_indexSec 9 //if have second index field
/* by simon at 23/9/26 */
// int OptNo_index;
#define HLR_OptNo_indexSec 11 //if have second index field
#define OptNo_password 9
#define OptNo_privilege 11
//exchange mode define
#define exM_same 0
#define exM_undefined 255
#define exM_byte0_bit0 100
#define exM_byte0_bit1 101
#define exM_byte0_bit2 102
#define exM_byte0_bit3 103
#define exM_byte0_bit4 104
#define exM_byte0_bit5 105
#define exM_byte0_bit6 106
#define exM_byte0_bit7 107
#define exM_byte1_bit0 110
#define exM_byte1_bit1 111
#define exM_byte1_bit2 112
#define exM_byte1_bit3 113
#define exM_byte1_bit4 114
#define exM_byte2_bit0 120
#define exM_byte2_bit1 121
#define exM_byte2_bit3 123
#define exM_byte2_bit4 124
#define exM_byte3_bit0 130
#define exM_byte4_bit0 140
#define exM_byte4_bit1 141
#define exM_byte4_bit5 145
/*
if (exchange mode ==x1*10000000+x2*100000+x3*1000+x4){
x1:the optValue type;//0:unsigned digit,1:unsigned hex,2:signed digit,3:signed hex,4:unsigned digit and bofore check the length of the optValue,the optValue need change to hex,5:signed digit and bofore check the length of the optValue,the optValue need change to hex,9:string
x2:the min length of the value
x3:the max length of the value
x4:exchange mode
}
*/
int exValueFieldToOpt(int optNo);
int exValueOptToField(int optNo);
int getBitValue(char *hexStr, int byteOffset, int bitOffset,
unsigned char *bitValue);
int setBitValue(char *hexStr, int byteOffset, int bitOffset,
unsigned char bitValue);
void fieldSync(int optNo);
int hex2dec(char *hexStr, char *decStr);
#endif

View File

@@ -0,0 +1,78 @@
#!/bin/sh
#Author: Cui Ticun
#Version: 9.00.00
#Date: 2007-7-1
#Description: Makefile for subsComm module.
CC = gcc
CFLAGS=-D_REENTRANT -g -Wall
dbINCLUDEFLAG = -I/usr/local/mysql/include
dbLINKFLAG = -L/usr/local/mysql/lib -lmariadbclient -lz
dbINCLUDEFLAG.ES = -I/usr/include/mariadb
dbLINKFLAG.ES = -L/usr/lib/mysql -lmariadbclient -lz
LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/x86_64-linux-gnu -lpthread \
LINK_SUFFIX = $(dbINCLUDEFLAG) $(dbLINKFLAG) $(LINKFLAG)
LINK_SUFFIX.ES = $(dbINCLUDEFLAG.ES) $(dbLINKFLAG.ES)$(LINKFLAG)
PROGS = subsComm
SUBSCOMM_OBJ = subsCommMain.o subsComm.o
SUBSCOMM_OBJ.ES = subsCommMain.o.ES subsComm.o.ES
LIB_OBJ = subsComm.o
LIB_OBJ.ES = subsComm.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files"
@echo "make linux72 -- Generate target files for Redhat Linux 72"
@echo "make linuxES -- Generate target files for Redhat Linux ES"
linux72: $(SUBSCOMM_OBJ)
@echo Linking $(PROGS)
@$(CC) $(CFLAGS) -o $(PROGS) $(SUBSCOMM_OBJ) $(LINK_SUFFIX) -lm
ar r libsubsComm.a $(LIB_OBJ)
rm -f *.o core *~
#cp -f $(PROGS) ../../../../bin
#cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(SUBSCOMM_OBJ.ES)
@echo Linking $(PROGS)
@$(CC) $(CFLAGS) -o $(PROGS) $(SUBSCOMM_OBJ) $(LINK_SUFFIX.ES) -lm
ar r libsubsComm.a $(LIB_OBJ)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
subsCommMain.o: subsCommMain.c
$(CC) $(CFLAGS) -c subsCommMain.c $(dbINCLUDEFLAG)
subsComm.o: subsComm.c
$(CC) $(CFLAGS) -c subsComm.c $(dbINCLUDEFLAG)
subsCommMain.o.ES: subsCommMain.c
$(CC) $(CFLAGS) -c subsCommMain.c $(dbINCLUDEFLAG.ES)
subsComm.o.ES: subsComm.c
$(CC) $(CFLAGS) -c subsComm.c $(dbINCLUDEFLAG.ES)
clean:
rm -f *.o *.a $(PROGS)

View File

@@ -0,0 +1,27 @@
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//test Sql
INSERT INTO subscriberComm (commType, sysTypeNo, sysNo, subSysNo, bufferNo, fieldNameList, paramType, commState, totalNum, finishNum, sendTime, bgnTime, endTime, remark)
VALUES ('5', '360', '1', '0', '1', 'ALL', '4', '1', '', '', '2003-02-21 15:57:30', '', '', '')
INSERT INTO sysSubsConf
VALUES ( '251', '0', '1', '1.3.6.1.4.1.1373.1.3.3.6.2.2.2.1', '1.3.6.1.4.1.1373.1.3.3.6.2.3.1', 'imsi', '1000', '100', 'snDb.subscriberData');
INSERT INTO sysSubsConf
VALUES ( '330', '0', '1', '1.3.6.1.4.1.1373.1.3.3.3.2.6', '1.3.6.1.4.1.1373.1.3.3.3.2.7', 'imsi', '1000', '100', 'HlrDb.subscriberData');
INSERT INTO sysSubsConf
VALUES ( '340', '0', '1', '1.3.6.1.4.1.1373.1.3.3.6.2.2.2.1', '1.3.6.1.4.1.1373.1.3.3.6.2.3.1', 'key_imsi', '1000', '100', 'AUC_Para.AUC_Dyn_data');
INSERT INTO sysSubsConf
VALUES ( '360', '0', '1', '1.3.6.1.4.1.1373.1.3.3.6.2.2.2.1', '1.3.6.1.4.1.1373.1.3.3.6.2.3.1', 'msisdn', '1000', '100', 'PPS_User_DB.user_info');
INSERT INTO sysSubsConf
VALUES ( '380', '0', '1', '1.3.6.1.4.1.1373.1.3.3.6.2.2.2.1', '1.3.6.1.4.1.1373.1.3.3.6.2.3.1', 'imei', '1000', '100', 'EIR_Para.BlackGrayIMEI');
UPDATE OBJ_330.subscriberParamConf SET level_1 = level_5,level_2 =level_6,level_3 ='0',level_4 ='0',
level_7 ='0',level_8 ='0',level_9 ='0',level_10 ='0'
UPDATE OBJ_330.subscriberParamConf SET level_5 = '0',level_6 = '0'

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,173 @@
/*************************************************
File name: subsComm.h
Author: He wan Dong
Version: 9:00:00
Date: 2003/02/14
Description:subsComm.c<><63>ͷ<EFBFBD>ļ<EFBFBD>
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#ifndef subsComm__H
#define subsComm__H
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#ifndef MYSQL_H
#include "mysql.h"
#endif
#ifndef subsComm_DEBUG
#define subsComm_DEBUG 0
#endif
#define VMS_No 390
/* fj added 2010-01-19, UDM<44><4D>AUSFҪ֧<D2AA>ַ<EFBFBD>Ƭ */
#define UDM_No 365
#define AUSF_No 366
#define subsComm_LogPath "../log"
#define subsComm_LogFile "subsComm"
#define subsComm_backupPath "/usr/local/apache/htdocs/db_backup/subsData"
#define FlagCode 1373 //snmp company code of iwv
#define MaxCommNum 32 //max number of command can be execute as same time
//The maxCommNum divides into 2 parts,The 0-15 is used for processing the commands in the subscriberComm table
//The 16-31 is used for processing the loadData commands
#define loadDataCommStartNo 16
/* fj added 2020-01-19<31><39>UDM<44><4D>AUSF֧<46>ַ<EFBFBD>Ƭ */
#define MaxSysConfNum 80//30
#define MaxParamConfNum 2048 //512 -> 1024
#define MaxIndexNumPerSeg 100
#define MaxOidLen 20 //max number of object ID
#define MaxSubOidLen 10 //max number of sub object ID
//#define MaxLenOfOneVar 1024 //max len of one var_list
#define MaxVarNum 50 //max number of var in one pdu
#define DefPort 4959 //define port
#define HOSTNAME "localhost"
#define PUB_DB "OMC_PUB" //OMC's public database
#define SysConfTable "OMC_PUB.sysConf" //system config table
#define subsConfTable "OMC_PUB.sysSubsConf" //system config table
#define CommTable "OMC_PUB.subscriberComm" //command table
#define IpTable "OMC_PUB.sysInfo" //system's IP table
#define subsDataBackupTable "OMC_PUB.subsDataBackup" //
//procState flag define
#define nIdle 0 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>nInProcʱ<63><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>״̬<D7B4><CCAC>nIdleʱ<65><CAB1><EFBFBD>Żᷢ<C5BB><E1B7A2>snmp<6D><70><EFBFBD>ݰ<EFBFBD>
#define nWaitResponse 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>nInProcʱ<63><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>ִ<EFBFBD><D6B4>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ΪnWaitResponse
#define nWaitIdleComm 2
//commState flag define
#define nProcFail 0 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>״̬<D7B4><CCAC>nWaitResponseʱ<65><CAB1><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4>ظ<EFBFBD><D8B8><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>״̬
#define nWaitProc 1 //һ<><D2BB><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>״̬
#define nInProc 2 //<2F><>ʱ<EFBFBD><CAB1>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>nWaitProc״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>״̬
#define nOutProc 3 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>״̬<D7B4><CCAC>nWaitResponseʱ<65><CAB1><EFBFBD><EFBFBD>ȴ<EFBFBD><C8B4>ظ<EFBFBD><D8B8><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>Ϣ<EFBFBD><CFA2>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>״̬
//parameter type define
#define nSubSysParam 0
#define nSysParam 1
//snmp pdu type define [define in snmp.h]
#define nGet 0
#define nGetNext 1
#define nResp 2
#define nSet 3
//subscriber manage command type define
#define nReadComm 1
#define nChangeComm 2
#define nCreateComm 3
#define nDeleteComm 4
#define nLoadIndexComm 5
#define nReplaceIndexComm 6 //for hlr replace imsi
#define nLoadDataComm 7 //just used in program
//snmp var type code
#define nInteger 0x02
#define nOctetString 0x04
#define nNull 0x05
#define nObjectId 0x06
#define nNoSuchObject 0x80
#define nNoSuchInstance 0x81
#define nEndOfMibView 0x82
typedef struct unitSysConf{
int isEnable; //ʹ<>ܱ<EFBFBD>־λ
int sysTypeNo; //ϵͳ<CFB5><EFBFBD><E8B1B8>
int dataTypeNo; //<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD>Щϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ֲ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
int sysNo; //ϵͳ<CFB5>ţ<EFBFBD><C5A3>ó<EFBFBD><C3B3><EFBFBD>ֻ<EFBFBD><D6BB>VSS<53><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3>
DWORD preObjId[20]; //<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ݵ<EFBFBD>OID<49><44><EFBFBD><EFBFBD>Ҫ<EFBFBD>ڸ<EFBFBD>OID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>OID
int preObjIdLen; //<2F><><EFBFBD><EFBFBD>
DWORD indexObjId[20]; //<2F><>ȡ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OID
int indexObjIdLen; //<2F><><EFBFBD><EFBFBD>
int maxMsgLen; //<2F><>Ϣ<EFBFBD><CFA2>󳤶<EFBFBD>
char snmpCommunity[16]; //SNMP<4D><50>֤<EFBFBD><D6A4>
int maxSegmentNum; //<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
int maxIndexNumPerSeg; //<2F><><EFBFBD>豸ÿ<E8B1B8>ε<EFBFBD><CEB5>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char paramTableName[128]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
char tmpTableName[128]; //database.table
int paramConfArrOffset; //<2F><>ϵͳ<CFB5>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>paramConfArr<72><72><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD>ʼλ<CABC><CEBB>
int paramConfNum; //<2F><><EFBFBD><EFBFBD><EFBFBD>ֶεĸ<CEB5><C4B8><EFBFBD>
char indexFieldSubOid[16]; //<2F>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>subsParamConf_X<5F><58><EFBFBD>е<EFBFBD>level<65><6C><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char indexFieldName[64]; //<2F>ؼ<EFBFBD><D8BC>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>
BYTE indexValueLen; //<2F>ؼ<EFBFBD><D8BC>ֶγ<D6B6><CEB3><EFBFBD>
}unitSysConf;
typedef struct unitParamConf{
int sysTypeNo; //<2F>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ϵͳ<CFB5><EFBFBD><E8B1B8>
char fieldObjIdStr[16]; //<2F><>subsParamConf_<66><5F><EFBFBD>е<EFBFBD>level<65><6C><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
char fieldName[64]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int valueType; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int valueLen; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//int initValue;
}unitParamConf;
typedef struct unitComm{
//command info
WORD commNo; //ID in command table
WORD commType; //0:invaild,1:read,2:change,3:create,4:delete,5:get index,6:get data in indexBuffer
int sysConfArrNo; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>sysConfArr<72><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int dataTypeNo; //<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WORD sysTypeNo; //ϵͳ<CFB5><EFBFBD><E8B1B8>
WORD sysNo; //ϵͳ<CFB5><CDB3>
WORD subSysNo; //<2F><>ϵͳ<CFB5><CDB3>
char dstIP[16]; //Զ<><D4B6><EFBFBD>豸IP<49><50>ַ
WORD dstPort; //Զ<><D4B6><EFBFBD><EFBFBD>˿<EFBFBD>
int requestId; //snmp<6D><70><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>request ID
MYSQL_RES *paramSet; //<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ݼ<EFBFBD>
char indexBuffer[MaxIndexNumPerSeg][19]; //per Segment,MaxIndexNumPerSeg=100
BYTE tlvTotalNum; // <20><>ǰ<EFBFBD><C7B0>Ƭ<EFBFBD><C6AC><EFBFBD>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD>͵<EFBFBD>tlv<6C><76><EFBFBD><EFBFBD>Ŀ
BYTE tlvFinishNum; // <20><>ǰ<EFBFBD><C7B0>Ƭ<EFBFBD><C6AC><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tlv<6C><76><EFBFBD><EFBFBD>Ŀ
BYTE tlvInvaildNum;
char fieldNameList[2048]; //64*32
//command process info
BYTE commState; //-1:nFailed,0:nWaitProc,1:nNoFinish,2:nFinished
BYTE procState; //command process state:0=idle,1=waitResponse
BYTE waitTimeCount; //the times number of timeout
BYTE timeoutCount; //the timeCount
WORD totalNum;
WORD finishNum;
char desc[200]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//var_list info
BYTE varNum;
}unitComm;
//Interface Functions Declare,define in subsComm.c
int subsCommInit();
int subsCommTimer();
#endif

View File

@@ -0,0 +1,173 @@
/*************************************************
File name: subsCommMain.c
Author: He wan Dong
Version: 9:00:00
Date: 2003-2-14
Description:<3A><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>subsCommģ<6D><C4A3>
<09><><EFBFBD><EFBFBD>snmpģ<70><C4A3><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
void snmp_init(WORD nport);
int snmp_receive(snmp_pdu *msgbuf,snmp_addr *addr);
int snmp_send(snmp_pdu *msgbuf,snmp_addr *addr);
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "subsComm.h"
static struct itimerval itimer, old_itimer;
void onTimer();
void setTimer();
void setup_daemon(void);
int timerCounter = 0;
/*************************************************
Function: // main
Description: // <20><><EFBFBD><EFBFBD>subsCommģ<6D><EFBFBD><E9A3AC>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // snmp_init; iptrans_init;
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: // 1:successful; 0:failed;
Others: //
*************************************************/
int main(int argc, char *argv[])
{
char runMode;
debug_init();
fprintf(stderr, "\n Calling iptrans_init()");
iptrans_init();
fprintf(stderr, "\n Calling snmp_init()");
snmp_init(4959);
subsCommInit();
if (argc > 0) {
runMode = getopt(argc, argv, "d");
switch (runMode) {
case 'd':
setup_daemon();
break;
case '?':
break;
}
//debug_init();//must do it at first
}
setTimer();
while (1) {
usleep(50);
}
return (1);
}
/*************************************************
Function: // onTimer
Description: // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // subsCommTimer;
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void onTimer()
{
//debug_rt();
//snmp_timer();
if (timerCounter > 3) {
timerCounter = 0;
subsCommTimer();
}
timerCounter++;
}
/*************************************************
Function: // setTimer
Description: // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // onTimer;
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void setTimer()
{
struct sigaction act;
act.sa_handler = onTimer;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGALRM, &act, NULL) < 0) {
perror("Produce Sigaction");
exitLog("subsComm:setTimer, sigaction function error");
exit(1);
}
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 20 * 1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 20 * 1000;
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
printf("Setting Timer error! \n");
exitLog("subsComm:setTimer, setitimer function error");
exit(1);
}
}
void setup_daemon(void)
{
/*
int i;
for (i = 0; i < 3; ++i) {
close(i);
}
*/
switch (fork()) {
case -1:
perror("setup_daemon(), 1st fork()");
exit(2);
default:
exit(0);
case 0:
if (setsid() == -1) {
perror("setup_daemon(), setsid()");
exit(3);
}
switch (fork()) {
case -1:
perror("setup_daemon(), 2nd fork()");
exit(3);
default:
exit(0);
case 0:
umask(0);
/* and return with daemon set up */
return;
}
}
}

View File

@@ -0,0 +1,28 @@
#!/bin/sh
logFile=$1
echo "============Tesst Report================="
echo -n "Got total vaild index: "
grep -c " tlvValue = 9" $logFile
grep -c " tlvValue = 8" $logFile
grep -c " tlvValue = 7" $logFile
grep -c " tlvValue = 6" $logFile
grep -c " tlvValue = 5" $logFile
grep -c " tlvValue = 4" $logFile
grep -c " tlvValue = 3" $logFile
grep -c " tlvValue = 2" $logFile
grep -c " tlvValue = 1" $logFile
grep -c " tlvValue = 0" $logFile
#grep -c " tlvValue = 0" $logFile
echo -n "Got total Null index: "
grep -c " tlvValue = Null" $logFile
echo -n "Try to get: "
grep -c "Now get -> " $logFile
echo "============timeout================="
echo -n "Duplicate key index: "
grep -c " Description: Duplicate" $logFile
grep " Description: Duplicate" $logFile
echo "============timeout================="
echo -n "total : "
grep -c "data timeout" $logFile
grep "data timeout" $logFile

View File

@@ -0,0 +1,84 @@
#!/bin/sh
# Makefile for test snmpComm module.
CC = gcc
CFLAGS=-D_REENTRANT -g -Wall
dbINCLUDE_FLAGS = -I/usr/local/mysql/include
dbINCLUDE_FLAGS.ES = -I/usr/include/mariadb
dbLib = -L/usr/local/mysql/lib -lmariadbclient -lz
dbLib.ES = -L/usr/lib/mysql -lmariadbclient -lm
omcLib = -L../../../omcLib/c_program/omcLib -lomcLib
LIB_FLAGS = $(omcLib) $(dbLib)
#LIB_FLAGS.ES = $(omcLib) $(dbLib.ES)
LIB_FLAGS.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lm
LINK_SUFFIX = $(LIB_FLAGS)
LINK_SUFFIX.ES = $(LIB_FLAGS.ES)
PROGS = subsDataBackup
SNMPCOMM_OBJ = subsDataBackupMain.o subsDataBackup.o
SNMPCOMM_OBJ.ES = subsDataBackupMain.o.ES subsDataBackup.o.ES
LIB_OBJ = subsDataBackup.o
LIB_OBJ.ES = subsDataBackup.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files"
@echo "make linux72 -- Generate target files for Redhat Linux 72"
@echo "make linuxES -- Generate target files for Redhat Linux ES"
linux72: $(SNMPCOMM_OBJ)
@cd ../../../omcLib/c_program/omcLib; make clean; make linux72; cd -
@echo Linking $(PROGS)
@$(CC) $(CFLAGS) -o $(PROGS) $(SNMPCOMM_OBJ) $(LINK_SUFFIX)
ar r libsubsDataBackup.a $(LIB_OBJ)
rm -f *.o core *~
cp -f $(PROGS) ../../../bin/
cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(SNMPCOMM_OBJ.ES)
@cd ../../../omcLib/c_program/omcLib; make clean; make linuxES; cd -
@echo Linking $(PROGS)
@$(CC) $(CFLAGS) -o $(PROGS) $(SNMPCOMM_OBJ) $(LINK_SUFFIX.ES)
ar r libsubsDataBackup.a $(LIB_OBJ)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
subsDataBackupMain.o: subsDataBackupMain.c
$(CC) $(CFLAGS) -c subsDataBackupMain.c $(dbINCLUDE_FLAGS)
subsDataBackup.o: subsDataBackup.c
$(CC) $(CFLAGS) -c subsDataBackup.c $(dbINCLUDE_FLAGS)
subsDataBackupMain.o.ES: subsDataBackupMain.c
$(CC) $(CFLAGS) -c subsDataBackupMain.c $(dbINCLUDE_FLAGS.ES)
subsDataBackup.o.ES: subsDataBackup.c
$(CC) $(CFLAGS) -c subsDataBackup.c $(dbINCLUDE_FLAGS.ES)
clean:
rm -f *.o *.a $(PROGS)
@cd ../../../accountMgr/c_program/subsDataBackup; rm -f *.o *.a; cd ..

View File

@@ -0,0 +1,669 @@
#include <stdlib.h>
#include <string.h>
#include "mysql.h"
#include "subsDataBackup.h"
/******************************************************/
/****** Heartbeat Parameter ******/
/******************************************************/
DWORD PROC_HEARTBEAT_OID[12]={1,3,6,1,4,1,1373,2,4,10,7};
int PROC_HEARTBEAT_OIDLEN=11;
int sendHeartbeat();
/* by simon at 23/9/25 */
subsData_Backup subsDataBackup[MaxSysConfNum];
/**************subsdata backup functions declare**********************/
void backupTimer();
void sendCmd(int proc);
void scanCmd(int proc);
void backupFile(int proc);
void debug_log(const char *fmt,...);
/***********subsdata backup global var declare And init*********************/
//static FILE *subsDataBackupLog;
static MYSQL *dbConn;
int subsDataBackupFlag=0;
int automatic_scratch_card_time=0;
int automatic_scratch_card_flag=0;
int cmdId=0;
int oldDayForLog = 0; //1-31
int oldDayForBackup = 0; //1-31
unsigned long waitTime;
int waitFlag;
unsigned long inTime;
int inFlag;
int lastFinishNum=0;
int finishFlag;
unsigned long finishTime;
void subsDataBackupInit()
{
int i=0;
char tmpSql[1024];
MYSQL_RES *tmpResult = NULL;
MYSQL_ROW tmpRow = NULL;
debug_init(1);
iptrans_init();
snmp_init(4957);
//heartbeat_init(0);
debug_log("subsDataBackup is starting......");
dbConn = mysql_conn(HOSTNAME,PUB_DB);
if(dbConn == NULL){
debug_log("[ERR][subsDataBackupInit]connect OMC_PUB");
exitLog("subsDataBackup:subsDataBackupInit, Connect OMC_PUB error");
exit(1);
}
sprintf(tmpSql,
"SELECT pubVarValue FROM OMC_PUB.omcPubVarConf WHERE pubVarName='automatic_scratch_card_time'");
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult == NULL || mysql_num_rows(tmpResult) == 0){
automatic_scratch_card_time = 0;
mysql_free_result(tmpResult);
debug_log("The automatic_scratch_card_time value is NULL");
}else {
tmpRow = mysql_fetch_row(tmpResult);
automatic_scratch_card_time = atoi(tmpRow[0]);
mysql_free_result(tmpResult);
}
if (automatic_scratch_card_time < 0 || automatic_scratch_card_time > 23){
debug_log("The automatic_scratch_card_time value is %d not in range",automatic_scratch_card_time);
automatic_scratch_card_time = 0;
}
debug_log("automatic_scratch_card_time=%d",automatic_scratch_card_time);
sprintf(tmpSql,
"SELECT pubVarValue FROM OMC_PUB.omcPubVarConf WHERE pubVarName='automatic_scratch_card_flag'");
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult == NULL || mysql_num_rows(tmpResult) == 0){
automatic_scratch_card_flag = 0;
mysql_free_result(tmpResult);
debug_log("The automatic_scratch_card_flag value is NULL");
}else {
tmpRow = mysql_fetch_row(tmpResult);
automatic_scratch_card_flag = atoi(tmpRow[0]);
mysql_free_result(tmpResult);
}
if (automatic_scratch_card_flag < 0 || automatic_scratch_card_flag > 1){
debug_log("The automatic_scratch_card_time value %d is not in range",automatic_scratch_card_flag);
automatic_scratch_card_flag = 0;
}
debug_log("automatic_scratch_card_flag=%d",automatic_scratch_card_flag);
sprintf(tmpSql, "SELECT subsDataBackup.sysTypeNo,subsDataBackup.dataTypeNo,subsDataTable,tmpDataTable"\
" FROM subsDataBackup,sysSubsConf "\
" WHERE sysSubsConf.sysTypeNo = subsDataBackup.sysTypeNo AND sysSubsConf.dataTypeNo = subsDataBackup.dataTypeNo AND sysSubsConf.isEnable > '0' "\
" AND subsDataBackup.flag > '0' ORDER BY subsDataBackup.sysTypeNo AND subsDataBackup.dataTypeNo");
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult == NULL && mysql_num_rows(tmpResult) == 0) {
subsDataBackupFlag=0;
mysql_free_result(tmpResult);
debug_log("No subsdata backup");
return ;
}
debug_log("backup server list");
while((tmpRow=mysql_fetch_row(tmpResult)) > 0){
subsDataBackup[i].backupStat=nWaitBackup;
subsDataBackup[i].sysTypeNo=atoi(tmpRow[0]);
subsDataBackup[i].dataTypeNo=atoi(tmpRow[1]);
strcpy(subsDataBackup[i].subsDataTable,tmpRow[2]);
strcpy(subsDataBackup[i].tmpDataTable,tmpRow[3]);
debug_log("%d,sysTypeNo=%d,dataTypeNo=%d,subsDataTable=%s,tmpDataTable=%s",i,subsDataBackup[i].sysTypeNo,subsDataBackup[i].dataTypeNo,subsDataBackup[i].subsDataTable,subsDataBackup[i].tmpDataTable);
i++;
}
mysql_free_result(tmpResult);
return;
}
/*************************************************
Function: // sendHeartbeat
Description: // Send process heartbeat to beatProc
Calls: // snmp_send
Called By: // on_Timer
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: // 1:OK; 0:Fail
Others: //
*************************************************/
int sendHeartbeat()
{
snmp_pdu pdu;
snmp_addr addr;
char proc_name[16];
memset(proc_name,0,16);
sprintf(proc_name,"subsDataBackup");
//pdu
memset(&pdu,0,sizeof(snmp_pdu));
pdu.pdu_type=7;
pdu.request_id=0;
sprintf(pdu.community,"public");
pdu.var_num=1;
pdu.error_status=0;
pdu.error_index=0;
//Addr
addr.local_port = 4957;
//addr.remote_ip = inet_addr("127.0.0.1");
addr.remote_ip = GetLocalIP();
addr.broadcast = 0;
addr.remote_port = 4957;
//Varlist
memcpy(pdu.var[0].oid,PROC_HEARTBEAT_OID,PROC_HEARTBEAT_OIDLEN*sizeof(DWORD));
pdu.var[0].oidlen=PROC_HEARTBEAT_OIDLEN;
pdu.var[0].vartype=0x04;
pdu.var[0].msglen=16;
memcpy(pdu.var[0].msg,proc_name,16);
if(snmp_send(&pdu, &addr) <= 0)
{
debug_log("Send heartbeat fail");
return 0;
}
return 1;
}
unsigned long heartbeat_timeout=0;
void subsDataBackupTimer()
{
long l_time;
struct tm *t;
l_time=time(NULL);
t=localtime(&l_time);
if(time(NULL) - heartbeat_timeout > 5)
{
heartbeat_timeout=time(NULL);
sendHeartbeat();
}
if(t->tm_mday != oldDayForLog){
//init logfile,create a new log file to restore log
oldDayForLog = t->tm_mday;
}
if(automatic_scratch_card_flag==1&&t->tm_mday != oldDayForBackup&&t->tm_hour==automatic_scratch_card_time){
debug_log("start to backup process, last backup date is %d",oldDayForBackup);
subsDataBackupFlag=1;
oldDayForBackup = t->tm_mday;
}
//printf("subsDataBackupFlag=%d\n",subsDataBackupFlag);
if(subsDataBackupFlag==1){
backupTimer();
}
return ;
}
static int start_proc_index=0;
void backupTimer()
{
int i;
int proc;
char tmpSql[1024];
MYSQL_RES *tmpResult = NULL;
MYSQL_ROW tmpRow = NULL;
char tmpLoadoutSql[400];
char tmpLoadoutFile[100];
for(proc=start_proc_index;proc<MaxSysConfNum;proc++){
switch(subsDataBackup[proc].backupStat){
case nNotBackup:
break;
case nWaitBackup:
/*
sprintf(tmpSql, "SELECT * FROM %s ",CommTable);
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult != NULL && (mysql_num_rows(tmpResult) > 0)) {
mysql_free_result(tmpResult);
omcLog(subsDataBackupLog,"sysTypeNo=%d,dataTypeNo=%d;The database of subsComm is not NULL",subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
return ;
}
mysql_free_result(tmpResult);
*/
//check mysql connection
if(mysql_ping(dbConn))
{
debug_log("[ERR][backupTimer]mysql gone away,reconnect");
mysql_close(dbConn);
dbConn = mysql_conn(HOSTNAME,PUB_DB);
if(dbConn == NULL)
{
debug_log("[ERR][backupTimer]reconnect mysql OMC_PUB");
}
}
sprintf(tmpSql, "SELECT sysNo,subSysNo FROM %s WHERE sysTypeNo =\'%d\' ORDER BY baseStat DESC",IpTable, subsDataBackup[proc].sysTypeNo);
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult == NULL || mysql_num_rows(tmpResult) == 0) {
mysql_free_result(tmpResult);
subsDataBackup[proc].backupStat=nOutBackup;
debug_log("%d,system-%d,dataTypeNo=%d,can not get the IP",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
}else{
tmpRow = mysql_fetch_row(tmpResult);
subsDataBackup[proc].sysNo = atoi(tmpRow[0]);
subsDataBackup[proc].subSysNo = atoi(tmpRow[1]);
mysql_free_result(tmpResult);
subsDataBackup[proc].backupStat=nInBackup;
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath,subsDataBackup[proc].subsDataTable);
unlink(tmpLoadoutFile);
sprintf(tmpLoadoutSql,"SELECT * INTO OUTFILE '%s' "\
" FIELDS TERMINATED BY ',' FROM %s",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn,tmpLoadoutSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpLoadoutSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpLoadoutSql);
}
sprintf(tmpSql, "DELETE FROM %s",subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
sprintf(tmpSql, "DELETE FROM %s",subsDataBackup[proc].tmpDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
sendCmd(proc);
return ;
}
break;
case nInBackup:
if(finishFlag!=1)
scanCmd(proc);
else{
//if(time(NULL)-finishTime>MAX_GETALL_TIMEOUT)
backupFile(proc);
}
return ;
break;
case nOutBackup:
debug_log("%d,system-%d,dataTypeNo=%d,affair finish, start next",start_proc_index,subsDataBackup[start_proc_index].sysTypeNo,subsDataBackup[start_proc_index].dataTypeNo);
start_proc_index++;
break;
default:
break;
}
}
if(proc==MaxSysConfNum){
subsDataBackupFlag=0;
start_proc_index=0;
for(i=0;i<MaxSysConfNum;i++){
if(subsDataBackup[i].backupStat==nOutBackup)
subsDataBackup[i].backupStat=nWaitBackup;
}
}
return ;
}
void sendCmd(int proc)
{
char tmpSql[2048];
MYSQL_RES *tmpResult = NULL;
MYSQL_ROW tmpRow = NULL;
char tmpLoadoutFile[100];
if (cmdId > 50000) {
//sprintf(tmpSql, "DROP TABLE %s", CommTable);
sprintf(tmpSql, "TRUNCATE TABLE %s", CommTable);
mysql_getnores(dbConn, tmpSql);
/*
sprintf(tmpSql, "CREATE TABLE %s"
"(commId smallint(5) unsigned NOT NULL auto_increment,"
"commType tinyint(1) DEFAULT '0' NOT NULL,"
"dataTypeNo tinyint(4) DEFAULT '0' NOT NULL,"
"sysTypeNo smallint(5) unsigned DEFAULT '0' NOT NULL,"
"sysNo smallint(5) unsigned DEFAULT '0' NOT NULL,"
"subSysNo smallint(5) unsigned DEFAULT '0' NOT NULL,"
"indexValueList varchar(255) NOT NULL,"
"fieldNameList text NOT NULL,"
"paramType tinyint(4) DEFAULT '0' NOT NULL,"
"commState tinyint(3) unsigned DEFAULT '0' NOT NULL,"
"totalNum smallint(5) unsigned DEFAULT '0' NOT NULL,"
"finishNum smallint(5) unsigned DEFAULT '0' NOT NULL,"
"sendTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,"
"bgnTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,"
"endTime datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,"
"remark varchar(200) binary NOT NULL,"
"PRIMARY KEY (commId),"
"KEY sysTypeNo (sysTypeNo),"
"KEY sysNo (sysNo),"
"KEY subSysNo (subSysNo),"
"KEY bufferKey (indexValueList));", CommTable);
mysql_getnores(dbConn, tmpSql);
*/
}
//insert to command table
sprintf(tmpSql, "INSERT INTO %s "
"(commType,dataTypeNo,sysTypeNo,sysNo,subSysNo,indexValueList,"
"fieldNameList,paramType,commState,sendTime,remark)"
"VALUES"
"(\'5\',\'%d\',\'%d\',\'%d\',\'%d\',\'\',\'ALL\',"
"\'0\',\'1\',CURRENT_TIMESTAMP,\'by subsDatabackup\')",
CommTable,
subsDataBackup[proc].dataTypeNo,
subsDataBackup[proc].sysTypeNo,
subsDataBackup[proc].sysNo,
subsDataBackup[proc].subSysNo);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
//get commId
sprintf(tmpSql, "SELECT commId FROM %s "
" WHERE sysTypeNo=\'%d\' "
" AND dataTypeNo=\'%d\' "
" AND indexValueList=\'\'",
CommTable,
subsDataBackup[proc].sysTypeNo,
subsDataBackup[proc].dataTypeNo);
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult == NULL || mysql_num_rows(tmpResult) == 0) {
debug_log("%d,system-%d,dataTypeNo=%d,get commId fail",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
mysql_free_result(tmpResult);
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
sprintf(tmpSql, "LOAD DATA INFILE '%s' REPLACE INTO TABLE %s "\
" FIELDS TERMINATED BY ','",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
unlink(tmpLoadoutFile);
subsDataBackup[proc].backupStat=nOutBackup;
return ;
}
tmpRow = mysql_fetch_row(tmpResult);
cmdId = atoi(tmpRow[0]);
mysql_free_result(tmpResult);
debug_log("%d,system-%d,dataTypeNo=%d,get commId=%d",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,cmdId);
return ;
}
//scan command progress
void scanCmd(int proc)
{
int cmdState = 0;
char tmpSql[1024];
char ErrorMsg[256];
MYSQL_RES *tmpResult = NULL;
MYSQL_ROW tmpRow = NULL;
char tmpLoadoutFile[100];
long l_time;
struct tm *t;
l_time=time(NULL);
t=localtime(&l_time);
if (cmdId <= 0){
debug_log("%d,system-%d,dataTypeNo=%d,the commId is error when scanCmd",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
sprintf(tmpSql, "LOAD DATA INFILE '%s' REPLACE INTO TABLE %s "\
" FIELDS TERMINATED BY ','",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
unlink(tmpLoadoutFile);
subsDataBackup[proc].backupStat=nOutBackup;
return ;
}
sprintf(tmpSql, "SELECT commState,remark,finishNum "
" FROM %s WHERE commId=\'%d\'", CommTable, cmdId);
tmpResult = (MYSQL_RES *) mysql_getres(dbConn, tmpSql);
if (tmpResult == NULL || mysql_num_rows(tmpResult) == 0) {
debug_log("%d,system-%d,dataTypeNo=%d,the commId is lost when scanCmd",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
subsDataBackup[proc].backupStat=nOutBackup;
mysql_free_result(tmpResult);
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
sprintf(tmpSql, "LOAD DATA INFILE '%s' REPLACE INTO TABLE %s "\
" FIELDS TERMINATED BY ','",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
unlink(tmpLoadoutFile);
return ;
}
tmpRow = mysql_fetch_row(tmpResult);
cmdState = atoi(tmpRow[0]);
strcpy(ErrorMsg, tmpRow[1]);
mysql_free_result(tmpResult);
switch (cmdState) {
case nProcFail:
waitFlag=0;
inFlag=0;
debug_log("%d,system-%d,dataTypeNo=%d,the get all command execute fail when scanCmd,%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,ErrorMsg);
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
sprintf(tmpSql, "LOAD DATA INFILE '%s' REPLACE INTO TABLE %s "\
" FIELDS TERMINATED BY ','",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
unlink(tmpLoadoutFile);
sprintf(tmpSql, "DELETE FROM %s WHERE commId=\'%d\'", CommTable, cmdId);
mysql_getnores(dbConn, tmpSql);
subsDataBackup[proc].backupStat=nOutBackup;
lastFinishNum=0;
return ;
break;
case nWaitProc:
inFlag=0;
if(waitFlag==1){
if(time(NULL)-waitTime>100){
debug_log("%d,system-%d,dataTypeNo=%d,wait the get all command execute timeout",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
sprintf(tmpSql, "LOAD DATA INFILE '%s' REPLACE INTO TABLE %s "\
" FIELDS TERMINATED BY ','",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
unlink(tmpLoadoutFile);
sprintf(tmpSql, "DELETE FROM %s WHERE commId=\'%d\'",CommTable, cmdId);
mysql_getnores(dbConn, tmpSql);
waitFlag=0;
lastFinishNum=0;
subsDataBackup[proc].backupStat=nOutBackup;
return ;
}
}else{
waitTime=time(NULL);
waitFlag=1;
}
break;
case nInProc:
waitFlag=0;
if((atoi(tmpRow[2])-lastFinishNum)>0){
inFlag=0;
lastFinishNum=atoi(tmpRow[2]);
}else{
if(inFlag==1){
if((time(NULL)-inTime)>MAX_GETALL_TIMEOUT){
debug_log("%d,system-%d,dataTypeNo=%d,wait the get all command executing timeout,the lastFinishNum is %d",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,lastFinishNum);
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
sprintf(tmpSql, "LOAD DATA INFILE '%s' REPLACE INTO TABLE %s "\
" FIELDS TERMINATED BY ','",tmpLoadoutFile,subsDataBackup[proc].subsDataTable);
if(mysql_getnores(dbConn, tmpSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,tmpSql);
}
unlink(tmpLoadoutFile);
sprintf(tmpSql, "DELETE FROM %s WHERE commId=\'%d\'",CommTable, cmdId);
mysql_getnores(dbConn, tmpSql);
subsDataBackup[proc].backupStat=nOutBackup;
inFlag=0;
lastFinishNum=0;
return ;
}
}else{
inFlag=1;
inTime=time(NULL);
}
}
break;
case nOutProc:
waitFlag=0;
inFlag=0;
lastFinishNum=0;
finishFlag=1;
sprintf(tmpSql, "DELETE FROM %s WHERE commId=\'%d\'",CommTable, cmdId);
mysql_getnores(dbConn, tmpSql);
debug_log("%d,system-%d,dataTypeNo=%d,the get all command execute finish",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo);
finishTime=time(NULL);
break;
default:
break;
} //end of switch
return ;
}
void backupFile(int proc)
{
char loadoutSql[400];
char loadoutFile[100];
char tmpLoadoutFile[100];
long l_time;
struct tm *t;
l_time=time(NULL);
t=localtime(&l_time);
sprintf(loadoutFile,"%s/%s_%d_%d.csv",subsComm_backupPath,subsDataBackup[proc].subsDataTable,t->tm_mon + 1,t->tm_mday-1);
unlink(loadoutFile);
sprintf(loadoutSql,"SELECT * INTO OUTFILE '%s' "\
" FIELDS TERMINATED BY ',' FROM %s",loadoutFile,subsDataBackup[proc].subsDataTable);
mysql_getnores(dbConn,loadoutSql);
if(mysql_getnores(dbConn, loadoutSql) == 0)
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql success=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,loadoutSql);
}
else
{
debug_log("%d,system-%d,dataTypeNo=%d,execute sql fail=%s",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,loadoutSql);
}
sprintf(tmpLoadoutFile,"%s/%s_tmp.csv",subsComm_backupPath, subsDataBackup[proc].subsDataTable);
unlink(tmpLoadoutFile);
debug_log("%d,system-%d,dataTypeNo=%d,backup %s finish",proc,subsDataBackup[proc].sysTypeNo,subsDataBackup[proc].dataTypeNo,subsDataBackup[proc].subsDataTable);
subsDataBackup[proc].backupStat=nOutBackup;
finishFlag=0;
return ;
}
void debug_log(const char *fmt,...)
{
char logFile[64];
FILE *fp;
time_t l_time;
va_list ap;
char buf[8192];
struct tm *t;
char timestr[64];
l_time=time(NULL);
t=localtime(&l_time);
sprintf(logFile,"../log/subsDataBackup_%04d%02d%02d.log",t->tm_year+1900,t->tm_mon+1,t->tm_mday);
fp=fopen(logFile,"a");
if(fp!=NULL)
{
va_start(ap,fmt);
vsprintf(buf,fmt,ap);
sprintf(timestr,"%02d:%02d:%02d: ",t->tm_hour,t->tm_min,t->tm_sec);
fputs(timestr,fp);
fputs(buf,fp);
fputs("\n",fp);
fflush(fp);
va_end(ap);
fclose(fp);
}
}

View File

@@ -0,0 +1,88 @@
/* Title: subsDataBackup.h
* Description: back up the subscriber data
* Author: Cui Ticun
* Date: 2005/01/15
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <memory.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <sys/time.h>
#include <time.h>
#include <net/if.h>
#include <syslog.h>
#include <termio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <syslog.h>
#include <sys/io.h>
#include <error.h>
#include <sys/stat.h>
#include <ftw.h>
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "mysql.h"
#define subsDataBackup_LogPath "../log"
#define subsDataBackup_LogFile "subsDataBackup"
#define subsComm_backupPath "/usr/local/apache/htdocs/db_backup/subsData"
#define MaxSysConfNum 18
#define MAX_GETALL_TIMEOUT 7200
#define HOSTNAME "localhost"
#define PUB_DB "OMC_PUB" //OMC's public database
#define SysConfTable "OMC_PUB.sysConf" //system config table
#define subsConfTable "OMC_PUB.sysSubsConf" //system config table
#define CommTable "OMC_PUB.subscriberComm" //command table
#define IpTable "OMC_PUB.sysInfo" //system's IP table
#define subsDataBackupTable "OMC_PUB.subsDataBackup" //
#define omcPubVarConfTable "OMC_PUB.omcPubVarConf" //
//commState flag define
#define nProcFail 0
#define nWaitProc 1
#define nInProc 2
#define nOutProc 3
//subs data backup state
#define nNotBackup 0
#define nWaitBackup 1
#define nInBackup 2
#define nOutBackup 3
typedef struct subsData_Backup{
int backupStat;
int sysTypeNo;
int dataTypeNo;
int sysNo;
int subSysNo;
char subsDataTable[128];
char tmpDataTable[128];
}subsData_Backup;
/* by simon at 23/9/25 */
// subsData_Backup subsDataBackup[MaxSysConfNum];
//Interface Functions Declare,define in subsComm.c
void subsDataBackupInit();
void subsDataBackupTimer();

View File

@@ -0,0 +1,107 @@
/* Title: subsDataBackupMain.c
* Description: back up the subscriber data
* Author: Cui Ticun
* Date: 2003/02/14
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "subsDataBackup.h"
static struct itimerval itimer, old_itimer;
void onTimer();
void setTimer();
void setup_daemon(void);
int main(int argc, char *argv[])
{
char runMode;
subsDataBackupInit();
if (argc > 0) {
runMode = getopt(argc, argv, "d");
switch (runMode) {
case 'd':
setup_daemon();
break;
case '?':
break;
}
//debug_init();//must do it at first
}
setTimer();
while (1) {
usleep(50);
}
return (1);
}
void onTimer()
{
subsDataBackupTimer();
}
void setTimer()
{
struct sigaction act;
act.sa_handler = onTimer;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGALRM, &act, NULL) < 0) {
exitLog("subsDataBackup:setTimer, sigaction function error");
perror("Produce Sigaction");
exit(1);
}
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 20 * 1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 20 * 1000;
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
printf("Setting Timer error! \n");
exitLog("subsDataBackup:setTimer, setitimer function error");
exit(1);
}
}
void setup_daemon(void)
{
/*
int i;
for (i = 0; i < 3; ++i) {
close(i);
}
*/
switch (fork()) {
case -1:
perror("setup_daemon(), 1st fork()");
exit(2);
default:
exit(0);
case 0:
if (setsid() == -1) {
perror("setup_daemon(), setsid()");
exit(3);
}
switch (fork()) {
case -1:
perror("setup_daemon(), 2nd fork()");
exit(3);
default:
exit(0);
case 0:
umask(0);
/* and return with daemon set up */
return;
}
}
}

View File

@@ -0,0 +1,90 @@
#/bin/sh
# Makefile for CDR Module.
CC = gcc
CFLAGS=-g -Wall -I/usr/local/mysql/include
CFLAGS.ES=-g -Wall -I/usr/include/mariadb
COMPILE.c=$(CC) $(CFLAGS)
COMPILE.c.ES=$(CC) $(CFLAGS.ES)
LINK.c=$(CC) $(CFLAGS)
LINK.c.ES=$(CC) $(CFLAGS.ES)
LINKFLAG=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L../../../../wxc2plat/snmp -lsnmp \
-L../../../../wxc2plat/debug -ldebug \
-L../../../../wxc2plat/iptrans -liptrans \
-L../../../../wxc2plat/public -lpublic \
-L/usr/local/mysql/lib -lmariadbclient -lz
LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L../../../../plat/smpp/lib -lsmpp \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/mtp3/lib -lmtp3 \
-L../../../../plat/m2ua/lib -lm2ua \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lz
PROGS=wsms
WSMS_OBJ = wsms.o
WSMS_OBJ.ES = wsms.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files(*.o, *.a)"
@echo "make linux72 -- Generate target files for Redhat Linux 7.2"
@echo "make linuxES -- Generate target files for Redhat ES 4.0"
linux72: $(WSMS_OBJ) wsmsmain.o
@cd ../../../omcLib/c_program/ftp; make linux72; cd ..
@cd ../../../accountMgr/c_program/wsms;
@echo Linking $(PROGS)
@$(LINK.c) -o $(PROGS) wsmsmain.o $(WSMS_OBJ) $(LINKFLAG) -lm
ar r libwsms.a $(WSMS_OBJ)
rm -rf *.o
rm -rf *bak
rm -rf *~
cp -f $(PROGS) ../../../bin
cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(WSMS_OBJ.ES) wsmsmain.o.ES
@cd ../../../omcLib/c_program/ftp; make linuxES; cd ..
@cd ../../../accountMgr/c_program/wsms;
@echo Linking $(PROGS)
@$(LINK.c.ES) -o $(PROGS) wsmsmain.o $(WSMS_OBJ) $(LINKFLAG.ES) -lm
ar r libwsms.a $(WSMS_OBJ)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
wsmsmain.o: wsmsmain.c
$(COMPILE.c) -c wsmsmain.c
wsms.o: wsms.c wsms.h
$(COMPILE.c) -c wsms.c
wsmsmain.o.ES: wsmsmain.c
$(COMPILE.c.ES) -c wsmsmain.c
wsms.o.ES: wsms.c wsms.h
$(COMPILE.c.ES) -c wsms.c
clean:
rm -f *.o *.a $(PROGS)
@cd ../../../omcLib/c_program/ftp; rm -f *.o *.a; cd ..
@cd ../../../accountMgr/c_program/wsms;rm -f *.o *.a; cd ..

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
#ifndef wsms__H
#define wsms__H
#ifndef MYSQL_H
#include "mysql.h"
#endif
#ifndef WSMS_DEBUG
#define WSMS_DEBUG 0
#endif
#define CDR_ALARM_FLAG 1
#include "mysql.h"
#include "errmsg.h"
#include <dirent.h>
#include <time.h>
#include "../../../../plat/public/src/include/pub_include.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#include "../../../../plat/public/src/include/asn1.h"
#include "../../../../plat/iptrans/src/include/iptrans.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "../../../../plat/mtp3/src/include/mtp3.h"
#include "../../../../plat/sccp/src/include/sccp.h"
#include "../../../../plat/smpp/src/include/smpp.h"
#define HPMN_MAX 100
#define WEL_AD_MAX 32
/* Use for the information of every HPMN */
typedef struct HpmnServer
{
char mcc[8]; //The mcc of the hpmn server
char mnc[8]; //The mnc of the hpmn server
int flag; //1-enable, 0-disable
int smsEncode; //0-7 bit, 1-8 bit, 2-16 bit
unsigned char wlContent[512]; //The welcome short message of the hpmn server
int adCount; //The count of AD short messages
unsigned char adContent[WEL_AD_MAX][512]; //The content of each AD short message
int adValid[WEL_AD_MAX]; //The valid flag of each AD short message
}HpmnServer;
/**************************/
/**** function *****/
/**************************/
int wsms_init(void);
void wsms_timer(void);
#endif

View File

@@ -0,0 +1,102 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "wsms.h"
static struct itimerval itimer, old_itimer;
static void On_Timer();
static void SetTimer();
/*************************************************
Function: // main
Description: // The main function of the module
Calls: //
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
int main(int argc, char *argv[])
{
pid_t pid;
if (argc == 2 && strstr(argv[1], "-d")) {
if ((pid = fork()) != 0)
exit(0);
setsid();
}
wsms_init();
SetTimer();
while (1) {
usleep(50);
}
return 1;
}
/*************************************************
Function: // On_Timer
Description: // Timer function
Calls: //
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void On_Timer()
{
wsms_timer();
}
/*************************************************
Function: // SetTimer
Description: // Timer function
Calls: // On_Timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void SetTimer()
{
struct sigaction act;
act.sa_handler = On_Timer;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGALRM, &act, NULL) < 0)
{
perror("Produce Sigaction");
exitLog("wsms:SetTimer, sigaction function error");
exit(1);
}
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 20 * 1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 20 * 1000;
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0)
{
printf("Setting Timer error! \n");
exitLog("wsms:SetTimer, setitimer function error");
exit(1);
}
}

View File

@@ -0,0 +1,104 @@
#/bin/sh
# Makefile for CDR Module.
CC = gcc
CFLAGS=-g -Wall -I/usr/local/mysql/include
CFLAGS.ES=-g -Wall -I/usr/include/mariadb
COMPILE.c=$(CC) $(CFLAGS)
COMPILE.c.ES=$(CC) $(CFLAGS.ES)
LINK.c=$(CC) $(CFLAGS)
LINK.c.ES=$(CC) $(CFLAGS.ES)
LINKFLAG=-L../../../omcLib/c_program/ftp -lftp \
-L../../../../wxc2plat/snmp -lsnmp \
-L../../../../wxc2plat/debug -ldebug \
-L../../../../wxc2plat/iptrans -liptrans \
-L../../../../wxc2plat/public -lpublic \
-L/usr/local/mysql/lib -lmariadbclient -lz
LINKFLAG.ES=-L../../../omcLib/c_program/omcLib -lomcLib \
-L../../../omcLib/c_program/ftp -lftp \
-L../../../../plat/snmp/lib -lsnmp \
-L../../../../plat/debug/lib -ldebug \
-L../../../../plat/sccp/lib -lsccp \
-L../../../../plat/iptrans/lib -liptrans \
-L../../../../plat/public/lib -lpublic \
-L/usr/lib/mysql -lmariadbclient -lz
PROGS=cdrCollector
CDR_OBJ = cdr.o cdrdebug.o cdrdb.o cdrlog.o
CDR_OBJ.ES = cdr.o.ES cdrdebug.o.ES cdrdb.o.ES cdrlog.o.ES
default: linuxES
all:
@echo " **** Compiling $(PROGS) ****"
@echo "make clean -- Delete the target files(*.o, *.a)"
@echo "make linux72 -- Generate target files for Redhat Linux 7.2"
@echo "make linuxES -- Generate target files for Redhat ES 4.0"
linux72: $(CDR_OBJ) cdrmain.o
@cd ../../../omcLib/c_program/ftp; make linux72; cd ..
@cd ../../../accountMgr/c_program/cdrCollector;
@echo Linking $(PROGS)
@$(LINK.c) -o $(PROGS) cdrmain.o $(CDR_OBJ) $(LINKFLAG) -lm
ar r libcdr.a $(CDR_OBJ)
rm -rf *.o
rm -rf *bak
rm -rf *~
#cp -f $(PROGS) ../../../bin
#cp -f $(PROGS) /usr/local/omc/bin/
linuxES: $(CDR_OBJ.ES) cdrmain.o.ES
@cd ../../../omcLib/c_program/ftp; make linuxES; cd ..
@cd ../../../accountMgr/c_program/cdrCollector;
@echo Linking $(PROGS)
@$(LINK.c.ES) -o $(PROGS) cdrmain.o $(CDR_OBJ) $(LINKFLAG.ES) -lm
ar r libcdr.a $(CDR_OBJ)
installbin: linuxES
cp -f $(PROGS) ../../../../bin/
installomc: linuxES
cp -f $(PROGS) /usr/local/omc/bin/
installall: installbin installomc
cdrmain.o: cdrmain.c
$(COMPILE.c) -c cdrmain.c
cdr.o: cdr.c cdr.h
$(COMPILE.c) -c cdr.c
cdrdebug.o: cdrdebug.c
$(COMPILE.c) -c cdrdebug.c
cdrdb.o:cdrdb.c
$(COMPILE.c) -c cdrdb.c
cdrlog.o: cdrlog.c
$(COMPILE.c) -c cdrlog.c
cdrmain.o.ES: cdrmain.c
$(COMPILE.c.ES) -c cdrmain.c
cdr.o.ES: cdr.c cdr.h
$(COMPILE.c.ES) -c cdr.c
cdrdebug.o.ES: cdrdebug.c
$(COMPILE.c.ES) -c cdrdebug.c
cdrdb.o.ES:cdrdb.c
$(COMPILE.c.ES) -c cdrdb.c
cdrlog.o.ES: cdrlog.c
$(COMPILE.c.ES) -c cdrlog.c
clean:
rm -f *.o *.a $(PROGS)
@cd ../../../omcLib/c_program/ftp; rm -f *.o *.a; cd ..
@cd ../../../accountMgr/c_program/cdrCollector;rm -f *.o *.a; cd ..

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,155 @@
/*************************************************
File name: cdr.h
Author:
Version: 9:00:00
Date: 2002-5-7
Description:<3A><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cdrCollectorģ<72><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һЩ<D2BB><D0A9><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<09>ṹcdr_src,cdr_def,cdr_tlv
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#ifndef __CDR_HEAD_FILE
#define __CDR_HEAD_FILE
#include "mysql.h"
#include "errmsg.h"
#include <dirent.h>
#include "../../../../plat/public/src/include/asn1.h"
#include "../../../../plat/snmp/src/include/snmp.h"
#include "../../../omcLib/c_program/omcLib/omcLib.h"
#ifndef _T_DWORD
#define _T_DWORD
typedef unsigned int DWORD;
#endif
#define CDR_DEBUG 0
#define CDR_LINK_DEBUG 0
#define CDR_PORT 4968
#define CDR_SRC_NUM 32
#define CDR_TYPE_NUM 20
#define CDR_OBJ_MAX 128
#define HOST_NAME "localhost"
#define CDRDB_NAME "CDR_DB"
#define CSV_PATH "/usr/local/cdr"
#define CDR_LOG_PATH "../log"
#define CDR_LOG_FILE "cdrlog"
#define ST_GET_TAIL 0
#define ST_WAIT_TAIL 1
#define ST_CDR_IDLE 2
#define ST_GET_CDR 3
#define ST_WAIT_CDR 4
#define ST_TAIL_IDLE 5
#define ST_SET_TAIL 6
#define CDR_TIME_UNIT 20 //ms
#define CDR_T_idle 250 //5s lowest speed
#define CDR_T_getcdr 30 //60ms
#define CDR_T_gettail 500 //300*20=6000ms=10s
#define CDR_T_settail 100 //2s
#define HEAP_SIZE_MAX 256 //1024*28
#define HEAP_TIME_MAX 50*30 //30s
#define OMC_SINGLE 7
#define OMC_MASTER 5
char totalCdrFileName[128];
char cdrFileName[128];
int cdrHour;
//<2F>˽ṹ<CBBD><E1B9B9><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֶ<EFBFBD>
typedef struct cdr_tlv {
char tag_seq[17][20]; //16<31><36>tag<61><67>ֵ
char field_name[30]; //<2F>ֶε<D6B6><CEB5><EFBFBD><EFBFBD><EFBFBD>
BYTE type; //<2F>ֶε<D6B6><CEB5><EFBFBD><EFBFBD><EFBFBD>
BOOL optional; //<2F>ֶ<EFBFBD><D6B6>Ƿ<EFBFBD><C7B7><EFBFBD>ѡ
BYTE width; //<2F>ֶγ<D6B6><CEB3><EFBFBD>
} cdr_tlv;
//<2F>˽ṹ<CBBD><E1B9B9><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1>Ķ<EFBFBD><C4B6><EFBFBD><E5A3AC><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD>ֶζ<D6B6><CEB6><EFBFBD>
typedef struct cdr_def {
BOOL valid[17]; //tagλ<67><CEBB>ʶ
char field_set[1024]; //ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
char field_select[1024];//ָ<><D6B8><EFBFBD><EFBFBD><E6B1BE>ȫ<EFBFBD><C8AB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
char create_sql[2048]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>sql<71><6C><EFBFBD><EFBFBD>
BYTE field_count; //<2F>ֶεĸ<CEB5><C4B8><EFBFBD>
cdr_tlv obj[CDR_OBJ_MAX];//<2F>ֶζ<D6B6><CEB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} cdr_def;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ݽṹ<DDBD><E1B9B9><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>CDR<44><52><EFBFBD><EFBFBD>Դ
typedef struct cdr_src {
int loss; //<2F><><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>
int recv; //<2F><><EFBFBD>յİ<D5B5><C4B0>ĸ<EFBFBD><C4B8><EFBFBD>
int recd; //<2F><>¼<EFBFBD>İ<EFBFBD><C4B0>ĸ<EFBFBD><C4B8><EFBFBD>
BYTE cdr_ver; //<2F><EFBFBD><E6B1BE>
WORD sysTypeNo; //ϵͳ<CFB5><EFBFBD><E8B1B8>
BYTE sysid; //ϵͳ<CFB5><CDB3>
BYTE retry; //<2F><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
//informaion for getting cdr
int get_timeout; //get<65><74><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3>ʱ<EFBFBD><CAB1>
BOOL get_state; //get״̬
DWORD instance; //ͷָ<CDB7><D6B8>
DWORD head; //βָ<CEB2><D6B8>
BYTE maxbind; //<2F><><EFBFBD><EFBFBD><EFBFBD>󶨱<EFBFBD><F3B6A8B1><EFBFBD><EFBFBD><EFBFBD>
DWORD request_id; //get<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
//information for setting ptail
int set_timeout; //set<65><74><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3>ʱ<EFBFBD><CAB1>
BYTE set_fail; //setʧ<74>ܴ<EFBFBD><DCB4><EFBFBD>
BOOL set_state; //set״̬
BOOL move_flag; //βָ<CEB2><D6B8><EFBFBD>Ƿ<EFBFBD><C7B7>ı<EFBFBD>
DWORD set_rid; //set<65><74><EFBFBD><EFBFBD>ID
snmp_addr addr; //IP<49>Ͷ˿ڵ<CBBF>ַ
DWORD oid[20]; //OID
BYTE oid_len; //OID<49><44><EFBFBD><EFBFBD>
DWORD head_oid[20]; //ͷָ<CDB7><D6B8>OID
DWORD tail_oid[20]; //βָ<CEB2><D6B8>OID
char record_table[30]; //<2F><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>
char define_table[30]; //<2F><><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char csv_path[50]; //<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
int backup_max; //<2F><><EFBFBD>󱸷ݸ<F3B1B8B7><DDB8><EFBFBD>
int buf_size; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
cdr_def define; //<2F><>Ӧ<EFBFBD><D3A6><EFBFBD>ֶα<D6B6><CEB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//BOOL receive_tail;
//BOOL receive_cdr;
//int serial;
} cdr_src;
void converseFile();
void cdr_timer();
void cdr_init();
#if CDR_LINK_DEBUG
void cdrdebug_init();
#endif
void cdrdb_init();
void cdr_start();
void cdr_stop();
BOOL cdr_status();
void cdrdb_timer();
void cdrlog_init();
void cdrlog_timer();
void cdr_log(const char *fmt, ...);
void cdr_logmsg(BYTE * buf, int len);
void cdr_report();
int safe_query(MYSQL * conn, char *strquery, int retry);
#endif

View File

@@ -0,0 +1,990 @@
/*************************************************
File name: cdrdb.c
Author:
Version: 9:00:00
Date: 2002-5-7
Description:<3A><><EFBFBD>ļ<EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>cdrCollectorģ<72><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҷ<EFBFBD>ʱ<EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>б<EFBFBD><D0B1>ݣ<EFBFBD>
ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>csv<73><76><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include "cdr.h"
#include "../../../omcLib/c_program/ftp/ftp.h"
static MYSQL *cdrdb_conn;
static MYSQL *omcPub_conn;
extern cdr_src CdrSet[CDR_SRC_NUM];
extern BYTE iCdrNum;
static BYTE backup_flag=0;
static char tb_name[64][48];
static int cdr_index = 0, tb_index = 0, tb_num = 0;
static char compress_file[64];
static char send_file[64];
static char sening_dir[128];
void enum_cdrdb();
void backup_table(char *tb_name, char *csv_path,int flag,char *selfield,BYTE cdr_ver);
void create_csv(char *tb_name, char *csv_path,int flag,char *selfield);
void create_dat_for_wxc1(char *tb_name,char *csv_path,int flag,char *selfield);
void compress_csv(char *path_name);
//void chfilename(char *path_name, char *oldname);
void delfile(char *path_name,char *filename);
void clear_table(char *tb_name);
void send_csv(char *path_name);
/*************************************************
Function: // cdrdb_init
Description: // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ݿ⣬<DDBF><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // mysql_init; mysql_real_connect; mysql_query;
Called By: // cdrmain.c:cdr_init;
Table Accessed: // OMC_PUB.omcPubVarConf; CDR_DB.cdrPubVarConf;
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void cdrdb_init()
{
char sqlstr[256];
MYSQL_RES *res;
MYSQL_ROW row;
BYTE m_state = 1;
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
while ((cdrdb_conn = mysql_init(NULL)) == NULL) {
printf("Fail to init mysql:%s\n", mysql_error(cdrdb_conn));
sleep(2);
}
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
while (mysql_real_connect
(cdrdb_conn, "localhost", "root", "rootaa", "CDR_DB", 0, NULL,
0) == NULL) {
printf("Fail to init mysql:%s\n", mysql_error(cdrdb_conn));
sleep(2);
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sending_directory<72><79>ֵ
sprintf(sqlstr,
"SELECT pubVarValue FROM CDR_DB.cdrPubVarConf WHERE pubVarName='sending_directory'");
if (mysql_query(cdrdb_conn, sqlstr) != 0) {
cdr_log("%s\n", mysql_error(cdrdb_conn));
return;
}
if ((res = mysql_store_result(cdrdb_conn)) == NULL)
return;
if((row = mysql_fetch_row(res)) != NULL) {
strcpy(sening_dir,row[0]);
}
mysql_free_result(res);
while ((omcPub_conn = mysql_init(NULL)) == NULL) {
printf("Fail to init mysql:%s\n", mysql_error(omcPub_conn));
sleep(2);
}
while (mysql_real_connect
(omcPub_conn, "localhost", "root", "rootaa", "OMC_PUB", 0, NULL,
0) == NULL) {
printf("Fail to init mysql:%s\n", mysql_error(omcPub_conn));
sleep(2);
}
//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cdr_store_server<65><72>ֵ
sprintf(sqlstr,
"SELECT pubVarValue FROM OMC_PUB.omcPubVarConf WHERE pubVarName='cdr_store_server'");
if (mysql_query(omcPub_conn, sqlstr) != 0) {
cdr_log("%s\n", mysql_error(omcPub_conn));
return;
}
if ((res = mysql_store_result(omcPub_conn)) == NULL){
return;
}
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
if((row = mysql_fetch_row(res)) != NULL) {
if(strlen(row[0]) == 0)
{
backup_flag=0;
}
else
{
backup_flag=1;
}
}
mysql_free_result(res);
/*
while (m_state != 0) {
switch (m_state) {
case 1: //find tables in CDR_DB
if (cdr_index < iCdrNum) {
enum_cdrdb();
m_state = 2;
} else
m_state = 5;
break;
case 2: //backup table
if (tb_index < tb_num) {
backup_table(tb_name[tb_index],
CdrSet[cdr_index - 1].csv_path);
m_state = 3;
} else
m_state = 1;
break;
case 3: //delete old records
clear_table(tb_name[tb_index]);
tb_index++;
m_state = 4;
break;
case 4: //don't compress csv files
//compress_csv(CdrSet[cdr_index-1].csv_path);
m_state = 2;
break;
case 5: //finish
cdr_index = 0;
tb_index = 0;
m_state = 0;
return;
}
}*/
cdr_index = 0;
tb_index = 0;
m_state = 0;
return;
}
/*************************************************
Function: // cdrdb_timer
Description: // ÿСʱ<D0A1><CAB1>һЩ<D2BB>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E7B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><C9BE><EFBFBD>ɵļ<C9B5>¼<EFBFBD><C2BC>
Calls: // backup_table; enum_cdrdb; clear_table;
Called By: // cdrmain.c:cdr_timer;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void cdrdb_timer()
{
unsigned long l_time;
struct tm *t;
static BYTE m_state = 0;
//for backup table per hour
int h_cdr_index=0;
//for backup table per hour
char h_tb_name[64];
int flag;
l_time = time(NULL);
t = localtime(&l_time);
if(t->tm_min==0){
for(h_cdr_index=0;h_cdr_index<iCdrNum;h_cdr_index++){
if(t->tm_hour==0){
sprintf(h_tb_name,"%s_%d",CdrSet[h_cdr_index].record_table,23);
flag=1;
}else{
sprintf(h_tb_name,"%s_%02d",CdrSet[h_cdr_index].record_table,t->tm_hour-1);
flag=0;
}
backup_table(h_tb_name, CdrSet[h_cdr_index].csv_path,flag,CdrSet[h_cdr_index].define.field_select,CdrSet[h_cdr_index].cdr_ver);
// send_csv(CdrSet[h_cdr_index].csv_path);
}
}
switch (m_state) {
//IDLE
case 0:
l_time = time(NULL);
t = localtime(&l_time);
if (t->tm_hour == 3) {
m_state = 1;
cdr_index = 0;
tb_index = 0;
}
break;
//find tables in CDR_DB
case 1:
if (cdr_index < iCdrNum) {
enum_cdrdb();
m_state = 2;
} else
m_state = 5;
break;
//backup table
case 2:
if (tb_index < tb_num) {
//backup_table(tb_name[tb_index], CdrSet[cdr_index-1].csv_path,1,CdrSet[cdr_index-1].define.field_select,CdrSet[cdr_index-1].cdr_ver);
m_state = 3;
} else
m_state = 1;
break;
//delete old records
case 3:
clear_table(tb_name[tb_index]);
tb_index++;
m_state = 4;
break;
//compress csv files
case 4:
//compress_csv(CdrSet[cdr_index].csv_path);
m_state = 2;
break;
//finish
case 5:
l_time = time(NULL);
t = localtime(&l_time);
if (t->tm_hour != 3) {
cdr_index = 0;
tb_index = 0;
m_state = 0;
}
break;
}
}
/*************************************************
Function: // enum_cdrdb
Description: // <20>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // mysql_query; mysql_store_result; mysql_fetch_row;
Called By: // cdrdb_timer;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void enum_cdrdb()
{
cdr_src *pcdr;
char sqlstr[64];
MYSQL_RES *res_set;
MYSQL_ROW row;
int i;
tb_index = tb_num = 0;
pcdr = &CdrSet[cdr_index++];
for (i = 0; i < cdr_index - 2; i++) {
if (strstr(CdrSet[i].record_table, pcdr->record_table) != NULL) {
cdr_index++;
return;
}
}
cdr_log("Search tables like %s*\n", pcdr->record_table);
sprintf(sqlstr, "SHOW TABLES FROM CDR_DB LIKE '%s_%%'",
pcdr->record_table);
if (mysql_query(cdrdb_conn, sqlstr) != 0)
return;
if ((res_set = mysql_store_result(cdrdb_conn)) == NULL)
return;
while ((row = mysql_fetch_row(res_set)) != NULL && tb_num < 64) {
if (row[0] != NULL)
strcpy(tb_name[tb_num++], row[0]);
}
mysql_free_result(res_set);
}
/*************************************************
Function: // backup_table
Description: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>csv<73>ļ<EFBFBD><C4BC><EFBFBD>Щ׼<D0A9><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // mysql_query; mysql_store_result; mysql_fetch_row; create_dat_for_wxc1; create_csv;
Called By: // cdrdb_timer;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: // tb_name:<3A><><EFBFBD><EFBFBD>; csv_path:<3A><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>; flag:<3A><>־λ; selfield; cdr_ver:<3A>汾;
Output: //
Return: //
Others: //
*************************************************/
void backup_table(char *tb_name, char *csv_path,int flag,char *selfield,BYTE cdr_ver)
{
char sqlstr[256];
MYSQL_RES *res_set;
MYSQL_ROW row;
char timestr[50];
//char mytime[20],myday[20];
long l_time;
struct tm *t;
cdr_log("Start backup table %s\n", tb_name);
if(flag==1)
sprintf(sqlstr,
"SELECT DATE_FORMAT(releaseTime,'%%Y_%%m_%%d') FROM %s WHERE TO_DAYS(releaseTime)<TO_DAYS(NOW()) LIMIT 1",
tb_name);
else
sprintf(sqlstr,
"SELECT DATE_FORMAT(releaseTime,'%%Y_%%m_%%d') FROM %s WHERE TO_DAYS(releaseTime)=TO_DAYS(NOW()) LIMIT 1",
tb_name);
if (mysql_query(cdrdb_conn, sqlstr) != 0) {
cdr_log("Fail to query:%s\n", mysql_error(cdrdb_conn));
return;
}
if ((res_set = mysql_store_result(cdrdb_conn)) == NULL)
return;
if ((row = mysql_fetch_row(res_set)) == NULL || row[0] == NULL) {
mysql_free_result(res_set);
cdr_log("No old record in table\n");
l_time = time(NULL);
if(flag==1)
l_time = l_time-24*3600;//for the yesterday
t = localtime(&l_time);
sprintf(timestr,"%04d_%02d_%02d",t->tm_year + 1900, t->tm_mon + 1,t->tm_mday);
// return;
}else{
strcpy(timestr, row[0]);
mysql_free_result(res_set);
}
//<2F><><EFBFBD>ݰ汾<DDB0>Ų<EFBFBD><C5B2><EFBFBD>csv<73>ļ<EFBFBD>
/*if(cdr_ver==1)
create_dat_for_wxc1(tb_name, timestr, csv_path,flag,selfield);
else
create_csv(tb_name, timestr, csv_path,flag,selfield);*/
}
/*************************************************
Function: // create_csv
Description: // <20><><EFBFBD><EFBFBD>csv<73>ļ<EFBFBD>
Calls: // mysql_query;
Called By: // backup_table;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: // tb_name:<3A><><EFBFBD><EFBFBD>; time_str:ʱ<><CAB1>; csv_path:<3A><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>; flag:<3A><>־λ; selfield;
Output: //
Return: //
Others: //
*************************************************/
void create_csv(char *tb_name, char *csv_path,int flag,char *selfield)
{
char olddir[128], sqlstr[1024], csv_file[32], tb_prefix[32], *pchr, cmdstr[1024]; //cur_path[96],dirname[32];
struct stat fileinfo;
// char filestr[]
// MYSQL_RES *res_set;
// MYSQL_ROW row;
strcpy(tb_prefix, tb_name);
if ((pchr = strchr(tb_prefix, '_')) == NULL)
return;
*(pchr++) = '\0';
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼
getcwd(olddir, 128);
cdr_log("%s\n", tb_name);
cdr_log("%s\n", csv_path);
if (chdir(csv_path) == -1) {
sprintf(cmdstr, "mkdir -p -m777 %s", csv_path);
cdr_log("%s\n", cmdstr);
system(cmdstr);
if (chdir(csv_path) == -1)
return;
}
//<2F><>sending_dirĿ¼ȥ<C2BC><C8A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򴴽<EFBFBD>
if (chdir(sening_dir) == -1) {
sprintf(cmdstr, "mkdir -p -m777 %s", sening_dir);
cdr_log("%s\n", cmdstr);
system(cmdstr);
if (chdir(sening_dir) == -1)
return;
}
//sprintf(csv_file, "%s_%s_%s.csv", tb_prefix, time_str, pchr);
sprintf(csv_file, "%s", cdrFileName);
//chfilename(csv_path, csv_file);
delfile(csv_path, csv_file);
cdr_log("%s\n", csv_path);
cdr_log("%s\n", csv_file);
cdr_log("%s\n", CDRDB_NAME);
cdr_log("%s\n", tb_name);
//*************************************************************
//<2F><><EFBFBD><EFBFBD>csv<73>ļ<EFBFBD>
if(flag==1)
sprintf(sqlstr,
"SELECT %s INTO OUTFILE '%s/%s' FROM %s.%s ",
selfield,csv_path, csv_file, CDRDB_NAME, tb_name);
else
sprintf(sqlstr,
"SELECT %s INTO OUTFILE '%s/%s' FROM %s.%s ",
selfield,csv_path, csv_file, CDRDB_NAME, tb_name);
//sprintf(sqlstr,"SELECT * INTO OUTFILE '%s/%s' FIELDS TERMINATED BY ',' FROM %s.%s WHERE TO_DAYS(releaseTime)<TO_DAYS(NOW())",csv_path,csv_file,CDRDB_NAME,tb_name);
printf("%s\n", sqlstr);
if (mysql_query(cdrdb_conn, sqlstr) != 0) {
printf("Fail to create csv:%s\n", mysql_error(cdrdb_conn));
{
chdir(olddir);
return;
}
} else {
//if(backup_flag)
{
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>csv<73>ļ<EFBFBD><C4BC>ƶ<EFBFBD><C6B6><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>·<EFBFBD><C2B7>
sprintf(send_file,"%s",csv_file);
sprintf(cmdstr, "cp %s/%s %s/%s.bak",csv_path,csv_file,csv_path,csv_file);
system(cmdstr);
sprintf(cmdstr, "mv %s/%s.bak %s/%s",csv_path,csv_file,sening_dir,csv_file);
system(cmdstr);
}
if (stat(csv_file, &fileinfo) == 0)
{
/*if (fileinfo.st_size == 0) {
cdr_log("zero size,delete file %s\n", csv_file);
remove(csv_file);
} else*/
strcpy(compress_file, csv_file);
}
}
//chdir(olddir);
}
/*************************************************
Function: // clear_table
Description: // ɾ<><C9BE><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>ݱ<EFBFBD>
Calls: // mysql_query; mysql_store_result; mysql_fetch_row;
Called By: // cdrdb_timer;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: // tb_name:<3A><><EFBFBD><EFBFBD>;
Output: //
Return: //
Others: //
*************************************************/
void clear_table(char *tb_name)
{
char sqlstr[256];
MYSQL_RES *res_set;
MYSQL_ROW row;
cdr_log("clear table %s...", tb_name);
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD>ݱ<EFBFBD>
sprintf(sqlstr,
"DELETE FROM %s.%s ",
CDRDB_NAME, tb_name);
if (mysql_query(cdrdb_conn, sqlstr) != 0) {
cdr_log("Fail to clear table:%s\n", mysql_error(cdrdb_conn));
return;
}
/*
cdr_log("optimizing...\n");
sprintf(sqlstr, "OPTIMIZE TABLE %s", tb_name);
if (mysql_query(cdrdb_conn, sqlstr) != 0) {
cdr_log("Fail to optimizing table:%s\n", mysql_error(cdrdb_conn));
return;
}
if ((res_set = mysql_store_result(cdrdb_conn)) != NULL) {
while ((row = mysql_fetch_row(res_set))) {
cdr_log("%s/%s/%s/%s\n", row[0], row[1], row[2], row[3]);
}
}
mysql_free_result(res_set);*/
}
/*************************************************
Function: // compress_csv
Description: // ѹ<><D1B9>csv<73>ļ<EFBFBD>
Calls: //
Called By: // cdrdb_timer;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: // path_name:·<><C2B7><EFBFBD><EFBFBD>;
Output: //
Return: //
Others: //
*************************************************/
void compress_csv(char *path_name)
{
char olddir[128], *pchr, file_prefix[64], csv_file[64], tarfile[64],
cmdstr[128];
DWORD oldmask;
//<2F>Ƿ<EFBFBD><C7B7>ļ<EFBFBD>
if (strlen(compress_file) < 1)
return;
cdr_log("start compress file '%s' in %s\n", compress_file, path_name);
strcpy(csv_file, compress_file);
strcpy(file_prefix, compress_file);
compress_file[0] = '\0';
//<2F><><EFBFBD><EFBFBD>csv<73>ļ<EFBFBD>
if ((pchr = strstr(file_prefix, ".csv")) == NULL)
return;
*(pchr) = '\0';
getcwd(olddir, 128);
if (chdir(path_name) == -1)
return;
sprintf(tarfile, "%s.tgz", file_prefix);
//chfilename(path_name, tarfile);
delfile(path_name, tarfile);
//<2F><>ʼѹ<CABC><D1B9>
oldmask = umask(0);
sprintf(cmdstr, "tar zvfc ./%s ./%s", tarfile, csv_file);
system(cmdstr);
umask(oldmask);
if (access(tarfile, F_OK) == 0)
remove(csv_file);
else {
cdr_log("Fail to compress csv file %s\n", csv_file);
chdir(olddir);
return;
}
chdir(olddir);
}
/*
void chfilename(char *path_name, char *oldname)
{
char newname[64], newpath[96];
int n = 0;
strcpy(newname, oldname);
sprintf(newpath, "%s/%s", path_name, newname);
while (access(newpath, F_OK) == 0) {
sprintf(newname, "%s~%d", oldname, n++);
sprintf(newpath, "%s/%s", path_name, newname);
}
cdr_log("File %s/%s exist.change it's name to %s\n", path_name,
oldname, newname);
strcpy(oldname, newname);
}
*/
/*************************************************
Function: // delfile
Description: // ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
Calls: //
Called By: // create_csv;
Table Accessed: //
Table Updated: //
Input: // path_name:·<><C2B7><EFBFBD><EFBFBD>; file_name:<3A>ļ<EFBFBD><C4BC><EFBFBD>
Output: //
Return: //
Others: //
*************************************************/
void delfile(char *path_name, char *filename)
{
char path[96];
sprintf(path, "%s/%s", path_name, filename);
if(access(path, F_OK) == 0) {
unlink(path);
}
cdr_log("File %s/%s exist.It has been deleted for the new file\n", path_name,
filename);
}
/*************************************************
Function: // safe_query
Description: // <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>
Calls: // mysql_ping<6E><67>
Called By: //
Table Accessed: //
Table Updated: //
Input: // conn:<3A><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>; strquery:sql<71><6C><EFBFBD><EFBFBD>; retry:<3A><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
Output: //
Return: //
Others: // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ݹ麯<DDB9><E9BAAF><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>ģ<EFBFBD><C4A3>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>
*************************************************/
int safe_query(MYSQL * conn, char *strquery, int retry)
{
int errno;
if (mysql_query(conn, strquery) == 0) {
return 0;
} else {
errno = mysql_errno(conn);
if (errno == CR_SERVER_GONE_ERROR || errno == CR_SERVER_LOST) {
retry %= 5;
cdr_log("error NO.:%d,retry...remain %d times\n", errno,
retry);
if (mysql_ping(conn)) {
cdr_log("lost connection to mysql server\n");
return 1;
}
if (retry-- > 0)
return safe_query(conn, strquery, retry);
else {
cdr_log("%s\n", strquery);
cdr_log("error %d:%s\n", mysql_errno(conn),
mysql_error(conn));
cdr_log("can't fix the error\n");
return 1;
}
} else {
cdr_log("%s\n", strquery);
cdr_log("error %d:%s\n", mysql_errno(conn), mysql_error(conn));
return 1;
}
}
}
/*************************************************
Function: // send_csv
Description: // <20><><EFBFBD><EFBFBD>csv<73>ļ<EFBFBD><C4BC><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Ŀ¼
Calls: // mysql_query; mysql_store_result; mysql_fetch_row;
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: // <20>˺<EFBFBD><CBBA><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*************************************************/
void send_csv(char *path_name)
{
/*char serverinfo[128],sqlstr[256],*username,*pwd,*serverip,*remotepath, *pchr;
char locationpath[128];
char sendpath[128];
char getpath[128];
char localIP[16][16];
MYSQL_RES *res;
MYSQL_ROW row;
int nRet,tmppathlen,count;
if(*send_file==0){
return;
}
sprintf(sqlstr,
"SELECT pubVarValue FROM OMC_PUB.omcPubVarConf WHERE pubVarName='cdr_store_server'");
if (mysql_query(omcPub_conn, sqlstr) != 0) {
cdr_log("%s\n", mysql_error(omcPub_conn));
return;
}
if ((res = mysql_store_result(omcPub_conn)) == NULL)
return;
if((row = mysql_fetch_row(res)) != NULL) {
memset(serverinfo, 0, sizeof(serverinfo));
strcpy(serverinfo,row[0]);
}
mysql_free_result(res);
tmppathlen =0;
tmppathlen = strlen(serverinfo);
if (serverinfo[tmppathlen-1] != '/'||tmppathlen<127){
serverinfo[tmppathlen]='/';
serverinfo[tmppathlen+1]='\0';
//strcat(serverinfo,"/");
}
username= serverinfo;//get username
if((pchr = strstr(serverinfo, "@"))==NULL){
cdr_log("send csv files error,cdr_store_server param error!\n");
return;
}
*(pchr++) = '\0';
serverip = pchr; //get server ip
if((pchr = strstr(username, ":"))==NULL){
cdr_log("send csv files error,cdr_store_server param error!\n");
return;
}
*(pchr++) = '\0';
pwd = pchr;//get password
if((pchr = strstr(serverip, ">"))==NULL){
cdr_log("send csv files error,cdr_store_server param error!\n");
return;
}
*(pchr++) = '\0';
remotepath = pchr;//get remotepath
*/
//****************************************
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cdr<64><72>Ŀ¼<C4BF>ϴ<EFBFBD>
//****************************************
// serverip+remotepath eg:172.18.234.235/tmp/
/*sprintf(sendpath,"%s%s",serverip,remotepath);
nRet=ftp_getlocalip(localIP);
if(nRet>16) nRet=16;
for(count=0;count<nRet;count++){
sprintf(getpath,"%s%s/",localIP[count],path_name);
if(strcmp(getpath,sendpath)==0){
// printf("the same place..return\n");
return;
}
}*/
//****************************************
/*if((nRet=ftp_open(serverip,21)==1)){
cdr_log("send csv files error,%s->ftp open failed\n",ftp_retmsg);
ftp_logout();
return;
}
if((nRet=ftp_login(username,pwd)==1)){
cdr_log("send csv files error,%s->ftp login failed\n",ftp_retmsg);
ftp_logout();
return;
}
if((nRet = ftp_cwd(remotepath)==1)){
cdr_log("send csv files error,%s->ftp CWD failed\n",ftp_retmsg);
ftp_logout();
return;
}
sprintf(locationpath,"%s/",path_name);
if((nRet = ftp_putfile(send_file,locationpath)==1)){
cdr_log("send csv files error,%s->upload failed\n",ftp_retmsg);
ftp_logout();
return;
}
ftp_logout();
memset(send_file,0,64);
return; */
}
/*************************************************
Function: // create_dat_for_wxc1
Description: // <20><><EFBFBD><EFBFBD>wxc1<63><31>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>csv<73>ļ<EFBFBD>
Calls: // mysql_query; mysql_store_result; mysql_fetch_row;
Called By: // backup_table;
Table Accessed: // <20><><EFBFBD>ݱ<EFBFBD>
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void create_dat_for_wxc1(char *tb_name,char *csv_path,int flag,char *selfield)
{
char olddir[128], sqlstr[1024], csv_file[32], tb_prefix[32], *pchr, cmdstr[1024]; //cur_path[96],dirname[32];
int wcount=0;
char dat_file[64];
MYSQL_RES *res_set;
MYSQL_ROW row;
FILE *dat_fp;
unsigned long l_time;
struct tm *t;
char str[512];
int res_num,i;
int p_width[27]={8,18,23,23,23,23,23,11,11,16,7,7,22,23,23,23,15,9,7,23,7,7,7,23,23,11,9};
//int p_width[28]={8,18,23,23,23,23,23,11,11,6,10,7,7,22,23,23,23,15,9,7,23,7,7,7,23,23,11,9};
strcpy(tb_prefix, tb_name);
if ((pchr = strchr(tb_prefix, '_')) == NULL)
return;
*(pchr++) = '\0';
getcwd(olddir, 128);
cdr_log("%s\n", tb_name);
cdr_log("%s\n", csv_path);
if (chdir(csv_path) == -1) {
sprintf(cmdstr, "mkdir -p -m777 %s", csv_path);
cdr_log("%s\n", cmdstr);
system(cmdstr);
if (chdir(csv_path) == -1)
return;
}
if (chdir(sening_dir) == -1) {
sprintf(cmdstr, "mkdir -p -m777 %s", sening_dir);
cdr_log("%s\n", cmdstr);
system(cmdstr);
if (chdir(sening_dir) == -1)
return;
}
//sprintf(csv_file, "%s_%s_%s.csv", tb_prefix, time_str, pchr);
sprintf(csv_file, "%s", cdrFileName);
//chfilename(csv_path, csv_file);
delfile(csv_path, csv_file);
cdr_log("%s\n", csv_path);
cdr_log("%s\n", csv_file);
cdr_log("%s\n", CDRDB_NAME);
cdr_log("%s\n", tb_name);
//*************************************************************
if(flag==1)
sprintf(sqlstr,
"SELECT %s FROM %s.%s WHERE TO_DAYS(releaseTime)<TO_DAYS(NOW())",
selfield, CDRDB_NAME, tb_name);
else
sprintf(sqlstr,
"SELECT %s FROM %s.%s WHERE TO_DAYS(releaseTime)=TO_DAYS(NOW())",
// "SELECT %s FROM %s.%s",
selfield, CDRDB_NAME, tb_name);
cdr_log("%s\n", sqlstr);
if (mysql_query(cdrdb_conn, sqlstr) != 0) {
cdr_log("%s\n", mysql_error(cdrdb_conn));
return;
}
if ((res_set = mysql_store_result(cdrdb_conn)) == NULL) {
cdr_log("%s\n", mysql_error(cdrdb_conn));
return;
}
sprintf(dat_file, "%s/%s", csv_path, csv_file);
dat_fp = fopen(dat_file, "w");
if(dat_fp==NULL){
cdr_log("Fail to create file\n");
chdir(olddir);
return;
}
res_num = mysql_num_rows(res_set);
l_time = time(NULL);
t = localtime(&l_time);
fprintf(dat_fp,"FILE NAME: %s NO. OF RECORDS:%-10d\n",dat_file,res_num);
fprintf(dat_fp,"START DATE: %02d/%02d/%d START TIME: %02d:%02d:%02d\n\n",t->tm_mon+1,t->tm_mday,t->tm_year+1900,t->tm_hour,t->tm_min,t->tm_sec);
fprintf(dat_fp,"Type Imsi Msisdn Msrn Calling # Called # RE In.TkGp Ou.TkGp Location BS SS Mob. ClassMark Seizure Time Answer Time Release Time Duration TCos SSA SS Parm. SSR CR RCU SM Delivery Time SC Address SM Rslt MsgRf \n\n");
while ((row = mysql_fetch_row(res_set)) != NULL){
if(atoi(row[0])!=6&&atoi(row[0])!=7){ //not sms
if(row[16]==NULL||atoi(row[16])==0) //Duration=0 skip
continue;
}
for(i=0;i<27;i++){
if(row[i]==NULL){
if(i==7||i==8){
;//In.TkGp,Ou.TkGpr skip
}else{
fprintf(dat_fp,"%-*s",p_width[i],"--");
continue;
}
}
switch (i){
case 0: // Type
case 10:// basicService
case 11:// supplServicesUsed
case 18:// SSA
case 20:// SSR
case 26:// MsgRf
sprintf(str,"%03d",atoi(row[i]));
break;
case 7:// In.TkGp
case 8:// Ou.TkGp
if(atoi(row[0])==6||atoi(row[0])==7){//sms
sprintf(str,"--");
}else{
sprintf(str,"00 00 00");
}
break;
case 15:// releaseTime
if(atoi(row[0])==6||atoi(row[0])==7){
fprintf(dat_fp,"%-*s",p_width[i],"--");
continue;
}
case 13:// seizureTime
case 14:// answerTime
case 23:// SmDeliveryTime
// 2001-06-07 11:12:22->
// 06/07/2001 11:12:22
{
int y=0,m=0,d=0;
pchr=row[i];
y = atoi(pchr);
pchr = strchr(pchr,'-');
if(pchr==NULL)
{
sprintf(str,"%02d/%02d/%02d %s",m,d,y,pchr);
break;
}
pchr++;
m = atoi(pchr);
pchr = strchr(pchr,'-');
pchr++;
if(pchr==NULL)
{
sprintf(str,"%02d/%02d/%02d %s",m,d,y,pchr);
break;
}
d = atoi(pchr);
pchr = strchr(pchr,' ');
sprintf(str,"%02d/%02d/%02d %s",m,d,y,pchr);
break;
}
case 16://callDuration
{
int d,h,m,s,total;
total =atoi(row[i]);
d = total/86400;
h = (total%86400)/3600;
m = (total%3600)/60;
s = total%60;
sprintf(str,"%02d:%02d:%02d:%02d",d,h,m,s);
break;
}
// case 9: // location_mscNumber
// case 10:// location_mscNumber_2
case 17:// TCos
sprintf(str,"%05d",atoi(row[i]));
break;
case 21:// CR
sprintf(str,"%04d",atoi(row[i]));
break;
sprintf(str,"%s",row[i]);
break;
case 12:// Mob. ClassMark
sprintf(str,"1f %s",row[i]);
break;
default:
sprintf(str,"%s",row[i]);
break;
}
fprintf(dat_fp,"%-*s",p_width[i],str);
}
fprintf(dat_fp,"\n");
wcount++;
}
fseek(dat_fp,0,SEEK_SET);
fprintf(dat_fp,"FILE NAME: %s NO. OF RECORDS:%-10d\n",dat_file,wcount);
mysql_free_result(res_set);
strcpy(compress_file, csv_file);
fclose(dat_fp);
chdir(olddir);
if(backup_flag)
{
sprintf(send_file,"%s",csv_file);
sprintf(cmdstr, "cp %s/%s %s/%s.bak",csv_path,csv_file,csv_path,csv_file);
system(cmdstr);
sprintf(cmdstr, "mv %s/%s.bak %s/%s",csv_path,csv_file,sening_dir,csv_file);
system(cmdstr);
}
}

View File

@@ -0,0 +1,115 @@
/*************************************************
File name: cdrdebug.c
Author:
Version: 9:00:00
Date: 2002-5-7
Description:<3A><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>Եĺ<D4B5><C4BA><EFBFBD>
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include "cdr.h"
#if CDR_LINK_DEBUG
extern cdr_src CdrSet[CDR_SRC_NUM];
extern BYTE iCdrNum;
static char debug_buf[4096];
//static char asc_in[256];
void cdr_debug_info(BYTE npage, BYTE nline, BYTE * pt, BYTE len);
/*************************************************
Function: // cdrdebug_init
Description: // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
Calls: //
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void cdrdebug_init()
{
DWORD asc_id[20] = { 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 4 };
DWORD status_id[20] =
{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 1 };
DWORD name_id[20] =
{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 2 };
DWORD title_id[20] =
{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 6, 1 };
static char module_name[16] = "CDR";
static BYTE debug_status = 1;
cdr_src *pcdr;
BYTE i;
char title[320], info[320] = {
"1 2\r\n"
"IP\r\n"
"Port\r\n"
"receive\r\n"
"record\r\n"
"lost\r\n"
"tail\r\n"
"head\r\n"
"bind num\r\n"
"get state\r\n" "get timeout\r\n" "set state\r\n" "set timeout"
};
debug_set_response(15, asc_id, debug_buf, 1);
debug_set_response(15, status_id, &debug_status, 1);
debug_set_response(15, name_id, module_name, strlen(module_name));
for (i = 0; i < iCdrNum; i++) {
pcdr = &CdrSet[i];
sprintf(title, "\tCDR Collector\tPage %02d\t\tMessage\r\n%s",
i + 1, info);
title_id[14] = i + 6;
debug_set_response(15, title_id, title, strlen(title));
cdr_debug_info(i + 1, 2, (BYTE *) & pcdr->addr.remote_ip, 4);
cdr_debug_info(i + 1, 3, (BYTE *) & pcdr->addr.remote_port, 2);
cdr_debug_info(i + 1, 4, (BYTE *) & pcdr->recv, 4);
cdr_debug_info(i + 1, 5, (BYTE *) & pcdr->recd, 4);
cdr_debug_info(i + 1, 6, (BYTE *) & pcdr->loss, 4);
cdr_debug_info(i + 1, 7, (BYTE *) & pcdr->instance, 4);
cdr_debug_info(i + 1, 8, (BYTE *) & pcdr->head, 4);
cdr_debug_info(i + 1, 9, (BYTE *) & pcdr->maxbind, 4);
cdr_debug_info(i + 1, 10, (BYTE *) & pcdr->get_state, 1);
cdr_debug_info(i + 1, 11, (BYTE *) & pcdr->get_timeout, 4);
cdr_debug_info(i + 1, 12, (BYTE *) & pcdr->set_state, 1);
cdr_debug_info(i + 1, 13, (BYTE *) & pcdr->set_timeout, 4);
}
}
/*************************************************
Function: // cdr_debug_info
Description: // <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
Calls: //
Called By: //
Table Accessed: //
Table Updated: //
Input: // npage; nline; pt; len;
Output: //
Return: //
Others: //
*************************************************/
void cdr_debug_info(BYTE npage, BYTE nline, BYTE * pt, BYTE len)
{
DWORD oid[20] =
{ 1, 3, 6, 1, 4, 1, 1373, 1, 3, 2, 3, 1, 2, 16, 5, 2, 2 };
oid[14] = 5 + npage;
oid[15] = nline;
debug_set_response(17, oid, pt, len);
}
#endif

View File

@@ -0,0 +1,194 @@
/*************************************************
File name: cdrlog.c
Author:
Version: 9:00:00
Date: 2002-7-2
Description:<3A><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>cdrCollectorģ<72><C4A3><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include "cdr.h"
static FILE *log_fp;
extern BYTE iCdrNum;
extern cdr_src CdrSet[CDR_SRC_NUM];
/*************************************************
Function: // cdrlog_init
Description: // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ա<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
Calls: //
Called By: // cdrmain.c; cdrdb.c;
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void cdrlog_init()
{
char log_file[64], cmdstr[64];
long l_time;
struct tm *t;
l_time = time(NULL);
t = localtime(&l_time);
if (access(CDR_LOG_PATH, F_OK) != 0)
{
sprintf(cmdstr, "mkdir -p -m777 %s", CDR_LOG_PATH);
printf("%s\n", cmdstr);
system(cmdstr);
}
sprintf(log_file, "%s/%s_%d_%d", CDR_LOG_PATH, CDR_LOG_FILE,
t->tm_mon + 1, t->tm_mday);
log_fp = fopen(log_file, "a");
cdr_log("CDR Module start up.%s", ctime(&l_time));
}
/*************************************************
Function: // cdrlog_timer
Description: // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>дһЩ<D2BB><D0A9>־
Calls: // cdr_log;
Called By: // cdr.c:cdr_timer;
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void cdrlog_timer()
{
char log_file[64];
long l_time;
static BYTE ch = 0, ch2 = 0;
static short m_state;
struct tm *t;
if (m_state++ < 6)
return;
m_state = 0;
l_time = time(NULL);
t = localtime(&l_time);
if (ch2 == 0 && t->tm_min % 15 <= 3) //report per 15 minute
{
cdr_report();
ch2 = 1;
}
else if (t->tm_min % 15 > 3)
ch2 = 0;
if (t->tm_hour == 0 && ch == 0)
{
if (log_fp != NULL)
fclose(log_fp);
sprintf(log_file, "%s/%s_%d_%d", CDR_LOG_PATH, CDR_LOG_FILE,
t->tm_mon + 1, t->tm_mday);
if ((log_fp = fopen(log_file, "a")) != NULL)
ch = 1;
}
else if (t->tm_hour > 0)
ch = 0;
}
/*************************************************
Function: // cdr_report
Description: // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>д<EFBFBD><D0B4>CDR<44><52><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>һЩ<D2BB><D0A9>Ϣ
Calls: // cdr_log;
Called By: // cdrlog_timer;
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void cdr_report()
{
BYTE i;
long l_time;
struct tm *t;
cdr_src * pcdr;
l_time = time(NULL);
t = localtime(&l_time);
cdr_log("=================%02d:%02d:%02d================\n",
t->tm_hour, t->tm_min, t->tm_sec);
for (i = 0; i < iCdrNum; i++)
{
pcdr = &CdrSet[i];
cdr_log("%-08lX(%s-%d)\n", htonl(pcdr->addr.remote_ip),

View File

@@ -0,0 +1,139 @@
/*************************************************
File name: cdr.c
Author:
Version: 9:00:00
Date: 2002-5-7
Description:cdrCollectorģ<72><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>snmp<6D><70>iptransģ<73><EFBFBD><E9A3AC><EFBFBD><EFBFBD>cdr.c<><63><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
<09><><EFBFBD>嶨ʱ<E5B6A8><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>ʱ
<09><><EFBFBD><EFBFBD><EFBFBD>ⲿģ<E2B2BF><C4A3><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
void snmp_init(WORD nport);
void iptrans_init();
History:
No.
Author:
Date:
Version:
Description:
*************************************************/
#include "cdr.h"
static struct itimerval itimer, old_itimer;
static void On_Timer();
static void SetTimer();
/*************************************************
Function: // main
Description: // <20><>ʼ<EFBFBD><CABC>snmp<6D><70>iptransģ<73><C4A3>,<2C><>ʼ<EFBFBD><CABC><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // iptrans_init; snmp_init;
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
int main(int argc, char *argv[])
{
pid_t pid;
//debug_init();
//fprintf(stderr, "\n Calling iptrans_init()");
//iptrans_init();
//fprintf(stderr, "\n Calling snmp_init()");
//snmp_init(CDR_PORT);
/*
if (argc == 2 && strstr(argv[1], "-d")) {
if ((pid = fork()) != 0)
exit(0);
setsid();
//umask(0);
}*/
if (argc != 4) {
exit(0);
}
strcpy(totalCdrFileName,argv[1]);
strcpy(cdrFileName,argv[2]);
cdrHour=atoi(argv[3]);
cdr_init();
//cdr_start();
converseFile();
/*
SetTimer();
while (1) {
//cdr_loop();
usleep(50);
}
return 1;
*/
}
/*************************************************
Function: // On_Timer
Description: // <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // cdr_timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void On_Timer()
{
//debug_rt();
//snmp_timer();
cdr_timer();
}
/*************************************************
Function: // SetTimer
Description: // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Calls: // On_Timer
Called By: //
Table Accessed: //
Table Updated: //
Input: //
Output: //
Return: //
Others: //
*************************************************/
void SetTimer()
{
struct sigaction act;
act.sa_handler = On_Timer;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
if (sigaction(SIGALRM, &act, NULL) < 0) {
perror("Produce Sigaction");
exit(1);
}
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 20 * 1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 20 * 1000;
if (setitimer(ITIMER_REAL, &itimer, &old_itimer) != 0) {
printf("Setting Timer error! \n");
exit(1);
}
}

View File

@@ -0,0 +1,14 @@
#!/bin/sh
cdrFileArr=`ls /tmp/needConverseCdrFiles/*`
echo "Start conversing."
for totalCdrFileName in $cdrFileArr ; do
cdrFile=`echo $totalCdrFileName|awk -F"/" '{print $4}'`
hour=`echo $totalCdrFileName|awk -F"_" '{print $5}'|awk -F"." '{print $1}'`
echo $totalCdrFileName $cdrFile $hour
./cdrCollector $totalCdrFileName $cdrFile $hour
echo "."
done