]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Double feed detection seesm to be working
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 11 Aug 2025 15:44:46 +0000 (11:44 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 11 Aug 2025 15:44:46 +0000 (11:44 -0400)
data-feed/feed20.tst
data-feed/feed21.tst
lib/gessql.c
lib/lvleml.c

index 4f98f240d5476bf4bf695033266790fd1ad8732f..30e31b68e20bf5a02f86ca2f14ef6fba568a2c00 100644 (file)
@@ -5,6 +5,8 @@ R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
 #====================================================
 S:HELO example.com
 R:250 mailleur.example.com, link (cleartext) ready,...
+C:ORGN: 185.242.226.23
+R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
 C:WAIT 120     $wait "forever"
 S:QUIT
 R:221 2.0.0 Bye, closing connection...
index da5c4cfbedc57a1922e2ac1297993fb12249cc34..080eb8f201016fe71cd90a6c11184d509fef99e1 100644 (file)
@@ -5,10 +5,9 @@ R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
 #====================================================
 S:HELO example.com
 R:250 mailleur.example.com, link (cleartext) ready,...
-S:MAIL FROM: <trouble@mailref1.example.com>
-R:250 2.1.3 trouble@mailref1.example.com sender ok
-S:RCPT TO: <user1@mailref1.example.com>
-R:250 2.6.4 Address accepted <user1@mailref1.example.com>
+C:ORGN: 185.242.226.23
+R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
+C:WAIT 5       #wait 5 sec
 S:QUIT
 R:221 2.0.0 Bye, closing connection...
 #-------------------------------------------------------------------------
index abc9bf52ff6afca1e1a8e7c16401972c25924228..8c5429910fe63fba8059401ceaeddb0c3f305a46 100644 (file)
@@ -679,10 +679,12 @@ PUBLIC int sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta)
 {
 #define OPEP    "gessql.c:sql_newconnect,"
 
+static const char *sel="SELECT * FROM %s WHERE remoteip='%s' FOR UPDATE";
 static const char *upd="UPDATE %s SET links=links+%d,lastupdate=now() WHERE remoteip='%s'";
 static const char *ins="INSERT INTO %s (remoteip) values('%s')";
 
 int connect;
+SQLRES *sqlres;
 SRVTYP *srv;
 int phase;
 _Bool proceed;
@@ -701,24 +703,38 @@ while (proceed==true) {
         }
       break;
     case 1      :       //updating remotes record with links
-      if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==1) 
-        phase++;        //Record is existing
+      if ((sqlres=sql_gettupple(sqlptr,sel,RMTTBL,rmtip))==(SQLRES *)0) {
+        (void) rou_alert(0,"%s Unable to get tupple for remote ip <%s> "
+                           "in table <%s> (DB trouble?)",
+                            OPEP,rmtip,RMTTBL);
+        phase=999;      //no tupple information?
+        }
       break; 
-    case 2      :       //Let create a record
+    case 2      :       //is record already existing
+      if (sql_getnbrtupple(sqlptr,sqlres)==1) {
+        phase++;        //No need to create it
+        }
+      sqlres=sql_droptupple(sqlptr,sqlres);
+      break;
+    case 3      :       //Let create a new unique record
       if (sql_request(sqlptr,ins,RMTTBL,rmtip)!=1) {
         (void) rou_alert(0,"%s Unable to create entry "
                            "for remote ip <%s> in table <%s> (DB trouble?)",
                             OPEP,rmtip,RMTTBL);
+        (void) sql_unlock(sqlptr,true);
+        phase=999;
         }
-      else {
-        if (sql_request(sqlptr,ins,RMTTBL,rmtip)!=1) {
-          (void) rou_alert(0,"%s Unable to create entry "
-                             "for remote ip <%s> in table <%s> (DB trouble?)",
-                              OPEP,rmtip,RMTTBL);
-          }
+      else
+        phase++;        //record open
+      break; 
+    case 4      :       //lets update link
+      if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)!=1) {
+        (void) rou_alert(0,"%s Unable to update entry "
+                           "for remote ip <%s> in table <%s> (DB trouble?)",
+                            OPEP,rmtip,RMTTBL);
         }
       break; 
-    case 3      :       //lets find the the number of connection
+    case 5      :       //lets find the the number of connection
       if (sql_mngremote(sqlptr,sql_select,rmtip,&srv)==false) {
         (void) rou_alert(0,"%s Unable to get record "
                            "for remote ip <%s> in table <%s> (DB trouble?)",
@@ -729,7 +745,7 @@ while (proceed==true) {
         srv=sql_freesrv(srv);
         }
       break; 
-    case 4      :       //unlock database
+    case 6      :       //unlock database
       (void) sql_unlock(sqlptr,true);
       break; 
     default     :       //SAFE Guard
index 234272d2c4eedd3e49c3e5daf2f1ece363c1ec45..8ebab75b22c542bccca1854c740fad471f54d912 100644 (file)
@@ -1495,7 +1495,7 @@ while (proceed==true) {
       switch (contact->privilege) {
         case rel_authentic  :
           break;
-        case rel_isrelay    :   //ne to force rel_plain
+        case rel_isrelay    :   //need to force rel_plain
           contact->privilege=rel_plain;
           //NO BREAK;
         case rel_plain      :
@@ -1511,9 +1511,18 @@ while (proceed==true) {
       break;
     case 4      :       //let update links
       if (sql_newconnect(contact->sqlptr,rmtip,1)!=1) {
+        static char *end;
+
+        end="You have another connection still in progress";
         (void) rou_alert(0,"%s <%s> Too many '%d' links! (Testing?)",
                             OPEP,rmtip,sql_newconnect(contact->sqlptr,rmtip,0));
-        phase=999;
+        (void) eml_transmit(contact,true,"%d contact denied <%s>",NOTNOW,end);
+        contact->termend=rou_freestr(contact->termend);
+        contact->termend=strdup(end);
+        contact->credit=-1;     //small penalty
+        (void) sleep(1);        //To avoid avalanche
+        (void) sql_newconnect(contact->sqlptr,rmtip,-1);
+        phase++;        //connection rejected
         }
       break;
     case 5      :       //everything is now fine