From 34814cd4b3b14484269128123ac66b7423616472 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 27 May 2025 14:55:35 -0400 Subject: [PATCH] Able to merge trans if partly transmittes --- app/Makefile | 1 + lib/geseml.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- lib/geseml.h | 5 ++++ lib/unieml.h | 13 ---------- 4 files changed, 72 insertions(+), 16 deletions(-) diff --git a/app/Makefile b/app/Makefile index 3fe0d9b..99bb17a 100644 --- a/app/Makefile +++ b/app/Makefile @@ -42,6 +42,7 @@ LD = gcc -g CFLAGS = -I ../lib -Wall $(OPTIME) LIBMAIL = ../lib/libmail.a LIBS = $(LIBMAIL) \ + -luuid \ -lpq \ -lcrypto \ -lssl \ diff --git a/lib/geseml.c b/lib/geseml.c index f4a4d2f..e12d4d7 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -7,6 +7,7 @@ /********************************************************/ #include #include +#include #include "subrou.h" #include "unieml.h" @@ -174,6 +175,31 @@ return trans; */ /********************************************************/ /* */ +/* Procedure to duplicate TRATYP structure */ +/* */ +/********************************************************/ +PUBLIC TRATYP *eml_duptra(TRATYP *trans) + +{ +TRATYP *dup; + +dup=(TRATYP *)0; +if (trans!=(TRATYP *)0) { + dup=(TRATYP *)calloc(1,sizeof(TRATYP)); + dup->code=trans->code; + dup->date=trans->date; + dup->delay=trans->delay; + dup->rcptto=strdup(trans->rcptto); + dup->mailfrom=strdup(trans->mailfrom); + dup->sessid=strdup(trans->sessid); + } +return dup; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to scan the a qfile and build a */ /* list of email transport directive. */ /* */ @@ -249,7 +275,6 @@ PUBLIC void eml_todoqfile(TRATYP **list) { #define OPEP "geseml.c:eml_todoqfile," -#define EXTOBE "tobedone" REFTYP **domlist; @@ -310,7 +335,6 @@ if (domlist!=(REFTYP **)0) { (void) free(domlist); } -#undef EXTOBE #undef OPEP } /* @@ -327,8 +351,10 @@ PUBLIC void eml_doneqfile(TRATYP **list) #define OPEP "geseml.c:eml_doneqfile," SIDTYP **sids; +TRATYP **next; sids=(SIDTYP **)0; +next=(TRATYP **)0; (void) rou_alert(0,"%s JMPDBG trying check",OPEP); if (list!=(TRATYP **)0) { TRATYP **ptr; @@ -342,6 +368,7 @@ if (list!=(TRATYP **)0) { case 'C' : //completed break; default : + next=(TRATYP **)rou_addlist((void **)next,(void *)eml_duptra(*ptr)); found->count++; break; } @@ -361,7 +388,43 @@ if (sids!=(SIDTYP **)0) { } sids=eml_freesid(sids); } - +if (next!=(TRATYP **)0) { + FILE *qfile; + uuid_t id; + char qname[150]; + char struuid[40]; + int phase; + _Bool proceed; + + qfile=(FILE *)0; + (void) uuid_generate(id); + (void) uuid_unparse(id,struuid); + (void) snprintf(qname,sizeof(qname),"%s-%s-%04d",struuid,"redo",0); + phase=0; + proceed=true; + while (proceed==true) { + switch (phase) { + case 0 : //Opening qfile + if ((qfile=eml_createqfile(qname,EXTOBE))==(FILE *)0) + phase=999; //Trouble trouble + break; + case 1 : //dumping TRANS data to file + (void) eml_dumptra(qfile,next); + break; + case 2 : //Closing file + (void) eml_closeqfile(qfile); + break; + case 3 : //file ready, renaming file, + (void) eml_renameqfile(qname,EXTOBE,EXTRANS); + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } + next=(TRATYP **)rou_freelist((void **)next,(genfree_t)eml_freetra); + } #undef OPEP } /* diff --git a/lib/geseml.h b/lib/geseml.h index cd7a4d3..99e0cb4 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -11,6 +11,8 @@ #include #include +#define EXTOBE "tobedone" //directive enxtension in progress + //structure to define an email transport directive typedef struct { char code; //Transaction code @@ -27,6 +29,9 @@ extern void eml_dumptra(FILE *out,TRATYP **tra); //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 open a specific qfile extern TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile); diff --git a/lib/unieml.h b/lib/unieml.h index 4be728e..99bdd76 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -62,19 +62,6 @@ extern SIDTYP *eml_addsid(SIDTYP ***list,char *sessid); //procedure to Free one recipient info extern RCPTYP *eml_freerecipient(RCPTYP *info); -//get a session unique id -extern char *eml_getmainsesid(); - -//procedure to add recipient to a recipient list -//adding an session ID to a list of session -extern SIDTYP *eml_addsid(SIDTYP ***list,char *sessid); - -//procedure to Free one recipient info -extern RCPTYP *eml_freerecipient(RCPTYP *info); - -//get a session unique id -extern char *eml_getmainsesid(); - //procedure to add recipient to a recipient list extern _Bool eml_addrecipient(RCPTYP ***list,RCPTYP *rcpt); -- 2.47.3