From: Jean-Marc Pigeon (Delson) Date: Wed, 14 Aug 2024 00:44:07 +0000 (-0400) Subject: Logging message seems to work fine X-Git-Tag: tag-0.4.2 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=7fd2570b84ff502acbbf085675feee17fd476101;p=jmp%2Fmailleur Logging message seems to work fine --- diff --git a/lib/devlog.c b/lib/devlog.c index c4bfe00..055a0f8 100644 --- a/lib/devlog.c +++ b/lib/devlog.c @@ -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 diff --git a/lib/devlog.h b/lib/devlog.h index b0c4b6b..b3d2650 100644 --- a/lib/devlog.h +++ b/lib/devlog.h @@ -13,13 +13,13 @@ 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 diff --git a/lib/devsoc.c b/lib/devsoc.c index 3ee09fa..43abc82 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -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 : diff --git a/lib/gestcp.c b/lib/gestcp.c index 6189396..f408ba0 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -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; diff --git a/lib/gestcp.h b/lib/gestcp.h index 758fc81..3abb019 100644 --- a/lib/gestcp.h +++ b/lib/gestcp.h @@ -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); diff --git a/lib/lvleml.c b/lib/lvleml.c index 7e892e0..3504738 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -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 +} +/* */ /************************************************/ @@ -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", diff --git a/lib/subrou.c b/lib/subrou.c index d651e6a..e0a62b8 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -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