]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Better way todefine listening port
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 10 Mar 2025 20:32:24 +0000 (16:32 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 10 Mar 2025 20:32:24 +0000 (16:32 -0400)
app/emlrcvr.c
lib/modrec.c
lib/modrec.h

index eeba601b4c68b6b088405d017ccf56b0316bb00b..1762290da68a69d25db876f9e4497e62a11fdae8 100644 (file)
@@ -19,8 +19,6 @@
 #define RECNAME "emlrcvr"
 
 //port listening format is "IP:PORT NUMBER:num iteration"
-#define DFLTIP  "127.168.0.1"   //smtp test IP
-#define SMTPORT "1025"          //smtp test port
 /*
 \f
 */
@@ -49,7 +47,7 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //checking parameters
-      if ((params=par_getparams(argc,argv,"d:fhr:v"))==(ARGTYP *)0) {
+      if ((params=par_getparams(argc,argv,"d:fh:r:v"))==(ARGTYP *)0) {
         phase=999;      //no need to go further
         }
       break;
@@ -64,7 +62,7 @@ while (proceed==true) {
       (void) sig_trapsignal(true,sig_alrm);
       break;
     case 2      :       //doing main task
-      (void) rec_handlesmtp(DFLTIP,SMTPORT,1);
+      (void) rec_handlesmtp(params->argc,params->argv);
       break;
     case 3      :       //doing main tash
       (void) prc_cleantitle();
index 52e1f0353dd24d862dda93e26d010a0bd6e21a55..5ed2c044263899b4a2c50892a7c5200f11625104 100644 (file)
 #include        "modrec.h"
 
 static  _Bool modopen;          //boolean module open/close
+#define DFLTIP  "127.0.10.25"   //smtp test IP
+#define SMTPORT "1025"          //smtp test port
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*      Procedure to scan argument and generate binding */
+/*      information.                                    */
+/*      build a SOCPTR list and return the number of    */
+/*      entries.                                        */
+/*                                                     */
+/*      Possible argument format are:                   */
+/*      protocol:ipnum:port:iteration                   */
+/*      example:                                        */
+/*      :ipnum::: -> smtp:ipnum:25:1                    */
+/*      smtps:ipnum:465:2                               */
+/*              -> smtps protocol,port 465,2 iteration  */
+/*                                                     */
+/********************************************************/
+static int prepbinding(SOCPTR ***bindings,int argc,char *argv[])
+
+{
+*bindings=(SOCPTR **)0;
+for (int i=0;i<argc;i++) {
+  int iteration;
+  PROTYP proto;
+  char *ipnum;
+  char *port;
+
+  iteration=1;
+  proto=pro_smtp; 
+  ipnum=DFLTIP;
+  port=SMTPORT;
+  *bindings=soc_mkbindinf(*bindings,proto,ipnum,port,iteration);
+  }
+return rou_nbrlist(*bindings);
+}
 /*
 \f
 */
@@ -172,7 +210,7 @@ _Bool proceed;
 phase=0;
 proceed=true;
 while (proceed==true) {
-  (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+  //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
     case 0      :       //Opening logs
       (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
@@ -208,33 +246,32 @@ while (proceed==true) {
 /*      Waiting and handling smtp request               */
 /*                                                     */
 /********************************************************/
-PUBLIC void rec_handlesmtp(const char *ipnum,const char *port,int nbrbind)
+PUBLIC void rec_handlesmtp(int argc,char *argv[])
 
 {
 #define OPEP    "modrec.c:rec_handlesmtp"
 
 pid_t *childs;
+int nbrbind;
 SOCPTR **bindings;
 int phase;
 _Bool proceed;
 
 childs=(pid_t)0;
+nbrbind=0;
 bindings=(SOCPTR **)0;
 phase=0;
 proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //preparing iteration
-      (void) prc_settitle("Emlrec Daemon");
-      (void) rou_alert(0,"Starting Emlrec daemon for ip <%s>",ipnum);
-      childs=(pid_t *)calloc(nbrbind,sizeof(pid_t));
-      bindings=soc_mkbindinf((SOCPTR **)0,pro_smtp,ipnum,port,nbrbind);
-      if (bindings==(SOCPTR **)0) {
-        (void) rou_alert(0,"%s, No bindings definition found! (config?)",OPEP);
+      if ((nbrbind=prepbinding(&bindings,argc,argv))==0) {
+        (void) rou_alert(0,"%s, No listening IP found (config?)",OPEP);
         phase=999;
         }
       break;
     case 1      :       //Opening ALL channels
+      childs=(pid_t *)calloc(nbrbind,sizeof(pid_t));
       for (int i=0;i<nbrbind;i++) {
         (void) prc_nozombie();
         if (childs[i]==(pid_t)0)
@@ -265,7 +302,6 @@ while (proceed==true) {
         phase=0;        //Normal process, lets restart
       break;
     case 4      :       //we got a signal, kill all childs
-      (void) rou_alert(0,"Stopping Emlrec daemon for ip-<%s>",ipnum);
       (void) prc_killchilds(childs,nbrbind,10);
       break;
     default     :       //SAFE Guard
index 490fe9f97e655fb6fafc6e505746d85fc5e91176..3c0955e83efe24bde3f16d1697f98f8b79c1e898 100644 (file)
@@ -10,7 +10,7 @@
 #include        <stdbool.h>
 
 //procedure to receive email form outside
-extern void rec_handlesmtp(const char *ipnum,const char *port,int nbrbind);
+extern void rec_handlesmtp(int argc,char *argv[]);
 
 //homework to be done before starting/stoping module.
 extern int rec_modemodrec(_Bool mode);