From 3d7bcb90ecca627de953318f5137d28f55fcc737 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 22 Feb 1995 15:22:32 +0000 Subject: [PATCH] Much more checking of run-time state. Show command never retrieves more records than indicated by the previous search request. Help command available. The maximum number of records retrieved can be controlled now. --- kernel/default.res | 44 ++++++- kernel/kernel.h | 19 ++- kernel/lang.uk.res | 4 +- kernel/main.c | 55 +++++++- kernel/urp.c | 352 ++++++++++++++++++++++++++++++++++------------------ 5 files changed, 341 insertions(+), 133 deletions(-) diff --git a/kernel/default.res b/kernel/default.res index d2a915b..c561d11 100644 --- a/kernel/default.res +++ b/kernel/default.res @@ -1,11 +1,16 @@ # Email gateway - general kernel resources -# $Id: default.res,v 1.7 1995/02/20 21:16:17 adam Exp $ +# $Id: default.res,v 1.8 1995/02/22 15:22:32 adam Exp $ # # Important directories, programs, etc. -gw.reply.mta: /usr/bin/smail +gw.reply.mta: /usr/lib/sendmail gw.reply.tmp.prefix: gwr gw.reply.tmp.dir: /tmp -gw.path: /home/adam/egate/kernel +#gw.path: /home/adam/egate/kernel + +# Retrieval settings +gw.ignore.which: 1 +gw.default.show: 10 +gw.max.show: 100 # Target definitions gw.portno: 2000 @@ -21,7 +26,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.greeting: Europagate Email-Z39.50 gateway gw.err.nullbody: Empty body ccl.command.find: find f ccl.command.show: show s @@ -36,3 +41,34 @@ ccl.token.or: or ccl.token.not: not ccl.token.set: set +# Help messages +gw.help.general: You + have triggered the "help"-information on the Email gateway. \n\n + This preliminary service is a very early alpha release of a Email service\n + which acts as a Z39.50-client (origin). \n\n + With this service you can connect to several Z39.50-targets. Your Email\n + body consists of one or more commands. Each command must start on column\n + zero; otherwise it will be ignored. Also, everything AFTER the first\n + empty line in your body is ignored. Thus, you probably do not have to\n + delete your signature in the end.\n\n + All your requests will be logged. Hopefully you will get a reply with\n + the result of your queries in a minute or two. If you don't something\n + probably went wrong. Hopefully, we will be able to see what went wrong\n + by examining the log files.\n\n + This is what you do:\n\n + * First you must select a target (i.e. a host with a Z39.50-interface\n + to one or more databases) with the "target" command. For example:\n + \ttarget dranet.dra.com\n + * Second, select the databases in which you wish to search, with the\n + "base" command. For example:\n + \tbase drewdb\n\n + * Now you are ready to issue real queries by using the "find"-command.\n + The query consists of one or more search words. You can perform boolean\n + searches by using the operators "and", "or" and "not". For example:\n + \tfind computer and knuth\n + If the target supports it, you may also direct the search to special\n + indexes by using qualfiers. For example, the following query will search\n + for "computer" in the "title"-index and "knuth" in the "normal" index:\n + \tfind ti=computer and knuth\n\n + * If the query succeeds, you will be informed with the number of hits.\n + To display the records use the "show"-command.\n diff --git a/kernel/kernel.h b/kernel/kernel.h index 2ac7b19..0376550 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -2,7 +2,13 @@ * Europagate, 1995 * * $Log: kernel.h,v $ - * Revision 1.4 1995/02/20 21:16:18 adam + * Revision 1.5 1995/02/22 15:22:32 adam + * Much more checking of run-time state. Show command never retrieves + * more records than indicated by the previous search request. Help + * command available. The maximum number of records retrieved can be + * controlled now. + * + * Revision 1.4 1995/02/20 21:16:18 adam * FML support. Bug fixes. Profile for drewdb. * * Revision 1.3 1995/02/16 18:35:08 adam @@ -32,6 +38,12 @@ int urp (FILE *inf); +struct gw_user_set { + char *name; /* name of result set */ + int hits; /* -1 on error */ + struct gw_user_set *prev; +}; + struct gw_kernel_info { CCL_bibset bibset; GwRes kernel_res; @@ -48,6 +60,7 @@ struct gw_kernel_info { #if USE_FML Fml fml; #endif + struct gw_user_set *sets; }; extern struct gw_kernel_info info; @@ -55,3 +68,7 @@ extern struct gw_kernel_info info; extern FILE *reply_fd; 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); diff --git a/kernel/lang.uk.res b/kernel/lang.uk.res index 5411f43..0d50b67 100644 --- a/kernel/lang.uk.res +++ b/kernel/lang.uk.res @@ -1,5 +1,5 @@ # Email gateway - resources for english conversation -# $Id: lang.uk.res,v 1.1 1995/02/20 21:16:19 adam Exp $ +# $Id: lang.uk.res,v 1.2 1995/02/22 15:22:33 adam Exp $ # # Messages gw.msg.subject: Your Z39.50 Query @@ -12,6 +12,8 @@ gw.msg.msg.records: %d records found # Error messages gw.err.no.database: You must choose database before issuing a find-query +gw.err.no.target: No connection established - command ignored +gw.err.no.set: No result-set generated gw.err.nullbody: No email-body - no query performed gw.err.unimplemented: The command is not implemented - yet gw.err.unknown.command: Unknown command diff --git a/kernel/main.c b/kernel/main.c index c87b9b1..428ffac 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,13 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.6 1995/02/22 08:51:34 adam + * Revision 1.7 1995/02/22 15:22:33 adam + * Much more checking of run-time state. Show command never retrieves + * more records than indicated by the previous search request. Help + * command available. The maximum number of records retrieved can be + * controlled now. + * + * Revision 1.6 1995/02/22 08:51:34 adam * Output function can be customized in fml, which is used to print * the reply to reply_fd. * @@ -53,6 +59,7 @@ int main (int argc, char **argv) #if USE_FML info.fml = NULL; #endif + info.sets = NULL; gw_log_init (*argv); info.kernel_res = gw_res_init (); @@ -161,6 +168,46 @@ int main (int argc, char **argv) urp (stdin); return 0; } + +struct gw_user_set *user_set_add (const char *name, int hits) +{ + struct gw_user_set *s; + + s = malloc (sizeof (*s)); + assert (s); + + s->name = gw_strdup (name); + s->hits = hits; + s->prev = info.sets; + info.sets = s; + return s; +} + +void user_set_init (void) +{ + struct gw_user_set *s, *s1; + + for (s = info.sets; s; s = s1) + { + free (s->name); + s1 = s->prev; + free (s); + } + info.sets = NULL; +} + +struct gw_user_set *user_set_search (const char *name) +{ + struct gw_user_set *s; + + if (!name) + return info.sets; + for (s = info.sets; s; s = s->prev) + if (!strcmp (s->name, name)) + return s; + return NULL; +} + #if USE_FML static void fml_inf_write (int ch) { @@ -182,6 +229,8 @@ void read_kernel_res (void) char *cp; char resource_name[256]; + user_set_init (); + if (info.bibset) ccl_qual_rm (&info.bibset); info.bibset = ccl_qual_mk (); @@ -274,9 +323,7 @@ void read_kernel_res (void) if (info.databases) free (info.databases); v = gw_res_get (info.kernel_res, "gw.databases", ""); - info.databases = malloc (1+strlen(v)); - assert (info.databases); - strcpy (info.databases, v); + info.databases = gw_strdup (v); for (cp = info.databases; (cp = strchr (cp, ' ')); cp++) *cp = ','; if (info.override_portno) diff --git a/kernel/urp.c b/kernel/urp.c index 196bd03..0e2e4d6 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,13 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.10 1995/02/22 08:51:35 adam + * Revision 1.11 1995/02/22 15:22:33 adam + * Much more checking of run-time state. Show command never retrieves + * more records than indicated by the previous search request. Help + * command available. The maximum number of records retrieved can be + * controlled now. + * + * Revision 1.10 1995/02/22 08:51:35 adam * Output function can be customized in fml, which is used to print * the reply to reply_fd. * @@ -50,6 +56,37 @@ #define LINE_MAX 256 +static void put_esc_str (const char *s) +{ + int escape_flag = 0; + while (*s) + { + 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++; + } +} + static int reopen_target (void) { const char *v; @@ -186,14 +223,45 @@ static int email_header (FILE *inf, char *from_str, char *subject_str) return 1; } +static void help_general (void) +{ + put_esc_str (gw_res_get (info.kernel_res, "gw.help.general", + "Commands available in this service:\n")); +} + +static int exec_help (struct ccl_token *list) +{ + help_general (); + +#if 0 + put_esc_str (gw_res_get (info.kernel_res, "gw.help.target", + "target - selects a given target\n")); + + put_esc_str (gw_res_get (info.kernel_res, "gw.help.base", + "base .. - selects databases\n")); + + put_esc_str (gw_res_get (info.kernel_res, "gw.help.find", + "find - performs a search request\n")); + + 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; +} + static int exec_find (struct ccl_token *list) { const struct zass_searchent *p; + struct gw_user_set *us; struct ccl_rpn_node *rpn; int error; const char *pos; + us = user_set_add ("Default", -1); rpn = ccl_find (info.bibset, list, &error, &pos); if (!rpn) { @@ -216,8 +284,6 @@ static int exec_find (struct ccl_token *list) ccl_pr_tree (rpn, reply_fd); fprintf (reply_fd, "\n"); - if (!info.zass) - return -2; if (!*info.databases) { fprintf (reply_fd, "%s\n", @@ -227,17 +293,21 @@ static int exec_find (struct ccl_token *list) } gw_log (GW_LOG_DEBUG, "urp", "Searching in database %s", info.databases); + assert (info.zass); p = zass_search (info.zass, rpn, "Default", info.databases); if (!p) return -1; if (p->errcode != -1) + { fprintf (reply_fd, "%s %d: %s\n", gw_res_get (info.kernel_res, "gw.msg.z39errcode", "Z39.50 error code"), p->errcode, p->errstring); - else - fprintf (reply_fd, "%d %s\n", p->num, - gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)")); + return -2; + } + fprintf (reply_fd, "%d %s\n", p->num, + gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)")); + us->hits = p->num; return 0; } @@ -259,6 +329,7 @@ static int exec_base (struct ccl_token *list) struct ccl_token *li = list; int len = 0; + assert (info.zass); if (list->kind == CCL_TOK_EOL) return -1; free (info.databases); @@ -293,18 +364,97 @@ struct command_word show_tab [] = { NULL, NULL } }; -static int exec_show (struct ccl_token *list) +static void present (const char *set, int number, int offset, + struct ccl_token *format_token) { const struct zass_presentent *zp; - char num_str[20]; + int len; + int max_number; + char format_str[40]; + + max_number = atoi (gw_res_get (info.kernel_res, "gw.max.show", + "200")); + if (number > max_number) + number = max_number; + gw_log (GW_LOG_DEBUG, "urp", "present in set %s", set); + gw_log (GW_LOG_DEBUG, "urp", "present of %d records from offset %d", + number, offset); + zp = zass_present(info.zass, (char *) set, offset, number); + if (zp) + { + int i; + zass_record *pp; + + fprintf (reply_fd, gw_res_get (info.kernel_res, + "gw.msg.records", + "Got %d records"), + zp->num); + fprintf (reply_fd, "\n"); + for (i = 0, pp = zp->records; pp; pp = pp->next, i++) + { + Iso2709Rec rec; +#if USE_FML + const char *arg_ar[5]; +#endif + fprintf (reply_fd, "--- %d/%d ---\n", + i+offset, offset+zp->num-1); + if (!gw_res_get (info.kernel_res, "gw.ignore.which", NULL)) + { + if (pp->which == ZASS_REC_DIAG) + { + fprintf (reply_fd, "Record error %d: %s\n", + pp->errcode, pp->errstring); + continue; + } + else if (pp->which != ZASS_REC_USMARC) + { + fprintf (reply_fd, "Unknown record kind %d\n", + pp->which); + continue; + } + } + rec = iso2709_cvt (pp->record); + if (rec) + { +#if USE_FML + if (format_token) + { + len = format_token->len; + memcpy (format_str, format_token->name, len); + format_str[len] = '\0'; + } + if (info.fml && format_token && + (!strcmp (format_str, "0") || !strcmp (format_str, "1"))) + { + arg_ar[0] = "\\f"; + arg_ar[1] = format_str; + arg_ar[2] = " \\list"; + arg_ar[3] = marc_to_str (info.fml, rec); + arg_ar[4] = NULL; + fml_exec_call_argv (info.fml, arg_ar); + } + else + iso2709_display (rec, reply_fd); +#else + iso2709_display (rec, reply_fd); +#endif + iso2709_rm (rec); + } + else + fprintf (reply_fd, "Not a MARC record\n"); + } + } +} + +static int exec_show (struct ccl_token *list) +{ + char tmp_str[20]; struct ccl_token *set_token = NULL; struct ccl_token *format_token = NULL; struct ccl_token *li = list; + int no_of_present = 0; - if (list->kind == CCL_TOK_EOL) - return -1; - if (!info.zass) - return -2; + assert (info.zass); while (li->kind != CCL_TOK_EOL) { int modifier_no = 0; @@ -369,22 +519,22 @@ static int exec_show (struct ccl_token *list) && li->next->next != CCL_TOK_EOL) { len = li->len; - memcpy (num_str, li->name, len); - num_str [len] = '\0'; - offset = atoi (num_str); + memcpy (tmp_str, li->name, len); + tmp_str [len] = '\0'; + offset = atoi (tmp_str); li = li->next->next; len = li->len; - memcpy (num_str, li->name, len); - num_str [len] = '\0'; - number = atoi (num_str) - offset + 1; + memcpy (tmp_str, li->name, len); + tmp_str [len] = '\0'; + number = atoi (tmp_str) - offset + 1; } else { len = li->len; - memcpy (num_str, li->name, len); - num_str [len] = '\0'; - offset = atoi (num_str); + memcpy (tmp_str, li->name, len); + tmp_str [len] = '\0'; + offset = atoi (tmp_str); number = 1; } } @@ -393,124 +543,66 @@ static int exec_show (struct ccl_token *list) else { len = li->len; - memcpy (num_str, li->name, len); - num_str[len] = '\0'; - number = atoi (num_str); + memcpy (tmp_str, li->name, len); + tmp_str[len] = '\0'; + number = atoi (tmp_str); offset = 1; li = li->next; } if (offset > 0 && number > 0) { + struct gw_user_set *us; + if (set_token) { len = set_token->len; - memcpy (num_str, set_token->name, len); - num_str[len] = '\0'; + memcpy (tmp_str, set_token->name, len); + tmp_str[len] = '\0'; + us = user_set_search (tmp_str); } else - strcpy (num_str, "Default"); - gw_log (GW_LOG_DEBUG, "urp", "zass_present of %d records from" - " offset %d in set %s", number, offset, num_str); - zp = zass_present(info.zass, num_str, offset, number); - if (zp) + us = user_set_search (NULL); + if (us && us->hits != -1) /* proper result-set? */ { - int i; - zass_record *pp; - - fprintf (reply_fd, gw_res_get (info.kernel_res, - "gw.msg.records", - "Got %d records"), - zp->num); - fprintf (reply_fd, "\n"); - for (i = 0, pp = zp->records; pp; pp = pp->next, i++) + if (offset <= us->hits) { - Iso2709Rec rec; -#if USE_FML - const char *arg_ar[5]; -#endif - fprintf (reply_fd, "--- %d/%d ---\n", - i+offset, offset+zp->num-1); -#if 0 - if (pp->which == ZASS_REC_DIAG) - { - fprintf (reply_fd, "Record error %d: %s\n", - pp->errcode, pp->errstring); - continue; - } - else if (pp->which != ZASS_REC_USMARC) - { - fprintf (reply_fd, "Unknown record kind %d\n", - pp->which); - continue; - } -#endif - rec = iso2709_cvt (pp->record); -#if USE_FML - if (format_token) - { - len = format_token->len; - memcpy (num_str, format_token->name, len); - num_str[len] = '\0'; - } - if (format_token && - (!strcmp (num_str, "0") || !strcmp (num_str, "1"))) - { - arg_ar[0] = "\\f"; - arg_ar[1] = num_str; - arg_ar[2] = " \\list"; - arg_ar[3] = marc_to_str (info.fml, rec); - arg_ar[4] = NULL; - fml_exec_call_argv (info.fml, arg_ar); - } - else - iso2709_display (rec, reply_fd); -#else - iso2709_display (rec, reply_fd); -#endif - iso2709_rm (rec); + if (offset+number-1 > us->hits) + number = us->hits - offset+1; + present (us->name, offset, number, format_token); } } + else if (!no_of_present) /* display error message once! */ + { + fprintf (reply_fd, "%s\n", + gw_res_get (info.kernel_res, "gw.err.no.set", + "No result-set generated")); + } + no_of_present++; } } -#if 0 - len = list->len; - memcpy (num_str, list->name, len); - num_str[len] = '\0'; - - num = atoi (num_str); - if (!num) - return -3; - gw_log (GW_LOG_DEBUG, "urp", "zass_present of %d records", num); - zp = zass_present(info.zass, "Default", 1, num); - if (zp) + if (!no_of_present) /* no records shown so far? */ { - int i; - zass_record *pp; - - fprintf (reply_fd, gw_res_get (info.kernel_res, - "gw.msg.records", "Got %d records"), - zp->num); - fprintf (reply_fd, "\n"); - for (i = 1, pp = zp->records; pp; pp = pp->next, i++) - { -#if USE_FML - const char *arg_ar[3]; -#endif - Iso2709Rec rec = iso2709_cvt (pp->record); - - fprintf (reply_fd, "--- %d/%d ---\n", i, zp->num); -#if USE_FML - arg_ar[0] = "\\f0 \\list"; - arg_ar[1] = marc_to_str (info.fml, rec); - arg_ar[2] = NULL; - fml_exec_call_argv (info.fml, arg_ar); -#else - iso2709_display (rec, reply_fd); -#endif - iso2709_rm (rec); - } + struct gw_user_set *us; + int default_show; + + us = user_set_search (NULL); + if (us && us->hits != -1) /* proper result-set? */ + { + default_show = atoi (gw_res_get (info.kernel_res, + "gw.default.show", "20")); + if (us->hits > default_show) + present (us->name, 1, default_show, format_token); + else if (us->hits > 0) + present (us->name, 1, us->hits, format_token); + } + else /* display error message */ + { + fprintf (reply_fd, "%s\n", + gw_res_get (info.kernel_res, "gw.err.no.set", + "No result-set generated")); + return -3; + } } -#endif return 0; } @@ -522,9 +614,17 @@ static int exec_command (const char *str) if (cmd->kind != CCL_TOK_EOL && (no = command_search (command_tab, cmd, "ccl.command."))) { - if (!info.zass && no != 9) + if (!info.zass && no != 9 && no != 4) reopen_target (); fprintf (reply_fd, "\n> %s", str); + if (!info.zass && (no == 1 || no == 2 || no == 3)) + { + fprintf (reply_fd, "%s\n", + gw_res_get (info.kernel_res, "gw.err.no.target", + "No connection established - " + "command ignored")); + return 0; + } switch (no) { case 1: @@ -533,6 +633,8 @@ static int exec_command (const char *str) return exec_show (cmd->next); case 3: return exec_base (cmd->next); + case 4: + return exec_help (cmd->next); case 9: return exec_target (cmd->next); default: @@ -546,7 +648,8 @@ static int exec_command (const char *str) fprintf (reply_fd, "\n> %s", str); fprintf (reply_fd, " ^ %s\n", gw_res_get (info.kernel_res, "gw.err.unknown.command", - "unknown command")); + "unknown command. " + "Use help to see list of commands")); } return 0; } @@ -603,9 +706,12 @@ int urp (FILE *inf) command_no++; } if (!command_no) + { fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, "gw.err.nullbody", "No body")); + help_general (); + } if (*from_str) { const char *mta; -- 1.7.10.4