]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starting the "feeder" process
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 20 Mar 2025 23:25:36 +0000 (19:25 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 20 Mar 2025 23:25:36 +0000 (19:25 -0400)
app/Makefile
app/emlrcvr.c
app/feeder.c [new file with mode: 0644]
lib/devsoc.c
lib/lvleml.c
lib/subrou.c

index dbaf891429f0b3efe23ef22b185e5890f08bf7db..4b08821676cbc0eb234a9b4b4195855a55def828 100644 (file)
@@ -22,11 +22,13 @@ clean       :
 #--------------------------------------------------------------------
 EXE=                                                           \
        emlrcvr                                                 \
+       feeder                                                  \
        maild                                                   \
        chkspf                                                  \
 
 SRC=                                                           \
        emlrcvr.c                                               \
+       freeder.c                                               \
        maild.c                                                 \
        chkspf.c                                                \
 
@@ -47,6 +49,9 @@ LIBS  =       $(LIBMAIL)                      \
 emlrcvr        :  toremake emlrcvr.o
           @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
 
+feeder :  toremake feeder.o
+          @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
+
 maild  :  toremake maild.o
           @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
 
@@ -65,6 +70,11 @@ emlrec.o:  emlrec.c                          \
           ../lib/unipar.h                      \
           ../lib/subrou.h
 
+feeder.o:  feeder.c                            \
+          ../lib/unipar.h                      \
+          ../lib/subrou.h
+
+
 maild.o        :  maild.c                              \
           ../lib/uniprc.h                      \
           ../lib/unisig.h                      \
index f2eb98984b79a20ab9e40081beed2737aa694571..c8b93cafb79a054d14bfc1fbde3d518f35d104a1 100644 (file)
@@ -62,7 +62,7 @@ while (proceed==true) {
     case 2      :       //doing main task
       (void) rec_handlesmtp(params->argc,params->argv);
       break;
-    case 3      :       //doing main tash
+    case 3      :       //doing main task
       (void) prc_cleantitle();
       params=par_freeparams(params);
       (void) sig_trapsignal(false,sig_alrm);
diff --git a/app/feeder.c b/app/feeder.c
new file mode 100644 (file)
index 0000000..0af822e
--- /dev/null
@@ -0,0 +1,114 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*      SMTP protocol feeder.                           */
+/*     Used to transmit data to remote SMTP server.    */
+/*                                                      */
+/*      Format is:                                      */
+/*              feeder ip port [file1 file2...]         */
+/*                                                     */
+/********************************************************/
+#include       <signal.h>
+#include       <stdlib.h>
+#include       <stdio.h>
+#include       <unistd.h>
+
+#include       "subrou.h"
+#include       "unipar.h"
+#include       "devsoc.h"
+
+#define FNAME   "feeder"
+
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to display feeder usage               */
+/*                                                     */
+/********************************************************/
+static void usage(const char *name)
+
+{
+(void) fprintf(stderr,"usage:\n  ");
+(void) fprintf(stderr,"%s\t"
+                 "[-d debug] "
+                 "[-h] "
+                  "remote_name port [filename1 filename2...]\n",name);
+(void) fprintf(stderr,"\twhere:\n");
+(void) fprintf(stderr,"\t\t-d level\t: debug level [1-10]\n");
+(void) fprintf(stderr,"\t\t-h\t\t: print this help message\n");
+(void) fprintf(stderr,"\t\t:remote_name, fully qualified domain name\n");
+(void) fprintf(stderr,"\t\t:port, remote acces port to access\n");
+(void) fprintf(stderr,"\t\t:filenames, a set a filename to be feed to remote\n");
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Main routine                                    */
+/*             Start a channel to a remote ip.port     */
+/*              read file and transmit contecnts to     */
+/*              remote SMTP server.                     */
+/*                                                     */
+/********************************************************/
+int main(int argc,char *argv[])
+
+{
+int status;
+ARGTYP *params;
+SOCPTR *socptr;
+int numfile;
+int phase;
+_Bool proceed;
+
+status=0;
+params=(ARGTYP *)0;
+socptr=(SOCPTR *)0;
+numfile=0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //checking parameters
+      if ((params=par_getparams(argc,argv,"d:fh:r:v"))==(ARGTYP *)0) {
+        proceed=false;      //no need to go further
+        }
+      break;
+    case 1      :       //initialising process
+      if (params->argc<2) {
+        (void) fprintf(stdout,"Error, missing! remote_name? port?\n");
+        (void) usage("feeder");
+        phase=999;      //can not go further
+        }
+      break;
+    case 2      :       //opening remote channel
+      socptr=soc_openonesock(pro_smtp,params->argv[0],params->argv[1]);
+      if (socptr==(SOCPTR *)0) {
+        (void) fprintf(stdout,"Unable to contact remote!\n");
+        phase=999;      //can not go further
+        }
+      break;
+    case 3      :       //doing main task
+      for (int i=2;i<params->argc;i++) {
+        numfile++;
+      
+        (void) fprintf(stdout,"sending <%s>\n",params->argv[i]);
+        (void) sleep(3);
+        }
+      (void) fprintf(stdout,"%d file transmetted to <%s.%s>\n",
+                             numfile,params->argv[0],params->argv[1]);
+      break;
+    case 4      :       //closing remote channel
+      socptr=soc_closeonesock(socptr);
+      break;
+    default     :       //end of task
+      params=par_freeparams(params);
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+(void) exit(status);
+}
index 2ce895dbca61804f99e458c0528bc4ae7f954cc7..6b58eb1c699ba348bca2161f84b306cdf6a3241b 100644 (file)
@@ -34,6 +34,7 @@
 typedef struct  {
         PROTYP proto;   //Connexion protocol type
         int handle;     //connexion handle
+        _Bool connected;//soc is connected to remote
         _Bool modtls;   //soc is in TLS mode
         TLSTYP *tls;    //full TPS/SSL channel
         int maxcarin;   //absolute number within carin
@@ -143,10 +144,11 @@ SOCTYP *newsoc;
 
 newsoc=(SOCTYP *)newsocket();
 newsoc->proto=soc->proto;
+newsoc->handle=soc->handle;
+newsoc->connected=soc->connected;
 newsoc->ip=strdup(soc->ip);
 newsoc->port=strdup(soc->port);
 newsoc->iteration=soc->iteration;
-newsoc->handle=soc->handle;
 return newsoc;
 }
 /*
@@ -241,6 +243,7 @@ while (proceed==true) {
       break;
     case 3      :       //Socket ready
       soc->handle=newhandle;
+      soc->connected=true;
       good=true;
       break;
     default     :       //SAFE guard
@@ -272,7 +275,11 @@ phase=0;
 proceed=true;
 while (proceed==true) {
   switch (phase) {
-    case 0      :       //shutting down the link
+    case 0      :       //is the connect still active
+      if (soc->connected==false)        //no!, no need to shutdown
+        phase++;
+      break;
+    case 1      :       //shutting down the link
       if (shutdown(soc->handle,SHUT_RDWR)<0) {
         switch (errno) {
           case ENOTCONN :       //already disconnect by other side!
@@ -286,7 +293,7 @@ while (proceed==true) {
           }
         }
       break;
-    case 1      :       //closing connexion
+    case 2      :       //closing connexion
       if (close(soc->handle)<0) {
         (void) rou_alert(0,"%s unable to close channel [%s:%s] properly "
                            "(errno=<%s>)",
@@ -548,8 +555,6 @@ int status;
 int handle;
 fd_set rset;
 fd_set wset;
-int mxtime;
-struct timeval timeout;
 struct addrinfo hints;
 struct addrinfo *ai;
 int phase;
@@ -560,9 +565,6 @@ status=0;
 handle=0;
 FD_ZERO(&rset);
 FD_ZERO(&wset);
-mxtime=10;
-timeout.tv_usec=0;;
-timeout.tv_sec=mxtime;
 (void) memset(&hints,'\000',sizeof(hints));
 hints.ai_family=PF_UNSPEC;
 hints.ai_flags=HINTFLG;
@@ -573,13 +575,13 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //Do we have parameters
-      if ((ip!=(const char *)0)&&(port!=(const char *)0)) {
+      if ((ip==(const char *)0)||(port==(const char *)0)) {
         (void) rou_alert(0,"%s, ip (%s) or port (%s) missing (config?)",
                             OPEP,ip,port);
         phase=999;      //no need to go further
         }
       break;
-    case 2      :       //is address a good one
+    case 1      :       //is address a good one
       if ((status=getaddrinfo(ip,port,&hints,&ai))!=0) {
         (void) rou_alert(0,"%s, Unable to find a address about "
                            "IP:port '%s:%s' (error='%s')",
@@ -587,14 +589,14 @@ while (proceed==true) {
         phase=999;      //no need to go further
         }
       break;
-    case 3      :       //lets create socket
+    case 2      :       //lets create socket
       if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
         (void) rou_alert(0,"%s Unable to open socket for <%s> (error='%s')",
                           OPEP,ai->ai_canonname,strerror(errno));
         phase=999;      //no need to go further
         }
       break;
-    case 4      :       //connecting to remote
+    case 3      :       //connecting to remote
       if (connect(handle,ai->ai_addr,ai->ai_addrlen)<0) {
         switch (errno) {
           case EINPROGRESS      :       //its acceptable
@@ -608,29 +610,10 @@ while (proceed==true) {
           }
         }
       break;
-    case 5      :       //wait for connect completion
-      switch (select(handle+1,&rset,&wset,(fd_set *)0,&timeout)) {
-        case -1         :
-          (void) rou_alert(1,"%s trouble to establish connection with '%s.%s' "
-                             "(error=<%s>)",
-                             OPEP,ip,port,strerror(errno));
-          (void) close(handle);
-          phase=999;            //no ned to go further
-          break;
-        case 0          :
-          (void) rou_alert(1,"%s Unable establish connection with '%s.%s' "
-                              "within %d sec, (error=<%s>)",
-                              OPEP,ip,port,mxtime,strerror(ETIMEDOUT));
-          (void) close(handle);
-          phase=999;            //no ned to go further
-          break;
-        default         :       //everything fine
-          break;
-        }
-      break;
-    case 6      :       //socket is now ready
+    case 4      :       //socket is now ready
       soc=newsocket();
       soc->proto=proto;
+      soc->connected=true;
       soc->handle=handle;
       soc->ip=strdup(ip);
       soc->port=strdup(port);
@@ -1023,8 +1006,12 @@ if (soc!=(SOCTYP *)0) {
           switch (errno) {
             case EAGAIN     :    //no char available
               break;
+            case ECONNRESET :    //Connection reset by peer
+              soc->connected=false;
+              break;
             default         :
-              (void) rou_alert(0,"%s Unexpected error <%s> (Bug)",strerror(errno));
+              (void) rou_alert(0,"%s Unexpected error=%d <%s> (Bug)",
+                                  OPEP,errno,strerror(errno));
               break;
             }
           break;
index 824b66e85b534311e8be2f957878781555f4f31d..a870569e98f01cf9434c8e1df730bdad9b54ace8 100644 (file)
@@ -415,6 +415,8 @@ 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);
+      (void) rou_alert(0,"Contact from peer <%s> to port <%s> started",
+                          contact->peerip,contact->locserv);
       break;
     case 3      :       //check contact validity
       if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
@@ -465,7 +467,7 @@ while (proceed==true) {
         }
       break;
     case 1      :       //properly closing remote contact
-      (void) rou_alert(0,"Contact from peer <%s> on port <%s> Terminated",
+      (void) rou_alert(0,"Contact from peer <%s> to port <%s> terminated",
                           contact->peerip,contact->locserv);
       contact->socptr=soc_release(contact->socptr);
       break;
index f14523d143f623d1a887433f27961c74aaeee4d6..eb2e84424cc6231c18a1dfe4a6084b815d6dda59 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.6"
-#define RELEASE "7"
+#define RELEASE "8"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level