break;
case 1 : //waiting for a line with CRLF
received=(char *)0;
- got=tcp_getline(socptr,WAITLINE,&received);
+ got=tcp_getline(socptr,WAITRMT,&received);
(void) rou_alert(3,"%s, received=<%s>",OPEP,received);
switch (got) {
case 0 : //Reading timeout
devlog.h devlog.c
devsoc.o: \
- subrou.h \
- unieml.h \
- uniprc.h \
- unitls.h \
+ subafn.h subrou.h \
+ unieml.h uniprc.h unitls.h \
devsoc.h devsoc.c
devsql.o: \
gestcp.h: \
subrou.h \
+ unidns.h \
devlog.h devsoc.h
gesspf.h: \
#include <unistd.h>
#include "subrou.h"
+#include "subafn.h"
#include "unieml.h"
#include "uniprc.h"
#include "unitls.h"
#include <stdbool.h>
#include <time.h>
-//Need to have GNU_SOURCE define within CFLAGS
-#ifdef AI_ALL
-#define HINTFLG AI_ALL|AI_CANONNAME|AI_CANONIDN
-#else /*AI_ALL is not defined in linux <= rh9 */
-#define HINTFLG AI_CANONNAME
-#endif
-
//convenient adress structure
typedef struct sockaddr SOCKADDR;
}
return sent;
}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to wait answer from remote and log */
+/* all answer from remote. */
+/* return an SMTP reply code. */
+/* */
+/********************************************************/
+PUBLIC int tcp_get_smtp_reply(RMTTYP *rmt,int wait)
+
+{
+int code;
+int maxlines;
+
+code=ERRPROC;
+maxlines=20; //maximun number of line error
+while (maxlines>0) {
+ char *line;
+ int sofar;
+
+ line=(char *)0;
+ if (tcp_getline(rmt->socptr,wait,&line)<0) {
+ char cmt[100];
+
+ (void) snprintf(cmt,sizeof(cmt),"%d Timeout waiting '%d' sec for MX <%s>",
+ ERRPROC,wait,rmt->curmx->mxname);
+ line=strdup(cmt);
+ }
+ (void) log_fprintlog(rmt->logptr,false,line);
+ if (sscanf(line,"%d%n",&code,&sofar)==1) {
+ if (line[sofar]==' ')
+ maxlines=0; //found remote status
+ else
+ code=ERRPROC;
+ }
+ line=rou_freestr(line);
+ maxlines--;
+ }
+return code;
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to build a command and send it to */
+/* remote server, log request and return the */
+/* remote response code. */
+/* */
+/********************************************************/
+PUBLIC int tcp_smtp_command(RMTTYP *rmt,char *fmt,...)
+
+{
+va_list args;
+char strloc[300];
+
+va_start(args,fmt);
+(void) vsnprintf(strloc,sizeof(strloc),fmt,args);
+va_end(args);
+(void) tcp_write(rmt->socptr,strloc);
+(void) log_fprintlog(rmt->logptr,false,strloc);
+return tcp_get_smtp_reply(rmt,WAITRMT);
+}
#include <stdbool.h>
#include "subrou.h"
+#include "unidns.h"
#include "devlog.h"
#include "devsoc.h"
-#define WAITLINE 30 //full line waiting time
+//structure handling remote
+typedef struct {
+ SOCPTR *socptr; //socket to remote pointer
+ LOGPTR *logptr; //Log pointer
+ char *orgdomain; //originator domain
+ char *dstdomain; //Domain to be reached
+ MXTYP *curmx; //Current MX number
+ MXTYP **mxs; //MX list form domain
+ }RMTTYP;
//read a line from contact up to CRLF
extern int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr);
//Transmit formated data to the contact channel
extern int tcp_write(SOCPTR *socptr,char *buffer);
+//wait and answer from remote and return the reply code
+extern int tcp_get_smtp_reply(RMTTYP *rmt,int wait);
+
+//Transmit a command to remote SMTP server
+extern int tcp_smtp_command(RMTTYP *rmt,char *fmt,...);
+
#endif
#include <unistd.h>
#include "subrou.h"
-#include "unidns.h"
#include "unieml.h"
#include "devlog.h"
+#include "gestcp.h"
#include "geseml.h"
#include "lvleml.h"
-typedef struct {
- SOCPTR *socptr; //socket to remote pointer
- LOGPTR *logptr; //Log pointer
- char *orgdomain; //originator domain
- char *dstdomain; //Domain to be reached
- MXTYP *curmx; //Current MX number
- MXTYP **mxs; //MX list form domain
- }RMTTYP;
/*
^L
*/
char *line;
completed=false;
- got=tcp_getline(contact->socptr,WAITLINE,&line);
+ got=tcp_getline(contact->socptr,WAITRMT,&line);
if (got<0) { //data timeout
phase=999; //trouble trouble
break; //exiting loop
*/
/********************************************************/
/* */
-/* Procedure to check answer from remote SMTP */
-/* MX server. */
-/* Return the SMTP status code. */
-/* */
-/********************************************************/
-static int get_smtp_reply(RMTTYP *rmt,int wait)
-
-{
-int code;
-int maxlines;
-
-code=ERRPROC;
-maxlines=20; //maximun number of line error
-while (maxlines>0) {
- char *line;
- int sofar;
-
- line=(char *)0;
- if (tcp_getline(rmt->socptr,wait,&line)<0) {
- char cmt[100];
-
- (void) snprintf(cmt,sizeof(cmt),"%d Timeout waiting '%d' sec for MX <%s>",
- ERRPROC,wait,rmt->curmx->mxname);
- line=strdup(cmt);
- }
- (void) log_fprintlog(rmt->logptr,false,line);
- if (sscanf(line,"%d%n",&code,&sofar)==1) {
- if (line[sofar]==' ')
- maxlines=0; //found remote status
- else
- code=ERRPROC;
- }
- line=rou_freestr(line);
- maxlines--;
- }
-return code;
-}
-/*
-^L
-*/
-/********************************************************/
-/* */
/* Procedure to to send ehlo (or helo) to remote */
/* MX server. */
/* Return true if succesfull */
static _Bool greetings_rmt(RMTTYP *rmt)
{
+#define OPEP "lvleml.c:greetings_rmt,"
+
_Bool done;
int phase;
_Bool proceed;
phase=0;
proceed=true;
while (proceed==true) {
- char cmt[100];
+ int rspcode;
+ rspcode=ERRPROC;
switch (phase) {
case 0 : //Sending EHLO
- (void) snprintf(cmt,sizeof(cmt),"EHLO %s",rmt->orgdomain);
- (void) tcp_write(rmt->socptr,cmt);
- (void) log_fprintlog(rmt->logptr,false,cmt);
- switch (get_smtp_reply(rmt,WAITRMT)) {
+ rspcode=tcp_smtp_command(rmt,"EHLO %s",rmt->orgdomain);
+ switch (rspcode) {
case CMDOK : //So fare, so good
done=true;
phase=999;
break;
default : //Trouble
+ (void) rou_alert(0,"%s, EHLO Remote <%s> unexpected answer code '%d'",
+ OPEP,rmt->curmx,rspcode);
break;
}
break;
case 1 : //Sending HELO
- (void) snprintf(cmt,sizeof(cmt),"HELO %s",rmt->orgdomain);
- (void) tcp_write(rmt->socptr,cmt);
- (void) log_fprintlog(rmt->logptr,false,cmt);
- switch (get_smtp_reply(rmt,WAITRMT)) {
+ rspcode=tcp_smtp_command(rmt,"HELO %s",rmt->orgdomain);
+ switch (rspcode) {
case CMDOK : //So fare, so good
done=true;
phase=999;
break;
default : //Trouble
+ (void) rou_alert(0,"%s, HELO Remote <%s> unexpected answer code '%d'",
+ OPEP,rmt->curmx,rspcode);
break;
}
break;
phase++;
}
return done;
+
+#undef OPEP
}
/*
^L
case 2 : //waiting for signon
int res;
- res=get_smtp_reply(rmt,WAITRMT);
+ res=tcp_get_smtp_reply(rmt,WAITRMT);
switch (res) {
case SIGNON : //everything fine
break;
//space to store (at least) IPV6 number
#define AFT sizeof(struct in6_addr)
+//Need to have GNU_SOURCE define within CFLAGS
+#ifdef AI_ALL
#define HINTFLG AI_ALL|AI_CANONNAME|AI_CANONIDN
+#else /*AI_ALL is not defined in linux <= rh9 */
+#define HINTFLG AI_CANONNAME
+#endif
typedef struct {
char *strnumip; //IP in string format