From: Jean-Marc Pigeon (Delson) Date: Sun, 11 May 2025 00:56:36 +0000 (-0400) Subject: Startied the sorter implementation (reading directory) X-Git-Tag: tag-0.8~110 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=57a9e790049df0e64c251266ffa1f973d1ddc380;p=jmp%2Fmailleur Startied the sorter implementation (reading directory) --- diff --git a/Makefile b/Makefile index 303d8db..638e420 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,14 @@ TESTPORT= 1025 EXTIP = safemail3.safe.ca EXTPORT = 25 TESTITER= 4 +#-------------------------------------------------------------------- +#To test sorter +sorter : clean debug + @ bin/sorter \ + -d 2 \ + -c ./conf/feeder.conf.dvl \ + -r $(TESTDIR) + #-------------------------------------------------------------------- #testing feed FEEDPAR = \ @@ -51,7 +59,7 @@ extfeed : debug -c ./conf/feeder.conf.dvl \ $(EXTIP) \ $(EXTPORT) \ - $(DATATST)/extfeed00.tst + ./$(DATATST)/extfeed00.tst onefeed : debug bin/feeder \ @@ -60,7 +68,7 @@ onefeed : debug -c ./conf/feeder.conf.dvl \ $(TESTIP) \ $(TESTPORT) \ - $(DATATST)/xxfeed.tst + ./$(DATATST)/xxfeed.tst # # -i 127.63.31.15 @@ -80,7 +88,7 @@ dbgfeed : debug -c ./conf/feeder.conf.dvl \ $(TESTIP) \ $(TESTPORT) \ - $(DATATST)/xxfeed.tst + $./(DATATST)/xxfeed.tst valfeed : debug #valgring of emlrcvr @ echo "feed valgrind test" @@ -93,7 +101,7 @@ valfeed : debug #valgring of emlrcvr -c ./conf/feeder.conf.dvl \ $(TESTIP) \ $(TESTPORT) \ - $(DATATST)/feed00.tst + ./$(DATATST)/xxfeed.tst # --track-fds=yes \ @@ -238,8 +246,8 @@ newtest : deltest bin \ $(TESTDIR)/$(SBINDIR) @ cp -a \ - $(DATATST) \ - $(TESTDIR) + data-queue/* \ + $(TESTDIR)/var/spool/$(APPNAME)/queue deltest : @ rm -fr $(TESTDIR) diff --git a/app/sorter.c b/app/sorter.c index 150d994..4bd855a 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -8,16 +8,28 @@ /* feeder ip port [file1 file2...] */ /* */ /********************************************************/ +#include #include #include #include #include "subrou.h" -#include "unisig.h" +#include "unieml.h" #include "unipar.h" +#include "unisig.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 */ @@ -27,12 +39,16 @@ static _Bool scantrans() { _Bool status; +char **list; status=false; -(void) sleep(2); +list=(char **)0; (void) rou_alert(0,"JMPDBG sorter"); -(void) sleep(5); +if ((list=eml_getqfilelist(".trans"))!=(char **)0) { + list=(char **)rou_freelist((void *)list,(freehandler_t)rou_freestr); + } status=true; +(void) sleep(5); return status; } /* @@ -71,11 +87,12 @@ while (proceed==true) { (void) rou_modesubrou(true); (void) sig_modeunisig(true); (void) rou_setappname(SORTER); - (void) rou_loadconfig(config,true); + (void) rou_loadconfig(config,true); (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON); (void) closelog(); break; case 2 : //Scanning all file + phase--; //Looping on same phase if ((hangup==true)||(reload==true)) phase=999; //Process if (scantrans()==false) diff --git a/lib/unieml.c b/lib/unieml.c index babf6df..ac36df1 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -5,6 +5,7 @@ /* exchange. */ /* */ /********************************************************/ +#include #include #include #include @@ -276,6 +277,81 @@ return status; */ /********************************************************/ /* */ +/* Procedure to list all file with a specific */ +/* extension with the queue directory. */ +/* Return a list or NULL if no file. */ +/* */ +/********************************************************/ +PUBLIC char **eml_getqfilelist(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; +while (proceed==true) { + //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + switch (phase) { + case 0 : //lets open the queue directory + char *dirname; + + dirname=rou_apppath(QDIR); + if ((dir=opendir(dirname))==(DIR *)0) { + (void) rou_alert(0,"%s Unable to open director <%s> (error=<%s>, config?)", + OPEP,dirname,strerror(errno)); + phase=999; //No need to go further + } + dirname=rou_freestr(dirname); + break; + case 1 : //scanning directory contents + struct dirent *data; + register int taille; + + taille=0; + if (ext!=(char *)0) + taille=strlen(ext); + while ((data=readdir(dir))!=(struct dirent *)0) { + register char *ptr; + + ptr=data->d_name; + if (taille>0) { + ptr=strstr(data->d_name,ext); + if ((ptr!=(char *)0)&&(strlen(ptr)!=taille)) + ptr=(char *)0; + } + 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)); + } + } + break; + case 2 : //closing directory + if (closedir(dir)<0) { + (void) rou_alert(0,"%s Unable to close queue directory (error=<%s>, bug?)", + OPEP,strerror(errno)); + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return dirlst; +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to store an email to a list of email */ /* retune true if successful, false otherwise. */ /* */ diff --git a/lib/unieml.h b/lib/unieml.h index 01343d0..68e90c4 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -57,6 +57,13 @@ extern FILE *eml_createqfile(char *qfilename,char *ext); //procedure to close a file within the queue directory 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); + +//procedure to open a specific qfile +extern FILE *eml_openqfile(char *qfilename); + //procedure to add an email address to a chain //of email address extern _Bool eml_addemail(char ***emails,char *email);