]> SAFE projects GIT repository - jmp/mailleur/commitdiff
update of sessions start to work
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 29 Jun 2025 11:54:14 +0000 (07:54 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 29 Jun 2025 11:54:14 +0000 (07:54 -0400)
lib/devsql.c
lib/devsql.h
lib/lvleml.c
lib/unisql.h

index be443413392a9a904cb540d40f8dfd5ba5e626a9..2b5b4ebba6e506331f2d21c2fd9b93fec5bad85a 100644 (file)
@@ -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
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      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;
index 65b7b84c40fbfaba1c070ffd61955de62fd3e628..547e98b25fa9c4ff8285b57851940550e9b470e1 100644 (file)
@@ -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
index 7e9f70d395861f619d3af1211a11f927763b0f64..9f8fe6cd74c26e44e8d9af9f2650812dc2542ac4 100644 (file)
 #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);
index 764a16f9c088619b50df1463bb845f7fa67e9f5b..839eecc98458e7bc0decfda83599a5c1073c2d74 100644 (file)
@@ -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