]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Logging message seems to work fine tag-0.4.2
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 14 Aug 2024 00:44:07 +0000 (20:44 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 14 Aug 2024 00:44:07 +0000 (20:44 -0400)
lib/devlog.c
lib/devlog.h
lib/devsoc.c
lib/gestcp.c
lib/gestcp.h
lib/lvleml.c
lib/subrou.c

index c4bfe005e465283443e45f2e0866fba8d1b681cf..055a0f82e0e7bf200240df196f72f6102805ee6e 100644 (file)
@@ -14,7 +14,8 @@
 #include        "uniprc.h"
 #include        "devlog.h"
 
-#define JRLDIR  "/var/spool/clement/logs/"
+#define IJRLDIR  "/var/spool/clement/in-logs/"
+#define OJRLDIR  "/var/spool/clement/out-logs/"
 
 
 typedef struct  {
@@ -52,16 +53,20 @@ return log;
 /*      return a NULL file pointeur if trouble.         */
 /*                                                      */
 /********************************************************/
-PUBLIC LOGPTR *log_openlog(char *logname)
+PUBLIC LOGPTR *log_openlog(char *logname,_Bool inlog)
 
 {
 #define OPEP    "devlog.c:log_openlog"
 
 LOGTYP *log;
+const char *logdir;
 int phase;
 int proceed;
 
 log=(LOGTYP *)0;
+logdir=OJRLDIR;
+if (inlog==true)
+  logdir=IJRLDIR;
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -74,7 +79,7 @@ while (proceed==true) {
       break;
     case 1      :       //generating log file name
       log=(LOGTYP *)calloc(1,sizeof(LOGTYP));
-      log->filename=rou_apppath(JRLDIR);
+      log->filename=rou_apppath(logdir);
       log->filename=(char *)realloc(log->filename,
                                      strlen(log->filename)+strlen(logname)+10);
       (void) strcat(log->filename,logname);
@@ -152,7 +157,7 @@ return logptr;
 /*      log file.                                       */
 /*                                                      */
 /********************************************************/
-PUBLIC int log_fprintlog(LOGPTR *logptr,const char *format,...)
+PUBLIC int log_fprintlog(LOGPTR *logptr,_Bool suite,const char *format,...)
 
 {
 #define OPEP    "devlog.c:log_fprintlog"
@@ -185,11 +190,14 @@ while (proceed==true) {
         (void) snprintf(chrono,sizeof(chrono),"00:00:00.000");
         }
       else {
-        unsigned int delta;
+        (void) snprintf(chrono,sizeof(chrono),"%12s"," ");
+        if (suite==false) {
+          unsigned int delta;
 
-        delta=rou_getdifftime(&(log->start));
-        (void) snprintf(chrono,sizeof(chrono),"     +%02d.%03d",
-                                             delta/1000,delta%1000);
+          delta=rou_getdifftime(&(log->start));
+          (void) snprintf(chrono,sizeof(chrono),"%6s%02d.%03d","+",
+                                               delta/1000,delta%1000);
+          }
         }
       break;
     case 2      :       //formating the line
index b0c4b6b802f3c99ee0be80b99043620394fd44ae..b3d26503b48f5931614cdf9150e3079b36de82af 100644 (file)
 typedef void    LOGPTR;
 
 //procedure to open a session log
-extern LOGPTR *log_openlog(char *logname);
+extern LOGPTR *log_openlog(char *logname,_Bool inlong);
 
 //procedure to close a previously open session log
 extern LOGPTR *log_closelog(LOGPTR *logptr);
 
 //procedure to write a sequence within the current log
-extern int log_fprintlog(LOGPTR *logptr,const char *format,...);
+extern int log_fprintlog(LOGPTR *logptr,_Bool suite,const char *format,...);
 
 //procedure to merge session log contents to 
 //current daily log
index 3ee09faa0916403426faceb150b107acb0921b4d..43abc823f7edc28c9bd7af1f4cef905abf5eeedc 100644 (file)
@@ -966,11 +966,8 @@ if (soc!=(SOCTYP *)0) {
       break;
     case  0     :               //NO trouble to read socket data
       status=getnameinfo(&connip,taille,host,sizeof(host),serv,sizeof(serv),mode);
-      (void) printf("JMPDBG getname status='%d', local='%d' getname='%d'\n",
-                     status,local,getname);
       switch (status) {
         case 0                  :       //everything fine
-          (void) printf("JMPDBG host=<%s>\n",host);
           break;
         case EAI_AGAIN          :
         case EAI_NONAME         :
index 618939636a5be0fa218e441624ec7888ad928a3c..f408ba02dd4023cc6d322cfde73d07c3f94bdb90 100644 (file)
@@ -35,7 +35,7 @@ static CONTYP *freecontact(CONTYP *contact)
 #define OPEP    "gestcp.c:freecontact"
 
 if (contact!=(CONTYP *)0) {
-  contact->log=log_closelog(contact->log);
+  contact->logptr=log_closelog(contact->logptr);
   contact->cursesid=rou_freestr(contact->cursesid);
   contact->mainsesid=rou_freestr(contact->mainsesid);
   contact->fqdn=rou_freestr(contact->fqdn);
@@ -134,39 +134,6 @@ return sent;
 */
 /********************************************************/
 /*                                                      */
-/*     Procedure to send a signon on the current       */
-/*      channel (either plain of crypted).              */
-/*      Return the number of char transmitted.          */
-/*                                                      */
-/********************************************************/
-PUBLIC int tcp_signon(CONTYP *contact)
-
-{
-#define OPEP    "gestcp.c:tcp_signon"
-#define FMT     "%d %s ESMTP %s-%s; %s%s"
-
-int sent;
-
-sent=0;
-if (contact!=(CONTYP *)0) {
-  char signon[100];
-
-  (void) snprintf(signon,sizeof(signon),FMT,
-                                        SIGNON,contact->locname,
-                                        appname,rou_getversion(),
-                                        rou_ascsysstamp(time((time_t *)0)),CRLF);
-  if ((sent=tcp_write(contact,signon,strlen(signon)))<0) 
-    (void) rou_alert(0,"%s Unable to send signon to remote",OPEP);
-  }
-#undef  FMT
-#undef  OPEP
-return sent;
-}
-/*
-^L
-*/
-/********************************************************/
-/*                                                      */
 /*     Procedure to wait for a remote client.          */
 /*      return all reference to the established contact.*/
 /*                                                      */
@@ -208,7 +175,7 @@ while (proceed==true) {
       contact->locserv=soc_getaddrinfo(contact->socptr,true,false);
       contact->peername=soc_getaddrinfo(contact->socptr,false,true);
       contact->peerip=soc_getaddrinfo(contact->socptr,false,false);
-      contact->log=log_openlog(contact->mainsesid);
+      contact->logptr=log_openlog(contact->mainsesid,true);
       break;
     case 3      :       //check contact validity
       if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
@@ -218,12 +185,8 @@ while (proceed==true) {
         }
       break;
     case 4      :       //contact is good, then sending a signon
-      (void) log_fprintlog(contact->log,"SID: %s -> Contact open",
-                                         contact->mainsesid);
-      if (tcp_signon(contact)<=0) {
-        contact=freecontact(contact);
-        phase=999;      //no contact 
-        }
+      (void) log_fprintlog(contact->logptr,false,"SID: %s -> Contact open",
+                                                      contact->mainsesid);
       break;
     default     :       //SAFE guard
       proceed=false;
index 758fc81da24e1560362b5578abb4fe73dc559f1b..3abb019cc370831a9795869e939e62a4c6c13d1c 100644 (file)
@@ -24,7 +24,7 @@ typedef struct  {
         int numreset;   //number of SMTP reset received
         char *mainsesid;//session main ID
         char *cursesid; //current session ID
-        LOGPTR *log;    //reference to session log
+        LOGPTR *logptr; //reference to session log
         }CONTYP;
 
 //read a line from contact up to CRLF
@@ -33,9 +33,6 @@ extern int tcp_getline(CONTYP *contact,TIMESPEC *attend,char **lineptr);
 //Transmit formated data to the contact channel
 extern int tcp_write(CONTYP *contact,char *buffer,int tosend);
 
-//send signon on channel
-extern int tcp_signon(CONTYP *contact);
-
 //wait for an incoming contact
 extern CONTYP *tcp_getcontact(SOCPTR *socptr,int pos);
 
index 7e892e03c4eedde7c01225c2229ba0ec63c2d985..3504738b2b7a7815d64bc2f548af76c721b21cad 100644 (file)
@@ -34,12 +34,44 @@ char *line;
 va_start(args,fmt);
 line=(char *)0;
 if (rou_vasprintf(&line,fmt,args)>0) {
+  (void) log_fprintlog(contact->logptr,true,"%s",line);
   (void) tcp_write(contact,line,strlen(line));
   (void) tcp_write(contact,CRLF,strlen(CRLF));
   }
 va_end(args);
 }
 /*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to send the signon once the contact   */
+/*      with peer is detected.                          */
+/*                                                      */
+/********************************************************/
+static void signon(CONTYP *contact)
+
+{
+#define FMT     "%d %s ESMTP %s%s-%s; %s"
+
+if (contact!=(CONTYP *)0) {
+  char strcrypt[20];
+  char signon[100];
+
+  (void) strcpy(strcrypt,"");
+  if (contact->tlsok==true)
+    (void) strcpy(strcrypt,"(crypted) ");
+  (void) snprintf(signon,sizeof(signon),FMT,
+                                        SIGNON,contact->locname,
+                                        strcrypt,
+                                        appname,
+                                        rou_getversion(),
+                                        rou_ascsysstamp(time((time_t *)0)));
+  (void) transmit(contact,"%s",signon);
+  }
+#undef  FMT
+}
+/*
 \f
 */
 /************************************************/
@@ -72,8 +104,9 @@ while (proceed==true) {
     case 1      :       //thereis an FQDN
       contact->fqdn=rou_freestr(contact->fqdn);
       contact->fqdn=strdup(parameter);
-      (void) transmit(contact,"%d-%s ready, your IP=[%s]",
-                              CMDOK,contact->locname,contact->peerip);
+      (void) transmit(contact,"%d-%s ready, your IP/FQDN=[%s/%s]",
+                              CMDOK,contact->locname,
+                              contact->peerip,contact->peername);
       done=true;
       break;
     default     :       //SAFE guard
@@ -130,7 +163,7 @@ while (proceed==true) {
     case 1      :       //thereis an FQDN
       contact->fqdn=rou_freestr(contact->fqdn);
       contact->fqdn=strdup(parameter);
-      (void) transmit(contact,"%d-%s ready, your IP=[%s/%s]",
+      (void) transmit(contact,"%d-%s ready, your IP/FQDN=[%s/%s]",
                               CMDOK,contact->locname,
                               contact->peerip,contact->peername);
       (void) transmit(contact,"%d-SIZE %ld",CMDOK,MXMSIZE);
@@ -189,6 +222,7 @@ _Bool proceed;
 
 status=1;
 proceed=true;
+(void) signon(contact);
 while (proceed==true) {
   char *line;
   char *parameter;
@@ -199,6 +233,7 @@ while (proceed==true) {
   status=tcp_getline(contact,&attend,&line);
   if (status<=0)        //timeout or trouble?
     break;              //no need to go further
+  (void) log_fprintlog(contact->logptr,false,"%s",line);
   if (line!=(char *)0) {
     parameter=strchr(line,' ');
     if (parameter==(char *)0)
@@ -229,7 +264,7 @@ while (proceed==true) {
       switch (soc_starttls(contact->socptr,contact->peerip)) {
         case true       :       //link now in TLS crypted mode
           contact->tlsok=true;
-          (void) tcp_signon(contact);
+          (void) signon(contact);
           break;
         case false      :       //unable to establish link
           (void) transmit(contact,"%d 5.3.3 command starttls not successful",
index d651e6a2465b478f28df60f641fd09061fd9e1a0..e0a62b8691fa580c9b4a6624bb725f7ecc5885d9 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.4.1"
-#define RELEASE "5"
+#define RELEASE "6"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level