]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Starying program emlrec
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 10 Jul 2024 23:15:49 +0000 (19:15 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 10 Jul 2024 23:15:49 +0000 (19:15 -0400)
app/Makefile
app/emlrec.c [new file with mode: 0644]
lib/subrou.c
lib/subrou.h

index 4311de51e16b179509f4cd86fcc124bf80c1094f..7f6fcf53e4eb51bfea9e69202b1b2718b923f7fa 100644 (file)
@@ -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 (file)
index 0000000..e0e14de
--- /dev/null
@@ -0,0 +1,115 @@
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/*                                                     */
+/*     Main SMTP Daemon                                */
+/*                                                     */
+/********************************************************/
+#include       <signal.h>
+#include       <stdlib.h>
+#include       <stdio.h>
+#include       <unistd.h>
+
+#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"
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*      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++;
+  }
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     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);
+}
index 96e34eb2ec04e621b51558ead484c03521fd6231..e4cfd627ccf1e74b76900851f8a29db284ac9024 100644 (file)
@@ -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;
+}
+/*
 \f
 */
 /********************************************************/
@@ -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);
index ec36f11c611858875c6c0c1e06939d72ef8b99b7..06038f17ec8c68b188bc49c5e206226fd7bd7721 100644 (file)
@@ -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);