]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Able to read remotes table record
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 11 Jul 2025 15:37:23 +0000 (11:37 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 11 Jul 2025 15:37:23 +0000 (11:37 -0400)
lib/gessql.c
lib/gessql.h
lib/unisql.c
lib/unisql.h

index fb376fab0682b72e08853cd2ed265d97176cc53c..89624f62005b2ec62b19ee5f0ce0bb63c67d14f5 100644 (file)
@@ -190,7 +190,7 @@ while (proceed==true) {
       nbr=sql_getnbrtupple(sqlptr,rs);
       switch (nbr) {
         case 0  :       //No user email found
-          phase=999;    //this could append
+          phase=999;    //User name not in database
           break;
         case 1  :       //we have only one record, found user
           break;
@@ -247,6 +247,120 @@ while (proceed==true) {
 *usr=locusr;
 return isok;
 
+#undef  OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to select a user from emails tables   */
+/*      and return contents;                            */
+/*                                                      */
+/********************************************************/
+static _Bool select_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP **srv)
+
+{
+#define OPEP    "gessql.c:select_remote,"
+
+static const char *sel="SELECT * FROM "RMTTBL" WHERE remoteip=%s";
+
+//field available in table "emails"
+static const FLDTYP usrfield[]={
+          {1,"remoteip"},
+          {2,"lastscan"},
+          {3,"lastupdate"},
+          {4,"links"},
+          {5,"credit"},
+          {6,"status"},
+          {0,(char *)0}
+          };
+
+_Bool isok;
+SRVTYP *locsrv;
+SQLRES *rs;
+register int phase;
+register _Bool proceed;
+
+isok=false;
+locsrv=(SRVTYP *)0;
+rs=(SQLRES *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //checking parameters
+      if ((srv==(SRVTYP **)0)||(rmtip==(char *)0)||(strlen(rmtip)==0)) {
+        (void) rou_alert(0,"%s srv=<%p> or rmtip=<%s> sing (Bug?)",OPEP,srv,rmtip);
+        phase=999;
+        }
+      break;
+    case 1      :       //Selecting user
+      if ((rs=sql_gettupple(sqlptr,sel,rmtip))==(SQLRES *)0) {
+        (void) rou_alert(0,"%s Unable to get data for user <%s> (Database?)",
+                            OPEP,rmtip);
+        phase=999;      //user not found within database 
+        }
+      break;
+    case 2      :       //do we have ONE user
+      int nbr;
+
+      nbr=sql_getnbrtupple(sqlptr,rs);
+      switch (nbr) {
+        case 1  :       //we have only one record, found remote
+          break;
+        case 0  :      //no record found!
+        default :      //such case should never ever happen
+          (void) rou_alert(0,"%s got '%d' users record %s (Database corrupted?)",
+                             OPEP,nbr,"while only 1 is expected");
+          phase=999;
+          break;
+        }
+      break;
+    case 3      :       //user data extraction
+      isok=true;
+      locsrv=(SRVTYP *)calloc(1,sizeof(SRVTYP));
+      for (int i=0;(usrfield[i].name!=(char *)0)&&(isok==true);i++) {
+        char *locval;
+      
+        if ((locval=sql_getvalue(sqlptr,rs,0,usrfield[i].name))==(char *)0)
+          continue;
+        switch (usrfield[i].num) {
+          case 1        :       //user remoteip
+            locsrv->rmtip=strdup(locval);
+            break;
+          case 2        :       //lastscan
+            break;
+          case 3        :       //last update
+            break;
+          case 4        :       //Number of links
+            locsrv->links=atoi(locval);
+            break;
+          case 5        :       //remote server credibility
+            locsrv->credit=atoi(locval);
+            break;
+          case 6        :       //scanning status
+            locsrv->status=strdup(locval);
+            break;
+          default       :
+            (void) rou_alert(0,"%s field <%d:%s> not implemented (Bug?)",
+                                   OPEP,usrfield[i].num,usrfield[i].name);
+            locsrv=sql_freesrv(locsrv);
+            isok=false;
+            break;
+          }
+        }
+      break;
+    default     :       //SAFE Guard
+      rs=sql_droptupple(sqlptr,rs);
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+*srv=locsrv;
+return isok;
+
 #undef  OPEP
 }
 /*
@@ -520,3 +634,66 @@ return done;
 
 #undef  OPEP
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to retreive information about remote  */
+/*      server and get how reliable/trustable it is.    */
+/*                                                      */
+/********************************************************/
+PUBLIC _Bool sql_mngremote(SQLPTR *sqlptr,SQLENUM action,char *key,SRVTYP **srv)
+
+{
+#define OPEP    "gessql.c:sql_mnremote,"
+
+_Bool isok;
+char *gooddata;
+int phase;
+_Bool proceed;
+
+isok=false;
+gooddata=(char *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //checking SQL and user record
+      if (sqlptr==(SQLPTR *)0) {
+        (void) rou_alert(0,"%s SQL pointer is NULL (Bug?)",OPEP);
+        phase=999;
+        }
+      if (srv==(SRVTYP **)0) {
+        (void) rou_alert(0,"%s USER pointer is NULL (Bug?)",OPEP);
+        phase=999;
+        }
+      break;
+    case 1      :       //do we have a good key
+      if ((gooddata=sql_gooddata(sqlptr,key))==(char *)0) {
+        (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)",
+                            OPEP,EMLTBL,key);
+        phase=999;
+        }
+      break;
+    case 2      :       //getting user information
+      switch (action) {
+        case sql_select :
+          isok=select_remote(sqlptr,gooddata,srv);
+          break;
+        default :
+          (void) rou_alert(0,"%s action='%d' not yet implemented!",OPEP,action);
+        }
+      gooddata=rou_freestr(gooddata);
+      break;
+    default     :
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return isok;
+
+#undef  OPEP
+}
+
index 665d54a9947901896499dd8427a232560225bb61..7c85752c54bd77f26c80701705a14614c11faae5 100644 (file)
@@ -24,7 +24,9 @@ extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *key,USRTYP **usr);
 //procedure to manage information on email exchange session
 extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses);
 
-//Procedure to increment (or decrement) the remoteip
-//connection number
+//Procedure to increment (or decrement) the remoteip links number
 extern _Bool sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta);
+
+//procedure to extract the information about remotes server
+extern _Bool sql_mngremote(SQLPTR *sqlptr,SQLENUM action,char *key,SRVTYP **srv);
 #endif
index 52ec4facbd05df06fb4be0737bd5654fa02c4019..b3aba123990023c805e9a3a9ff2863360b4164f2 100644 (file)
@@ -146,14 +146,14 @@ return ses;
 /*      data record definition.                         */
 /*                                                      */
 /********************************************************/
-PUBLIC SMTTYP *sql_freesmtp(SMTTYP *smtpdata)
+PUBLIC SRVTYP *sql_freesrv(SRVTYP *smtpdata)
 
 {
-if (smtpdata!=(SMTTYP *)0) {
+if (smtpdata!=(SRVTYP *)0) {
   smtpdata->status=rou_freestr(smtpdata->status);
   smtpdata->rmtip=rou_freestr(smtpdata->rmtip);
   (void) free(smtpdata);
-  smtpdata=(SMTTYP *)0;
+  smtpdata=(SRVTYP *)0;
   }
 return smtpdata;
 }
index ae9932348e2ea0c47b7b7758b8a2566646737af8..8c30dcd95b083135ee5d5c8ad81db53b2a6c1365 100644 (file)
@@ -55,12 +55,13 @@ typedef struct  {
 
 //Structure about remotes SMTP server
 typedef struct  {
-        time_t lupdate; //last update time
         char *rmtip;    //Remote IP number
+        time_t lastscan;//last scan time
+        time_t lupdate; //last update time
         int links;      //Number of connection from this remote 
         int credit;     //Remote credit number
         char *status;   //Remote record current status
-        }SMTTYP;
+        }SRVTYP;
 
 //procedure to free space used by an USRTYP
 extern USRTYP *sql_freeusr(USRTYP *usr);
@@ -68,8 +69,8 @@ extern USRTYP *sql_freeusr(USRTYP *usr);
 //procedure to free memory used by a SESTYP
 extern SESTYP *sql_freeses(SESTYP *ses);
 
-//procedure to free memory used by a SMTTYP
-extern SMTTYP *sql_freesmtp(SMTTYP *smtpdata);
+//procedure to free memory used by a remote server data
+extern SRVTYP *sql_freesrv(SRVTYP *srvdata);
 
 //Procedure to check if string is properly coded according DB_LANG
 extern char *sql_checkencoding(char *strencoded);