From: Jean-Marc Pigeon (Delson) Date: Tue, 13 May 2025 18:47:53 +0000 (-0400) Subject: Able to scan the queue transfile X-Git-Tag: tag-0.8~108 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=e9b59deb33d92a2a8cefb2606eb9a1a3054f2566;p=jmp%2Fmailleur Able to scan the queue transfile --- diff --git a/app/Makefile b/app/Makefile index 5cf068a..2432df5 100644 --- a/app/Makefile +++ b/app/Makefile @@ -79,6 +79,7 @@ feeder.o: feeder.c \ ../lib/subrou.h sorter.o: sorter.c \ + ../lib/geseml.h \ ../lib/subrou.h toremake: Makefile $(LIBAI) diff --git a/app/sorter.c b/app/sorter.c index 4bd855a..03ff987 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -17,19 +17,10 @@ #include "unieml.h" #include "unipar.h" #include "unisig.h" +#include "geseml.h" #define SORTER "sorter" //application name -//structure to build a email directive -typedef struct { - char code; //Transaction code - u_long date; //Transaction date - u_int delay; //Transaction execution delay - char *sessid; //session id - char *mailfrom; //EMail Originator - char *recptto; //EMail Recipient - }TRATYP; - /********************************************************/ /* */ /* procedure to scan all files */ @@ -38,18 +29,65 @@ typedef struct { static _Bool scantrans() { +#define OPEP "sorter.c:scantrans," + _Bool status; -char **list; +char **fname; +TRATYP **trans; +int phase; +_Bool proceed; status=false; -list=(char **)0; -(void) rou_alert(0,"JMPDBG sorter"); -if ((list=eml_getqfilelist(".trans"))!=(char **)0) { - list=(char **)rou_freelist((void *)list,(freehandler_t)rou_freestr); +fname=(char **)0; +trans=(TRATYP **)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //Getting the list of file + fname=eml_getqfilelist(fname,".trans"); + fname=eml_getqfilelist(fname,".todo"); + if (fname==(char **)0) + phase=999; //Nothing to do + break; + case 1 : //Building the "trans" list + if (fname!=(char **)0) { //walways + char **ptr; + + ptr=fname; + while (*ptr!=(char *)0) { + FILE *qfile; + + (void) rou_alert(0,"%s fame=<%s>",OPEP,*ptr); + if ((qfile=eml_openqfile(*ptr))!=(FILE *)0) { + trans=eml_scanqfile(trans,qfile); + } + ptr++; + } + fname=(char **)rou_freelist((void *)fname,(freehandler_t)rou_freestr); + } + break; + case 2 : //Cscanning translit + if (trans!=(TRATYP **)0) { + TRATYP **ptr; + + ptr=trans; + while (*ptr!=(TRATYP *)0) { + (void) eml_dumptra(*ptr); + ptr++; + } + trans=(TRATYP **)rou_freelist((void **)trans,(freehandler_t)eml_freetra); + status=true; + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; } -status=true; -(void) sleep(5); return status; +#undef OPEP } /* diff --git a/lib/Makefile b/lib/Makefile index 6de9776..02764ab 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -18,7 +18,7 @@ clean : OBJS= \ modrec.o \ lvleml.o \ - gesspf.o gestcp.o \ + gesspf.o gestcp.o geseml.o \ devlog.o devsoc.o devsql.o \ unidns.o unieml.o unipos.o \ unipar.o uniprc.o unisig.o unitls.o \ @@ -46,6 +46,10 @@ gesspf.o: \ subrou.h \ gesspf.h gesspf.h +geseml.o: \ + subrou.h \ + geseml.h geseml.h + gestcp.o: \ subrou.h \ unieml.h \ diff --git a/lib/geseml.c b/lib/geseml.c new file mode 100644 index 0000000..33fdc87 --- /dev/null +++ b/lib/geseml.c @@ -0,0 +1,122 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Implement all routine to manage email transport */ +/* exchange. */ +/* */ +/********************************************************/ +#include + +#include "subrou.h" +#include "geseml.h" + +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to display/debug TRATYP record content*/ +/* */ +/********************************************************/ +PUBLIC void eml_dumptra(TRATYP *tra) + +{ +if (tra!=(TRATYP *)0) { + (void) rou_alert(0,"TRA-> %c,%lu,%u %s %s %s", + tra->code, + tra->date, + tra->delay, + tra->sessid, + tra->mailfrom, + tra->rcptto + ); + } +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to free memory used by a TRATYP record*/ +/* */ +/********************************************************/ +PUBLIC TRATYP *eml_freetra(TRATYP *trans) + +{ +if (trans!=(TRATYP *)0) { + trans->rcptto=rou_freestr(trans->rcptto); + trans->mailfrom=rou_freestr(trans->mailfrom); + trans->sessid=rou_freestr(trans->sessid); + (void) free(trans); + trans=(TRATYP *)0; + } +return trans; +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to scan the a qfile and build a */ +/* list of email transport directive. */ +/* */ +/********************************************************/ +PUBLIC TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile) + +{ +#define OPEP "geseml.c:eml_scanqfile," + +char *ptr; +char line[300]; + +while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) { + char id[300]; + char from[100]; + char to[100]; + char code; + u_long date; + u_int delay; + int phase; + _Bool proceed; + + phase=0; + proceed=true; + while (proceed==true) { + switch (phase) { + case 0 : //Removing comment + if ((ptr=strchr(line,'#'))!=(char *)0) + *ptr='\000'; + if (strlen(line)==0) + phase=999; //No data within line + break; + case 1 : //scanning line contents + if (sscanf(line,"%c %ld %d %s %s %s",&code,&date,&delay,id,from,to)!=6) { + (void) rou_alert(0,"%s, Unable to scan <%s> (config?)",OPEP,line); + phase=999; //No data within line + } + break; + case 2 : //scanning line contents + if (strlen(id)>0) { //always? + TRATYP *tra; + + tra=(TRATYP *)calloc(1,sizeof(TRATYP)); + tra->code=code; + tra->date=date; + tra->delay=delay; + tra->sessid=strdup(id); + tra->mailfrom=strdup(from); + tra->rcptto=strdup(to); + (void) eml_dumptra(tra); + list=(TRATYP **)rou_addlist((void **)list,(void *)tra); + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } + } +return list; +#undef OEP +} diff --git a/lib/geseml.h b/lib/geseml.h new file mode 100644 index 0000000..6c172f5 --- /dev/null +++ b/lib/geseml.h @@ -0,0 +1,33 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Define all procedure to manage email transport */ +/* data. */ +/* */ +/********************************************************/ +#ifndef GESEML +#define GESEML + +#include +#include + +//structure to define an email transport directive +typedef struct { + char code; //Transaction code + u_long date; //Transaction date + u_int delay; //Transaction execution delay + char *sessid; //session id + char *mailfrom; //EMail Originator + char *rcptto; //EMail Recipient + }TRATYP; + +//procedure to dump a transfert record (debug purpose) +extern void eml_dumptra(TRATYP *tra); + +//procedure to fee memory used by a TRATYP structure +extern TRATYP *eml_freetra(TRATYP *tra); + +//procedure to open a specific qfile +extern TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile); + +#endif diff --git a/lib/gesspf.h b/lib/gesspf.h index 7eed2c0..940e27b 100644 --- a/lib/gesspf.h +++ b/lib/gesspf.h @@ -5,8 +5,8 @@ /* DNS record. */ /* */ /********************************************************/ -#ifndef GESTSPF -#define GESTSPF +#ifndef GESSPF +#define GESSPF #include "subafn.h" diff --git a/lib/unieml.c b/lib/unieml.c index 1c7e1d6..a59d2ef 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -312,17 +312,15 @@ return status; /* Return a list or NULL if no file. */ /* */ /********************************************************/ -PUBLIC char **eml_getqfilelist(char *ext) +PUBLIC char **eml_getqfilelist(char **dnames,char *ext) { #define OPEP "unieml.c:eml_getqfilelist" -char **dirlst; DIR *dir; int phase; _Bool proceed; -dirlst=(char **)0; dir=(DIR *)0; phase=0; proceed=true; @@ -358,7 +356,7 @@ while (proceed==true) { } if (ptr!=(char *)0) { (void) rou_alert(0,"%s JMPDBG got <%s>",OPEP,data->d_name); - dirlst=(char **)rou_addlist((void **)dirlst,(void *)strdup(data->d_name)); + dnames=(char **)rou_addlist((void **)dnames,(void *)strdup(data->d_name)); } } break; @@ -374,7 +372,36 @@ while (proceed==true) { } phase++; } -return dirlst; +return dnames; +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to open a fine within the MTA queue */ +/* directory. */ +/* */ +/********************************************************/ +PUBLIC FILE *eml_openqfile(char *qfilename) + +{ +#define OPEP "unieml.c:eml_openqfile," + +FILE *qfile; +char *dirname; +char fullname[300]; + +qfile=(FILE *)0; +dirname=rou_apppath(QDIR); +(void) snprintf(fullname,sizeof(fullname),"%s/%s",dirname,qfilename); +if ((qfile=fopen(fullname,"r"))==(FILE *)0) { + (void) rou_alert(0,"%s Unable to open file <%s> (error-<%s> bug?)", + OPEP,fullname,strerror(errno)); + } +dirname=rou_freestr(dirname); +return qfile; #undef OPEP } /* diff --git a/lib/unieml.h b/lib/unieml.h index 5088d4b..7982015 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -62,7 +62,7 @@ extern int eml_closeqfile(FILE *qfile); //Procedure to list all file within queue directory //and with a specific extenstion -extern char **eml_getqfilelist(char *ext); +extern char **eml_getqfilelist(char **dnames,char *ext); //procedure to open a specific qfile extern FILE *eml_openqfile(char *qfilename);