From 92d83f4da8146d58af3997cc489514ecd64aca32 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 16 Feb 1995 18:35:07 +0000 Subject: [PATCH] First use of Zdist library. Search requests are supported. Present requests are not supported yet. --- kernel/Makefile | 13 ++-- kernel/default.bib | 5 +- kernel/default.res | 3 +- kernel/kernel.h | 28 +++++++-- kernel/lang.dk.res | 8 ++- kernel/loc.res | 4 +- kernel/main.c | 173 +++++++++++++++++++++++++++++++++++++++++----------- kernel/urp.c | 95 +++++++++++++++++++++++------ 8 files changed, 260 insertions(+), 69 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 536fe6d..d2e74af 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,11 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.1 1995/02/15 17:45:29 adam +# Revision 1.2 1995/02/16 18:35:07 adam +# First use of Zdist library. Search requests are supported. +# Present requests are not supported yet. +# +# Revision 1.1 1995/02/15 17:45:29 adam # First version of email gateway kernel. Email requests are read # from stdin. The output is transferred to an MTA if 'From' is # found in the header - or stdout if absent. No Z39.50 client is used. @@ -11,11 +15,12 @@ SHELL=/bin/sh INCLUDE=-I../include CFLAGS=-g -Wall -pedantic -ansi -CC=gcc +#CC=gcc TPROG1=kernel -O=urp.o main.o +O=main.o urp.o CPP=cc -E -USELIBS=../lib/ccl.a ../lib/fml.a ../lib/libres+log.a ../lib/util.a +USELIBS=../lib/ccl.a ../lib/fml.a ../lib/libzass.a ../lib/libres+log.a \ +../lib/util.a /home/proj/zdist/zdist102b1-1/libz3950/libz3950.a DEFS=$(INCLUDE) all: $(TPROG1) diff --git a/kernel/default.bib b/kernel/default.bib index 3f27d57..29091c4 100644 --- a/kernel/default.bib +++ b/kernel/default.bib @@ -1,7 +1,8 @@ # Subset of bib-1 attributes map to CCL qualifiers -# $Id: default.bib,v 1.1 1995/02/16 13:20:59 adam Exp $ +# $Id: default.bib,v 1.2 1995/02/16 18:35:07 adam Exp $ # -term s=pw t=l,r +term t=l,r s=pw +clean t=l au u=1 s=pw ti u=4 s=pw isbn u=7 diff --git a/kernel/default.res b/kernel/default.res index 4c8711a..20c06d6 100644 --- a/kernel/default.res +++ b/kernel/default.res @@ -1,5 +1,5 @@ # Email gateway - general kernel resources -# $Id: default.res,v 1.2 1995/02/16 13:20:59 adam Exp $ +# $Id: default.res,v 1.3 1995/02/16 18:35:08 adam Exp $ # # Important directories, programs, etc. gw.reply.mta: /usr/bin/smail @@ -12,6 +12,7 @@ gw.portno: 2000 gw.hostname: localhost gw.bibset: default.bib gw.target.loc: loc.res +gw.databases: Default # Language definitions gw.lang.dk: lang.dk.res diff --git a/kernel/kernel.h b/kernel/kernel.h index 7548335..f604dac 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -2,7 +2,11 @@ * Europagate, 1995 * * $Log: kernel.h,v $ - * Revision 1.2 1995/02/16 13:20:59 adam + * Revision 1.3 1995/02/16 18:35:08 adam + * First use of Zdist library. Search requests are supported. + * Present requests are not supported yet. + * + * Revision 1.2 1995/02/16 13:20:59 adam * Organization of resource files for targets and conversion * language implemented. * @@ -16,14 +20,26 @@ #include #include #include +#include int urp (FILE *inf); -extern CCL_bibset bibset; -extern GwRes kernel_res; -extern const char *default_res; -extern const char *target; -extern const char *lang; +struct gw_kernel_info { + CCL_bibset bibset; + GwRes kernel_res; + const char *default_res; + const char *override_res; + char target[128]; + char hostname[128]; + int port; + const char *lang; + const char *override_portno; + const char *override_hostname; + char *databases; + ZASS zass; +}; + +extern struct gw_kernel_info info; extern FILE *reply_fd; diff --git a/kernel/lang.dk.res b/kernel/lang.dk.res index c20c6ef..789d330 100644 --- a/kernel/lang.dk.res +++ b/kernel/lang.dk.res @@ -1,14 +1,19 @@ # Email gateway - resources for danish conversation -# $Id: lang.dk.res,v 1.1 1995/02/16 13:21:00 adam Exp $ +# $Id: lang.dk.res,v 1.2 1995/02/16 18:35:08 adam Exp $ # # Beskeder gw.msg.subject: Din forespørgsel gw.msg.greeting: Europagate email-Z39.50 gateway, dansk udgave. +gw.msg.hits: fund +gw.msg.z39errcode: Z39.50 fejl kode +gw.msg.databases: Følgende databaser er til rådighed i # Fejlmeddelelser gw.err.nullbody: Ingen email-krop. Ingen forespørgsel foretaget. gw.err.unimplemented: Kommandoen er endnu ikke implementeret gw.err.unknown.command: Ukendt kommando +gw.err.notarget: Target er ikke defineret +gw.err.connect: Kan ikke få forbindelse med gw.err.term.expected: Søgeord forventet gw.err.rp.expected: ')' forventet gw.err.setname.expected: Navn på søgesæt forventet @@ -24,6 +29,7 @@ gw.err.trunc.not.right: H # Navne på kommandoer og operatorer ccl.command.find: find f +ccl.command.target: server target ccl.command.show: vis ccl.command.base: base ccl.command.help: help hjælp h diff --git a/kernel/loc.res b/kernel/loc.res index b517591..b0dea46 100644 --- a/kernel/loc.res +++ b/kernel/loc.res @@ -1,9 +1,9 @@ # Email gateway - resource for a specific target -# $Id: loc.res,v 1.1 1995/02/16 13:21:00 adam Exp $ +# $Id: loc.res,v 1.2 1995/02/16 18:35:09 adam Exp $ # See p. 40-43 in Europagate, Background Study, Part II gw.portno: 210 gw.hostname: IBM2.LOC.gov gw.description: LC Z39.50 Test Server Information, Library of Congress gw.bibset: loc.bib -gw.bases: BOOKS NAMES +gw.databases: BOOKS NAMES diff --git a/kernel/main.c b/kernel/main.c index dbcbc89..7427d97 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,11 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.2 1995/02/16 13:21:00 adam + * Revision 1.3 1995/02/16 18:35:09 adam + * First use of Zdist library. Search requests are supported. + * Present requests are not supported yet. + * + * Revision 1.2 1995/02/16 13:21:00 adam * Organization of resource files for targets and conversion * language implemented. * @@ -15,21 +19,30 @@ #include #include +#include +#include #include "kernel.h" -GwRes kernel_res = NULL; -const char *default_res = "default.res"; -const char *target = NULL; -const char *lang = NULL; -CCL_bibset bibset = NULL; - FILE *reply_fd = stdout; +struct gw_kernel_info info; + int main (int argc, char **argv) { + info.kernel_res = NULL; + info.default_res = "default.res"; + info.override_res = NULL; + *info.target = 0; + info.lang = NULL; + info.bibset = NULL; + info.zass = NULL; + info.override_portno = NULL; + info.override_hostname = NULL; + info.databases = NULL; + gw_log_init (*argv); - kernel_res = gw_res_init (); + info.kernel_res = gw_res_init (); while (--argc > 0) { if (**++argv == '-') @@ -41,11 +54,11 @@ int main (int argc, char **argv) break; case 't': if (argv[0][2]) - target = argv[0]+2; + strcpy (info.target, argv[0]+2); else if (argc > 0) { --argc; - target= *++argv; + strcpy (info.target, *++argv); } else { @@ -55,11 +68,11 @@ int main (int argc, char **argv) break; case 'l': if (argv[0][2]) - lang = argv[0]+2; + info.lang = argv[0]+2; else if (argc > 0) { --argc; - lang = *++argv; + info.lang = *++argv; } else { @@ -67,13 +80,55 @@ int main (int argc, char **argv) exit (1); } break; + case 'o': + if (argv[0][2]) + info.override_res = argv[0]+2; + else if (argc > 0) + { + --argc; + info.override_res = *++argv; + } + else + { + gw_log (GW_LOG_FATAL, "main", "missing language name"); + exit (1); + } + break; + case 'p': + if (argv[0][2]) + info.override_portno = argv[0]+2; + else if (argc > 0) + { + --argc; + info.override_portno = *++argv; + } + else + { + gw_log (GW_LOG_FATAL, "main", "missing portno"); + exit (1); + } + break; + case 'h': + if (argv[0][2]) + info.override_hostname = argv[0]+2; + else if (argc > 0) + { + --argc; + info.override_hostname = *++argv; + } + else + { + gw_log (GW_LOG_FATAL, "main", "missing hostname"); + exit (1); + } + break; default: gw_log (GW_LOG_FATAL, "main", "unknown option %s", *argv); exit (1); } } else - default_res = *argv; + info.default_res = *argv; } read_kernel_res (); urp (stdin); @@ -85,50 +140,60 @@ void read_kernel_res (void) char path_prefix[128]; char fname[160]; const char *v; + char *cp; char resource_name[256]; - bibset = ccl_qual_mk (); + if (info.bibset) + ccl_qual_rm (&info.bibset); + info.bibset = ccl_qual_mk (); + + if (info.kernel_res) + gw_res_close (info.kernel_res); + info.kernel_res = gw_res_init (); gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, default %s", - default_res); - if (target) + info.default_res); + if (*info.target) gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, target %s", - target); - if (lang) + info.target); + if (info.lang) gw_log (GW_LOG_DEBUG, "main", "reading kernel resource, lang %s", - lang); - if (kernel_res) - gw_res_close (kernel_res); - kernel_res = gw_res_init (); - if (gw_res_merge (kernel_res, default_res)) + info.lang); + + if (gw_res_merge (info.kernel_res, info.default_res)) { gw_log (GW_LOG_WARN, "main", "Couldn't read resource file %s", - default_res); + info.default_res); return; } - strcpy (path_prefix, gw_res_get (kernel_res, "gw.path", ".")); + strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", ".")); - if (target) + if (*info.target) { - sprintf (resource_name, "gw.target.%s", target); - v = gw_res_get (kernel_res, resource_name, NULL); + sprintf (resource_name, "gw.target.%s", info.target); + v = gw_res_get (info.kernel_res, resource_name, NULL); if (v) { sprintf (fname, "%s/%s", path_prefix, v); - gw_res_merge (kernel_res, fname); + gw_res_merge (info.kernel_res, fname); } - } - if (lang) + } + if (info.lang) { - sprintf (resource_name, "gw.lang.%s", lang); - v = gw_res_get (kernel_res, resource_name, NULL); + sprintf (resource_name, "gw.lang.%s", info.lang); + v = gw_res_get (info.kernel_res, resource_name, NULL); if (v) { sprintf (fname, "%s/%s", path_prefix, v); - gw_res_merge (kernel_res, fname); + gw_res_merge (info.kernel_res, fname); } } - v = gw_res_get (kernel_res, "gw.bibset", NULL); + if (info.override_res) + { + sprintf (fname, "%s/%s", path_prefix, info.override_res); + gw_res_merge (info.kernel_res, fname); + } + v = gw_res_get (info.kernel_res, "gw.bibset", NULL); if (v) { FILE *bib_inf; @@ -140,8 +205,44 @@ void read_kernel_res (void) else { gw_log (GW_LOG_DEBUG, "main", "reading bib file %s", fname); - ccl_qual_file (bibset, bib_inf); + ccl_qual_file (info.bibset, bib_inf); fclose (bib_inf); } } + sprintf (resource_name, "gw.target.%s", info.target); + if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL)) + { + /* target is there, and there is no sub-resource for it... */ + char *split; + + if ((split = strchr (info.target, ':'))) + *split++ = '\0'; + strncpy (info.hostname, info.target, sizeof(info.hostname)-1); + if (split) + info.port = atoi (split); + else + info.port = atoi (gw_res_get + (info.kernel_res, "gw.portno", "210")); + } + else + { + strncpy (info.hostname, gw_res_get (info.kernel_res, + "gw.hostname", "localhost"), + sizeof(info.hostname)-1); + info.port = atoi (gw_res_get (info.kernel_res, + "gw.portno", "210")); + } + if (info.databases) + free (info.databases); + v = gw_res_get (info.kernel_res, "gw.databases", "Default"); + info.databases = malloc (1+strlen(v)); + assert (info.databases); + strcpy (info.databases, v); + for (cp = info.databases; (cp = strchr (cp, ' ')); cp++) + *cp = ','; + if (info.override_portno) + info.port = atoi (info.override_portno); + if (info.override_hostname) + strncpy (info.hostname, info.override_hostname, + sizeof(info.hostname)-1); } diff --git a/kernel/urp.c b/kernel/urp.c index dce2ba8..d047cac 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,11 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.2 1995/02/16 13:21:00 adam + * Revision 1.3 1995/02/16 18:35:09 adam + * First use of Zdist library. Search requests are supported. + * Present requests are not supported yet. + * + * Revision 1.2 1995/02/16 13:21:00 adam * Organization of resource files for targets and conversion * language implemented. * @@ -23,6 +27,30 @@ #define LINE_MAX 256 +static int reopen_target (void) +{ + const char *v; + if (info.zass) + gw_log (GW_LOG_WARN, "urp", "Zass free..."); + info.zass = zass_open (info.hostname, info.port); + if (!info.zass) + { + fprintf (reply_fd, "%s %s:%d\n", + gw_res_get (info.kernel_res, "gw.err.connect", + "Cannot connect to target"), + info.hostname, info.port); + return -1; + } + v = gw_res_get (info.kernel_res, "gw.description", NULL); + if (v) + fprintf (reply_fd, "%s\n", v); + fprintf (reply_fd, "%s %s:%d\n %s\n", + gw_res_get (info.kernel_res, "gw.msg.databases", + "Available databases on"), + info.hostname, info.port, info.databases); + return 0; +} + static char line_buf[LINE_MAX+1]; static struct command_word { @@ -58,7 +86,7 @@ const char *resource_prefix) sprintf (resource_name, "%s%s", resource_prefix, tab->resource_suffix); - v = gw_res_get (kernel_res, resource_name, tab->default_value); + v = gw_res_get (info.kernel_res, resource_name, tab->default_value); assert (v); strcpy (command_names, v); cp = command_names; @@ -128,11 +156,13 @@ static int email_header (FILE *inf, char *from_str) static int exec_find (struct ccl_token *list) { + const struct zass_searchent *p; + struct ccl_rpn_node *rpn; int error; const char *pos; - rpn = ccl_find (bibset, list, &error, &pos); + rpn = ccl_find (info.bibset, list, &error, &pos); if (!rpn) { const char *v = NULL, *n; @@ -144,7 +174,7 @@ static int exec_find (struct ccl_token *list) if (n) { sprintf (name, "gw.err.%s", n); - v = gw_res_get (kernel_res, name, NULL); + v = gw_res_get (info.kernel_res, name, NULL); } if (!v) v = ccl_err_msg (error); @@ -153,33 +183,62 @@ static int exec_find (struct ccl_token *list) } ccl_pr_tree (rpn, reply_fd); fprintf (reply_fd, "\n"); + + if (!info.zass) + return -2; + p = zass_search (info.zass, rpn, "Default", info.databases); + if (!p) + return -1; + fprintf (reply_fd, "%d %s\n", p->num, + gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)")); + 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); return 0; } +static int exec_target (struct ccl_token *list) +{ + if (list->kind == CCL_TOK_EOL) + return -1; + memcpy (info.target, list->name, list->len); + info.target [list->len] = '\0'; + + read_kernel_res (); + return reopen_target (); +} + static int exec_command (const char *str) { struct ccl_token *cmd = ccl_tokenize (str); int no; - fprintf (reply_fd, "> %s", str); if (cmd->kind != CCL_TOK_EOL && (no = command_search (command_tab, cmd, "ccl.command."))) { + if (!info.zass && no != 9) + reopen_target (); + fprintf (reply_fd, "\n> %s", str); switch (no) { case 1: return exec_find (cmd->next); break; + case 9: + return exec_target (cmd->next); + break; default: - fprintf (reply_fd, " %s\n", - gw_res_get (kernel_res, "gw.err.unimplemented", + fprintf (reply_fd, "%s\n", + gw_res_get (info.kernel_res, "gw.err.unimplemented", "Not implemented yet")); } } else { fprintf (reply_fd, " ^ %s\n", - gw_res_get (kernel_res, "gw.err.unknown.command", + gw_res_get (info.kernel_res, "gw.err.unknown.command", "unknown command")); } return 0; @@ -198,9 +257,9 @@ int urp (FILE *inf) } if (*from_str) { - reply_fname = tempnam (gw_res_get (kernel_res, + reply_fname = tempnam (gw_res_get (info.kernel_res, "gw.reply.tmp.dir", NULL), - gw_res_get (kernel_res, + gw_res_get (info.kernel_res, "gw.reply.tmp.prefix", "gwr")); reply_fd = fopen (reply_fname, "w"); @@ -213,22 +272,23 @@ int urp (FILE *inf) } else gw_log (GW_LOG_WARN, "urp", "No From in email header"); - fprintf (reply_fd, "%s\n", gw_res_get (kernel_res, "gw.msg.greeting", + 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)) { if (line_buf[0] == '\n') break; - ccl_token_and = gw_res_get (kernel_res, "ccl.token.and", "and"); - ccl_token_or = gw_res_get (kernel_res, "ccl.token.or", "or"); - ccl_token_not = gw_res_get (kernel_res, "ccl.token.not", "not"); - ccl_token_set = gw_res_get (kernel_res, "ccl.token.set", "set"); + 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++; } if (!command_no) - fprintf (reply_fd, "%s\n", gw_res_get (kernel_res, "gw.err.nullbody", + fprintf (reply_fd, "%s\n", gw_res_get (info.kernel_res, + "gw.err.nullbody", "No body")); if (*from_str) { @@ -240,7 +300,8 @@ int urp (FILE *inf) fclose (reply_fd); reply_fd = stdout; - mta = gw_res_get (kernel_res, "gw.reply.mta", "/usr/lib/sendmail"); + mta = gw_res_get (info.kernel_res, "gw.reply.mta", + "/usr/lib/sendmail"); sprintf (cmd, "%s %s < %s", mta, from_str, reply_fname); mta_code = system (cmd); -- 1.7.10.4