From 8bcd5941e5a3da8cbba6900cad946e53a8c94821 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Fri, 11 Jul 2025 07:38:47 -0400 Subject: [PATCH] Majour code adjustment --- lib/Makefile | 5 ++ lib/geseml.c | 116 ------------------------------------ lib/geseml.h | 17 +----- lib/gessql.c | 162 +++++++++++++++++++++++++++++++-------------------- lib/gessql.h | 7 ++- lib/lvleml.c | 4 +- lib/unieml.c | 37 ++++++++++++ lib/unieml.h | 42 +++++++++---- 8 files changed, 180 insertions(+), 210 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index ea2db41..0f5cfe2 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -143,8 +143,13 @@ gestcp.h: \ unidns.h \ devlog.h devsoc.h +gessql.h: \ + unieml.h \ + devsql.h + gesspf.h: \ subafn.h + devsoc.h: \ unitls.h diff --git a/lib/geseml.c b/lib/geseml.c index 7a725c0..a1e99aa 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -157,27 +157,6 @@ 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*/ /* */ /********************************************************/ @@ -281,22 +260,6 @@ return action; */ /********************************************************/ /* */ -/* Procedure to free memory used by the TRATYP */ -/* response part. */ -/* */ -/********************************************************/ -PUBLIC void eml_freetra_resp(TRATYP *tra) - -{ -if (tra!=(TRATYP *)0) { - tra->resp=(char **)rou_freelist((void **)tra->resp,(genfree_t)rou_freestr); - } -} -/* - -*/ -/********************************************************/ -/* */ /* Procedure to duplicate an resp list within a tra*/ /* record. */ /* */ @@ -353,21 +316,6 @@ 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. */ /* */ @@ -990,67 +938,3 @@ return extracted; #undef OPEP } -/* -^L -*/ -/********************************************************/ -/* */ -/* Procedure to update the database with respond */ -/* Record associated with TRA. */ -/* Return the number of record stored within the */ -/* database. */ -/* */ -/********************************************************/ -PUBLIC int eml_update_tradb(TRATYP **tra) - -{ -#define OPEP "geseml.c:eml_update_tradb," - -int num; - -num=0; -if (tra!=(TRATYP **)0) { - SQLPTR *sqlptr; - int phase; - _Bool proceed; - - sqlptr=(SQLPTR *)0; - phase=0; - proceed=(*tra!=(TRATYP *)0); - while (proceed==true) { - switch (phase) { - case 0 : //opening the database - if ((sqlptr=sql_opensql())==(SQLPTR *)0) { - (void) rou_alert(0,"%s Unable to open database (system?)",OPEP); - phase=999; - } - break; - case 1 : //checking all transation - while (*tra!=(TRATYP *)0) { - if ((*tra)->resp!=(char **)0) { - ACTTYP action; - - action.sessid=(*tra)->sessid; - action.code=(*tra)->code; - action.rcptto=(*tra)->rcptto; - action.resp=(*tra)->resp; - (void) sql_mngact(sqlptr,sql_delete,&action); - num++; - } - tra++; - } - break; - case 2 : //closing the database - sqlptr=sql_closesql(sqlptr); - break; - default : //SAFE Guard - proceed=false; - break; - } - phase++; - } - } -return num; - -#undef OPEP -} diff --git a/lib/geseml.h b/lib/geseml.h index c6f16db..5edb501 100644 --- a/lib/geseml.h +++ b/lib/geseml.h @@ -14,27 +14,12 @@ #include "unisql.h" -//structure to define an email transport directive -typedef struct { - char code; //Transaction code - time_t date; //Transaction date - u_int delay; //Transaction execution delay - char *sessid; //session id - char *mailfrom; //Email Originator - char *rcptto; //Email Recipient - int sendcode; //Email sending status; - char **resp; //Transfer response status - }TRATYP; - //procedure to dump a list of transfert record extern _Bool eml_dump_one_tra(FILE *out,TRATYP *tra); //procedure to dump a list of transfert record extern _Bool eml_dump_list_tra(FILE *out,TRATYP **tra); -//procedure to fee memory used by the resp record within TRATYP structure -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); @@ -42,7 +27,7 @@ extern void eml_duptra_resp(TRATYP *tra,char **resp); extern TRATYP *eml_duptra(TRATYP *tra); //procedure to fee memory used by a TRATYP structure -extern TRATYP **eml_freeall_tra(TRATYP **tra); +//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/gessql.c b/lib/gessql.c index 0df04f5..2854530 100644 --- a/lib/gessql.c +++ b/lib/gessql.c @@ -18,6 +18,106 @@ #define ACTTBL "actions" //action tables #define SESTBL "sessions" //session tables +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to update database information about */ +/* emails echange current and last status. */ +/* */ +/********************************************************/ +PUBLIC _Bool mngact(SQLPTR *sqlptr,ACTTYP *act) + +{ +#define OPEP "gessql.c:sql_mngact," + +static const char *del="DELETE FROM "ACTTBL" WHERE sessid=%s AND rcptto=%s"; +static const char *ins="INSERT INTO "ACTTBL" (%s) VALUES(%s,%s,%s,%d,%s)"; + +_Bool isok; + +isok=false; +if (act!=(ACTTYP *)0) { + char strcode[10]; + char *goodid; + char *goodrcpt; + char *goodcode; + + (void) memset(strcode,'\000',sizeof(strcode)); + strcode[0]=act->code; + goodid=sql_gooddata(sqlptr,act->sessid); + goodrcpt=sql_gooddata(sqlptr,act->rcptto); + goodcode=sql_gooddata(sqlptr,strcode); + if (act->resp!=(char **)0) { + char *field; + + field="code,sessid,rcptto,numline,info"; + (void) sql_request(sqlptr,del,goodid,goodrcpt); + if (act->resp!=(char **)0) { + char **resp; + int num; + + resp=act->resp; + num=1; + while (*resp!=(char *)0) { + char *goodinfo; + + goodinfo=sql_gooddata(sqlptr,*resp); + (void) sql_request(sqlptr,ins,field,goodcode,goodid,goodrcpt,num,goodinfo); + goodinfo=rou_freestr(goodinfo); + resp++; + num++; + } + } + } + goodcode=rou_freestr(goodcode); + goodrcpt=rou_freestr(goodrcpt); + goodid=rou_freestr(goodid); + isok=true; + } +return isok; + +#undef OPEP +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to update the database with respond */ +/* Record associated with TRA. */ +/* Return the number of record stored within the */ +/* database. */ +/* */ +/********************************************************/ +PUBLIC int sql_update_tradb(SQLPTR *sqlptr,TRATYP **tralist) + +{ +#define OPEP "gesql.c:qlupdate_tradb," + +int num; + +num=0; +if (tralist!=(TRATYP **)0) { + while (*tralist!=(TRATYP *)0) { + if ((*tralist)->resp!=(char **)0) { + ACTTYP action; + + action.sessid=(*tralist)->sessid; + action.code=(*tralist)->code; + action.rcptto=(*tralist)->rcptto; + action.resp=(*tralist)->resp; + (void) mngact(sqlptr,&action); + num++; + } + tralist++; + } + } +return num; + +#undef OPEP +} /* */ @@ -339,68 +439,6 @@ while (proceed==true) { } 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) - -{ -#define OPEP "gessql.c:sql_mngact," - -static const char *del="DELETE FROM "ACTTBL" WHERE sessid=%s AND rcptto=%s"; -static const char *ins="INSERT INTO "ACTTBL" (%s) VALUES(%s,%s,%s,%d,%s)"; - -_Bool isok; - -isok=false; -if (act!=(ACTTYP *)0) { - char strcode[10]; - char *goodid; - char *goodrcpt; - char *goodcode; - - (void) memset(strcode,'\000',sizeof(strcode)); - strcode[0]=act->code; - goodid=sql_gooddata(sqlptr,act->sessid); - goodrcpt=sql_gooddata(sqlptr,act->rcptto); - goodcode=sql_gooddata(sqlptr,strcode); - if (act->resp!=(char **)0) { - char *field; - - field="code,sessid,rcptto,numline,info"; - (void) sql_request(sqlptr,del,goodid,goodrcpt); - if (act->resp!=(char **)0) { - char **resp; - int num; - - resp=act->resp; - num=1; - while (*resp!=(char *)0) { - char *goodinfo; - - goodinfo=sql_gooddata(sqlptr,*resp); - (void) sql_request(sqlptr,ins,field,goodcode,goodid,goodrcpt,num,goodinfo); - goodinfo=rou_freestr(goodinfo); - resp++; - num++; - } - } - } - goodcode=rou_freestr(goodcode); - goodrcpt=rou_freestr(goodrcpt); - goodid=rou_freestr(goodid); - isok=true; - } -return isok; - #undef OPEP } /* diff --git a/lib/gessql.h b/lib/gessql.h index 64b44ee..f736773 100644 --- a/lib/gessql.h +++ b/lib/gessql.h @@ -9,14 +9,15 @@ #include +#include "unieml.h" #include "devsql.h" +//procedure to update transaction information +extern int sql_update_tradb(SQLPTR *sqlptr,TRATYP **tralist); + //procedure to manage information on exiting user extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *key,USRTYP **usr); -//procedure to manage action stats on email exhange status -extern _Bool sql_mngact(SQLPTR *sqlptr,SQLENUM action,ACTTYP *act); - //procedure to manage information on email exchange session extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses); diff --git a/lib/lvleml.c b/lib/lvleml.c index 8aaf112..de17d15 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -24,6 +24,7 @@ #include "unieml.h" #include "devlog.h" #include "gestcp.h" +#include "gessql.h" #include "geseml.h" #include "lvleml.h" @@ -2346,7 +2347,8 @@ if ((contact!=(CONTYP *)0)&&(contact->recipients!=(RCPTYP **)0)) { ptr++; } (void) eml_dump_list_tra(qfile,tralist); - tralist=eml_freeall_tra(tralist); + (void) sql_update_tradb(contact->sqlptr,tralist); + tralist=(TRATYP **)rou_freelist((void **)tralist,(genfree_t)eml_freetra); } return status; #undef OPEP diff --git a/lib/unieml.c b/lib/unieml.c index cd06745..5a6ef9e 100644 --- a/lib/unieml.c +++ b/lib/unieml.c @@ -62,6 +62,43 @@ if (info!=(RCPTYP *)0) { return info; } /* + +*/ +/********************************************************/ +/* */ +/* Procedure to free memory used by the TRATYP */ +/* response part. */ +/* */ +/********************************************************/ +PUBLIC void eml_freetra_resp(TRATYP *tra) + +{ +if (tra!=(TRATYP *)0) { + tra->resp=(char **)rou_freelist((void **)tra->resp,(genfree_t)rou_freestr); + } +} +/* + +*/ +/********************************************************/ +/* */ +/* 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; +} +/* ^L */ /********************************************************/ diff --git a/lib/unieml.h b/lib/unieml.h index b5a7fb4..d35bc07 100644 --- a/lib/unieml.h +++ b/lib/unieml.h @@ -55,18 +55,18 @@ //list of keyword typedef enum { //list of SMTP protocol keyword - c_auth, //Requesting authentication - c_data, //DATA email contents transfer request - c_ehlo, //EHLO command - c_helo, //Basic Helo command - c_mail, //'mail from:' sequence detected - c_noop, //No Operation request - c_quit, //quit exchange - c_rcpt, //'rcpt to:' sequence detected - c_rset, //resetting session - c_starttls, //Starting a TLS crypted link - c_unknown //key word unknown - }CODTYP; + c_auth, //Requesting authentication + c_data, //DATA email contents transfer request + c_ehlo, //EHLO command + c_helo, //Basic Helo command + c_mail, //'mail from:' sequence detected + c_noop, //No Operation request + c_quit, //quit exchange + c_rcpt, //'rcpt to:' sequence detected + c_rset, //resetting session + c_starttls, //Starting a TLS crypted link + c_unknown //key word unknown + }CODTYP; typedef struct { //*definition of recipient char code; //'L' rcipient local, 'R' recipient remote @@ -74,9 +74,27 @@ typedef struct { //*definition of recipient char *userid; //recipient email userid }RCPTYP; +//structure to define an email transport directive +typedef struct { + char code; //Transaction code + time_t date; //Transaction date + u_int delay; //Transaction execution delay + char *sessid; //session id + char *mailfrom; //Email Originator + char *rcptto; //Email Recipient + int sendcode; //Email sending status; + char **resp; //Transfer response status + }TRATYP; + //procedure to Free one recipient info extern RCPTYP *eml_freerecipient(RCPTYP *info); +//procedure to fee memory used by the resp record within TRATYP structure +extern void eml_freetra_resp(TRATYP *tra); + +//procedure to Free one transaction inf +extern TRATYP *eml_freetra(TRATYP *tra); + //procedure to add recipient to a recipient list extern _Bool eml_addrecipient(RCPTYP ***list,RCPTYP *rcpt); -- 2.47.3