../lib/subrou.h
sorter.o: sorter.c \
+ ../lib/geseml.h \
../lib/subrou.h
toremake: Makefile $(LIBAI)
#include "unieml.h"
#include "unipar.h"
#include "unisig.h"
+#include "geseml.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 */
static _Bool scantrans()
{
+#define OPEP "sorter.c:scantrans,"
+
_Bool status;
-char **list;
+char **fname;
+TRATYP **trans;
+int phase;
+_Bool proceed;
status=false;
-list=(char **)0;
-(void) rou_alert(0,"JMPDBG sorter");
-if ((list=eml_getqfilelist(".trans"))!=(char **)0) {
- list=(char **)rou_freelist((void *)list,(freehandler_t)rou_freestr);
+fname=(char **)0;
+trans=(TRATYP **)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //Getting the list of file
+ fname=eml_getqfilelist(fname,".trans");
+ fname=eml_getqfilelist(fname,".todo");
+ if (fname==(char **)0)
+ phase=999; //Nothing to do
+ break;
+ case 1 : //Building the "trans" list
+ if (fname!=(char **)0) { //walways
+ char **ptr;
+
+ ptr=fname;
+ while (*ptr!=(char *)0) {
+ FILE *qfile;
+
+ (void) rou_alert(0,"%s fame=<%s>",OPEP,*ptr);
+ if ((qfile=eml_openqfile(*ptr))!=(FILE *)0) {
+ trans=eml_scanqfile(trans,qfile);
+ }
+ ptr++;
+ }
+ fname=(char **)rou_freelist((void *)fname,(freehandler_t)rou_freestr);
+ }
+ break;
+ case 2 : //Cscanning translit
+ if (trans!=(TRATYP **)0) {
+ TRATYP **ptr;
+
+ ptr=trans;
+ while (*ptr!=(TRATYP *)0) {
+ (void) eml_dumptra(*ptr);
+ ptr++;
+ }
+ trans=(TRATYP **)rou_freelist((void **)trans,(freehandler_t)eml_freetra);
+ status=true;
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
}
-status=true;
-(void) sleep(5);
return status;
+#undef OPEP
}
/*
\f
OBJS= \
modrec.o \
lvleml.o \
- gesspf.o gestcp.o \
+ gesspf.o gestcp.o geseml.o \
devlog.o devsoc.o devsql.o \
unidns.o unieml.o unipos.o \
unipar.o uniprc.o unisig.o unitls.o \
subrou.h \
gesspf.h gesspf.h
+geseml.o: \
+ subrou.h \
+ geseml.h geseml.h
+
gestcp.o: \
subrou.h \
unieml.h \
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Implement all routine to manage email transport */
+/* exchange. */
+/* */
+/********************************************************/
+#include <string.h>
+
+#include "subrou.h"
+#include "geseml.h"
+
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to display/debug TRATYP record content*/
+/* */
+/********************************************************/
+PUBLIC void eml_dumptra(TRATYP *tra)
+
+{
+if (tra!=(TRATYP *)0) {
+ (void) rou_alert(0,"TRA-> %c,%lu,%u %s %s %s",
+ tra->code,
+ tra->date,
+ tra->delay,
+ tra->sessid,
+ tra->mailfrom,
+ tra->rcptto
+ );
+ }
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to free memory used by a TRATYP record*/
+/* */
+/********************************************************/
+PUBLIC TRATYP *eml_freetra(TRATYP *trans)
+
+{
+if (trans!=(TRATYP *)0) {
+ trans->rcptto=rou_freestr(trans->rcptto);
+ trans->mailfrom=rou_freestr(trans->mailfrom);
+ trans->sessid=rou_freestr(trans->sessid);
+ (void) free(trans);
+ trans=(TRATYP *)0;
+ }
+return trans;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to scan the a qfile and build a */
+/* list of email transport directive. */
+/* */
+/********************************************************/
+PUBLIC TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile)
+
+{
+#define OPEP "geseml.c:eml_scanqfile,"
+
+char *ptr;
+char line[300];
+
+while ((ptr=fgets(line,sizeof(line),qfile))!=(char *)0) {
+ char id[300];
+ char from[100];
+ char to[100];
+ char code;
+ u_long date;
+ u_int delay;
+ int phase;
+ _Bool proceed;
+
+ phase=0;
+ proceed=true;
+ while (proceed==true) {
+ switch (phase) {
+ case 0 : //Removing comment
+ if ((ptr=strchr(line,'#'))!=(char *)0)
+ *ptr='\000';
+ 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 <%s> (config?)",OPEP,line);
+ phase=999; //No data within line
+ }
+ 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);
+ (void) eml_dumptra(tra);
+ list=(TRATYP **)rou_addlist((void **)list,(void *)tra);
+ }
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+ }
+return list;
+#undef OEP
+}
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Define all procedure to manage email transport */
+/* data. */
+/* */
+/********************************************************/
+#ifndef GESEML
+#define GESEML
+
+#include <stdlib.h>
+#include <stdio.h>
+
+//structure to define an email transport 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 *rcptto; //EMail Recipient
+ }TRATYP;
+
+//procedure to dump a transfert record (debug purpose)
+extern void eml_dumptra(TRATYP *tra);
+
+//procedure to fee memory used by a TRATYP structure
+extern TRATYP *eml_freetra(TRATYP *tra);
+
+//procedure to open a specific qfile
+extern TRATYP **eml_scanqfile(TRATYP **list,FILE *qfile);
+
+#endif
/* DNS record. */
/* */
/********************************************************/
-#ifndef GESTSPF
-#define GESTSPF
+#ifndef GESSPF
+#define GESSPF
#include "subafn.h"
/* Return a list or NULL if no file. */
/* */
/********************************************************/
-PUBLIC char **eml_getqfilelist(char *ext)
+PUBLIC char **eml_getqfilelist(char **dnames,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;
}
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));
+ dnames=(char **)rou_addlist((void **)dnames,(void *)strdup(data->d_name));
}
}
break;
}
phase++;
}
-return dirlst;
+return dnames;
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to open a fine within the MTA queue */
+/* directory. */
+/* */
+/********************************************************/
+PUBLIC FILE *eml_openqfile(char *qfilename)
+
+{
+#define OPEP "unieml.c:eml_openqfile,"
+
+FILE *qfile;
+char *dirname;
+char fullname[300];
+
+qfile=(FILE *)0;
+dirname=rou_apppath(QDIR);
+(void) snprintf(fullname,sizeof(fullname),"%s/%s",dirname,qfilename);
+if ((qfile=fopen(fullname,"r"))==(FILE *)0) {
+ (void) rou_alert(0,"%s Unable to open file <%s> (error-<%s> bug?)",
+ OPEP,fullname,strerror(errno));
+ }
+dirname=rou_freestr(dirname);
+return qfile;
#undef OPEP
}
/*
//Procedure to list all file within queue directory
//and with a specific extenstion
-extern char **eml_getqfilelist(char *ext);
+extern char **eml_getqfilelist(char **dnames,char *ext);
//procedure to open a specific qfile
extern FILE *eml_openqfile(char *qfilename);