X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=kernel%2Furp.c;h=f3d61bcbce978ebb1998bd1f370e8d86833cb775;hb=ecdb6851b4c28d55a434c58532894e4c5e082adc;hp=788d7be76bacd531b1439d60836f44e97531334d;hpb=4fc919060b269ed951045e3dd6fce2721f17b930;p=egate.git diff --git a/kernel/urp.c b/kernel/urp.c index 788d7be..f3d61bc 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,17 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.18 1995/03/01 14:32:26 adam + * Revision 1.21 1995/03/27 08:24:04 adam + * First use of gip interface and gw-db. + * First work on eti program. + * + * Revision 1.20 1995/03/03 17:19:17 adam + * Smarter presentation. Bug fix in email header interpretation. + * + * Revision 1.19 1995/03/02 09:32:11 adam + * New presentation formats. f0=full, f1=brief, f2=mid + * + * Revision 1.18 1995/03/01 14:32:26 adam * Better diagnostics. Default is, that only one database selected when * several are known. * @@ -78,33 +88,31 @@ static void put_esc_str (const char *s) { - int escape_flag = 0; while (*s) + tty_emit (*s++); +} + +int lgets (char *buf, int max, int fd) +{ + int r, no = 0; + + --max; + while (no <= max) { - if (*s == '\\' && s[1]) - { - switch (*++s) - { - case 'n': - fputc ('\n', reply_fd); - break; - case 't': - fputc ('\t', reply_fd); - break; - default: - fputc (*s, reply_fd); - break; - } - escape_flag = 1; - } - else - { - if (*s != ' ' || !escape_flag) - fputc (*s, reply_fd); - escape_flag = 0; - } - s++; + if ((r=read (fd, buf+no, 1)) != 1) + { + if (r == -1) + gw_log (GW_LOG_WARN, KERNEL_LOG, "read fail"); + buf[no] = '\0'; + return 0; + } + if (buf[no] == 1) + return 0; + if (buf[no++] == '\n') + break; } + buf[no] = '\0'; + return 1; } static int reopen_target (void) @@ -234,11 +242,11 @@ static char *error_no_search (struct error_no_struct *tab, int no) return NULL; } -static int email_header (FILE *inf, char *from_str, char *subject_str) +static int email_header (int fd, char *from_str, char *subject_str) { *from_str = '\0'; *subject_str = '\0'; - while (fgets (line_buf, LINE_MAX, inf)) + while (lgets (line_buf, LINE_MAX, fd)) { if (line_buf[0] == '\n') return 0; @@ -259,23 +267,26 @@ static void help_general (void) static int exec_help (struct ccl_token *list) { + static char *sep = "-------------------------------\\n"; help_general (); -#if 0 +#if 1 + put_esc_str (sep); put_esc_str (gw_res_get (info.kernel_res, "gw.help.target", "target - selects a given target\n")); + put_esc_str (sep); put_esc_str (gw_res_get (info.kernel_res, "gw.help.base", "base .. - selects databases\n")); + put_esc_str (sep); put_esc_str (gw_res_get (info.kernel_res, "gw.help.find", "find - performs a search request\n")); + put_esc_str (sep); put_esc_str (gw_res_get (info.kernel_res, "gw.help.show", "show - retrieves and displays " "records\n")); - put_esc_str (gw_res_get (info.kernel_res, "gw.help.help", - "help - displays help\n")); #endif return 0; } @@ -407,7 +418,7 @@ static void present (const char *set, int offset, int number, const struct zass_presentent *zp; int len; int max_number; - char format_str[40]; + char format_str[16]; max_number = atoi (gw_res_get (info.kernel_res, "gw.max.show", "200")); @@ -472,11 +483,14 @@ static void present (const char *set, int offset, int number, if (format_token) { len = format_token->len; + if (len >= sizeof(format_str)) + len = sizeof(format_str)-1; memcpy (format_str, format_token->name, len); format_str[len] = '\0'; } if (info.fml && format_token && - (!strcmp (format_str, "0") || !strcmp (format_str, "1"))) + (!strcmp (format_str, "0") || !strcmp (format_str, "1") + || !strcmp(format_str, "2"))) { arg_ar[0] = "\\f"; arg_ar[1] = format_str; @@ -708,18 +722,19 @@ static int exec_command (const char *str) return 0; } -int urp (FILE *inf) +int urp (int fd) { char from_str[128]; char subject_str[128]; int command_no = 0; char *reply_fname = NULL; - if (email_header (inf, from_str, subject_str)) + if (email_header (fd, from_str, subject_str)) { gw_log (GW_LOG_WARN, KERNEL_LOG, "No message body"); return -1; } + tty_init (stdout, 40, 70); if (*from_str) { reply_fname = tempnam (gw_res_get (info.kernel_res, @@ -734,6 +749,7 @@ int urp (FILE *inf) reply_fname); return -1; } + tty_init (reply_fd, 0, 0); fprintf (reply_fd, "From: %s\n", gw_res_get (info.kernel_res, "gw.msg.from","Email-gateway")); fprintf (reply_fd, "Subject: "); @@ -750,12 +766,19 @@ int urp (FILE *inf) 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 (fgets (line_buf, LINE_MAX, inf)) + while (lgets (line_buf, LINE_MAX, fd)) { char *cp; if (line_buf[0] == '\n') - break; + if (command_no) + { + while (lgets (line_buf, LINE_MAX, fd)) + ; + break; + } + else + continue; if ((cp = strchr (line_buf, '\n'))) *cp = '\0'; gw_log (GW_LOG_ACCT, KERNEL_LOG, "cmd: %s", line_buf);