]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Defining the session ID
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 12 Aug 2024 18:51:11 +0000 (14:51 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 12 Aug 2024 18:51:11 +0000 (14:51 -0400)
lib/gestcp.c
lib/gestcp.h
lib/lvleml.c
lib/subrou.c
lib/subrou.h
lib/unieml.c
lib/unieml.h

index 65d692b78d0a43fcd4a45ea284c5a5cdd486f59c..5e171e34e53443f1931788262b5811db3ad53703 100644 (file)
@@ -35,6 +35,7 @@ static CONTYP *freecontact(CONTYP *contact)
 #define OPEP    "gesttcp.c:freecontact"
 
 if (contact!=(CONTYP *)0) {
+  contact->sessid=rou_freestr(contact->sessid);
   contact->fqdn=rou_freestr(contact->fqdn);
   contact->peerip=rou_freestr(contact->peerip);
   contact->locname=rou_freestr(contact->locname);
@@ -201,13 +202,14 @@ while (proceed==true) {
       contact->locname=soc_getaddrinfo(contact->socptr,true,true);
       contact->locserv=soc_getaddrinfo(contact->socptr,true,false);
       contact->peerip=soc_getaddrinfo(contact->socptr,false,true);
+      contact->sessid=eml_getsessionid();
       if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
         (void) rou_alert(0,"%s Unable to establish contact entities",OPEP);
         contact=freecontact(contact);
         phase=999;      //no identity
         }
       break;
-    case 3      :       //contact is good sending signon
+    case 3      :       //contact is good, then sending a signon
       if (tcp_signon(contact)<=0) {
         contact=freecontact(contact);
         phase=999;      //no contact 
index 8655c5957a44a2a13250d35a1b7d37aa14a8ffde..b8201651f5dec1c81bcbf20645947b27cf74fd75 100644 (file)
@@ -19,6 +19,8 @@ typedef struct  {
         char *locname;  //socket local hostname
         char *locserv;  //local service port
         char *peerip;   //socket remote peer IP
+        char *sessid;   //current session ID
+        int numreset;   //number of SMTP reset received
         }CONTYP;
 
 //read a line from contact up to CRLF
index d56911fee9e7048a75395ac4d768a003c6e4211d..e00e819f196985f4a526650d5228a63c92c73151 100644 (file)
@@ -195,7 +195,8 @@ while (proceed==true) {
       proceed=doehlo(contact,line,parameter);
       break;
     case c_quit         :       //QUIT SMTP protocol
-      (void) transmit(contact,"%d 2.0.0 Bye, closing connection",QUITOK);
+      (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",
+                              QUITOK,contact->sessid);
       proceed=false;
       break;
     case c_starttls     :       //EHLO start encryptel link
index 36f1e24d28f2c9bc00cefccada3cbec8090454f2..d69da9437ab2e61133b8b511e24e5042cdea3422 100644 (file)
@@ -4,6 +4,7 @@
 /*     Module for low level subroutine                 */
 /*                                                     */
 /********************************************************/
+#include        <sys/time.h>
 #include        <dirent.h>
 #include        <errno.h>
 #include        <math.h>
@@ -19,8 +20,8 @@
 
 
 //version definition 
-#define VERSION "0.4"
-#define RELEASE "2"
+#define VERSION "0.4.1"
+#define RELEASE "1"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level
@@ -81,7 +82,7 @@ PUBLIC void rou_checkleak(_Bool onoff)
 
 static  _Bool current=false;
 
-if (current!=onoff) {
+if ((debug>2)&&(current!=onoff)) {
   int status;
   char cmd[200];
 
@@ -105,6 +106,33 @@ if (current!=onoff) {
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to return the current time            */
+/*     expressed with a millisecond precision starting */
+/*     from the firt time it was called.               */
+/*                                                      */
+/********************************************************/
+PUBLIC unsigned int rou_getmillisec()
+
+{
+struct timeval newtime;
+(void) gettimeofday(&newtime,(struct timezone *)0);
+return (unsigned int)((newtime.tv_usec/1000));
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to transform the local system time in */
+/*     ASCII time stamp.                               */
+/*     Stored in STATIC memory area.                   */
+/*                                                      */
+/********************************************************/
+/*
+\f
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to transform the local system time in */
 /*     ASCII time stamp.                               */
 /*     Stored in STATIC memory area.                   */
index 438fe57349e2a0116c9dfe3aa9859903d6ba71d5..2b2bce30f26208f43d628e0fa93fb99d2f18b445 100644 (file)
@@ -31,6 +31,9 @@ extern char          *appname;  //application "official" name
 //open/close memory leak detector.
 extern void rou_checkleak(_Bool onoff);
 
+//procedure to return the current number of milli-second
+extern unsigned int rou_getmillisec();
+
 //transform local system time in ASCII stamp.
 extern char *rou_ascsysstamp(time_t curtime);
 
index 9aebca394d6e54fcb9e5388df8912f924f339d24..4f9e4379b2660279735bf45d7d6904d8b841027a 100644 (file)
@@ -8,6 +8,7 @@
 #include        <stdbool.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <unistd.h>
 
 #include       "subrou.h"
 #include       "unieml.h"
@@ -32,6 +33,32 @@ static VOCTYP vocsmtp[]={
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to format and return a dynamicaly     */
+/*      allocated char array filled with uniq session ID*/
+/*                                                      */
+/********************************************************/
+PUBLIC char *eml_getsessionid()
+
+{
+#define UFTIME  "%Y%m%d%H%M%S"
+#define UNIQUE  "%05d-%s-%04d"
+
+time_t curtime;
+char asctemps[100];
+char buffer[300];
+
+curtime=time((time_t)0);
+(void) strftime(asctemps,sizeof(asctemps),UFTIME,localtime(&curtime));
+(void) snprintf(buffer,sizeof(buffer),UNIQUE,getpid(),asctemps,rou_getmillisec());
+return strdup(buffer);
+#undef  UNIQUE
+#undef  UFTIME
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to return a protocol keywork code     */
 /*                                                      */
 /********************************************************/
index c37cbcc70d9af4808e8ba317f64489485f19d572..924ae8fdf5c71ba0ae515dfb9dee21526cc08409 100644 (file)
@@ -25,7 +25,10 @@ typedef enum    {               //list of SMTP protocol keyword
                 c_unknown       //key word unknown
                 }CODTYP;
 
-//conver keyword to CODTYP
+//get a session unique id
+extern char *eml_getsessionid();
+
+//convert SMTP keyword to CODTYP
 extern CODTYP eml_getcode(char *keyword);
 
 //homework to be done before starting/stopping module.