From 8c98550e34657405508280f4e7825cd9139361d2 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Fri, 13 Jun 2025 04:32:33 -0400 Subject: [PATCH] Adding eml_countqfile procedure --- Makefile | 6 +-- data-feed/feed01.tst | 2 - data-feed/feed02.tst | 6 +-- data-feed/feed11.tst | 2 +- lib/geseml.c | 7 ++- lib/unieml.c | 103 +++++++++++++++++++++++++++++++++++++++++++ lib/unieml.h | 3 ++ 7 files changed, 116 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 5d7858c..28335a9 100644 --- a/Makefile +++ b/Makefile @@ -123,6 +123,7 @@ FEEDPAR = \ $(TESTIP) \ $(TESTPORT) \ ./$(DATATST)/feed*.tst +ONEFEED=feed01.tst #to test with an external server extfeed : debug @@ -132,8 +133,7 @@ extfeed : debug -c ./conf/feeder.conf.dvl \ $(EXTIP) \ $(EXTPORT) \ - ./$(DATATST)/extfeed00.tst -ONEFEED=feed00.tst + ./$(DATATST)/$(ONEFEED) onefeed : debug @ rm -fr ./data-queue/* @ rm -fr $(TESTDIR)/var/spool/$(APPNAME)/queue/* @@ -189,7 +189,7 @@ valfeed : debug #valgring of emlrcvr -c ./conf/feeder.conf.dvl \ $(TESTIP) \ $(TESTPORT) \ - ./$(DATATST)/feed.tst + ./$(DATATST)/$(ONEFEED) # --track-fds=yes \ diff --git a/data-feed/feed01.tst b/data-feed/feed01.tst index acc9720..d48e1ce 100644 --- a/data-feed/feed01.tst +++ b/data-feed/feed01.tst @@ -13,8 +13,6 @@ S:RCPT TO: R:250 2.6.4 Address accepted S:RCPT TO: R:250 2.6.4 Address accepted -S:RCPT TO: -R:250 2.6.4 Address accepted #------------------------------------------------------------------------- #-sending data C:DATA 354 3.5.0 End data with . diff --git a/data-feed/feed02.tst b/data-feed/feed02.tst index a3888ed..aa3b188 100644 --- a/data-feed/feed02.tst +++ b/data-feed/feed02.tst @@ -24,7 +24,7 @@ S:RCPT TO: R:250 2.6.4 Address accepted #------------------------------------------------------------------------- #-sending data -C:DATA +C:DATA 354 3.5.0 End data with . D:Subject: Very Simple email contents D:From: Maitre Post D:To: Maitre WEB @@ -64,7 +64,7 @@ S:RCPT TO: R:250 2.6.4 Address accepted #------------------------------------------------------------------------- #-sending data -C:DATA +C:DATA 354 3.5.0 End data with . D:Subject: Second email contents D: D:SECOND FIRST Line @@ -95,7 +95,7 @@ S:RCPT TO: R:250 2.6.4 Address accepted #------------------------------------------------------------------------- #-sending data -C:DATA +C:DATA 354 3.5.0 End data with . D:Subject: Third email contents D: D:THIRD FIRST Line diff --git a/data-feed/feed11.tst b/data-feed/feed11.tst index 7e4672d..a2bbe64 100644 --- a/data-feed/feed11.tst +++ b/data-feed/feed11.tst @@ -14,7 +14,7 @@ S:RCPT TO: R:250 2.6.4 Address accepted #------------------------------------------------------------------------- #-sending data -C:DATA +C:DATA 354 3.5.0 End data with . D:Subject: A email to not exitsing user D:From: Trouble maker diff --git a/lib/geseml.c b/lib/geseml.c index d33729c..4824794 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -421,7 +421,7 @@ if (domlist!=(REFTYP **)0) { REFTYP **ptr; iter=0; - (void) time(¤t ); + (void) time(¤t); tinfo=localtime(¤t); (void) strftime(buffer,sizeof(buffer),"%s",tinfo); ptr=domlist; @@ -436,7 +436,7 @@ if (domlist!=(REFTYP **)0) { qfile=(FILE *)0; action=false; ext=EXTRANS; - (void) snprintf(qname,sizeof(qname),"%s-%s-%04d",(*ptr)->domain,buffer,iter); + (void) snprintf(qname,sizeof(qname),"%08ld-%08d-%04d",current,getpid(),iter); phase=0; proceed=true; while (proceed==true) { @@ -458,9 +458,8 @@ if (domlist!=(REFTYP **)0) { (void) eml_renameqfile(qname,EXTOBE,ext); break; case 4 : //do we need to start sender - if (action==true) { + if ((action==true)&&(foreground==false)) (void) eml_start_sender(qname); - } break; default : //SAFE Guard proceed=false; diff --git a/lib/unieml.c b/lib/unieml.c index f320e89..3b19f87 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -663,6 +663,109 @@ while (proceed==true) { } filename=rou_freestr(filename); return status; +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to increase or decrase the "count" */ +/* session id file. */ +/* return 0 or a positive count number. */ +/* return -1 if trouble. */ +/* */ +/********************************************************/ +PUBLIC int eml_countqfile(char *qfilename,int count) + +{ +#define OPEP "unieml.c:eml_countqfile," + +int result; +FILE *fcount; +char *filename; +int phase; +_Bool proceed; + +result=-1; +fcount=(FILE *)0; +filename=rou_apppath(QDIR); +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //lets open the queue directory + if (qfilename==(char *)0) { + (void) rou_alert(0,"%s filename=<%s> missing (Bug?)",OPEP,qfilename); + phase=999; //Big trouble + } + break; + case 1 : //opening count file + char name[300]; + + (void) snprintf(name,sizeof(name),"%s.%s/%s",filename,qfilename,EXTCNT); + if ((fcount=fopen(name,"rw"))==(FILE *)0) { + (void) rou_alert(0,"%s unable to open count file <%s> (error=<%s>)", + OPEP,name,strerror(errno)); + phase=999; //Big trouble + } + break; + case 2 : //locking access + int try; + + try=100; //wait 1 sec total + while (try>0) { + if (flock(fileno(fcount),LOCK_EX|LOCK_NB)==0) + break; //We have the lock + else { + switch (errno) { + case (EWOULDBLOCK) : + try--; + if (try>0) + (void) usleep(10000); //Wait 10 millisec + else + (void) rou_alert(0,"%s unable to lock count file <%s> in time", + OPEP,name); + break; + default : + (void) rou_alert(0,"%s unable to lock count file <%s> (error=<%s>)", + OPEP,name,strerror(errno)); + (void) fclose(fcount); + phase=999;// trouble trouble + try=0; + break; + } + } + } + break; + case 3 : //reading count + if (fscanf(fcount,"%d",&result)!=1) { + (void) rou_alert(0,"%s unable to read file <%s> contents (error=<%s>)", + OPEP,name,strerror(errno)); + (void) fclose(fcount); + phase=999; //trouble trouble + } + break; + case 4 : //doing count + result+=count; + if (result<0) + result=-1; + (void) rewind(fcount); + if (fprintf(fcount,"%d\n",result)<0) { + (void) rou_alert(0,"%s unable to write file <%s> count value (error=<%s>)", + OPEP,name,strerror(errno)); + } + (void) fclose(fcount); + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +filename=rou_freestr(filename); +return result; + #undef OPEP } /* diff --git a/lib/unieml.h b/lib/unieml.h index 5083877..f2be473 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -115,6 +115,9 @@ extern FILE *eml_openqfile(const char *qfilename,const char *ext); //procedure to duplicate a specific qfile to another file extern _Bool eml_dupqfile(char *qfilename,const char *dest); +//procedure to increase or decrease the "count" file contents +extern int eml_countqfile(char *qfilename,int count); + //procedure to check email address format //of an email address extern RCPTYP *eml_isemailok(char *email,char **report); -- 2.47.3