X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=kernel%2Feti.c;h=de0634b6d013320257306a084e8b7bb8c6a85175;hb=4938d0c2e8f4e1eec397c2bfbbc7e23fd150c369;hp=f5a8b0f900798649cd7c7efb41fb223812497a21;hpb=d9dc334cfdbe42f9acf56266c0bdd53522315304;p=egate.git diff --git a/kernel/eti.c b/kernel/eti.c index f5a8b0f..de0634b 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -45,7 +45,23 @@ * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.13 1995/05/16 09:40:41 adam + * Revision 1.18 1996/03/01 14:25:28 adam + * Email gateway obeys 'Reply-To:' in header. + * + * Revision 1.17 1995/12/20 16:27:24 adam + * Extra parameter block to gw_db_open. + * + * Revision 1.16 1995/07/11 11:49:11 adam + * LINE_MAX renamed to STR_LINE_MAX. + * + * Revision 1.15 1995/07/03 12:59:28 adam + * New option for eti: -c dir to chdir before start. + * Setting change: gw.max.show defaults to 100. + * + * Revision 1.14 1995/05/19 13:25:59 adam + * Bug fixes. Better command line options. + * + * Revision 1.13 1995/05/16 09:40:41 adam * LICENSE. Setting of CCL token names (and/or/not/set) in read_kernel_res. * * Revision 1.12 1995/05/03 07:37:35 adam @@ -104,10 +120,11 @@ #include #include +#include #include #include -#define LINE_MAX 1024 +#define STR_LINE_MAX 1024 static char *module = "eti"; static jmp_buf retry_jmp; @@ -131,6 +148,8 @@ static int email_header (struct str_queue *sq, return 0; if (memcmp (msg, "From ", 5) == 0) sscanf (msg+4, "%s", from_str); + if (memcmp (msg, "Reply-To: ", 10) == 0) + sscanf (msg+10, "%s", from_str); if (memcmp (msg, "Subject: ", 9) == 0 && sscanf (msg+9, "%s", subject_str+1) == 1) strcpy (subject_str, msg+9); @@ -138,7 +157,6 @@ static int email_header (struct str_queue *sq, return 1; } -#if !USE_MONITOR static void start_kernel (int argc, char **argv, int id) { pid_t pid; @@ -173,7 +191,6 @@ static void start_kernel (int argc, char **argv, int id) exit (1); } } -#endif static void deliver (struct str_queue *sq, GIP gip, const char *msg) { @@ -187,9 +204,9 @@ static void deliver (struct str_queue *sq, GIP gip, const char *msg) int main (int argc, char **argv) { - char from_str[LINE_MAX+1]; - char subject_str[LINE_MAX+1]; - char line_str[LINE_MAX+1]; + char from_str[STR_LINE_MAX+1]; + char subject_str[STR_LINE_MAX+1]; + char line_str[STR_LINE_MAX+1]; char msg[20]; GW_DB user_db; GIP gip; @@ -201,17 +218,79 @@ int main (int argc, char **argv) char fifo_client_name[1024]; char fifo_server_name[1024]; struct str_queue *queue; + int monitor_flag = 1; + int argno = 0; gw_log_init (*argv); - gw_log_level (GW_LOG_ALL); - gw_log_file (GW_LOG_ALL, "eti.log"); - + while (++argno < argc) + { + if (argv[argno][0] == '-') + { + if (argv[argno][1] == '-') + { + monitor_flag = 0; + break; + } + switch (argv[argno][1]) + { + case 'h': + case 'H': + fprintf (stderr, "eti [options] -- [kernelOptions]\n"); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -l log Set Log file\n"); + fprintf (stderr, " -d Enable debugging log\n"); + fprintf (stderr, " -D Enable more debugging log\n"); + fprintf (stderr, " -c dir Change to directory\n"); + fprintf (stderr, " -- Precedes kernel options " + "(kernel is invoked instead of monitor)\n"); + exit (1); + case 'l': + if (argv[argno][2]) + gw_log_file (GW_LOG_ALL, argv[argno]+2); + else if (++argno < argc) + gw_log_file (GW_LOG_ALL, argv[argno]); + else + { + fprintf (stderr, "%s: missing log filename\n", *argv); + exit (1); + } + break; + case 'd': + gw_log_level (GW_LOG_ALL & ~RES_DEBUG); + break; + case 'D': + gw_log_level (GW_LOG_ALL); + break; + case 'c': + if (argv[argno][2]) + { + if (chdir (argv[argno]+2)) + gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "chdir"); + } + else if (++argno < argc) + { + if (chdir (argv[argno])) + gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "chdir"); + } + else + { + fprintf (stderr, "%s: missing chdir name\n", *argv); + exit (1); + } + break; + default: + fprintf (stderr, "%s: unknown option `%s'; use -H for help\n", + *argv, argv[argno]); + exit (1); + } + } + } if (!(queue = str_queue_mk ())) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, module, "str_queue_mk"); exit (1); } - while (fgets (line_str, LINE_MAX, stdin)) + while (fgets (line_str, STR_LINE_MAX, stdin)) str_queue_enq (queue, line_str); r = email_header (queue, from_str, subject_str); @@ -221,7 +300,7 @@ int main (int argc, char **argv) exit (1); } gw_log (GW_LOG_STAT, module, "Mail from %s", from_str); - user_db = gw_db_open ("user.db", 1); + user_db = gw_db_open ("user.db", 1, 1); r = gw_db_lookup (user_db, from_str, strlen(from_str), &user_info, &info_length); @@ -248,13 +327,16 @@ int main (int argc, char **argv) gw_log (GW_LOG_FATAL, module, "gw_db_lookup fail"); exit (1); } -#if USE_MONITOR - sprintf (fifo_server_name, "fifo.s.m"); - sprintf (fifo_client_name, "fifo.c.m"); -#else - sprintf (fifo_server_name, "fifo.s.%d", id); - sprintf (fifo_client_name, "fifo.c.%d", id); -#endif + if (monitor_flag) + { + sprintf (fifo_server_name, "fifo.s.m"); + sprintf (fifo_client_name, "fifo.c.m"); + } + else + { + sprintf (fifo_server_name, "fifo.s.%d", id); + sprintf (fifo_client_name, "fifo.c.%d", id); + } gip = gipc_initialize (fifo_client_name); @@ -264,30 +346,25 @@ int main (int argc, char **argv) signal (SIGPIPE, pipe_handle); gw_log (GW_LOG_DEBUG, module, "Pass %d", pass); if (pass == 1) + { + gipc_close (gip); r = gipc_open (gip, fifo_server_name, 0); + } else if (pass == 2) { -#if USE_MONITOR - gw_log (GW_LOG_FATAL, module, "Cannot contact monitor"); - exit (1); -#else -#if 0 - gipc_close (gip); - gipc_destroy (gip); - unlink (fifo_server_name); - unlink (fifo_client_name); - gip = gipc_initialize (fifo_client_name); -#endif - + if (monitor_flag) + { + gw_log (GW_LOG_FATAL, module, "Cannot contact monitor"); + exit (1); + } mknod (fifo_server_name, S_IFIFO|0666, 0); - start_kernel (argc, argv, id); + start_kernel (argc-argno, argv+argno, id); r = gipc_open (gip, fifo_server_name, 1); } else if (pass == 3) { gw_log (GW_LOG_FATAL, module, "Cannot start kernel"); exit (1); -#endif } if (r < 0) if (r == -2) @@ -307,11 +384,10 @@ int main (int argc, char **argv) } /* deliver message ... */ gw_log (GW_LOG_DEBUG, module, "Delivering mail"); -#if USE_MONITOR - sprintf (msg, "eti %d\n", id); -#else - strcpy (msg, "mail\n"); -#endif + if (monitor_flag) + sprintf (msg, "eti %d\n", id); + else + strcpy (msg, "mail\n"); deliver (queue, gip, msg); gw_log (GW_LOG_DEBUG, module, "Closing"); gipc_close (gip);