/* */
/********************************************************/
#include <dirent.h>
+#include <errno.h>
#include <string.h>
+#include <unistd.h>
#include <uuid/uuid.h>
#include "subrou.h"
#include "unieml.h"
+#include "unipar.h"
#include "geseml.h"
//dovecot local storage directory
/* Procedure to display/debug TRATYP record content*/
/* */
/********************************************************/
-PUBLIC void eml_dumptra(FILE *qfile,TRATYP **tra)
+PUBLIC _Bool eml_dumptra(FILE *qfile,TRATYP **tra)
{
+_Bool action;
+
+action=false;
if (tra!=(TRATYP **)0) {
+ time_t isnow;
+
+ isnow=time((time_t *)0);
if (qfile!=(FILE *)0) {
(void) fprintf(qfile,"#'C', completed email task\n");
(void) fprintf(qfile,"#'L', Local email\n");
(*tra)->mailfrom,
(*tra)->rcptto
);
+ if (((*tra)->date+(*tra)->delay)<=isnow)
+ action=true;
if (qfile==(FILE *)0) {
(void) rou_alert(0,"TRA=<%s>",line);
}
tra++;
}
}
+return action;
}
/*
\f
ptr=domlist;
while (*ptr!=(REFTYP *)0) {
FILE *qfile;
+ _Bool action;
+ const char *ext;
char qname[150];
int phase;
_Bool proceed;
qfile=(FILE *)0;
+ action=false;
+ ext=EXTRANS;
(void) snprintf(qname,sizeof(qname),"%s-%s-%04d",(*ptr)->domain,buffer,iter);
phase=0;
proceed=true;
phase=999; //Trouble trouble
break;
case 1 : //dumping TRANS data to file
- (void) eml_dumptra(qfile,(*ptr)->todo);
+ if ((action=eml_dumptra(qfile,(*ptr)->todo))==true)
+ ext=EXTODO;
break;
case 2 : //Closing file
(void) eml_closeqfile(qfile);
break;
case 3 : //file ready, renaming file,
- (void) eml_renameqfile(qname,EXTOBE,EXTODO);
+ (void) eml_renameqfile(qname,EXTOBE,ext);
+ break;
+ case 4 : //do we need to start sender
+ if (action==true) {
+ (void) eml_start_sender(qname);
+ }
break;
default : //SAFE Guard
proceed=false;
}
return status;
}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to fork process and execute the */
+/* "sender" component. */
+/* */
+/********************************************************/
+PUBLIC _Bool eml_start_sender(char *todo)
+
+{
+#define OPEP "unieml.c:eml_start_sender,"
+
+_Bool status;
+
+status=false;
+switch (fork()) {
+ case -1 : //trouble trouble
+ (void) rou_alert(0,"%s Unable to fork process (error=<%s> Bug?)",
+ OPEP,strerror(errno));
+ break;
+ case 0 : //the forked process
+ int exitval;
+ char *xx;
+ char *rootpath;
+ char *execpath;
+ char buffer[300];
+
+ exitval=0;
+ rootpath=(char *)0;
+ xx=(char *)0;
+ if (rootdir!=(char *)0) {
+ xx="-r";
+ rootpath=rootdir;
+ }
+ (void) snprintf(buffer,sizeof(buffer),"%s%s",SBINDIR,SENDER);
+ execpath=rou_apppath(buffer);
+ (void) snprintf(buffer,sizeof(buffer),"%s.%s",todo,EXTODO);
+ (void) rou_alert(0,"%s JMPDBG starting sender=<%s> testing=<%s> todo= <%s>",OPEP,execpath,rootpath,buffer);
+ if (execl(execpath,"Bigre","-c",config,buffer,xx,rootpath,(char *)0)<0) {
+ (void) rou_alert(0,"%s Unable to exec process=<%s> (error=<%s> Bug?)",
+ OPEP,execpath,strerror(errno));
+ exitval=-1;
+ }
+ (void) exit(exitval);
+ break;
+ default : //the forking process itself
+ (void) usleep(10000); //relax delay
+ status=true;
+ break;
+ }
+return status;
+#undef OPEP
+}
PUBLIC void rou_loadconfig(char *conffile,_Bool load)
{
+#define OPEP "subrou.c:rou_loadconfig,"
+
FILE *fichier;
char line[200];
char *name;
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));
+ char cwd[PATH_MAX];
+
+ (void) getcwd(cwd, sizeof(cwd));
+ (void) fprintf(stdout,"%s exiting!, Unable to open file <%s> "
+ "within <%s> (error=<%s>)\n",
+ OPEP,conffile,cwd,strerror(errno));
(void) exit(-1);//Big Trouble
}
break;
}
phase++;
}
+#undef OPEP
}
/*
^L