📄 复件 lwjktj.ec
字号:
#include <sys/termio.h>
#include <sys/locking.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
/*
#include "map.h"
#include "omcsyb.h"
*/
#include "init.h"
#include "msg_omc.h"
#include "omcS.h"
//define L_SIZE 128
#define K 1024
char *paswd,*user;
struct con
{
char send_char;
char connect_char;
char release_char;
char iogtype[9];
char omcport[7];
char office_name[6];
}conf;
char combuff[2*K],teleno[12];
int fdd,fp;
int sendfile;
int port,jobno;
int msg_handle();
int msg_init(); /* This two line belong to Progma */
int func17();
int init();
int err_handler();
int msg_handler();
int sigflag;
char BLANK_C,CONNECT_C,RELEASE_C,SEND_C;
char PASS[7],COMM[80],tjtime[20];
main(argc,argv)
int argc;
char *argv[];
{
int i,n,nn,j,pid,resul;
BLANK_C=0x00;
CONNECT_C=0x02;
SEND_C=0x0a;
RELEASE_C=0x04;
strcpy(PASS,"pw001;");
strcpy(COMM,"19;");
port=0;
jobno=1;
msg_qid = atoi(argv[1]);
strcpy(ARGV_0,argv[0]);
msg_init();
printf("start\n");
/*scandok(); */
/*****************/
do_tj();
/*** for I>0 ****/
return(i);
}
/************************************************************/
do_tj()
{
/*
EXEC SQL begin declare section;
char tele[10];
char office[15];
char bzw[2];
char opt[4];
int telecount;
EXEC SQL end declare section;
*/
EXEC SQL begin declare section;
char telephone[10];
char officenum[15];
char str1[60][30];
char chartelecount;
int telecount;
EXEC SQL end declare section;
int i;
/*signal(SIGUSR1,fqquit);*/
putenv("INFORMIXDIR=/usr/informix");
putenv("INFORMIXSERVER=online_a");
EXEC SQL connect to 'yl97';
if (sqlca.sqlcode<0)
{
printf("Can not login to INFORMIX ,Please check!\n");
exit(-1);
}
EXEC SQL DECLARE line_cursor CURSOR FOR select telephone,officenum,subname into :str1[0],:str1[1],:str1[2] from subscribercard where substr(officenum,1,3)='904';
EXEC SQL OPEN line_cursor;
while(sqlca.sqlcode==0)
{
/*EXEC SQL begin work;*/
EXEC SQL fetch line_cursor;
printf("The linedata telephone=%s,officenum=%s,subname=%s \n",str1[0],str1[1],str1[2]);
if(sqlca.sqlcode!=0)
{
/*EXEC SQL commit rollback;*/
printf("The databfetch errord\n");
break;
/*continue;*/
}
else
{ printf("The linedata telephone=%s,officenum=%s,subname=%s \n",str1[0],str1[1],str1[2]);
printf("########################################################\n");
printf("######## THE JOB NO. %d ############################\n",jobno);
printf("########################################################\n");
printdate();
strcpy(teleno,telephone);
printf("The CLOSE TELE NUMBER IS:=>%s\n",teleno);
sprintf(COMM,"4294:dn=k'%s,intcp=badp.",teleno);
printf("THE COMMAND IS: %s\n",COMM);
printf("#########################################################\n");
/* exec_comm();
update_tjbz();
printdate();
*/
jobno++;
}/** else sqlcode==0 **/
} /** while **/
EXEC SQL close line_cursor;
EXEC SQL disconnect current;
}
/****************************************************************
int update_tjbz()
{
DBPROCESS *proc;
LOGINREC *login;
int i,ok;
DBCHAR cno[10];
DBCHAR tele[12];
DBDATETIME jfsj[21];
DBDATETIME kjsj[21];
DBCHAR kjbz[1];
DBDATETIME scsj[21];
DBDATETIME tjsj[21];
DBCHAR tjbz[1];
DBCHAR bz[20];
char *paswd,*user,proccom[128];
paswd=(char *)getenv("SYBPWD");
user=(char *)getenv("SYBUSER");
login = dblogin();
DBSETLPWD(login, paswd);
DBSETLUSER(login, user);
if( (proc = dbopen(login, NULL)) == NULL ) {
printf("\tWarning: SYBASE SQL Server is non-normal\n");
printf("\t\tSee the computer(SYBASER) whether has wrong!\n");
printf("\t\tType 'term 0 LLZZZO' to run terminal,\n");
printf("\t\t when computer(SYBASER) is wrong,\n");
printf("\t\t or call progammer of GuangZhou.\n");
}
dbuse(proc,"trafficdb");
ok=scandok();
if(ok==1)
sprintf(proccom, "update zdtj set tjbz='1' where tele='%s'",teleno);
if(ok==2)
sprintf(proccom, "update zdtj set tjbz='2' where tele='%s'",teleno);
if(ok==3)
sprintf(proccom, "update zdtj set tjbz='3' where tele='%s'",teleno);
dbcmd(proc,proccom);
dbsqlexec(proc);
dbresults(proc);
sprintf(proccom, "update zdtj set tjsj='%s' where tele='%s'",tjtime,teleno);
dbcmd(proc,proccom);
dbsqlexec(proc);
dbresults(proc);
if(ok==1)
sprintf(proccom, "update zdtj set bz='SUCCESS CLOSE' where tele='%s'",teleno);
if(ok==2)
sprintf(proccom, "update zdtj set bz='NOT SUCCESS CLOSE' where tele='%s'",teleno);
if(ok==3)
sprintf(proccom, "update zdtj set bz='CANOT KNOW' where tele='%s'",teleno);
dbcmd(proc,proccom);
dbsqlexec(proc);
dbresults(proc);
dbclose(proc);
dbexit();
return(i);
}
****************************************************************/
exec_comm()
{int i,resul;
if(!strcmp(conf.iogtype,"MMC"))
{
startconnect:
connect_file();
nap(5000);
resul=justsend("<",0)&&justsend("00",1);
if(resul>0) goto putcomm;
resul=justsend("PASSWORD <",0);
printf("------------------scan PASSWORD NOW!------------\n");
for(i=1;resul<=0&&i<=100;i++)
{
resul=justsend("<",0)&&justsend("00",1);
if(resul>0) goto putcomm;
release_file();
nap(2000);
connect_file();
nap(3000);
resul=justsend("PASSWORD <",0);
printf("--------------->>scan connect_char: %d time\n",i);
}
if(resul>0)
{
printf("++++++++++++++++++CONNECT OK! ++++++++++++\n");
printf("******************SEND PWD NOW ************\n");
passwd_file();
}
else
{printf("Can't cnnnect the S1240 MMC PORT,PLEASE CHECK!!!!\n");
return;
}
nap(3000);
printf("------------------scan prompt< NOW!------------\n");
resul=justsend("<",0)&&justsend("00",1);
putcomm:
for(i=1;resul<=0&&i<=20;i++)
{
printf("--------------->>scan prompt: %d time\n",i);
if(justsend("INVALID PASSWORD",0)>0) goto startconnect;
if(justsend("PASSWORD <",0)>0) passwd_file();
nap(3000);
resul=justsend("<",0)&&justsend("00",1);
}
if(resul>0)
{
printf("++++++++++++++++++PASSWORD PASS OK! ++++++++++++\n");
printf("******************SEND COMMAND NOW ************\n");
command_file();
}
nap(10000);
resul=justsend("LAST REPORT",1);
printf("------------------scan LAST REPORT NOW!------------\n");
for(i=1;resul<=0&&i<=100;i++)
{
printf("--------------->>scan LAST REPORT %d\n",i);
if(justsend("TIME OUT",1)>0) goto startconnect;
if(justsend("<",0)>0) command_file();
nap(10000);
resul=justsend("LAST REPORT",1);
}
if(resul>=0)
{
printf("++++++++++++++++++COMMAND EXEC OK! ++++++++++++\n");
printf("******************SEND RELEASE NOW ************\n");
release_file();
}
} /* if MMc */
}
/****************************************************************/
connect_file()
{
int fdd,i;
/******creat the send char file **************/
if((fdd=open("/u/omc/tmp/lwj1",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
printf("lwj1 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&CONNECT_C,1);
for(i=1;i<=79;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/lwj1 /u/omc/tmp/send_file");
}
/****************************************************************/
passwd_file()
{
int fdd,i;
/******creat the password char file **************/
if((fdd=open("/u/omc/tmp/lwj2",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
printf("lwj2 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&PASS,6);
write(fdd,&SEND_C,1);
for(i=1;i<=73;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/lwj2 /u/omc/tmp/send_file");
}
/****************************************************************/
release_file()
{
int fdd,i;
/******creat the release char file **************/
if((fdd=open("/u/omc/tmp/lwj4",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
printf("lwj4 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&RELEASE_C,1);
for(i=1;i<=79;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/lwj4 /u/omc/tmp/send_file");
}
/****************************************************************/
command_file()
{
int fdd,len,i;
/******creat the command char file **************/
if((fdd=open("/u/omc/tmp/lwj3",O_CREAT|O_RDWR,0666))<0)
{ perror("Open !!!");
exit(0);
}
len=strlen(COMM);
printf("lwj3 creat \n");
write(fdd,&conf.omcport,6);
write(fdd,&BLANK_C,1);
write(fdd,&COMM,len);
write(fdd,&SEND_C,1);
len=87-8-len;
for(i=1;i<=len;i++) write(fdd,&BLANK_C,1);
close(fdd);
system("cp /u/omc/tmp/lwj3 /u/omc/tmp/send_file");
}
/****************************************************************/
justsend(str,mod)
char *str;
int mod;
{char buff[L_SIZE],endbuff[L_SIZE],portname[6];
FILE *fp;
char fname[50];
long time(),lg;
struct tm *localtime(),*tim;
lg=time(&lg);
tim=localtime(&lg);
strcpy(portname,conf.omcport);
sprintf(fname,"%s/data/%sO%s_%d%d%d%d%d",PATH,conf.office_name,&portname[3],tim->tm_year,(tim->tm_mon+1)/10,(tim->tm_mon+1)%10,tim->tm_mday/10,tim->tm_mday%10);
printf("%s\n",fname);
if((fp=fopen(fname,"r"))==NULL)
{printf("open rawfile error ! \n");
fclose(fp);
nap(30000);
return(-1);
}
fgets(endbuff,L_SIZE,fp);
while(!feof(fp))
{
strcpy(buff,endbuff);
fgets(endbuff,L_SIZE,fp);
}
fclose(fp);
printf("raw buff:%s\n",buff);
printf("raw endbuff:%s\n",endbuff);
if(mod==1) strcpy(endbuff,buff);
if(sub_str(endbuff,str)>0)
return(1);
else
return(0);
}
/****************************************************************/
scandok()
{char portname[6],rawbuff[21][L_SIZE];
FILE *fp;
char fname[50],hour[6];
long time(),lg;
struct tm *localtime(),*tim;
int i,lastok,succok,teleok;
int yy,mm,dd;
char mon_name[12][4]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
lg=time(&lg);
tim=localtime(&lg);
strcpy(portname,conf.omcport);
sprintf(fname,"%s/data/%sO%s_%d%d%d%d%d",PATH,conf.office_name,&portname[3],tim->tm_year,(tim->tm_mon+1)/10,(tim->tm_mon+1)%10,tim->tm_mday/10,tim->tm_mday%10);
printf("%s\n",fname);
if((fp=fopen(fname,"r"))==NULL)
{printf("open rawfile error ! \n");
fclose(fp);
nap(30000);
return(-1);
}
for(i=0;i<21;i++)
if(!feof(fp))
fgets(rawbuff[i],L_SIZE,fp);
else
break;
for(;!feof(fp);)
{
for(i=1;i<21;i++)
strcpy(rawbuff[i-1],rawbuff[i]);
if(!feof(fp)) fgets(rawbuff[20],L_SIZE,fp);
}
for(i=0;i<21;i++)
printf("%s",rawbuff[i]);
lastok=0;
teleok=0;
succok=0;
for(i=0;i<20;i++)
{ if(sub_str(rawbuff[i],"LAST REPORT")>0) lastok=1;
if(sub_str(rawbuff[i],teleno)>0) teleok=1;
if(sub_str(rawbuff[i],"SUCCESSFUL")>0)
{
succok=1;
if(sub_str(rawbuff[i],"NOT SUCCESSFUL")>0) succok=2;
}
if(sub_str(rawbuff[i],"Y.L.CHENGBEI")>0)
{sscanf(rawbuff[i],"%*s %4d-%2d-%2d %5s",&yy,&mm,&dd,hour);
sprintf(tjtime,"%d %s %d %5s:00",yy,mon_name[mm-1],dd,hour);
}
}
printf("lastok=%d,teleok=%d,succok=%d,time=%s\n",lastok,teleok,succok,tjtime);
/****1 is success,2 is not success,3 is can't know */
if(lastok==1&&teleok==1&&succok==1)
return(1);
else
if(lastok==1&&teleok==1&&succok==2)
return(2);
else
return(3);
}
/****************************************************************/
printdate()
{ long time(),lg;
lg=time(&lg);
printf("%s\n",ctime(&lg));
}
/****************************************************************/
sub_str(str1,str2)
char *str1,*str2;
{
int l1,l2,i;
l1=strlen(str1);
l2=strlen(str2);
if(l1<l2) return(-1);
for(i=0;i<l1;i++) {
if(l1-i<l2) return(-1);
if(!strncmp(str1+i,str2,l2)) return(i);
}
}
/****************************************************************/
func17()
{
printf("COMIS: SIGUSR2 has recieved\n");
signal(SIGUSR2, func17);
sigflag=1;
}
/****************************************************************/
msg_handle()
{
printf("COMIS: ALARM has recieved\n");
signal(SIGALRM,msg_handle);
}
/****************************************************************/
msg_init()
{
signal(SIGALRM,msg_handle);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -