#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 {
/* 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) {
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);
/* 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"
(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
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
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 :
#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);
*/
/********************************************************/
/* */
-/* 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.*/
/* */
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)) {
}
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;
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
//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);
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
*/
/************************************************/
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
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);
status=1;
proceed=true;
+(void) signon(contact);
while (proceed==true) {
char *line;
char *parameter;
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)
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",
//version definition
#define VERSION "0.4.1"
-#define RELEASE "5"
+#define RELEASE "6"
//Public variables
PUBLIC int debug=0; //debug level