#define RECNAME "emlrcvr"
//port listening format is "IP:PORT NUMBER:num iteration"
-#define DFLTIP "127.168.0.1" //smtp test IP
-#define SMTPORT "1025" //smtp test port
/*
\f
*/
while (proceed==true) {
switch (phase) {
case 0 : //checking parameters
- if ((params=par_getparams(argc,argv,"d:fhr:v"))==(ARGTYP *)0) {
+ if ((params=par_getparams(argc,argv,"d:fh:r:v"))==(ARGTYP *)0) {
phase=999; //no need to go further
}
break;
(void) sig_trapsignal(true,sig_alrm);
break;
case 2 : //doing main task
- (void) rec_handlesmtp(DFLTIP,SMTPORT,1);
+ (void) rec_handlesmtp(params->argc,params->argv);
break;
case 3 : //doing main tash
(void) prc_cleantitle();
#include "modrec.h"
static _Bool modopen; //boolean module open/close
+#define DFLTIP "127.0.10.25" //smtp test IP
+#define SMTPORT "1025" //smtp test port
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to scan argument and generate binding */
+/* information. */
+/* build a SOCPTR list and return the number of */
+/* entries. */
+/* */
+/* Possible argument format are: */
+/* protocol:ipnum:port:iteration */
+/* example: */
+/* :ipnum::: -> smtp:ipnum:25:1 */
+/* smtps:ipnum:465:2 */
+/* -> smtps protocol,port 465,2 iteration */
+/* */
+/********************************************************/
+static int prepbinding(SOCPTR ***bindings,int argc,char *argv[])
+
+{
+*bindings=(SOCPTR **)0;
+for (int i=0;i<argc;i++) {
+ int iteration;
+ PROTYP proto;
+ char *ipnum;
+ char *port;
+
+ iteration=1;
+ proto=pro_smtp;
+ ipnum=DFLTIP;
+ port=SMTPORT;
+ *bindings=soc_mkbindinf(*bindings,proto,ipnum,port,iteration);
+ }
+return rou_nbrlist(*bindings);
+}
/*
\f
*/
phase=0;
proceed=true;
while (proceed==true) {
- (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
+ //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
switch (phase) {
case 0 : //Opening logs
(void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
/* Waiting and handling smtp request */
/* */
/********************************************************/
-PUBLIC void rec_handlesmtp(const char *ipnum,const char *port,int nbrbind)
+PUBLIC void rec_handlesmtp(int argc,char *argv[])
{
#define OPEP "modrec.c:rec_handlesmtp"
pid_t *childs;
+int nbrbind;
SOCPTR **bindings;
int phase;
_Bool proceed;
childs=(pid_t)0;
+nbrbind=0;
bindings=(SOCPTR **)0;
phase=0;
proceed=true;
while (proceed==true) {
switch (phase) {
case 0 : //preparing iteration
- (void) prc_settitle("Emlrec Daemon");
- (void) rou_alert(0,"Starting Emlrec daemon for ip <%s>",ipnum);
- childs=(pid_t *)calloc(nbrbind,sizeof(pid_t));
- bindings=soc_mkbindinf((SOCPTR **)0,pro_smtp,ipnum,port,nbrbind);
- if (bindings==(SOCPTR **)0) {
- (void) rou_alert(0,"%s, No bindings definition found! (config?)",OPEP);
+ if ((nbrbind=prepbinding(&bindings,argc,argv))==0) {
+ (void) rou_alert(0,"%s, No listening IP found (config?)",OPEP);
phase=999;
}
break;
case 1 : //Opening ALL channels
+ childs=(pid_t *)calloc(nbrbind,sizeof(pid_t));
for (int i=0;i<nbrbind;i++) {
(void) prc_nozombie();
if (childs[i]==(pid_t)0)
phase=0; //Normal process, lets restart
break;
case 4 : //we got a signal, kill all childs
- (void) rou_alert(0,"Stopping Emlrec daemon for ip-<%s>",ipnum);
(void) prc_killchilds(childs,nbrbind,10);
break;
default : //SAFE Guard