]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting to do ehlo command
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 8 Jun 2025 07:42:45 +0000 (03:42 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 8 Jun 2025 07:42:45 +0000 (03:42 -0400)
app/feeder.c
lib/gestcp.c
lib/gestcp.h
lib/lvleml.c

index c027ef41b011c7c047aa6b477c4b0dbb9386676b..01592bdd3c91a44551b9e65b394c4883cab25e79 100644 (file)
@@ -87,23 +87,6 @@ static void report(int numline,char *line,char *trouble)
 (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
 */
 /************************************************/
@@ -161,7 +144,7 @@ while (proceed==true) {
   //(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
@@ -195,14 +178,14 @@ while (proceed==true) {
           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
@@ -211,7 +194,7 @@ while (proceed==true) {
 
                 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?)",
@@ -265,7 +248,7 @@ proceed=true;
 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
@@ -568,7 +551,7 @@ while (proceed==true) {
           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));
index 5c7d17e9bcd05170e2eb54ba97d812711c361109..eaeabd251405dc02e7ab2e43467439bde69efb8e 100644 (file)
@@ -92,17 +92,23 @@ return got;
 */
 /********************************************************/
 /*                                                      */
-/*     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;
 }
index 6962c50dc466194057c1f07d48d96ec769f08763..dfdb5790b27cc658843a15f1980f2ee67f1b5ca3 100644 (file)
@@ -19,6 +19,6 @@
 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
index 274e04c02f52226e6ca56bf9f33cb7e81d568fa7..127fcea6cd4ef79320050097def6dde60902d83b 100644 (file)
@@ -130,8 +130,7 @@ 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->socptr,line,strlen(line));
-  (void) tcp_write(contact->socptr,CRLF,strlen(CRLF));
+  (void) tcp_write(contact->socptr,line);
   (void) free(line);
   }
 va_end(args);
@@ -687,7 +686,7 @@ return true;
 /*      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;
@@ -724,6 +723,53 @@ return 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  */
 /*                                                      */
 /********************************************************/
@@ -780,7 +826,11 @@ while (proceed==true) {
           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;