From: Jean-Marc Pigeon (Delson) Date: Sun, 29 Jun 2025 11:54:14 +0000 (-0400) Subject: update of sessions start to work X-Git-Tag: tag-0.11~23 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=65071d49eaf1ea2db7de7a6b7708c61c50eba059;p=jmp%2Fmailleur update of sessions start to work --- diff --git a/lib/devsql.c b/lib/devsql.c index be44341..2b5b4eb 100644 --- a/lib/devsql.c +++ b/lib/devsql.c @@ -405,10 +405,77 @@ static _Bool insert_ses(SQLTYP *sql,char *seskey,SESTYP **ses) _Bool isok; isok=true; -(void) rou_alert(0,"%s JMPDBG Insertin session <%s>",OPEP,seskey); +(void) rou_alert(0,"%s JMPDBG Inserting session <%s>",OPEP,seskey); isok=(sqlrequest(sql,INSSES,seskey)==1); return isok; +#undef INSSES +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to update a session contents */ +/* */ +/********************************************************/ +static _Bool update_ses(SQLTYP *sql,char *seskey,SESTYP **ses) + +{ +#define OPEP "devseql.c:update_ses," +#define UPDSES "UPDATE "SESSIONS" set %s WHERE sessid=%s" + +_Bool isok; +char *cmtset; + +isok=true; +cmtset=strdup(""); +for (int i=0;(isok==true)&&(sesfield[i]!=(char *)0);i++) { + char *data; + char items[50]; + + data=(char *)0; + (void) strcpy(items,""); + switch (i) { + case 0 : //session ID + break; //nothing to do + case 1 : //sfrom + data=sql_gooddata(sql,(*ses)->sfrom); + break; //nothing to do + case 2 : //efrom + data=sql_gooddata(sql,(*ses)->efrom); + break; + case 3 : //taille + (*ses)->taille=5555; + (void) rou_asprintf(&data,"%d",(*ses)->taille); + break; + default : + isok=false; + (void) rou_alert(0,"%s Unexpected field <%s> (Bug?)",OPEP,sesfield[i]); + break; + } + if (data!=(char *)0) { + char *newset; + char *sep; + + newset=(char *)0; + sep=""; + if (strlen(cmtset)>0) + sep=","; + (void) rou_asprintf(&newset,"%s%s%s=%s",cmtset,sep,sesfield[i],data); + data=rou_freestr(data); + cmtset=rou_freestr(cmtset); + cmtset=newset; + (void) rou_alert(0,"JMPDBG cmtset=<%s>",cmtset); + } + } +if (isok==true) + isok=(sqlrequest(sql,UPDSES,cmtset,seskey)==1); +cmtset=rou_freestr(cmtset); +return isok; + +#undef INSSES #undef OPEP } /* @@ -688,7 +755,7 @@ return isok; /* exchange session. */ /* */ /********************************************************/ -PUBLIC _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,char *seskey,SESTYP **ses) +PUBLIC _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses) { #define OPEP "devsql.c:sql_mngses," @@ -707,13 +774,13 @@ proceed=true; while (proceed==true) { switch (phase) { case 0 : //checking SQL - if (sql==(SQLTYP *)0) { + if ((sql==(SQLTYP *)0)||(ses==(SESTYP **)0)||(*ses==(SESTYP *)0)) { (void) rou_alert(0,"%s SQL pointer is NUll (Bug?)",OPEP); phase=999; } - if ((gooddata=sql_gooddata(sql,seskey))==(char *)0) { + if ((gooddata=sql_gooddata(sql,(*ses)->sessid))==(char *)0) { (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)", - OPEP,SESSIONS,seskey); + OPEP,SESSIONS,(*ses)->sessid); phase=999; } break; @@ -722,8 +789,12 @@ while (proceed==true) { case sql_insert : isok=insert_ses(sql,gooddata,ses); break; + case sql_update : + isok=update_ses(sql,gooddata,ses); + break; default : - (void) rou_alert(0,"%s action='%d' not yet implemented!",OPEP,action); + (void) rou_alert(0,"%s action='%d' not yet implemented! (BUG?)", + OPEP,action); } gooddata=rou_freestr(gooddata); break; diff --git a/lib/devsql.h b/lib/devsql.h index 65b7b84..547e98b 100644 --- a/lib/devsql.h +++ b/lib/devsql.h @@ -27,6 +27,6 @@ extern char *sql_gooddata(SQLPTR *sqlptr,char *key); 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,char *seskey,SESTYP **ses); +extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses); #endif diff --git a/lib/lvleml.c b/lib/lvleml.c index 7e9f70d..9f8fe6c 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -25,6 +25,24 @@ #include "geseml.h" #include "lvleml.h" +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to update database and free the */ +/* current session. */ +/* */ +/********************************************************/ +static void freesessid(CONTYP *contact) + +{ +if (contact->session!=(SESTYP *)0) { + (void) sql_mngses(contact->sqlptr,sql_update,&(contact->session)); + contact->session->sfrom=strdup(contact->mailfrom); + contact->session=sql_freeses(contact->session); + } +} /* ^L */ @@ -40,11 +58,12 @@ static void getsessid(CONTYP *contact) if (contact!=(CONTYP *)0) { char *newsid; + (void) freesessid(contact); + contact->session=(SESTYP *)calloc(1,sizeof(SESTYP)); newsid=eml_getcursesid(contact->mainsesid,contact->numreset); - contact->session=sql_freeses(contact->session); contact->session=(SESTYP *)calloc(1,sizeof(SESTYP)); contact->session->sessid=newsid; - (void) sql_mngses(contact->sqlptr,sql_insert,newsid,&(contact->session)); + (void) sql_mngses(contact->sqlptr,sql_insert,&(contact->session)); } } /* @@ -61,12 +80,12 @@ static CONTYP *freecontact(CONTYP *contact) #define OPEP "lvleml.c:freecontact" if (contact!=(CONTYP *)0) { + (void) freesessid(contact); contact->sqlptr=sql_closesql(contact->sqlptr); contact->logptr=log_closelog(contact->logptr); contact->recipients=(RCPTYP **)rou_freelist((void **)contact->recipients, (genfree_t)eml_freerecipient); contact->mailfrom=rou_freestr(contact->mailfrom); - contact->session=sql_freeses(contact->session); contact->mainsesid=rou_freestr(contact->mainsesid); contact->fqdn=rou_freestr(contact->fqdn); contact->peername=rou_freestr(contact->peername); diff --git a/lib/unisql.h b/lib/unisql.h index 764a16f..839eecc 100644 --- a/lib/unisql.h +++ b/lib/unisql.h @@ -33,6 +33,7 @@ typedef struct { char *sessid; //session id char *sfrom; //the "mail from" comming from SMTP exchange char *efrom; //the "mail from" as within the email itself + int taille; //Email size }SESTYP; //procedure to free space used by an USRTYP