From 39c9dc290c51b294270fde9aacb9222b096b2950 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Sun, 29 Jun 2025 18:26:13 -0400 Subject: [PATCH] Starting to implement action table --- Makefile | 1 + app/Makefile | 21 ++++++++++++--- app/sender.c | 2 +- app/sorter.c | 2 +- lib/Makefile | 1 + lib/devsql.c | 32 ++++++++++++++++++++++ lib/devsql.h | 3 +++ lib/geseml.c | 70 ++++++++++++++++++++++++++++++++---------------- lib/geseml.h | 6 ++--- lib/lvleml.c | 2 +- lib/unisql.h | 7 +++++ mailleur.spec.in | 18 ++++++++++--- 12 files changed, 129 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index a7b1aa4..f393b97 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ debug \ done @ ln -nsf rcvrpsql bin/receiver @ ln -nsf sndrpsql bin/sender + @ ln -nsf srtrpsql bin/sorter diff --git a/app/Makefile b/app/Makefile index c4c05d4..adb60be 100644 --- a/app/Makefile +++ b/app/Makefile @@ -27,7 +27,8 @@ EXE= \ feeder \ sndrpsql \ sndrmsql \ - sorter \ + srtrpsql \ + srtrmsql \ SRC= \ chkspf.c \ @@ -86,15 +87,27 @@ sndrmsql: toremake receiver.o ../lib/libmar.a \ -lmysqlclient +srtrpsql: toremake sorter.o + @ $(LD) $(LDFLAGS) \ + -o ../bin/$@ sorter.o \ + $(LIBS) \ + ../lib/libpos.a \ + -lpq + +srtrmsql: toremake sorter.o + @ $(LD) $(LDFLAGS) \ + -o ../bin/$@ sorter.o \ + $(LIBS) \ + ../lib/libmar.a \ + -lmysqlclient + + feeder : toremake feeder.o @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) sender : toremake sender.o @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) -sorter : toremake sorter.o - @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) - chkspf.o: chkspf.c \ ../lib/unidns.h \ ../lib/subafn.h \ diff --git a/app/sender.c b/app/sender.c index 08ea320..6e4e2c7 100644 --- a/app/sender.c +++ b/app/sender.c @@ -124,7 +124,7 @@ while (proceed==true) { case 5 : //updating transfile (void) eml_dump_list_tra(qfile,tra); (void) eml_update_tradb(tra); - tra=(TRATYP **)rou_freelist((void **)tra,(genfree_t)eml_freetra); + tra=eml_freeall_tra(tra); break; case 6 : //closing file qfile=eml_closeqfile(qfile); diff --git a/app/sorter.c b/app/sorter.c index ffd6979..461be07 100644 --- a/app/sorter.c +++ b/app/sorter.c @@ -82,7 +82,7 @@ while (proceed==true) { (void) eml_doneqfile(trans); break; } - trans=(TRATYP **)rou_freelist((void **)trans,(genfree_t)eml_freetra); + trans=eml_freeall_tra(trans); break; default : //SAFE Guard proceed=false; diff --git a/lib/Makefile b/lib/Makefile index 143d386..69afed4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -55,6 +55,7 @@ gesspf.o: \ geseml.o: \ subrou.h \ unidns.h unieml.h unipar.h unitls.h \ + devsql.h \ geseml.h geseml.h gestcp.o: \ diff --git a/lib/devsql.c b/lib/devsql.c index 32d3e47..cb16ce4 100644 --- a/lib/devsql.c +++ b/lib/devsql.c @@ -809,3 +809,35 @@ return isok; #undef OPEP } +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to update database information about */ +/* emails echange current and last status. */ +/* */ +/********************************************************/ +PUBLIC _Bool sql_mngact(SQLPTR *sqlptr,SQLENUM action,ACTTYP *act) + +{ +_Bool isok; + +isok=false; +if (act!=(ACTTYP *)0) { + (void) rou_alert(0,"JMPDBG ses=<%s>d rcpt=<%s>",act->sessid,act->rcptto); + if (act->resp!=(char **)0) { + char **resp; + int num; + + resp=act->resp; + num=0; + while (*resp!=(char *)0) { + num++; + (void) rou_alert(0,"\tRESP[%0d]=<%s>",num,*resp); + resp++; + } + } + } +return isok; +} diff --git a/lib/devsql.h b/lib/devsql.h index 547e98b..a9b68fa 100644 --- a/lib/devsql.h +++ b/lib/devsql.h @@ -29,4 +29,7 @@ extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *email,USRTYP **usr); //procedure to manage information on email exchange session extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses); +//procedure to manage action stats on email exhange status +extern _Bool sql_mngact(SQLPTR *sqlptr,SQLENUM action,ACTTYP *act); + #endif diff --git a/lib/geseml.c b/lib/geseml.c index cd47404..0dfa028 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -16,6 +16,7 @@ #include "unieml.h" #include "unipar.h" #include "unitls.h" +#include "devsql.h" #include "geseml.h" //dovecot local storage directory @@ -156,6 +157,27 @@ return reflist; */ /********************************************************/ /* */ +/* Procedure to free memory used by a TRATYP record*/ +/* */ +/********************************************************/ +static TRATYP *eml_freetra(TRATYP *tra) + +{ +if (tra!=(TRATYP *)0) { + (void) eml_freetra_resp(tra); + tra->rcptto=rou_freestr(tra->rcptto); + tra->mailfrom=rou_freestr(tra->mailfrom); + tra->sessid=rou_freestr(tra->sessid); + (void) free(tra); + tra=(TRATYP *)0; + } +return tra; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to display/debug TRATYP record content*/ /* */ /********************************************************/ @@ -275,28 +297,7 @@ if (tra!=(TRATYP *)0) { */ /********************************************************/ /* */ -/* Procedure to free memory used by a TRATYP record*/ -/* */ -/********************************************************/ -PUBLIC TRATYP *eml_freetra(TRATYP *tra) - -{ -if (tra!=(TRATYP *)0) { - (void) eml_freetra_resp(tra); - tra->rcptto=rou_freestr(tra->rcptto); - tra->mailfrom=rou_freestr(tra->mailfrom); - tra->sessid=rou_freestr(tra->sessid); - (void) free(tra); - tra=(TRATYP *)0; - } -return tra; -} -/* - -*/ -/********************************************************/ -/* */ -/* Procedure to duplcate an resp list within a tra */ +/* Procedure to duplicate an resp list within a tra*/ /* record. */ /* */ /********************************************************/ @@ -352,6 +353,21 @@ return dup; */ /********************************************************/ /* */ +/* Procedure to free memory used by a tra list */ +/* */ +/********************************************************/ +PUBLIC TRATYP **eml_freeall_tra(TRATYP **tra) + +{ +(void) eml_update_tradb(tra); +tra=(TRATYP **)rou_freelist((void **)tra,(genfree_t)eml_freetra); +return tra; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to scan the a qfile and build a */ /* list of email transport directive. */ /* */ @@ -982,11 +998,19 @@ PUBLIC int eml_update_tradb(TRATYP **tra) { int num; +SQLPTR *sqlptr; num=0; +sqlptr=(SQLPTR *)0; if (tra!=(TRATYP **)0) { while (*tra!=(TRATYP *)0) { - (void) rou_alert(0,"JMPDBG ses=<%s>d rcpt=<%s>",(*tra)->sessid,(*tra)->rcptto); + ACTTYP action; + + action.sessid=(*tra)->sessid; + action.rcptto=(*tra)->rcptto; + action.resp=(*tra)->resp; + (void) sql_mngact(sqlptr,sql_delete,&action); + num++; tra++; } } diff --git a/lib/geseml.h b/lib/geseml.h index 0d2d493..c6f16db 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -38,12 +38,12 @@ extern void eml_freetra_resp(TRATYP *tra); //procedure to fee memory used to duplicate a resp list to tra resp extern void eml_duptra_resp(TRATYP *tra,char **resp); -//procedure to fee memory used by a TRATYP structure -extern TRATYP *eml_freetra(TRATYP *tra); - //procedure to duplicate a TRATYP structure extern TRATYP *eml_duptra(TRATYP *tra); +//procedure to fee memory used by a TRATYP structure +extern TRATYP **eml_freeall_tra(TRATYP **tra); + //procedure to open a specific qfile extern TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile); diff --git a/lib/lvleml.c b/lib/lvleml.c index a25fa07..39c5c8b 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1836,7 +1836,7 @@ if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) { ptr++; } (void) eml_dump_list_tra(qfile,tralist); - tralist=(TRATYP **)rou_freelist((void **)tralist,(genfree_t)eml_freetra); + tralist=eml_freeall_tra(tralist); } return status; #undef OPEP diff --git a/lib/unisql.h b/lib/unisql.h index ba874e6..30e8986 100644 --- a/lib/unisql.h +++ b/lib/unisql.h @@ -38,6 +38,13 @@ typedef struct { u_long taille; //Email size }SESTYP; +//Tructure about email action status (managing email) +typedef struct { + char *sessid; //session id + char *rcptto; //email recipient + char **resp; //Multiline status + }ACTTYP; + //procedure to free space used by an USRTYP extern USRTYP *sql_freeusr(USRTYP *usr); diff --git a/mailleur.spec.in b/mailleur.spec.in index 5433286..6a7cf81 100644 --- a/mailleur.spec.in +++ b/mailleur.spec.in @@ -45,7 +45,6 @@ search about email exchange within time and transaction context. %attr(0640,%{name},dovecot) %config(noreplace) %{dovedir}/passfile %{_sbindir}/chkspf %{_sbindir}/feeder -%attr(0755,%{name},mail) %{_sbindir}/sorter %attr(0754,root,root) %{_libdir}/%{name}/shell/*.sh %attr(0754,root,root) %{_libdir}/%{name}/support/addconfig.sh %attr(0754,root,root) %{_libdir}/%{name}/support/crdb.sh @@ -167,6 +166,7 @@ Obsoletes : %{name}-mysql <= %{version}-%{release} %defattr(-,root,root,-) %attr(0755,%{name},mail) %{_sbindir}/rcvrpsql %attr(0755,%{name},mail) %{_sbindir}/sndrpsql +%attr(0755,%{name},mail) %{_sbindir}/srtrpsql %post postgresql if [ "$1" = 1 ]; then @@ -183,10 +183,15 @@ if [ "$1" = 1 ]; then %{__ln_s} -nf \ ./sndrpsql \ %{_sbindir}/sender +%{__ln_s} -nf \ + ./srtrpsql \ + %{_sbindir}/sorter %postun postgresql if [ "$1" = 0 ]; then - rm -f %{_sbindir}/%{name} + rm -f %{_sbindir}/receiver + rm -f %{_sbindir}/sender + rm -f %{_sbindir}/sorter fi #============================================================================= @@ -209,6 +214,7 @@ Obsoletes : %{name}-postgresql <= %{version}-%{release} %defattr(-,root,root,-) %attr(0755,%{name},mail) %{_sbindir}/rcvrmsql %attr(0755,%{name},mail) %{_sbindir}/sndrmsql +%attr(0755,%{name},mail) %{_sbindir}/srtrmsql %post mysql if [ "$1" = 1 ]; then @@ -224,11 +230,15 @@ if [ "$1" = 1 ]; then %{__ln_s} -nf \ ./sndrmsql \ %{_sbindir}/sender +%{__ln_s} -nf \ + ./srtrmsql \ + %{_sbindir}/sorter %postun mysql if [ "$1" = 0 ]; then rm -f %{_sbindir}/receiver rm -f %{_sbindir}/sender + rm -f %{_sbindir}/sorter fi #============================================================================= @@ -252,9 +262,11 @@ if [ "$1" = 0 ]; then DESTDIR="%{buildroot}" \ install +#removing default link generated by make %{__rm} -fr \ + %{buildroot}%{_sbindir}/receiver\ %{buildroot}%{_sbindir}/sender \ - %{buildroot}%{_sbindir}/receiver + %{buildroot}%{_sbindir}/sorter \ #============================================================================= %changelog -- 2.47.3