From 7d911b772d7116575f2537b48005ad873fde4473 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 17 Apr 1995 09:34:23 +0000 Subject: [PATCH] Timeout (idletime) adjustable. Minor changes in kernel. --- kernel/Makefile | 17 ++++++----- kernel/default.res | 4 ++- kernel/eti.c | 8 ++++-- kernel/kernel.h | 16 ++++++++--- kernel/main.c | 32 ++++++++++++++------- kernel/urp.c | 80 ++++++++++++++++++++++++++++++++-------------------- 6 files changed, 102 insertions(+), 55 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 0be3750..ef0d10d 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.13 1995/03/27 12:51:04 adam +# Revision 1.14 1995/04/17 09:34:23 adam +# Timeout (idletime) adjustable. Minor changes in kernel. +# +# Revision 1.13 1995/03/27 12:51:04 adam # New log level in use: GW_LOG_ERRNO. # # Revision 1.12 1995/03/27 08:23:57 adam @@ -59,7 +62,7 @@ USELIBS1=../lib/ccl.a ../lib/fml.a ../lib/libzass.a ../lib/libres+log.a \ ../lib/util.a $(ZLIB) $(REGEXOBJ) PROG1=kernel -O1=main.o urp.o ttyemit.o +O1=main.o urp.o PROG2=eti O2=eti.o @@ -82,14 +85,14 @@ clean: depend: depend2 depend1: - mv Makefile Makefile.tmp - sed '/^#Depend/q' Makefile - $(CPP) $(INCLUDE) -M *.c >>Makefile - -rm Makefile.tmp + sed '/^#Depend/q' Makefile.tmp + $(CPP) $(DEFS) -M *.c >>Makefile.tmp + mv -f Makefile.tmp Makefile depend2: - $(CPP) $(INCLUDE) -M *.c >.depend + $(CPP) $(DEFS) -M *.c >.depend +#GNU make style depend ifeq (.depend,$(wildcard .depend)) include .depend endif diff --git a/kernel/default.res b/kernel/default.res index 82e4bb4..67bbac2 100644 --- a/kernel/default.res +++ b/kernel/default.res @@ -1,5 +1,5 @@ # Email gateway - general kernel resources -# $Id: default.res,v 1.14 1995/03/27 08:23:59 adam Exp $ +# $Id: default.res,v 1.15 1995/04/17 09:34:25 adam Exp $ # # Important directories, programs, etc. gw.reply.mta: /usr/lib/sendmail @@ -7,6 +7,7 @@ gw.reply.tmp.prefix: gwr gw.reply.tmp.dir: /tmp #gw.path: /home/adam/egate/kernel gw.marc.log: marc.log +gw.timeout: 60 # Retrieval settings gw.ignore.which: 1 @@ -28,6 +29,7 @@ gw.lang.uk: lang.uk.res # Messages gw.msg.subject: Your Z39.50 Query... gw.msg.greeting: Europagate Email-Z39.50 gateway +gw.msg.cont: Session continued... gw.msg.from: Email-gateway gw.err.nullbody: Empty body ccl.command.find: find f diff --git a/kernel/eti.c b/kernel/eti.c index 6cce040..c36edd8 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -1,8 +1,11 @@ -/* Gateway kernel +/* Gateway Email Transport Interface * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.5 1995/03/31 09:43:13 adam + * Revision 1.6 1995/04/17 09:34:27 adam + * Timeout (idletime) adjustable. Minor changes in kernel. + * + * Revision 1.5 1995/03/31 09:43:13 adam * Removed unused variable. * * Revision 1.4 1995/03/28 11:42:34 adam @@ -172,6 +175,7 @@ int main (int argc, char **argv) else { gw_log (GW_LOG_FATAL, module, "gw_db_lookup fail"); + exit (1); } sprintf (fifo_server_name, "fifo.s.%d", id); sprintf (fifo_client_name, "fifo.c.%d", id); diff --git a/kernel/kernel.h b/kernel/kernel.h index 4c66d52..7ca0316 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: kernel.h,v $ - * Revision 1.11 1995/03/28 11:42:34 adam + * Revision 1.12 1995/04/17 09:34:29 adam + * Timeout (idletime) adjustable. Minor changes in kernel. + * + * Revision 1.11 1995/03/28 11:42:34 adam * First use of string-queue utility. * * Revision 1.10 1995/03/27 08:24:01 adam @@ -54,7 +57,7 @@ #endif #include -int urp (struct str_queue *queue); +#define LINE_MAX 1024 struct gw_user_set { char *name; /* name of result set */ @@ -76,6 +79,9 @@ struct gw_kernel_info { char *databases; char *database; ZASS zass; + int command_no; + char from_str[LINE_MAX+1]; + const char *reply_fname; #if USE_FML Fml fml; #endif @@ -86,13 +92,15 @@ extern struct gw_kernel_info info; extern FILE *reply_fd; +int urp_start (int continuation, struct str_queue *queue); +int urp_command (struct str_queue *queue); +void urp_end (void); + void read_kernel_res (void); struct gw_user_set *user_set_add (const char *name, int hits); struct gw_user_set *user_set_search (const char *name); void user_set_init (void); -void tty_emit (int ch); -void tty_init (FILE *out, int min, int max); int lgets (char *buf, int max, int fd); diff --git a/kernel/main.c b/kernel/main.c index e6d0081..9398e2b 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,8 +1,11 @@ -/* Gateway kernel +/* Gateway kernel - Main * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.14 1995/03/28 11:42:34 adam + * Revision 1.15 1995/04/17 09:34:30 adam + * Timeout (idletime) adjustable. Minor changes in kernel. + * + * Revision 1.14 1995/03/28 11:42:34 adam * First use of string-queue utility. * * Revision 1.13 1995/03/28 08:01:25 adam @@ -79,7 +82,10 @@ static void kernel_events (struct str_queue *queue, int userid) fd_set set_r; int r, gip_fd; struct timeval tv; + int timeout; + int continuation = 0; + timeout = atoi(gw_res_get (info.kernel_res, "gw.timeout", "600")); gw_log (GW_LOG_DEBUG, KERNEL_LOG, "kernel event loop"); sprintf (fifo_client_name, "fifo.c.%d", userid); @@ -93,7 +99,7 @@ static void kernel_events (struct str_queue *queue, int userid) { FD_ZERO (&set_r); FD_SET (gip_fd, &set_r); - tv.tv_sec = 60; + tv.tv_sec = timeout; tv.tv_usec = 0; gw_log (GW_LOG_DEBUG, KERNEL_LOG, "IPC select"); @@ -105,7 +111,8 @@ static void kernel_events (struct str_queue *queue, int userid) } if (r == 0) { - gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout"); + gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds", + timeout); break; } if (FD_ISSET (gip_fd, &set_r)) @@ -125,7 +132,9 @@ static void kernel_events (struct str_queue *queue, int userid) gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n"); while (lgets (line_buf, sizeof(line_buf)-1, gip_fd)) str_queue_enq (queue, line_buf); - urp (queue); + urp_start (continuation, queue); + urp_command (queue); + urp_end (); while (str_queue_deq (queue, 0, 0)) ; } @@ -138,6 +147,7 @@ static void kernel_events (struct str_queue *queue, int userid) { gw_log (GW_LOG_WARN, KERNEL_LOG, "Unknown IPC: %s", command); } + continuation = 1; } } gips_close (gip); @@ -182,11 +192,11 @@ int main (int argc, char **argv) fprintf (stderr, "Options:\n"); fprintf (stderr, " -d Enable debugging log\n"); fprintf (stderr, " -t target Open target immediately\n"); - fprintf (stderr, " -l lang Set language\n"); + fprintf (stderr, " -g lang Set language\n"); fprintf (stderr, " -o resource Override with resource\n"); fprintf (stderr, " -h host Override host\n"); fprintf (stderr, " -p port Override port\n"); - fprintf (stderr, " -g log Set Log file\n"); + fprintf (stderr, " -l log Set Log file\n"); fprintf (stderr, " -i id Set IPC userid\n"); exit (1); case 'd': @@ -206,7 +216,7 @@ int main (int argc, char **argv) exit (1); } break; - case 'l': + case 'g': if (argv[0][2]) info.lang = argv[0]+2; else if (argc > 0) @@ -262,7 +272,7 @@ int main (int argc, char **argv) exit (1); } break; - case 'g': + case 'l': if (argv[0][2]) gw_log_file (GW_LOG_ALL, argv[0]+2); else if (argc > 0) @@ -311,7 +321,9 @@ int main (int argc, char **argv) char line_buf[512]; while (lgets (line_buf, sizeof(line_buf)-1, 0)) str_queue_enq (queue, line_buf); - urp (queue); + urp_start (0, queue); + urp_command (queue); + urp_end (); } return 0; } diff --git a/kernel/urp.c b/kernel/urp.c index 1197a6c..aaba374 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -1,8 +1,11 @@ -/* Gateway kernel +/* Gateway kernel - User Request Processor * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.24 1995/03/28 11:42:35 adam + * Revision 1.25 1995/04/17 09:34:33 adam + * Timeout (idletime) adjustable. Minor changes in kernel. + * + * Revision 1.24 1995/03/28 11:42:35 adam * First use of string-queue utility. * * Revision 1.23 1995/03/28 08:01:28 adam @@ -91,10 +94,10 @@ #include #include +#include #include #include "kernel.h" -#define LINE_MAX 1024 static char line_buf[LINE_MAX+1]; static void put_esc_str (const char *s) @@ -734,32 +737,31 @@ static int exec_command (const char *str) return 0; } -int urp (struct str_queue *queue) +int urp_start (int continuation, struct str_queue *queue) { - char from_str[128]; char subject_str[128]; - int command_no = 0; - char *reply_fname = NULL; - char *cp; - if (email_header (queue, from_str, subject_str)) + info.command_no = 0; + info.reply_fname = NULL; + + if (email_header (queue, info.from_str, subject_str)) { gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body"); return -1; } tty_init (stdout, 40, 70); - if (*from_str) + if (*info.from_str) { - reply_fname = tempnam (gw_res_get (info.kernel_res, + info.reply_fname = tempnam (gw_res_get (info.kernel_res, "gw.reply.tmp.dir", NULL), gw_res_get (info.kernel_res, "gw.reply.tmp.prefix", "gwr")); - reply_fd = fopen (reply_fname, "w"); + reply_fd = fopen (info.reply_fname, "w"); if (!reply_fd) { gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "Cannot create %s", - reply_fname); + info.reply_fname); return -1; } tty_init (reply_fd, 0, 0); @@ -773,16 +775,31 @@ int urp (struct str_queue *queue) "gw.msg.subject", "Your Query")); fprintf (reply_fd, "\n"); - gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", from_str); + gw_log (GW_LOG_ACCT, KERNEL_LOG, "User start %s", info.from_str); } else gw_log (GW_LOG_WARN, KERNEL_LOG, "No From in email header"); fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.msg.greeting", "Email->Z39.50 gateway")); + if (continuation) + fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, + "gw.msg.cont", + "Continued...")); + ccl_token_and = gw_res_get (info.kernel_res, "ccl.token.and", "and"); + ccl_token_or = gw_res_get (info.kernel_res, "ccl.token.or", "or"); + ccl_token_not = gw_res_get (info.kernel_res, "ccl.token.not", "not"); + ccl_token_set = gw_res_get (info.kernel_res, "ccl.token.set", "set"); + return 0; +} + +int urp_command (struct str_queue *queue) +{ + char *cp; + while (str_queue_deq (queue, line_buf, LINE_MAX)) { if (line_buf[0] == '\n') - if (command_no) + if (info.command_no) { while (str_queue_deq (queue, 0, 0)) ; @@ -793,41 +810,42 @@ int urp (struct str_queue *queue) if ((cp = strchr (line_buf, '\n'))) *cp = '\0'; gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf); - ccl_token_and = gw_res_get (info.kernel_res, "ccl.token.and", "and"); - ccl_token_or = gw_res_get (info.kernel_res, "ccl.token.or", "or"); - ccl_token_not = gw_res_get (info.kernel_res, "ccl.token.not", "not"); - ccl_token_set = gw_res_get (info.kernel_res, "ccl.token.set", "set"); if (isalpha (line_buf[0])) exec_command (line_buf); - command_no++; + info.command_no++; } - if (!command_no) + return 0; +} + +void urp_end (void) +{ + if (!info.command_no) { - fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, - "gw.err.nullbody", - "No body")); + fprintf (reply_fd, "%s\n", + gw_res_get (info.kernel_res, "gw.err.nullbody", "No body")); help_general (); } - if (*from_str) + if (*info.from_str) { const char *mta; char cmd[256]; int mta_code; - assert (reply_fname); + assert (info.reply_fname); fclose (reply_fd); reply_fd = stdout; mta = gw_res_get (info.kernel_res, "gw.reply.mta", - "/usr/lib/sendmail"); - sprintf (cmd, "%s %s < %s", mta, from_str, reply_fname); + "/usr/lib/sendmail"); + sprintf (cmd, "%s %s < %s", mta, info.from_str, info.reply_fname); mta_code = system (cmd); if (mta_code) gw_log (GW_LOG_FATAL, KERNEL_LOG, "Reply '%s' got exit code %d", cmd, mta_code); - unlink (reply_fname); - gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", from_str); + else + unlink (info.reply_fname); + gw_log (GW_LOG_ACCT, KERNEL_LOG, "User end %s", info.from_str); } - return 0; } + -- 1.7.10.4