]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Defining emlrcvr (email receiver)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 10 Mar 2025 18:03:35 +0000 (14:03 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 10 Mar 2025 18:03:35 +0000 (14:03 -0400)
app/Makefile
app/emlrcvr.c [moved from app/emlrec.c with 88% similarity]
lib/modrec.c
lib/modrec.h

index 4ac6bd5694e2b8d330e827eadaf83d4e1d5cf0b9..dbaf891429f0b3efe23ef22b185e5890f08bf7db 100644 (file)
@@ -21,12 +21,12 @@ clean       :
 #Equivalences
 #--------------------------------------------------------------------
 EXE=                                                           \
-       emlrec                                                  \
+       emlrcvr                                                 \
        maild                                                   \
        chkspf                                                  \
 
 SRC=                                                           \
-       emlrec.c                                                \
+       emlrcvr.c                                               \
        maild.c                                                 \
        chkspf.c                                                \
 
@@ -44,7 +44,7 @@ LIBS  =       $(LIBMAIL)                      \
 #--------------------------------------------------------------------
 #Dependances
 #--------------------------------------------------------------------
-emlrec :  toremake emlrec.o
+emlrcvr        :  toremake emlrcvr.o
           @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS)
 
 maild  :  toremake maild.o
similarity index 88%
rename from app/emlrec.c
rename to app/emlrcvr.c
index 87666ae95d91e874b100d76dd1de6ca9e82c7292..eeba601b4c68b6b088405d017ccf56b0316bb00b 100644 (file)
@@ -1,7 +1,8 @@
 // vim: smarttab tabstop=8 shiftwidth=2 expandtab
 /********************************************************/
 /*                                                     */
-/*     Main SMTP Daemon                                */
+/*      Email Receiver                                  */
+/*     SMTP Daemon dedicated to receive Email.         */
 /*                                                     */
 /********************************************************/
 #include       <signal.h>
 #include       "unisig.h"
 #include       "modrec.h"
 
-#define RECNAME "emlrec"
+#define RECNAME "emlrcvr"
 
 //port listening format is "IP:PORT NUMBER:num iteration"
-#define PORTREC "192.168.0.1:25:1"
+#define DFLTIP  "127.168.0.1"   //smtp test IP
+#define SMTPORT "1025"          //smtp test port
 /*
 \f
 */
@@ -62,7 +64,7 @@ while (proceed==true) {
       (void) sig_trapsignal(true,sig_alrm);
       break;
     case 2      :       //doing main task
-      (void) rec_handlesmtp();
+      (void) rec_handlesmtp(DFLTIP,SMTPORT,1);
       break;
     case 3      :       //doing main tash
       (void) prc_cleantitle();
index 77503ee29a7ef93b8a717ed365f0403bd9dd74e2..52e1f0353dd24d862dda93e26d010a0bd6e21a55 100644 (file)
@@ -172,6 +172,7 @@ _Bool proceed;
 phase=0;
 proceed=true;
 while (proceed==true) {
+  (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);
@@ -207,37 +208,31 @@ while (proceed==true) {
 /*      Waiting and handling smtp request               */
 /*                                                     */
 /********************************************************/
-PUBLIC void rec_handlesmtp()
+PUBLIC void rec_handlesmtp(const char *ipnum,const char *port,int nbrbind)
 
 {
 #define OPEP    "modrec.c:rec_handlesmtp"
-#define LINE    "---------------------------------"
 
 pid_t *childs;
-int nbrbind;
 SOCPTR **bindings;
 int phase;
 _Bool proceed;
 
 childs=(pid_t)0;
 bindings=(SOCPTR **)0;
-bindings=soc_mkbindinf(bindings,pro_smtps,"192.219.254.70","1465",3);
-bindings=soc_mkbindinf(bindings,pro_smtp,"192.219.254.70","1025",3);
-//bindings=soc_mkbindinf(bindings,pro_smtp,"192.219.254.70","1587",3);
-nbrbind=rou_nbrlist((void **)bindings);
 phase=0;
 proceed=true;
-if (nbrbind==0) {
-  (void) rou_alert(0,"No bindings definition found! (config?)");
-  proceed=false; 
-  }
 while (proceed==true) {
   switch (phase) {
-    case 0      :       //looping forever email receiving processes
-      (void) rou_alert(0,LINE);
+    case 0      :       //preparing iteration
       (void) prc_settitle("Emlrec Daemon");
-      (void) rou_alert(0,"Starting 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);
+        phase=999;
+        }
       break;
     case 1      :       //Opening ALL channels
       for (int i=0;i<nbrbind;i++) {
@@ -248,7 +243,7 @@ while (proceed==true) {
           childs[i]=(pid_t)0;
         }
       break;
-    case 2      :       //starting restarting all waiter process
+    case 2      :       //starting/restarting all waiting process
       for (int i=0;i<nbrbind;i++) {
         int offset;
 
@@ -270,20 +265,18 @@ 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
-      (void) rou_alert(0,"Stopping Emlrec daemon");
-      (void) rou_alert(0,LINE);
       if (childs!=(pid_t *)0)
         (void) free(childs);
+      bindings=soc_freebindinf(bindings);
       proceed=false;
       break;
     }
   phase++;
   }
-bindings=soc_freebindinf(bindings);
-#undef  LINE
 #undef  OPEP
 }
 /*
index 1c2e4bbfb37c686ea7ac08caf52813f59ee35c6d..490fe9f97e655fb6fafc6e505746d85fc5e91176 100644 (file)
@@ -10,7 +10,7 @@
 #include        <stdbool.h>
 
 //procedure to receive email form outside
-extern void rec_handlesmtp();
+extern void rec_handlesmtp(const char *ipnum,const char *port,int nbrbind);
 
 //homework to be done before starting/stoping module.
 extern int rec_modemodrec(_Bool mode);