]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Updating remote record with credit
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 26 Jul 2025 18:02:25 +0000 (14:02 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 26 Jul 2025 18:02:25 +0000 (14:02 -0400)
lib/devsql.c
lib/devsql.h
lib/gessql.c
lib/lvleml.c
lib/lvleml.h
lib/modrec.c

index 9fa6c81c72b23f53ada7132a3aa20bac75b787ce..f02c99f7f7f8040c304968e499edc4ba54e59c76 100644 (file)
@@ -368,7 +368,7 @@ return (SQLPTR *)sql;
 /*      format (data-base compatible).                  */
 /*                                                      */
 /********************************************************/
-PUBLIC const char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp)
+PUBLIC char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp)
 
 {
 #define OPEP    "devsql.c:sql_fromunixtime,"
@@ -393,7 +393,7 @@ if (sqlptr!=(SQLPTR *)0) {
       break;
     }
   }
-return unixdate;
+return strdup(unixdate);
 
 #undef  OPEP
 }
index 05ecb235b026b5d8154be0d72b75d14c6d76952f..1332fdad1e6c7c0784551e98e4081b8b1d4f1080 100644 (file)
@@ -31,7 +31,7 @@ extern SQLPTR *sql_opensql();
 extern SQLPTR *sql_closesql(SQLPTR *sqlptr);
 
 //converting a time to a database representation
-extern const char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp);
+extern char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp);
 
 //converting a database time representation to unix time
 extern time_t sql_tounixtime(SQLPTR *sqlptr,const char *date);
index 9b27df74298bf3d0f92f22776398aa15e6c1752e..cde27d0fc0d9d1b4968ad5982e1c0e6f8e1cbded 100644 (file)
@@ -431,17 +431,20 @@ static _Bool update_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP *srv)
 {
 #define OPEP    "gessql.c:update_remote,"
 
-static const char *upd= "UPDATE "RMTTBL
-                        " SET lastscan='%s',credit=%d,listing=%s,reverse=%s"
-                        " WHERE remoteip='%s'";
+static const char *upd= "UPDATE "RMTTBL"SET "
+                        "lastscan='%s',lastupdate='%s',"
+                        "credit=%d,listing=%s,reverse=%s "
+                        "WHERE remoteip='%s'";
 
 _Bool isok;
-const char *lastscan;
+char *lastscan;
+char *update;
 char *listing;
 char *reverse;
 
 isok=true;
 lastscan=sql_fromunixtime(sqlptr,srv->lastscan);
+update=sql_fromunixtime(sqlptr,srv->update);
 listing=sql_gooddata(sqlptr,srv->listing);
 reverse=sql_gooddata(sqlptr,srv->reverse);
 if (sql_request(sqlptr,upd,lastscan,srv->credit,listing,reverse,srv->rmtip)!=1) {
@@ -451,6 +454,8 @@ if (sql_request(sqlptr,upd,lastscan,srv->credit,listing,reverse,srv->rmtip)!=1)
   }
 reverse=rou_freestr(reverse);
 listing=rou_freestr(listing);
+update=rou_freestr(update);
+lastscan=rou_freestr(lastscan);
 return isok;
 
 #undef  OPEP
index b8af38172e100a5034e0d0d7f660efb31f9ecbb9..2b3a9675c91b6cb3fedd32f208c023d51ed3f247 100644 (file)
@@ -548,7 +548,7 @@ else
   decoded=cnv_getb64(received);
 if (decoded!=(char *)0) {
   if (checklogin(contact,rmtpass,decoded)==true) {
-    contact->credits+=2;
+    contact->credit+=2;
     contact->privilege=rel_authentic;
     }
   decoded=rou_freestr(decoded);
@@ -596,7 +596,7 @@ for (int i=0;i<2;i++) {
   }
 if (strlen(local)>0) {
   if (checklogin(contact,rmtpass,local)==true) {
-    contact->credits+=2;
+    contact->credit+=2;
     contact->privilege=rel_authentic;
     }
   }
@@ -734,7 +734,7 @@ while (proceed==true) {
         break;
         }
       if (strcmp(HA0,resp->response)==0) {
-        contact->credits+=3;    //very good authentication
+        contact->credit+=3;     //very good authentication
         contact->privilege=rel_authentic;
         }
       HA0=rou_freestr(HA0);
@@ -971,7 +971,7 @@ while (proceed==true) {
           break;
         case rel_plain          :
           cmt="No relay accepted";
-          contact->credits-=2;          //Trying to abuse server
+          contact->credit-=2;           //Trying to abuse server
           phase=999;    //not relayable
           break;
         default         :
@@ -2404,7 +2404,7 @@ while (proceed==true) {
       }
     (void) log_fprintlog(contact->logptr,true,"Contact terminated (credit='%d'); "
                                                "condition=<%s>",
-                                                contact->credits,str);
+                                                contact->credit,str);
     //(void) rou_alert(0,"%s exit status='%d'",OPEP,status);
     break;              //no need to go further
 
@@ -2426,7 +2426,7 @@ while (proceed==true) {
                                    CMDOK,contact->mainsesid);
       break;
     case c_quit         :       //QUIT SMTP protocol
-      contact->credits++;       //clean disconnect
+      contact->credit++;        //clean disconnect
       (void) transmit(contact,true,"%d 2.0.0 Bye, closing connection CNT=%s",
                                     QUITOK,contact->mainsesid);
       status=1;                 //every thing fine
@@ -2474,7 +2474,7 @@ while (proceed==true) {
         }
       break;
     case c_unknown      :       //unknown keyword
-      contact->credits-=2;      //Trying to confuse server?
+      contact->credit-=2;       //Trying to confuse server?
       (void) rou_alert(0,"SMTP Command <%s> from [%s] is unknown (config?)",
                          line,contact->peerip);
       (void) transmit(contact,true,"%d-5.5.1 Unrecognized command, see RFC 5321",
@@ -2484,7 +2484,7 @@ while (proceed==true) {
                                     CMDBAD,contact->mainsesid);
       break;
     default             : 
-      contact->credits-=10;     //Trying to bug server
+      contact->credit-=10;      //Trying to bug server
       (void) rou_alert(0,"%s Unable to find entry for code='%d' (Bug?)",OPEP,code);
       (void) transmit(contact,true,"%d-5.5.1 Unrecognized command, see RFC 5321",
                                     CMDBAD);
@@ -2537,7 +2537,7 @@ while (proceed==true) {
     case 1      :       //connecting to database
       contact=(CONTYP *)calloc(1,sizeof(CONTYP));
       contact->sqlptr=sql_opensql();
-      contact->credits=0;
+      contact->credit=0;
       if (contact->sqlptr==(SQLPTR *)0) {
         (void) rou_alert(0,"%s Unable to contact database",OPEP);
         (void) sleep(2);//delay to avoid avalanche
@@ -2591,7 +2591,7 @@ while (proceed==true) {
     case 6      :       //checking if remote IP is relayable
       if (afn_is_ip_relayable(contact->peerip,contact->relayok)==true) {
         contact->privilege=rel_isrelay;     //IP is relayable
-        contact->credits++;
+        contact->credit++;
         }
       break;
     case 7      :       //contact is good, then sending a signon
@@ -2632,9 +2632,11 @@ PUBLIC CONTYP *eml_dropcontact(CONTYP *contact)
 {
 #define OPEP    "lvleml.c:eml_dropcontact"
 
+SRVTYP *srv;
 int phase;
 _Bool proceed;
 
+srv=(SRVTYP *)0;
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -2646,12 +2648,28 @@ while (proceed==true) {
         phase=999;      //not going further
         }
       break;
-    case 1      :       //properly closing remote contact
+    case 1      :       //getting the remote server information
+      if (sql_mngremote(contact->sqlptr,sql_select,contact->peerip,&srv)==false) {
+        (void) rou_alert(0,"%s Unable to get remote [%s] data (Bug!?)",
+                            OPEP,contact->peerip);
+        phase++;        //No need to do update
+        }
+      break;
+    case 2      :       //Updating remote server data
+      srv->credit+=contact->credit;
+      srv->update=time((time_t *)0);
+      if (sql_mngremote(contact->sqlptr,sql_update,contact->peerip,&srv)==false) {
+        (void) rou_alert(0,"%s Unable to UPDATE remote [%s] data (Bug!?)",
+                            OPEP,contact->peerip);
+        }
+      srv=sql_freesrv(srv);
+      break;
+    case 3      :       //properly closing remote contact
       (void) rou_alert(0,"Contact from peer <%s> to port <%s> terminated",
                           contact->peerip,contact->locserv);
       contact->socptr=soc_release(contact->socptr);
       break;
-    case 2      :       //freeing contact memory
+    case 4      :       //freeing contact memory
       contact=freecontact(contact);              
       break;
     default     :       //SAFE guard
index 21d0b01d15833b4c7f9ed97a6bca0cc218a83812..505eaf1f32a10f9f9780585401e60d3f539657ae 100644 (file)
@@ -20,7 +20,7 @@ typedef struct  {
         SQLPTR *sqlptr;         //established contact database access
         int delay;              //communication max delay
         char *fqdn;             //fully qualified domain from peer
-        int credits;            //Credits to be added or removed from contact
+        int credit            //Credits to be added or removed from contact
         RELTYP privilege;       //onnection privilege
         char *authname;         //Link is authenticated name
         AFNTYP **localafns;     //local IP as an AFNUM
index f8001b7b38a784c43dd2acb4c2ff24441546c4a3..8955f3f0df68e03d51cc9b03c566d2b59fab578f 100644 (file)
@@ -185,7 +185,7 @@ while (proceed==true) {
       break;
     case 2      :       //check if remote link is acceptable
       if (sql_newconnect(contact->sqlptr,contact->peerip,1)==false) {
-        contact->credits-=1;
+        contact->credit-=1;
         phase=999;      //connection rejected
         }
       break;
@@ -213,7 +213,7 @@ while (proceed==true) {
     default     :       //SAFE guard
       if (contact!=(CONTYP *)0) {
         (void) log_fprintlog(contact->logptr,true,"    (%s, credit='%d')",
-                                             "Contact terminated",contact->credits);
+                                             "Contact terminated",contact->credit);
         (void) sql_newconnect(contact->sqlptr,contact->peerip,-1);
         contact=eml_dropcontact(contact);
         }