]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to implement lock table function
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 10 Jul 2025 17:24:49 +0000 (13:24 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 10 Jul 2025 17:24:49 +0000 (13:24 -0400)
lib/Makefile
lib/devsql.c
lib/devsql.h
lib/gessql.c [new file with mode: 0644]
lib/gessql.h [new file with mode: 0644]
lib/gestcp.c
lib/gestcp.h
lib/modrec.c
lib/unisql.c
lib/unisql.h
sql/mailleur.sql

index 45a07b2dda22ef7346eab6c272299ced093b3fb2..185a0f40612a59276e021a935c8640b601a35bfb 100644 (file)
@@ -21,7 +21,7 @@ clean :
 OBJS=                                          \
          modrec.o                              \
          lvleml.o                              \
-         gesspf.o gestcp.o geseml.o            \
+         geseml.o gestcp.o gesspf.o gessql.o   \
          devlog.o devsoc.o devsql.o            \
          unidig.o unidns.o unieml.o unipar.o   \
          uniprc.o unisig.o unisql.o unitls.o   \
@@ -46,6 +46,7 @@ modrec.o:                                     \
 lvleml.o:                                      \
           subcnv.h subrou.h                    \
           unidig.h unidns.h unieml.h           \
+          gestcp.h gessql.h                    \
           lvleml.h lvleml.c
 
 gesspf.o:                                      \
@@ -65,6 +66,10 @@ gestcp.o:                                    \
           unisig.h                             \
           gestcp.h gestcp.c
 
+gessql.o:                                      \
+          devsql.h                             \
+          gessql.h gessql.c
+
 devlog.o:                                      \
           subrou.h                             \
           uniprc.h                             \
index 47d543e45f27fe3c4b4db951f0f44dec35ae2123..6f9ad80ea30618c42ab4f66e9212fa89162d2ddb 100644 (file)
@@ -884,3 +884,16 @@ return isok;
 #undef  DELACT
 #undef  OPEP
 }
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to lock access to a table.            */
+/*                                                      */
+/********************************************************/
+PUBLIC _Bool sql_locktable(SQLPTR *sqlptr,char *tblname,_Bool action)
+
+{
+return action;
+}
index a9b68fa667391c8a3b8ff085837054b6f540345b..212ba3d2e3a55ea662cb87e87f1aeb41bdc5a203 100644 (file)
@@ -32,4 +32,7 @@ extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses);
 //procedure to manage action stats on email exhange status
 extern _Bool sql_mngact(SQLPTR *sqlptr,SQLENUM action,ACTTYP *act);
 
+//procedure to locak access to a full table
+extern _Bool sql_locktable(SQLPTR *sqlptr,char *tblname,_Bool action);
+
 #endif
diff --git a/lib/gessql.c b/lib/gessql.c
new file mode 100644 (file)
index 0000000..b2fba5a
--- /dev/null
@@ -0,0 +1,66 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Module to manage complexe SQL request           */
+/*                                                     */
+/********************************************************/
+
+#include        "subrou.h"
+#include        "gessql.h"
+
+#define REMOTES "remotes"       //Table about remotes site
+
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*      Procedure to increase (of decrease the remote   */
+/*      IP connection number.                           */
+/*                                                      */
+/********************************************************/
+PUBLIC int sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta)
+
+{
+#define OPEP    "gessql.c:sql_newconnect,"
+
+int links;
+_Bool locked;
+SMTTYP *smtpdata;
+int phase;
+_Bool proceed;
+
+links=0;
+locked=false;
+smtpdata=(SMTTYP *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //Locking table
+      if ((locked=sql_locktable(sqlptr,REMOTES,true))==false) {
+        (void) rou_alert(0,"%s Unable to lock %s table (Bug?)",
+                            OPEP,REMOTES);
+        phase=999;      //Trouble trouble
+        }
+      break; 
+    case 1      :       //loading record
+      break; 
+    case 2      :       //creating record if not exiting
+      break; 
+    case 3      :       //updating record
+      smtpdata->links+=delta;
+      links=smtpdata->links;
+      smtpdata=sql_freesmtp(smtpdata);
+      break; 
+    default     :       //SAFE Guard
+      if (locked==true)
+        (void) sql_locktable(sqlptr,REMOTES,false);
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return links;
+#undef  OPEP
+}
diff --git a/lib/gessql.h b/lib/gessql.h
new file mode 100644 (file)
index 0000000..7d0ab05
--- /dev/null
@@ -0,0 +1,17 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/************************************************/
+/*                                             */
+/*     gestion level fto manage sql request    */
+/*                                             */
+/************************************************/
+#ifndef        GESSQL
+#define GESSQL
+
+#include        <stdbool.h>
+
+#include        "devsql.h"
+
+//Procedure to increment (or decrement) the remoteip
+//connection number
+extern int sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta);
+#endif
index 30095fc48cf9b3c039c5f35ae6d80219b0c20262..2252aaae96cbe3068c0a40a587c3246aac0e3ebd 100644 (file)
@@ -1,7 +1,7 @@
 // vim: smarttab tabstop=8 shiftwidth=2 expandtab
 /********************************************************/
 /*                                                     */
-/*     Module to handle TCP communication              */
+/*     Module to manage TCP communication              */
 /*                                                     */
 /********************************************************/
 #include        <sys/wait.h>
index 43e5d99ffe2fbb7d50252aa91303c07d13893b19..af3b656d85befc10959af6494d97266549155c39 100644 (file)
@@ -1,7 +1,8 @@
 // vim: smarttab tabstop=8 shiftwidth=2 expandtab
 /************************************************/
 /*                                             */
-/*     Unit level to handle TCP communication  */
+/*     gestion level to handle TCP             */
+/*      communication                           */
 /*                                             */
 /************************************************/
 #ifndef        GESTCP
index e9da5992a8d2fb54f9b7d01882e42e3b7e9e66eb..adfddeb9a31afb43364784b3860e77e57a9c9ae3 100644 (file)
@@ -17,6 +17,7 @@
 #include        "unieml.h"
 #include        "unisig.h"
 #include        "devsoc.h"
+#include        "gessql.h"
 #include        "gestcp.h"
 #include        "lvleml.h"
 #include        "modrec.h"
@@ -174,13 +175,16 @@ while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //waiting contact
-      (void) rou_checkleak(true);
       if ((contact=eml_getcontact(socptr,pos))==(CONTYP *)0)
         phase=999;      //No contact!
       break;
     case 1      :       //within forked process
       (void) prc_settitle("%s, incoming contact from [%s] on [%s:%s]",
-                           appname,contact->peerip,contact->locname,contact->locserv);
+                           appname,contact->peerip,
+                           contact->locname,contact->locserv);
+      if (sql_newconnect(contact->sqlptr,contact->peerip,1)>1) {
+        phase=999;      //need to explain no contact;
+        }
       break;
     case 2      :       //do contact
       intstat=eml_docontact(contact);
@@ -206,10 +210,10 @@ while (proceed==true) {
         } 
       break;
     case 4      :       //connection terminated
-      contact=eml_dropcontact(contact);
-      (void) rou_checkleak(false);
       break;
     default     :       //SAFE guard
+      if (contact!=(CONTYP *)0)
+        contact=eml_dropcontact(contact);
       proceed=false;
       break;
     }
index 975aba6f8b422801997b6957d45908fad210fed0..52ec4facbd05df06fb4be0737bd5654fa02c4019 100644 (file)
@@ -119,7 +119,7 @@ return usr;
 */
 /********************************************************/
 /*                                                      */
-/*      Procedure to free memory used by a usesion      */
+/*      Procedure to free memory used by a session      */
 /*      definition.                                     */
 /*                                                      */
 /********************************************************/
@@ -140,6 +140,26 @@ return ses;
 /*
 \f
 */
+/********************************************************/
+/*                                                      */
+/*      Procedure to free memory used by a remote SMTP  */
+/*      data record definition.                         */
+/*                                                      */
+/********************************************************/
+PUBLIC SMTTYP *sql_freesmtp(SMTTYP *smtpdata)
+
+{
+if (smtpdata!=(SMTTYP *)0) {
+  smtpdata->status=rou_freestr(smtpdata->status);
+  smtpdata->rmtip=rou_freestr(smtpdata->rmtip);
+  (void) free(smtpdata);
+  smtpdata=(SMTTYP *)0;
+  }
+return smtpdata;
+}
+/*
+\f
+*/
 /************************************************/
 /*                                             */
 /*     Routine to check if string is properly  */
index 7903c54dc76229ed5b2a16e0d50cf46256420033..dde32c438e741064c6a1d97cce5d70ef6b9bbdc4 100644 (file)
@@ -39,7 +39,7 @@ typedef struct  {
         u_long taille;  //Email size
         }SESTYP;
 
-//Tructure about email action status (managing email)
+//Structure about email action status (managing email)
 typedef struct  {
         char *sessid;   //session id
         char code;      //Email status code
@@ -47,12 +47,24 @@ typedef struct  {
         char **resp;    //Multiline status
         }ACTTYP;
 
+//Structure about remotes SMTP server
+typedef struct  {
+        time_t lupdate; //last update time
+        char *rmtip;    //Remote IP number
+        int links;      //Number of connection from this remote 
+        int credit;     //Remote credit number
+        char *status;   //Remote record current status
+        }SMTTYP;
+
 //procedure to free space used by an USRTYP
 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 check if string is properly coded according DB_LANG
 extern char *sql_checkencoding(char *strencoded);
 
index b44c5d024e0e2c093db8b1f495d84e7558cd0644..c5956c745f0e8d5c5135ebdc8cad1ed6516a9009 100644 (file)
@@ -100,8 +100,8 @@ CREATE TABLE remotes        (
        lastupdate      DBTIMESTAMP     //record creation
                        DFLT NOW(),
        remoteip        TEXTUNIQUE,     //remote IP number
-       connections     INTEGER
-                       DFLT 1,         //how many time the remote connected
+       links           INTEGER
+                       DFLT 0,         //how many time the remote connected
        credit          INTEGER //Remote IP current credit (-100..+100)
                        DFLT -100,
        status          TEXT            //'toscan','inscan','valide'