]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Able to load config file
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 5 May 2025 00:40:37 +0000 (20:40 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 5 May 2025 00:40:37 +0000 (20:40 -0400)
Makefile
app/emlrcvr.c
conf/feeder.conf.dvl [new file with mode: 0644]
conf/mailleur.conf
conf/mailleur.conf.dvl [new file with mode: 0644]
lib/subrou.c
lib/subrou.h
lib/unipar.c
lib/unipar.h

index 8f7c32281968837908d1175c838adcaef8fea029..190069c0bc98a540b7d3b200aa839737280fe1da 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,7 @@ TESTITER=     3
 #testing feed
 FEEDPAR        =                                               \
                -d3                                     \
+               -c ./conf/feeder.conf.dvl               \
                $(TESTIP)                               \
                $(TESTPORT)                             \
                $(TESTDIR)/$(DATATST)/feed*.tst         \
@@ -129,6 +130,7 @@ tlsref:
 
 EMLPAR =                                               \
           -r $(TESTDIR)                                \
+          -c ./conf/$(APPNAME).conf.dvl                \
           -d 3                                         \
           $(TESTPROT):$(TESTIP):$(TESTPORT):
 
index 99545948907dc28efd9a14ade2c3332df6879663..6b5de8f06297be580d30c5b6707616ab7b44380c 100644 (file)
@@ -47,13 +47,14 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //checking parameters
-      if ((params=par_getparams(argc,argv,"d:fh:r:v"))==(ARGTYP *)0) {
+      if ((params=par_getparams(argc,argv,"c:d:fh:r: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_loadconfig(config,true);
       (void) rou_modesubrou(true);
       (void) prc_modeuniprc(true);
       (void) sig_modeunisig(true);
@@ -76,6 +77,7 @@ while (proceed==true) {
       (void) sig_modeunisig(false);
       (void) prc_modeuniprc(false);
       (void) rou_modesubrou(false);
+      (void) rou_loadconfig(config,false);
       break;
     default     :       //end of task
       proceed=false;
diff --git a/conf/feeder.conf.dvl b/conf/feeder.conf.dvl
new file mode 100644 (file)
index 0000000..0630506
--- /dev/null
@@ -0,0 +1 @@
+#file used to set environement configuration
index 06305067898c03b3f820d661579cff479c789360..b26d459f836848502507384ea85fcf02f6dc23a5 100644 (file)
@@ -1 +1,7 @@
 #file used to set environement configuration
+#------------------------------------------------
+#Defining Certificate for the application
+CA_ROOT        =       "/etc/pki/mailleur/certs/root-safe_CA.pem"
+CA_CERT        =       "/etc/pki/mailleur/mailleur-chain-cert_x509.pem"
+CA_KEY =       "/etc/pki/mailleur/mailleur-key.pem"
+#------------------------------------------------
diff --git a/conf/mailleur.conf.dvl b/conf/mailleur.conf.dvl
new file mode 100644 (file)
index 0000000..f03c293
--- /dev/null
@@ -0,0 +1,8 @@
+#file used to set environment configuration
+#Used for developpement purpose ONLY
+#------------------------------------------------
+#Defining Certificate
+CA_ROOT        =       "./certs/root-safe_CA.pem"
+CA_CERT        =       "./certs/mailleur_server-chain-cert_x509.pem"
+CA_KEY =       "./certs/mailleur_server-key.pem"
+#------------------------------------------------
index 22aaabb51d48dd04efc43f5df709541f59164f6a..389188f4888d6366718f985a1899a4c0ae1f1524 100644 (file)
@@ -588,6 +588,93 @@ if (doabort==true)
 #undef  COREDELAY
 }
 /*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Procedure to load the configuartion file        */
+/*     message and terminate application               */
+/*                                                     */
+/********************************************************/
+PUBLIC void rou_loadconfig(char *conffile,_Bool load)
+
+{
+FILE *fichier;
+char line[200];
+char *name;
+char *value;
+char *ptr;
+int phase;
+_Bool proceed;
+
+fichier=(FILE *)0;
+(void) memset(line,'\000',sizeof(line));
+name=(char *)0;
+value=(char *)0;
+ptr=(char *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+  switch (phase) {
+    case 0      :       //Opening the config file
+      if ((fichier=fopen(conffile,"r"))==(FILE *)0) {
+        (void) fprintf(stdout,"exiting!, Unable to open file <%s> (error=<%s>)\n",
+                              conffile,strerror(errno));
+        (void) exit(-1);//Big Trouble
+        }
+      break;
+    case 1      :       //scanning file
+      (void) memset(line,'\000',sizeof(line));
+      if ((ptr=fgets(line,sizeof(line)-1,fichier))==(char *)0)
+        phase=999;      //scan terminated 
+      break;
+    case 2      :       //trimming line
+      if ((ptr=strchr(line,'#'))!=(char *)0)
+        *ptr='\000';
+      if ((ptr=strrchr(line,'\n'))!=(char *)0)
+        *ptr='\000';
+      if (strlen(line)==0)
+        phase=0;        //next line
+      break;
+    case 3      :       //Spliting data
+      if ((ptr=strchr(line,'='))==(char *)0)
+        phase=0;        //line without '='
+      break;
+    case 4      :       //set name and value
+      name=line;
+      value=ptr+1;
+      *ptr='\000';
+      while ((ptr=strrchr(name,' '))!=(char *)0)
+        *ptr='\000';
+      while ((ptr=strrchr(name,'\t'))!=(char *)0)
+        *ptr='\000';
+      while ((value[0]==' ')||(value[0]=='\t'))
+        value++;
+      //removing quote if present
+      if (value[0]=='"')
+        value++;
+      if ((ptr=strrchr(value,'"'))!=(char *)0)
+        *ptr='\000';
+      //make sure we have data to set
+      if ((strlen(name)==0)||(strlen(value)==0))
+        phase=0;        //No name or value??
+      break;
+    case 5      :       //set name and value
+      if (load==true) 
+        (void) setenv(name,value,true);
+      else
+        (void) unsetenv(name);
+      phase=0;
+      break;
+    default     :       //SAFE Guard
+      (void) fclose(fichier);
+      proceed=false;
+      break;
+    }
+  phase++;
+  }
+}
+/*
 ^L
 */
 /********************************************************/
index 5c0b5fa6ff920a01bfc7948e7ce22f08ed3ae84c..a647e8fdbf5cba00ce02893723c85c051e14987b 100644 (file)
@@ -94,6 +94,9 @@ extern void rou_crash(const char *fmt,...);
 //with an explication message
 extern void rou_core_dump(const char *fmt,...);
 
+//load/unload environement configuration
+extern void rou_loadconfig(char *conffile,_Bool load);
+
 //homework to be done before starting/stoping module.
 extern int rou_modesubrou(_Bool mode);
 
index 7c9b60945830702d8c3de0c3bf23d554710bbeb8..f57bb53e1ba5cd2d068cb366dbfea7b2f3f52ef4 100644 (file)
@@ -14,6 +14,9 @@
 #include       "subrou.h"
 #include       "unipar.h"
 
+//application default config file
+PUBLIC  char  config[200]="/etc/"APPNAME"/"APPNAME".conf";
+
 /*
 ^L
 */
@@ -45,6 +48,7 @@ static void usage_aid(char *name)
 (void) fprintf(stderr,"usage:\n  ");
 (void) fprintf(stderr,"%s\t"
                  "[-d debug] "
+                 "[-c config] "
                  "[-f] "
                  "[-h] "
                  "[-r root] "
@@ -52,6 +56,7 @@ static void usage_aid(char *name)
                   "\n",name);
 (void) fprintf(stderr,"\twhere:\n");
 (void) fprintf(stderr,"\t\t-d level\t: debug level [1-10]\n");
+(void) fprintf(stderr,"\t\t-c config\t: set config file\n");
 (void) fprintf(stderr,"\t\t-f\t\t: start program in foreground (CLI)  mode\n");
 (void) fprintf(stderr,"\t\t-h\t\t: print this help message\n");
 (void) fprintf(stderr,"\t\t-r root\t\t: root working directory\n");
@@ -111,6 +116,9 @@ else
 opterr=0;               //no error message from getopt library routine
 while (((c=getopt(argc,argv,optstring))!=EOF)&&(params!=(ARGTYP *)0)) {
   switch(c) {
+    case 'c'   :       //config file
+      (void) memset(config,'\000',sizeof(config));
+      (void) strncpy(config,optarg,sizeof(config)-1);
     case 'd'   :       //debug level
       debug=atoi(optarg);
       (void) rou_alert(1,"debug level is now '%d'",debug);
index a66672b037243585f98114b679bece236a148ad2..124e51eaaa59b024339abd8b270242a985173769 100644 (file)
@@ -17,6 +17,8 @@ typedef struct        {
        char **argv;            //list of argument
        }ARGTYP;
 
+extern char           config[]; //Application config file
+
 //free allocated memory used by a ARGTYP structure
 extern ARGTYP *par_freeparams(ARGTYP *params);