From: Jean-Marc Pigeon (Delson) Date: Wed, 10 Jul 2024 23:15:49 +0000 (-0400) Subject: Starying program emlrec X-Git-Tag: tag-0.3~16 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=930012d640423077e5b18a7e7bec4a89499a7f51;p=jmp%2Fmailleur Starying program emlrec --- diff --git a/app/Makefile b/app/Makefile index 4311de5..7f6fcf5 100644 --- a/app/Makefile +++ b/app/Makefile @@ -21,9 +21,11 @@ clean : #Equivalences #-------------------------------------------------------------------- EXE= \ + emlrec \ maild \ SRC= \ + emlrec.c \ maild.c \ #-------------------------------------------------------------------- @@ -40,6 +42,14 @@ LIBS = $(LIBAI) maild : toremake maild.o @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) +emlrec : toremake emlrec.o + @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) + +emlrec.o: emlrec.c \ + ../lib/modrec.h \ + ../lib/uniprc.h \ + ../lib/unipar.h \ + ../lib/subrou.h \ maild.o : maild.c \ ../lib/modrec.h \ diff --git a/app/emlrec.c b/app/emlrec.c new file mode 100644 index 0000000..e0e14de --- /dev/null +++ b/app/emlrec.c @@ -0,0 +1,115 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Main SMTP Daemon */ +/* */ +/********************************************************/ +#include +#include +#include +#include + +#include "subrou.h" +#include "unipar.h" +#include "uniprc.h" +#include "unisig.h" +#include "modrec.h" + +#define RECNAME "emlrec" + +//port listening format is "IP:PORT NUMBER:num iteration" +#define PORTREC "192.168.0.1:25:2" +/* + +*/ +/********************************************************/ +/* */ +/* Waiting and handling smtp request */ +/* */ +/********************************************************/ +static void rec_handlesmtp() + +{ +int phase; +_Bool proceed; + +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //looping forever email receiving processes + (void) prc_settitle("emlrec with pid='%06d'",getpid()); + break; + case 1 : //Terminating all remaining process + (void) sleep(1); + if (hangup==false) + phase--; //looping forever + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +} +/* + +*/ +/********************************************************/ +/* */ +/* Main routine */ +/* Start multiple SMTP daemon and make */ +/* sure there always ready to answer to */ +/* SMTP request. */ +/* */ +/********************************************************/ +int main(int argc,char *argv[]) + +{ +int status; +ARGTYP *params; +int phase; +_Bool proceed; + +status=0; +params=(ARGTYP *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //checking parameters + if ((params=par_getparams(argc,argv,"d:fhr:v"))==(ARGTYP *)0) { + phase=999; //no need to go further + } + break; + case 1 : //initialising process + (void) prc_preptitle(argc,argv,environ); + (void) rou_setappname(RECNAME); + (void) rou_modesubrou(true); + (void) par_modeunipar(true); + (void) prc_modeuniprc(true); + (void) sig_modeunisig(true); + (void) rec_modemodrec(true); + (void) sig_trapsignal(true,sig_alrm); + break; + case 2 : //doing main tash + (void) rec_handlesmtp(); + break; + case 3 : //doing main tash + (void) prc_cleantitle(); + params=par_freeparams(params); + (void) sig_trapsignal(false,sig_alrm); + (void) rec_modemodrec(false); + (void) sig_modeunisig(false); + (void) prc_modeuniprc(false); + (void) par_modeunipar(false); + (void) rou_modesubrou(false); + break; + default : //end of task + proceed=false; + break; + } + phase++; + } +(void) exit(status); +} diff --git a/lib/subrou.c b/lib/subrou.c index 96e34eb..e4cfd62 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -17,8 +17,8 @@ //version definition -#define VERSION "0.1" -#define RELEASE "14" +#define VERSION "0.2" +#define RELEASE "1" //Public variables PUBLIC int debug=0; //debug level @@ -68,6 +68,29 @@ const char *rou_getversion() return VERSION"."RELEASE; } /* +^L +*/ +/********************************************************/ +/* */ +/* Returne set a new application name to be used in*/ +/* logs. */ +/* */ +/********************************************************/ +char *rou_setappname(const char *newname) + +{ +char *name; + +name=(char *)0; +if (newname!=(char *)0) { + if (appname!=(char *)0) + (void) free(appname); + appname=strdup(newname); + name=appname; + } +return name; +} +/* */ /********************************************************/ @@ -312,14 +335,13 @@ if (mode!=modopen) { (void) srand(getpid()*355); if (foreground==true) (void) srand((int)(M_PI*100000000)); - if (appname!=(char *)0) - (void) free(appname); - appname=strdup(APPNAME); - (void) openlog(APPNAME,LOG_PID,LOG_DAEMON); - (void) rou_alert(0,"Starting: %s-%s",APPNAME,rou_getversion()); + if (appname==(char *)0) + appname=strdup(APPNAME); + (void) openlog(appname,LOG_PID,LOG_DAEMON); + (void) rou_alert(0,"Starting: %s-%s",appname,rou_getversion()); break; case false : - (void) rou_alert(0,"Exiting: %s-%s",APPNAME,rou_getversion()); + (void) rou_alert(0,"Exiting: %s-%s",appname,rou_getversion()); (void) closelog(); if (appname!=(char *)0) { (void) free(appname); diff --git a/lib/subrou.h b/lib/subrou.h index ec36f11..06038f1 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -26,6 +26,9 @@ extern char *appname; //application "official" name //return program version extern const char *rou_getversion(); +//change the application name +extern char *rou_setappname(const char *newname); + //to compute an application path with the root directory extern char *rou_apppath(const char *path);