From: Jean-Marc Pigeon (Delson) Date: Mon, 2 Sep 2024 02:28:12 +0000 (-0400) Subject: Starting to have the new test program "valide" to work X-Git-Tag: tag-0.4.2-end~8 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=69ad47120d07ef4ba8eb92ff2a5ca27aeb39860a;p=jmp%2Fmailleur Starting to have the new test program "valide" to work --- diff --git a/Makefile b/Makefile index 3919fb5..a37a63b 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,8 @@ clean : #-------------------------------------------------------------------- #test procedure #-------------------------------------------------------------------- -test : prod - @ echo $@ need to implemented +test : clean debug + @ bin/valide data-tst/spf.tst #-------------------------------------------------------------------- #Installation procedure diff --git a/app/valide.c b/app/valide.c index 8bc801c..3fc4771 100644 --- a/app/valide.c +++ b/app/valide.c @@ -84,7 +84,7 @@ return status; /* Procedure to scan a line from the test file */ /* */ /********************************************************/ -static int scanline(char *filename,FILE *fichier) +static int scanlines(char *testname,FILE *fichier) { #define MAX 300 @@ -126,7 +126,7 @@ while (fgets(line,sizeof(line),fichier)!=(char *)0) { } if (status!=0) { (void) rou_alert(0,"SPF fail in file <%s> in line='%03d'", - filename,num); + testname,num); (void) rou_alert(0,"\t for domain <%s> peerip=<%s>", domain,peerip); } @@ -139,41 +139,38 @@ return status; */ /********************************************************/ /* */ -/* Procedure to scan one file stop at soon test */ -/* line is not successful. */ +/* Procedure to scan one file, return -1 if a test */ +/* is not successfull, zero otherwise. */ /* */ /********************************************************/ -static int scantest(char *testfile) +static int scantest(char *tfile) { +#define OPEP "valide.c:scantest" + int status; -char *rootname; FILE *fichier; int phase; _Bool proceed; status=-1; -rootname=rou_apppath(testfile); phase=0; proceed=true; while (proceed==true) { + (void) rou_alert(0,"%s phase='%d'",OPEP,phase); switch (phase) { - case 0 : //using root directory if need - if ((fichier=fopen(rootname,"r"))==(FILE *)0) { - (void) rou_alert(0,"Unable to open file <%s> (error=<%s>)", - rootname,strerror(errno)); - phase=999; //no need to go further + case 0 : //opening the file + if ((fichier=fopen(tfile,"r"))==(FILE *)0) { + (void) rou_alert(0,"%s Unable to open file <%s> (error=<%s>)", + OPEP,tfile,strerror(errno)); + phase=999; } break; case 1 : //scan the file - (void) rou_alert(0,"scanning test file <%s>",rootname); - status=scanline(rootname,fichier); - if (status==0) - (void) rou_alert(0,"\t Test OK"); + status=scanlines(tfile,fichier); break; case 2 : //scan the file (void) fclose(fichier); - status=0; break; default : //SAFE guard proceed=false; @@ -181,7 +178,6 @@ while (proceed==true) { } phase++; } -rootname=rou_freestr(rootname); return status; } /* @@ -197,11 +193,47 @@ static int testfiles(ARGTYP *params) { int status; +char *curdir; status=0; +curdir=getcwd((char *)0,0); for (int i=0;iargc;i++) { - (void) scantest(params->argv[i]); + char *basedir; + char *fname; + char *ptr; + + basedir=strdup(""); + fname=strdup(params->argv[i]); + ptr=strrchr(fname,'/'); + if (ptr!=(char *)0) { + *ptr='\000'; + (void) free(basedir); + basedir=strdup(fname); + ptr++; + (void) strcpy(fname,ptr); + } + if (strlen(basedir)>0) { + if (chdir(basedir)<0) { + (void) rou_alert(0,"%s Unable to chdir to <%s> (error=<%s>)", + OPEP,basedir,strerror(errno)); + fname=rou_freestr(fname); + basedir=rou_freestr(basedir); + continue; + } + } + status=scantest(fname); + if (chdir(curdir)<0) + (void) rou_alert(0,"%s Unable to return <%s> (error=<%s>) (Bug?)", + OPEP,curdir,strerror(errno)); + fname=rou_freestr(fname); + basedir=rou_freestr(basedir); + if (status<0) { + (void) rou_alert(0,"%s, <%s> test is no successfull exiting", + OPEP,params->argv[i]); + break; + } } +curdir=rou_freestr(curdir); return status; } /* diff --git a/lib/subrou.c b/lib/subrou.c index 89f78bc..7b121bf 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.4.2" -#define RELEASE "27" +#define RELEASE "28" //Public variables PUBLIC int debug=0; //debug level