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,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;
}