]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Startied the sorter implementation (reading directory)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 11 May 2025 00:56:36 +0000 (20:56 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sun, 11 May 2025 00:56:36 +0000 (20:56 -0400)
Makefile
app/sorter.c
lib/unieml.c
lib/unieml.h

index 303d8db45d8b8f849275e8efb4ce54d8fbb3e826..638e42026923bcdcb5148b891bc65780c3eea0d6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,14 @@ TESTPORT=    1025
 EXTIP  =       safemail3.safe.ca
 EXTPORT =      25
 TESTITER=      4
+#--------------------------------------------------------------------
+#To test sorter
+sorter :       clean debug
+               @ bin/sorter                            \
+                  -d 2                                 \
+                  -c ./conf/feeder.conf.dvl            \
+                  -r $(TESTDIR) 
+
 #--------------------------------------------------------------------
 #testing feed
 FEEDPAR        =                                               \
@@ -51,7 +59,7 @@ extfeed       :       debug
                        -c ./conf/feeder.conf.dvl       \
                        $(EXTIP)                        \
                        $(EXTPORT)                      \
-                       $(DATATST)/extfeed00.tst
+                       ./$(DATATST)/extfeed00.tst
 
 onefeed        :  debug
            bin/feeder                                  \
@@ -60,7 +68,7 @@ onefeed       :  debug
                        -c ./conf/feeder.conf.dvl       \
                        $(TESTIP)                       \
                        $(TESTPORT)                     \
-                       $(DATATST)/xxfeed.tst
+                       ./$(DATATST)/xxfeed.tst
 
 #                      # -i 127.63.31.15
 
@@ -80,7 +88,7 @@ dbgfeed       :  debug
                          -c ./conf/feeder.conf.dvl     \
                          $(TESTIP)                     \
                          $(TESTPORT)                   \
-                         $(DATATST)/xxfeed.tst
+                         $./(DATATST)/xxfeed.tst
 
 valfeed        :  debug                        #valgring of emlrcvr
           @ echo "feed valgrind test"
@@ -93,7 +101,7 @@ valfeed      :  debug                        #valgring of emlrcvr
                          -c ./conf/feeder.conf.dvl     \
                          $(TESTIP)                     \
                          $(TESTPORT)                   \
-                         $(DATATST)/feed00.tst
+                         ./$(DATATST)/xxfeed.tst
 
             
 #              --track-fds=yes                         \
@@ -238,8 +246,8 @@ newtest     :  deltest
                bin                                     \
                $(TESTDIR)/$(SBINDIR)
           @ cp -a                                      \
-               $(DATATST)                              \
-               $(TESTDIR)
+               data-queue/*                            \
+               $(TESTDIR)/var/spool/$(APPNAME)/queue
 
 deltest        :  
           @ rm -fr $(TESTDIR)
index 150d994c8283af5dfc89fc8f7bb13ac85053e1c9..4bd855a183922966f235fdc023959509090f6967 100644 (file)
@@ -8,16 +8,28 @@
 /*              feeder ip port [file1 file2...]         */
 /*                                                     */
 /********************************************************/
+#include        <dirent.h>
 #include        <stdlib.h>
 #include        <syslog.h>
 #include        <unistd.h>
 
 #include       "subrou.h"
-#include       "unisig.h"
+#include       "unieml.h"
 #include       "unipar.h"
+#include       "unisig.h"
 
 #define SORTER  "sorter"        //application name
 
+//structure to build a email directive
+typedef struct  {
+        char code;      //Transaction code
+        u_long date;    //Transaction date
+        u_int delay;    //Transaction execution delay
+        char *sessid;   //session id
+        char *mailfrom; //EMail Originator
+        char *recptto;  //EMail Recipient
+        }TRATYP;
+
 /********************************************************/
 /*                                                     */
 /*     procedure to scan all files                     */
@@ -27,12 +39,16 @@ static _Bool scantrans()
 
 {
 _Bool status;
+char **list;
 
 status=false;
-(void) sleep(2);
+list=(char **)0;
 (void) rou_alert(0,"JMPDBG sorter");
-(void) sleep(5);
+if ((list=eml_getqfilelist(".trans"))!=(char **)0) {
+  list=(char **)rou_freelist((void *)list,(freehandler_t)rou_freestr); 
+  }
 status=true;
+(void) sleep(5);
 return status;
 }
 /*
@@ -71,11 +87,12 @@ while (proceed==true) {
       (void) rou_modesubrou(true);
       (void) sig_modeunisig(true);
       (void) rou_setappname(SORTER);
-      (void)  rou_loadconfig(config,true);
+      (void) rou_loadconfig(config,true);
       (void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
       (void) closelog();
       break;
     case 2      :       //Scanning all file             
+      phase--;          //Looping on same phase
       if ((hangup==true)||(reload==true))
         phase=999;      //Process 
       if (scantrans()==false)
index babf6dfe30c577a426b9a9da25165c5a3de14d8c..ac36df16470842899d14873de3110ac056785b85 100644 (file)
@@ -5,6 +5,7 @@
 /*     exchange.                                       */
 /*                                                     */
 /********************************************************/
+#include        <dirent.h>
 #include        <errno.h>
 #include        <fcntl.h>
 #include        <stdbool.h>
@@ -276,6 +277,81 @@ return status;
 */
 /********************************************************/
 /*                                                      */
+/*     Procedure to list all file with a specific      */
+/*      extension with the queue directory.             */
+/*      Return a list or NULL if no file.               */
+/*                                                      */
+/********************************************************/
+PUBLIC char **eml_getqfilelist(char *ext)
+
+{
+#define OPEP    "unieml.c:eml_getqfilelist"
+
+char **dirlst;
+DIR *dir;
+int phase;
+_Bool proceed;
+
+dirlst=(char **)0;
+dir=(DIR *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+  switch (phase) {
+    case 0      :        //lets open the queue directory
+      char *dirname;
+
+      dirname=rou_apppath(QDIR);
+      if ((dir=opendir(dirname))==(DIR *)0) {
+        (void) rou_alert(0,"%s Unable to open director <%s> (error=<%s>, config?)",
+                            OPEP,dirname,strerror(errno));
+        phase=999;      //No need to go further
+        }
+      dirname=rou_freestr(dirname);
+      break;
+    case 1      :       //scanning directory contents
+      struct dirent *data;
+      register int taille;
+
+      taille=0;
+      if (ext!=(char *)0)
+        taille=strlen(ext);
+      while ((data=readdir(dir))!=(struct dirent *)0) {
+        register char *ptr;
+  
+        ptr=data->d_name;
+        if (taille>0) {
+          ptr=strstr(data->d_name,ext);
+          if ((ptr!=(char *)0)&&(strlen(ptr)!=taille)) 
+            ptr=(char *)0;
+          }
+        if (ptr!=(char *)0) {
+          (void) rou_alert(0,"%s JMPDBG got <%s>",OPEP,data->d_name);
+          dirlst=(char **)rou_addlist((void **)dirlst,(void *)strdup(data->d_name));
+          }
+        }
+      break;
+    case 2      :       //closing directory
+      if (closedir(dir)<0) {
+        (void) rou_alert(0,"%s Unable to close queue directory (error=<%s>, bug?)",
+                            OPEP,strerror(errno));
+        }
+      break;
+    default     :       //SAFE Guard
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+return dirlst;
+#undef  OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
 /*     Procedure to store an email to a list of email  */
 /*      retune true if successful, false otherwise.     */
 /*                                                      */
index 01343d0bc4f4e25db6703f164e34203f2de71ada..68e90c4bba9146706d0168e122dffb07c9aa8487 100644 (file)
@@ -57,6 +57,13 @@ extern FILE *eml_createqfile(char *qfilename,char *ext);
 //procedure to close a file within the queue directory
 extern int eml_closeqfile(FILE *qfile);
 
+//Procedure to list all file within queue directory
+//and with a specific extenstion
+extern char **eml_getqfilelist(char *ext);
+
+//procedure to open a specific qfile
+extern FILE *eml_openqfile(char *qfilename);
+
 //procedure to add an email address to a chain
 //of email address
 extern _Bool eml_addemail(char ***emails,char *email);