]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Restart link directiv within feeder is working fine
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 5 May 2025 22:24:21 +0000 (18:24 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 5 May 2025 22:24:21 +0000 (18:24 -0400)
app/feeder.c
data-tst/feed00.tst
lib/devsoc.c
lib/devsoc.h

index 38c627ebc2fec3e60726670f03e06dbc7754c8a3..2b73132092bd270c62848a8268906ccc3f01a008 100644 (file)
 
 #define FNAME   "feeder"
 
-static  char titre[100];                //test title
-static  char testname[100];             //dest description
+static  char titre[100];        //test title
+static  char testname[100];     //dest description
+
+typedef struct  {
+        char *destip;           //IP to connect to
+        char *destport;         //Port to connect to
+        char *srcip;            //Ip to be used as source
+        SOCPTR *socptr;         //connection socket
+        }FEEDTYP;
 
 /*
 \f
@@ -311,7 +318,7 @@ return status;
 /*     Scanning one line from test file                */
 /*                                                     */
 /********************************************************/
-static _Bool scanline(SOCPTR *socptr,int numline,char *line)
+static _Bool scanline(FEEDTYP *fd,int numline,char *line)
 
 {
 #define OPEP "feeder.c:scanline"
@@ -345,13 +352,23 @@ while (proceed==true) {
     case 2      :       //discarding comment
       switch (action) {
         case 'C'        :       //command to execute
-          status=docommand(socptr,numline,line);
+          status=docommand(fd->socptr,numline,line);
+          break;
+        case 'L'        :       //Restart Session
+          fd->socptr=soc_closefeedsock(fd->socptr);
+          (void) usleep(100000); //wait 10 millisec
+          fd->socptr=soc_openfeedsock(pro_smtp,fd->srcip,fd->destip,fd->destport);
+          if (fd->socptr==(SOCPTR *)0) {
+            (void) report(numline,line,"Unable to restart feed socket!");
+            status=false;
+            phase=999;          //Aborting feed job
+            }
           break;
         case 'R'        :       //Receiving data
-          status=doincoming(socptr,numline,line);
+          status=doincoming(fd->socptr,numline,line);
           break;
         case 'S'        :       //sending data
-          (void) dooutgoing(socptr,line);
+          (void) dooutgoing(fd->socptr,line);
           break;
         case 'T'        :       //Get the test titre
           status=strncpy(testname,line,sizeof(testname));
@@ -383,7 +400,7 @@ return status;
 /*     Scanning data file.                             */
 /*                                                     */
 /********************************************************/
-static _Bool scanonefile(SOCPTR *socptr,const char *filename)
+static _Bool scanonefile(FEEDTYP *fd,const char *filename)
 
 {
 _Bool status;
@@ -420,23 +437,33 @@ while (proceed==true) {
         proceed=false;
         }
       break;
-    case 1      :       //reading line;
+    case 1      :       //Opening the socket
+      fd->socptr=soc_openfeedsock(pro_smtp,fd->srcip,fd->destip,fd->destport);
+      if (fd->socptr==(SOCPTR *)0) {
+        (void) rou_alert(0,"Unable to open link to [%s:%s]",
+                            fd->destip,fd->destport);
+        (void) fclose(fichier);
+        proceed=false;  //Can not scan file
+        }
+      break;
+    case 2      :       //reading line;
       while (fgets(line,sizeof(line),fichier)!=(char *)0) {
         char *ptr;
 
         numline++;
         while ((ptr=strrchr(line,'\n'))!=(char *)0)
           *ptr='\000';
-        if (scanline(socptr,numline,line)==false) {
+        if (scanline(fd,numline,line)==false) {
           phase=999;    //Trouble trouble exiting
           break;
           }
         }
       break;
-    case 2      :       //scanning went well
+    case 3      :       //scanning went well
       status=true;
       break;
     default     :       //SAFE Guard
+      fd->socptr=soc_closefeedsock(fd->socptr);
       (void) fclose(fichier);
       proceed=false;
       break;
@@ -454,30 +481,25 @@ static int scanallfiles(int argc,char *argv[])
 
 {
 int numfile;
-SOCPTR *socptr;
+FEEDTYP *feed;
+
 int next;
 int phase;
 
 numfile=0;
-socptr=(SOCPTR *)0;
+feed=(FEEDTYP *)calloc(1,sizeof(FEEDTYP));
+feed->srcip=strdup(srcip);
+feed->destip=strdup(argv[0]);
+feed->destport=strdup(argv[1]);
 next=2;
 phase=0;
 while (next<argc) {
   switch (phase) {
     case  0     :       //display scanned file
       break;
-    case  1     :       //opening a socket
-      //socptr=soc_openonesock(pro_smtp,"127.63.31.15",argv[0],argv[1]);
-      socptr=soc_openonesock(pro_smtp,srcip,argv[0],argv[1]);
-      if (socptr==(SOCPTR *)0) {
-        (void) rou_alert(0,"Unable to contact remote!");
-        phase=999;
-        }
-      break;
-    case  2     :       //scanning file
-      if (scanonefile(socptr,argv[next])==false) 
+    case  1     :       //scanning file
+      if (scanonefile(feed,argv[next])==false) 
         next=argc;      //do not check next file
-      socptr=soc_closeonesock(socptr);
       break;
     case  3     :       //incrementing numfile scanned
       numfile++;
@@ -489,6 +511,10 @@ while (next<argc) {
     }
   phase++;
   }
+feed->destport=rou_freestr(feed->destport);
+feed->destip=rou_freestr(feed->destip);
+feed->srcip=rou_freestr(feed->srcip);
+(void) free(feed);
 return numfile;
 }
 /*
index e8fa8cfe24f83081b28194dd4200f6b2794fca1e..57dbc7a136b96b99a4ae8b89aceafee70449c760 100644 (file)
@@ -41,5 +41,8 @@ R:Disconnected
 #waiting 1 sec
 W:1
 #-restarting link
-#L:first restart link
+L:first restart link
+R:220 mailleur.example.com ESMTP (cleartext) emlrcvr...
+S:QUIT
+R:221 2.0.0 Bye, closing connection...
 #-------------------------------------------------------------------------
index cc742fe1630a012ff3bc4dfd36e1a20bbf0966df..0703d8f1a3522b5b31b5fb9bc0caf744e8ba4fdd 100644 (file)
@@ -569,10 +569,10 @@ return socptr;
 /*      server. Return a socptr if successful.          */
 /*                                                     */
 /********************************************************/
-PUBLIC SOCPTR *soc_openonesock(PROTYP proto,const char *srcip,const char *ip,const char *port)
+PUBLIC SOCPTR *soc_openfeedsock(PROTYP proto,const char *srcip,const char *ip,const char *port)
 
 {
-#define OPEP    "devsoc.c:soc_openonesoc"
+#define OPEP    "devsoc.c:soc_openfeedsoc"
 
 SOCTYP *soc;
 int status;
@@ -696,10 +696,10 @@ return (SOCPTR *)soc;
 /*     server. Return a so remote smtp server.          */
 /*                                                     */
 /********************************************************/
-PUBLIC SOCPTR *soc_closeonesock(SOCPTR *socptr)
+PUBLIC SOCPTR *soc_closefeedsock(SOCPTR *socptr)
 
 {
-#define OPEP    "devsoc.c:soc_closeonesoc"
+#define OPEP    "devsoc.c:soc_closefeedsoc"
 
 SOCTYP *soc;
 int phase;
index 3ae6bf6944a50244a73fc0ce0bb8b16841fdc9fd..fcfd173d2724c0433b8226e87902dc88a5978927 100644 (file)
@@ -46,10 +46,10 @@ extern SOCPTR **soc_mkbindinf(SOCPTR **s,PROTYP proto,
 
 //procedure to open one exchange socket
 //to connect a remote smtp server
-extern SOCPTR *soc_openonesock(PROTYP proto,const char *src,const char *ip,const char *port);
+extern SOCPTR *soc_openfeedsock(PROTYP proto,const char *src,const char *ip,const char *port);
 
 //procedure to close an exchange socket connected to a remote smtp server
-extern SOCPTR *soc_closeonesock(SOCPTR *socptr);
+extern SOCPTR *soc_closefeedsock(SOCPTR *socptr);
 
 //procedure to return the number of channel to open on the soc
 extern int soc_getiterations(SOCPTR *socptr);