From: Jean-Marc Pigeon (Delson) Date: Sat, 7 Jun 2025 20:22:52 +0000 (-0400) Subject: Starting to implement connect_to_mx X-Git-Tag: tag-0.8~60 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=d91c1c355fe676d21aa7b1a7cba01ed75699847b;p=jmp%2Fmailleur Starting to implement connect_to_mx --- diff --git a/lib/devlog.c b/lib/devlog.c index dc03bad..90aa4e6 100644 --- a/lib/devlog.c +++ b/lib/devlog.c @@ -162,7 +162,7 @@ return status; /* return a NULL file pointeur if trouble. */ /* */ /********************************************************/ -PUBLIC LOGPTR *log_openlog(char *logname,_Bool inlog) +PUBLIC LOGPTR *log_openlog(char *logname,_Bool inlog,const char *cmt) { #define OPEP "devlog.c:log_openlog" @@ -208,6 +208,8 @@ while (proceed==true) { (void) clock_gettime(CLOCK_REALTIME,&(log->start)); (void) fprintf(log->file,"\n#-----------------------------\n"); (void) fprintf(log->file,"#%s",ctime(&(log->start.tv_sec))); + if (cmt!=(const char *)0) + (void) fprintf(log->file,"#%s\n",cmt); (void) fflush(log->file); log->start.tv_sec=0; break; diff --git a/lib/devlog.h b/lib/devlog.h index fc294f7..8b42caf 100644 --- a/lib/devlog.h +++ b/lib/devlog.h @@ -13,7 +13,7 @@ typedef void LOGPTR; //procedure to open a session log -extern LOGPTR *log_openlog(char *logname,_Bool inlong); +extern LOGPTR *log_openlog(char *logname,_Bool inlog,const char *cmt); //procedure to close a previously open session log extern LOGPTR *log_closelog(LOGPTR *logptr); diff --git a/lib/lvleml.c b/lib/lvleml.c index 4f623d1..62e4d18 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -24,6 +24,11 @@ #include "geseml.h" #include "lvleml.h" +typedef struct { + SOCPTR *socptr; + LOGPTR *logptr; + MXTYP **mxs; + }RMTTYP; /* ^L */ @@ -675,6 +680,37 @@ return true; */ /********************************************************/ /* */ +/* Procedure to connect to the remote SMTP server */ +/* */ +/********************************************************/ +static _Bool connect_to_mx(RMTTYP *rmt) + +{ +_Bool done; +int phase; +int proceed; + + +done=false; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //do ve have MX + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return done; +} +/* +^L +*/ +/********************************************************/ +/* */ /* Procedure to send the whole email transaction */ /* */ /********************************************************/ @@ -684,13 +720,14 @@ static void sending_email(char *domain,char *sessid,TRATYP **tra) #define OPEP "lvleml.c:sending_email," time_t isnow; -MXTYP **mxs; +RMTTYP rmt; TRATYP **tosend; int phase; _Bool proceed; isnow=time((time_t *)0); -mxs=dns_getmx(domain); +(void) memset(&rmt,'\000',sizeof(rmt)); +rmt.mxs=dns_getmx(domain); tosend=(TRATYP **)0; phase=0; proceed=true; @@ -702,6 +739,7 @@ while (proceed==true) { phase=999; //all scanning done break; case 1 : //collecting email to be sent + rmt.logptr=log_closelog(rmt.logptr); while (*tra!=(TRATYP *)0) { if (strcmp((*tra)->sessid,sessid)!=0) { sessid=(*tra)->sessid; @@ -722,12 +760,27 @@ while (proceed==true) { } break; case 2 : //Checking if we have email to be sent + char cmt[100]; + + (void) strncpy(cmt,sessid,sizeof(cmt)); + rmt.logptr=log_openlog(sessid,false,cmt); if (tosend==(TRATYP **)0) phase=-1; //lets continue to see other email break; case 3 : //checking if connection is open + if (rmt.socptr!=(SOCPTR *)0) { //reset the connection + phase++; //NO need to open connection + } break; case 4 : //Opening connection if not open + if (connect_to_mx(&rmt)==false) { + char cmt[100]; + + (void) snprintf(cmt,sizeof(cmt),"Unable to contact ANY MX for domain <%s>", + domain); + (void) log_fprintlog(rmt.logptr,false,cmt); + phase=999; //No need to go further + } break; case 5 : //sending recipient list break; @@ -739,12 +792,14 @@ while (proceed==true) { phase=0; //Lets see if we have other recipient break; default : //SAFE Guard + rmt.logptr=log_closelog(rmt.logptr); proceed=false; break; } phase++; } -mxs=dns_freemxlist(mxs); +rmt.mxs=dns_freemxlist(rmt.mxs); + #undef OPEP } /* @@ -947,7 +1002,7 @@ while (proceed==true) { } contact->peername=soc_getaddrinfo(contact->socptr,false,true); contact->peerip=soc_getaddrinfo(contact->socptr,false,false); - contact->logptr=log_openlog(contact->mainsesid,true); + contact->logptr=log_openlog(contact->mainsesid,true,(const char *)0); (void) rou_alert(0,"Contact from peer <%s> to port <%s> started", contact->peerip,contact->locserv); break;