From: Jean-Marc Pigeon (Delson) Date: Tue, 10 Jun 2025 10:28:47 +0000 (-0400) Subject: Able to add response information to transaction (TRATYP) record X-Git-Tag: tag-0.8~38 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=0c160ddac4b27a3f59cd64011a478b713bb8c29e;p=jmp%2Fmailleur Able to add response information to transaction (TRATYP) record --- diff --git a/lib/geseml.c b/lib/geseml.c index b6c11e8..530c4f5 100644 --- a/lib/geseml.c +++ b/lib/geseml.c @@ -144,7 +144,8 @@ static void print_tra(FILE *qfile,char *line,char *temps) if (qfile==(FILE *)0) (void) rou_alert(0,"TRA=<%s>",line); else { - (void) fprintf(qfile,"%s\n",temps); + if (temps!=(char *)0) + (void) fprintf(qfile,"%s\n",temps); (void) fprintf(qfile,"%s\n",line); } } @@ -160,6 +161,7 @@ else { PUBLIC _Bool eml_dump_one_tra(FILE *qfile,TRATYP *tra) { +#define OPEP "geseml.c:eml_dump_one_tra," _Bool status; status=false; @@ -179,8 +181,20 @@ if (tra!=(TRATYP *)0) { tra->rcptto ); (void) print_tra(qfile,line,temps); + if (tra->resp!=(char **)0) { + char **ptr; + + ptr=tra->resp; + while (*ptr!=(char *)0) { + (void) rou_alert(0,"%s JMPDBG ptr=<%s>",OPEP,*ptr); + (void) snprintf(line,sizeof(line),"\t%s",*ptr); + (void) print_tra(qfile,line,(char *)0); + ptr++; + } + } } return status; +#undef OPEP } /* @@ -288,10 +302,13 @@ PUBLIC TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile) { #define OPEP "geseml.c:eml_scanqfile," +#define FMT "%c %ld %d %s %s %s" +TRATYP *cur; //previous trans record char *ptr; char line[300]; +cur=(TRATYP *)0; while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) { char id[300]; char from[100]; @@ -309,27 +326,44 @@ while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) { case 0 : //Removing comment if ((ptr=strchr(line,'#'))!=(char *)0) *ptr='\000'; + (void) rou_stripcrlf(line); if (strlen(line)==0) phase=999; //No data within line break; case 1 : //scanning line contents - if (sscanf(line,"%c %ld %d %s %s %s",&code,&date,&delay,id,from,to)!=6) { - (void) rou_alert(0,"%s Unable to scan (config?)",OPEP,line); - phase=999; //No data within line + switch (line[0]) { + case '\t' : //extra response line + (void) rou_alert(0,"%s JMPDBG extra=<%s> cur='%p'",OPEP,line,cur); + if ((cur!=(TRATYP *)0)&&(strlen(line)>1)) + cur->resp=(char **)rou_addlist((void **)cur->resp,strdup(line+1)); + phase=999; //not a scanable trans line + break; + case 'C' : //Directives + case 'L' : + case 'R' : + case 'W' : + if (sscanf(line,FMT,&code,&date,&delay,id,from,to)!=6) { + (void) rou_alert(0,"%s Unable to scan (config?)",OPEP,line); + phase=999; //No data within line + } + break; + default : + (void) rou_alert(0,"%s Unexpected code within (config?)", + OPEP,line); + phase=999; //No data within line + break; } break; case 2 : //scanning line contents if (strlen(id)>0) { //always? - TRATYP *tra; - - tra=(TRATYP *)calloc(1,sizeof(TRATYP)); - tra->code=code; - tra->date=date; - tra->delay=delay; - tra->sessid=strdup(id); - tra->mailfrom=strdup(from); - tra->rcptto=strdup(to); - list=(TRATYP **)rou_addlist((void **)list,(void *)tra); + cur=(TRATYP *)calloc(1,sizeof(TRATYP)); + cur->code=code; + cur->date=date; + cur->delay=delay; + cur->sessid=strdup(id); + cur->mailfrom=strdup(from); + cur->rcptto=strdup(to); + list=(TRATYP **)rou_addlist((void **)list,(void *)cur); } break; default : //SAFE Guard diff --git a/lib/lvleml.c b/lib/lvleml.c index a01b4d1..ff816fe 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -1046,8 +1046,9 @@ while (proceed==true) { (*dest)->sendcode=rspcode; break; case UKNUSER : //originator accepted - (*dest)->code='C'; //completed (Temporary JMPDBG); + (*dest)->code='W'; //Need to send a Warning (*dest)->sendcode=rspcode; + (*dest)->resp=(char **)rou_addlist((void **)(*dest)->resp,strdup("bigre")); break; default : //Not accepted recipient (void) rou_alert(0,"%s sessid=<%s>, unknwon code='%d'", diff --git a/lib/subrou.c b/lib/subrou.c index d33cde7..cb5777f 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -261,6 +261,35 @@ if (str!=(char *)0) { } return str; } +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to get rid of any \r or \n at the end */ +/* of a string. */ +/* */ +/********************************************************/ +char *rou_stripcrlf(char *line) + +{ +if (line!=(char *)0) { + register int taille; + register char *ptr; + + taille=strlen(line)-1; + ptr=line+taille; + while ((*ptr=='\n') || (*ptr=='\r')) { + *ptr='\000'; + taille--; + if (taille<0) + break; + ptr--; + } + } +return line; +} + /* */ diff --git a/lib/subrou.h b/lib/subrou.h index bba6e83..281dd30 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -58,6 +58,9 @@ extern const char *rou_getversion(); //a NULL pointer extern char *rou_freestr(char *str); +//procedure to remove '\r' or '\n' at end of a line +extern char *rou_stripcrlf(char *line); + //to return the number of element within a list extern int rou_nbrlist(void **list);