From 68f94d37af65cf1c9827f26693ec06b4690bc332 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 15 Jul 2025 15:45:57 -0400 Subject: [PATCH] Adding routine to clean conf file line --- app/scarmt.c | 16 ++------------ conf/relayed.conf | 2 ++ lib/subrou.c | 55 ++++++++++++++++++++++++++++++++++------------- lib/subrou.h | 3 +++ 4 files changed, 47 insertions(+), 29 deletions(-) create mode 100644 conf/relayed.conf diff --git a/app/scarmt.c b/app/scarmt.c index faa1f98..37e3214 100644 --- a/app/scarmt.c +++ b/app/scarmt.c @@ -177,22 +177,10 @@ while (proceed==true) { break; case 2 : //scaning file if (blkfile!=(FILE *)0) { //always - char line[200]; + char line[300]; while (fgets(line,sizeof(line)-1,blkfile)!=(char *)0) { - char *ptr; - int taille; - - if ((ptr=strchr(line,'#'))!=(char *)0) - *ptr='\000'; - taille=strlen(line); - while (taille>0) { - taille--; - ptr=line+taille; - if ((*ptr!=' ')&&(*ptr!='\t')&&(*ptr!='\n')&&(*ptr!='\r')) - break; - *ptr='\000'; - } + (void) rou_clean_conf_line(line); if (strlen(line)>0) { dnsbls=(char **)rou_addlist((void **)dnsbls,(void *)strdup(line)); } diff --git a/conf/relayed.conf b/conf/relayed.conf new file mode 100644 index 0000000..863788a --- /dev/null +++ b/conf/relayed.conf @@ -0,0 +1,2 @@ +#list of IP number which are relayable +127.0.0.1/32 diff --git a/lib/subrou.c b/lib/subrou.c index 5e0015c..a67b747 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -743,6 +743,44 @@ if (doabort==true) { */ /********************************************************/ /* */ +/* Procedure to clean a line form a configuration */ +/* line, removing comment part and end of space */ +/* within the line. */ +/* */ +/********************************************************/ +PUBLIC char *rou_clean_conf_line(char *line) + +{ +if (line!=(char *)0) { + char *ptr; + int taille; + + if ((ptr=strchr(line,'#'))!=(char *)0) + *ptr='\000'; + taille=strlen(line); + while (taille>0) { + taille--; + ptr=line+taille; + switch (*ptr) { + case ' ' : //Space characteres + case '\t' : + case '\r' : + case '\n' : + *ptr='\000'; + break; + default : //end of search + taille=0; + break; + } + } + } +return line; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to load the configuartion file */ /* message and terminate application */ /* */ @@ -753,7 +791,7 @@ PUBLIC void rou_loadconfig(char *conffile,_Bool load) #define OPEP "subrou.c:rou_loadconfig," FILE *fichier; -char line[200]; +char line[300]; char *name; char *value; char *ptr; @@ -786,20 +824,7 @@ while (proceed==true) { 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'; - //cleaning the end of line - if (strlen(line)>0) { - ptr=line+strlen(line)-1; - while (*ptr!='\000') { - if ((*ptr!=' ')&&(*ptr!='\t')) - break; - *ptr='\000'; - ptr--; - } - } + (void) rou_clean_conf_line(line); //check remaining clean line if (strlen(line)==0) phase=0; //next line diff --git a/lib/subrou.h b/lib/subrou.h index d66f26d..d95cb53 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -113,6 +113,9 @@ extern void rou_crash(const char *fmt,...); //with an explication message extern void rou_core_dump(const char *fmt,...); +//clean configuration file line +extern char *rou_clean_conf_line(char *line); + //load/unload environement configuration extern void rou_loadconfig(char *conffile,_Bool load); -- 2.47.3