From: Adam Dickmeiss Date: Tue, 28 Mar 1995 11:42:34 +0000 (+0000) Subject: First use of string-queue utility. X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=27f77c83ecdd2452bc6756bfdc6b9ebc9703298a;p=egate.git First use of string-queue utility. --- diff --git a/kernel/eti.c b/kernel/eti.c index 0398f56..b0623d6 100644 --- a/kernel/eti.c +++ b/kernel/eti.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: eti.c,v $ - * Revision 1.3 1995/03/28 08:01:23 adam + * Revision 1.4 1995/03/28 11:42:34 adam + * First use of string-queue utility. + * + * Revision 1.3 1995/03/28 08:01:23 adam * FIFO existence is used to test for a running kernel. * * Revision 1.2 1995/03/27 12:51:05 adam @@ -27,6 +30,7 @@ #include #include #include +#include #define LINE_MAX 1024 static char line_buf[LINE_MAX+1]; @@ -39,19 +43,23 @@ static void pipe_handle (int dummy) longjmp (retry_jmp, 1); } -static int email_header (FILE *inf, char *from_str, char *subject_str) +static int email_header (struct str_queue *sq, + char *from_str, char *subject_str) { + char *msg; + int index = 0; + *from_str = '\0'; - *subject_str = '\0'; - while (fgets (line_buf, LINE_MAX, inf)) + *subject_str = '\0'; + while ((msg = str_queue_get (sq, index++))) { - if (line_buf[0] == '\n') + if (msg[0] == '\n') return 0; - if (strncmp (line_buf, "From ", 5) == 0) - sscanf (line_buf+4, "%s", from_str); - if (strncmp (line_buf, "Subject: ", 9) == 0 && - sscanf (line_buf+9, "%s", subject_str+1) == 1) - strcpy (subject_str, line_buf+9); + if (memcmp (msg, "From ", 5) == 0) + sscanf (msg+4, "%s", from_str); + if (memcmp (msg, "Subject: ", 9) == 0 && + sscanf (msg+9, "%s", subject_str+1) == 1) + strcpy (subject_str, msg+9); } return 1; } @@ -91,6 +99,17 @@ static void start_kernel (int argc, char **argv, int id) } } +static void deliver (struct str_queue *sq, GIP gip) +{ + int index = 0; + char *msg; + + gip_wline (gip, "mail\n"); + while ((msg = str_queue_get (sq, index++))) + gip_wline (gip, msg); + gip_wline (gip, "\001"); +} + int main (int argc, char **argv) { char from_str[LINE_MAX+1]; @@ -105,11 +124,21 @@ int main (int argc, char **argv) static int pass = 0; char fifo_client_name[1024]; char fifo_server_name[1024]; + struct str_queue *queue; gw_log_init (*argv); gw_log_level (GW_LOG_ALL); gw_log_file (GW_LOG_ALL, "eti.log"); - r = email_header (stdin, from_str, subject_str); + + 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)) + str_queue_enq (queue, line_str); + + r = email_header (queue, from_str, subject_str); if (! *from_str) { gw_log (GW_LOG_WARN, module, "No \"From\" in mail"); @@ -167,12 +196,12 @@ int main (int argc, char **argv) if (r < 0) if (r == -2) { - gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "r==-2"); + gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-2"); longjmp (retry_jmp, 1); } else if (r == -1) { - gw_log (GW_LOG_WARN|GW_LOG_ERRNO, module, "r==-1"); + gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, "r==-1"); longjmp (retry_jmp, 1); } else @@ -181,26 +210,13 @@ int main (int argc, char **argv) exit (1); } /* deliver message ... */ - gw_log (GW_LOG_DEBUG, module, "Delivering mail header"); - gip_wline (gip, "mail\n"); - gip_wline (gip, "From "); - gip_wline (gip, from_str); - gip_wline (gip, "\n"); - if (*subject_str) - { - gip_wline (gip, "Subject: "); - gip_wline (gip, subject_str); - gip_wline (gip, "\n"); - } - gip_wline (gip, "\n"); - gw_log (GW_LOG_DEBUG, module, "Delivering mail body"); - while (fgets (line_str, LINE_MAX, stdin)) - gip_wline (gip, line_str); - gip_wline (gip, "\001"); + gw_log (GW_LOG_DEBUG, module, "Delivering mail"); + deliver (queue, gip); gw_log (GW_LOG_DEBUG, module, "Closing"); gipc_close (gip); gipc_destroy (gip); gw_db_close (user_db); + gw_log (GW_LOG_DEBUG, module, "Exiting"); exit (0); } diff --git a/kernel/kernel.h b/kernel/kernel.h index 5aab169..4c66d52 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: kernel.h,v $ - * Revision 1.10 1995/03/27 08:24:01 adam + * 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 * First use of gip interface and gw-db. * First work on eti program. * @@ -49,8 +52,9 @@ #if USE_FML #include #endif +#include -int urp (int fd); +int urp (struct str_queue *queue); struct gw_user_set { char *name; /* name of result set */ diff --git a/kernel/main.c b/kernel/main.c index fd6ef7e..e6d0081 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.13 1995/03/28 08:01:25 adam + * 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 * FIFO existence is used to test for a running kernel. * * Revision 1.12 1995/03/27 12:51:05 adam @@ -60,16 +63,18 @@ #include #include +#include #include "kernel.h" FILE *reply_fd = stdout; struct gw_kernel_info info; -static void kernel_events (int userid) +static void kernel_events (struct str_queue *queue, int userid) { char fifo_client_name[1024]; char fifo_server_name[1024]; + char line_buf[1024]; GIP gip; fd_set set_r; int r, gip_fd; @@ -118,7 +123,11 @@ static void kernel_events (int userid) if (!strcmp (command, "mail")) { gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Incoming mail...\n"); - urp (gip_fd); + while (lgets (line_buf, sizeof(line_buf)-1, gip_fd)) + str_queue_enq (queue, line_buf); + urp (queue); + while (str_queue_deq (queue, 0, 0)) + ; } else if (!strcmp (command, "stop")) { @@ -140,6 +149,7 @@ static void kernel_events (int userid) int main (int argc, char **argv) { int userid = -1; + struct str_queue *queue; info.kernel_res = NULL; info.default_res = "default.res"; @@ -289,10 +299,20 @@ int main (int argc, char **argv) info.default_res = *argv; } read_kernel_res (); + if (!(queue = str_queue_mk ())) + { + gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "str_queue_mk"); + exit (1); + } if (userid != -1) - kernel_events (userid); + kernel_events (queue, userid); else - urp (0); + { + char line_buf[512]; + while (lgets (line_buf, sizeof(line_buf)-1, 0)) + str_queue_enq (queue, line_buf); + urp (queue); + } return 0; } diff --git a/kernel/urp.c b/kernel/urp.c index 5e2d9b1..1197a6c 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.23 1995/03/28 08:01:28 adam + * 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 * FIFO existence is used to test for a running kernel. * * Revision 1.22 1995/03/27 12:51:05 adam @@ -88,9 +91,11 @@ #include #include +#include #include "kernel.h" -#define LINE_MAX 256 +#define LINE_MAX 1024 +static char line_buf[LINE_MAX+1]; static void put_esc_str (const char *s) { @@ -158,7 +163,6 @@ static int reopen_target (void) return 0; } -static char line_buf[LINE_MAX+1]; static struct command_word { char *default_value; @@ -249,17 +253,18 @@ static char *error_no_search (struct error_no_struct *tab, int no) return NULL; } -static int email_header (int fd, char *from_str, char *subject_str) +static int email_header (struct str_queue *sq, + char *from_str, char *subject_str) { *from_str = '\0'; - *subject_str = '\0'; - while (lgets (line_buf, LINE_MAX, fd)) + *subject_str = '\0'; + while (str_queue_deq (sq, line_buf, LINE_MAX)) { if (line_buf[0] == '\n') return 0; - if (strncmp (line_buf, "From ", 5) == 0) + if (memcmp (line_buf, "From ", 5) == 0) sscanf (line_buf+4, "%s", from_str); - if (strncmp (line_buf, "Subject: ", 9) == 0 && + if (memcmp (line_buf, "Subject: ", 9) == 0 && sscanf (line_buf+9, "%s", subject_str+1) == 1) strcpy (subject_str, line_buf+9); } @@ -729,14 +734,15 @@ static int exec_command (const char *str) return 0; } -int urp (int fd) +int urp (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 (fd, from_str, subject_str)) + if (email_header (queue, from_str, subject_str)) { gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body"); return -1; @@ -773,14 +779,12 @@ int urp (int fd) 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")); - while (lgets (line_buf, LINE_MAX, fd)) + while (str_queue_deq (queue, line_buf, LINE_MAX)) { - char *cp; - if (line_buf[0] == '\n') if (command_no) { - while (lgets (line_buf, LINE_MAX, fd)) + while (str_queue_deq (queue, 0, 0)) ; break; }