From: Jean-Marc Pigeon (Delson) Date: Mon, 5 May 2025 22:24:21 +0000 (-0400) Subject: Restart link directiv within feeder is working fine X-Git-Tag: tag-0.8~137 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=59af0f596ecc10e47483b6cd06c84f06c5e64f4f;p=jmp%2Fmailleur Restart link directiv within feeder is working fine --- diff --git a/app/feeder.c b/app/feeder.c index 38c627e..2b73132 100644 --- a/app/feeder.c +++ b/app/feeder.c @@ -24,8 +24,15 @@ #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; /* @@ -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 (nextdestport=rou_freestr(feed->destport); +feed->destip=rou_freestr(feed->destip); +feed->srcip=rou_freestr(feed->srcip); +(void) free(feed); return numfile; } /* diff --git a/data-tst/feed00.tst b/data-tst/feed00.tst index e8fa8cf..57dbc7a 100644 --- a/data-tst/feed00.tst +++ b/data-tst/feed00.tst @@ -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... #------------------------------------------------------------------------- diff --git a/lib/devsoc.c b/lib/devsoc.c index cc742fe..0703d8f 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -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; diff --git a/lib/devsoc.h b/lib/devsoc.h index 3ae6bf6..fcfd173 100644 --- a/lib/devsoc.h +++ b/lib/devsoc.h @@ -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);