From: Jean-Marc Pigeon (Delson) Date: Thu, 20 Mar 2025 23:25:36 +0000 (-0400) Subject: Starting the "feeder" process X-Git-Tag: tag-0.7~67 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=bfc9cb9d2fbf95eab90f3d644e5f2ad28d09ff39;p=jmp%2Fmailleur Starting the "feeder" process --- diff --git a/app/Makefile b/app/Makefile index dbaf891..4b08821 100644 --- a/app/Makefile +++ b/app/Makefile @@ -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 \ diff --git a/app/emlrcvr.c b/app/emlrcvr.c index f2eb989..c8b93ca 100644 --- a/app/emlrcvr.c +++ b/app/emlrcvr.c @@ -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 index 0000000..0af822e --- /dev/null +++ b/app/feeder.c @@ -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 +#include +#include +#include + +#include "subrou.h" +#include "unipar.h" +#include "devsoc.h" + +#define FNAME "feeder" + +/* + +*/ +/********************************************************/ +/* */ +/* 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"); +} +/* + +*/ +/********************************************************/ +/* */ +/* 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;iargc;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); +} diff --git a/lib/devsoc.c b/lib/devsoc.c index 2ce895d..6b58eb1 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -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; diff --git a/lib/lvleml.c b/lib/lvleml.c index 824b66e..a870569 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -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; diff --git a/lib/subrou.c b/lib/subrou.c index f14523d..eb2e844 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "7" +#define RELEASE "8" //Public variables PUBLIC int debug=0; //debug level