(void) rou_alert(0,"\t'%s'",line);
}
/*
-\f
-*/
-/********************************************************/
-/* */
-/* Procedure to send a line to remote */
-/* */
-/********************************************************/
-static int dooutgoing(SOCPTR *socptr,char *line)
-
-{
-int count;
-
-count=soc_writebuffer(socptr,line,strlen(line));
-count+=soc_writebuffer(socptr,"\r\n",2);
-return count;
-}
-/*
^L
*/
/************************************************/
//(void) rou_alert(0,"%s JMPDBG phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //Transmit "DATA" to remote
- if (dooutgoing(fd->socptr,action)!=(strlen(action)+2))
+ if (tcp_write(fd->socptr,action)!=(strlen(action)+2))
phase=999; //Unable to send STARTTLS sequence
break;
case 1 : //Get DATA command status
case 'D' : //pure data
if ((strcmp(data+2,".")==0)&&(empty==true))
(void) strcat(data,".");
- (void) dooutgoing(fd->socptr,data+2);
+ (void) tcp_write(fd->socptr,data+2);
empty=(strlen(data+2)==0);
break;
case 'C' : //data marker
switch (data[2]) {
case '.' : //end of data marker
- (void) dooutgoing(fd->socptr,"");
- (void) dooutgoing(fd->socptr,".");
+ (void) tcp_write(fd->socptr,"");
+ (void) tcp_write(fd->socptr,".");
completed=true;
break;
case 'T' : //timer data
isnow=time((time_t *)0);
(void) snprintf(ed,sizeof(ed),"Date: %s",rou_ascsysstamp(isnow));
- (void) dooutgoing(fd->socptr,ed);
+ (void) tcp_write(fd->socptr,ed);
break;
default : //unexpected data marker
(void) rou_alert(0,"%s Unexpected data marker <%s> (Bug?)",
while (proceed==true) {
switch (phase) {
case 0 : //Sending START TLS command
- if (dooutgoing(socptr,action)!=(strlen(action)+2))
+ if (tcp_write(socptr,action)!=(strlen(action)+2))
phase=999; //Unable to send STARTTLS sequence
break;
case 1 : //Get STARTTLS command status
status=doincoming(fd->socptr,*numline,line);
break;
case 'S' : //sending data
- (void) dooutgoing(fd->socptr,line);
+ (void) tcp_write(fd->socptr,line);
break;
case 'T' : //Get the test titre
status=strncpy(testname,line,sizeof(testname));
*/
/********************************************************/
/* */
-/* Procedure to write buffer on the socket output */
+/* Procedure to write a string on the socket output*/
/* return the number of char sent on channel. */
/* */
/********************************************************/
-PUBLIC int tcp_write(SOCPTR *socptr,char *buffer,int tosend)
+PUBLIC int tcp_write(SOCPTR *socptr,char *buffer)
{
int sent;
sent=-1;
-if (socptr!=(SOCPTR *)0)
- sent=soc_writebuffer(socptr,buffer,tosend);
+if (socptr!=(SOCPTR *)0) {
+ int taille;
+
+ taille=strlen(buffer);
+ if (taille>0)
+ sent=soc_writebuffer(socptr,buffer,taille);
+ sent+=soc_writebuffer(socptr,CRLF,strlen(CRLF));
+ }
return sent;
}
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,int tosend);
+extern int tcp_write(SOCPTR *socptr,char *buffer);
#endif
line=(char *)0;
if (rou_vasprintf(&line,fmt,args)>0) {
(void) log_fprintlog(contact->logptr,true,"%s",line);
- (void) tcp_write(contact->socptr,line,strlen(line));
- (void) tcp_write(contact->socptr,CRLF,strlen(CRLF));
+ (void) tcp_write(contact->socptr,line);
(void) free(line);
}
va_end(args);
/* Return the SMTP status code. */
/* */
/********************************************************/
-static _Bool get_smtp_reply(RMTTYP *rmt,int wait)
+static int get_smtp_reply(RMTTYP *rmt,int wait)
{
int code;
*/
/********************************************************/
/* */
+/* Procedure to to send ehlo (or helo) to remote */
+/* MX server. */
+/* Return true if succesfull */
+/* */
+/********************************************************/
+static _Bool greetings_rmt(RMTTYP *rmt)
+
+{
+_Bool done;
+int phase;
+_Bool proceed;
+
+done=false;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //Sending EHLO
+ char cmt[100];
+
+ (void) snprintf(cmt,sizeof(cmt),"EHLO %s",rmt->domain);
+ (void) tcp_write(rmt->socptr,cmt);
+ (void) log_fprintlog(rmt->logptr,false,cmt);
+ break;
+ case 1 : //waiting for ehlo reply
+ switch (get_smtp_reply(rmt,WAITRMT)) {
+ case CMDOK : //So fare, so good
+ done=true;
+ phase=999;
+ break;
+ default : //Trouble
+ break;
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return done;
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
/* Procedure to connect to the remote SMTP server */
/* */
/********************************************************/
break;
}
break;
- case 3 : //establishing secured link
+ case 3 : //send greetings
+ if (greetings_rmt(rmt)==false)
+ phase=999; //greeting not successful!
+ break;
+ case 4 : //establishing secured link
break;
default : //SAFE Guard
proceed=false;