From: Adam Dickmeiss Date: Wed, 19 Apr 1995 10:46:17 +0000 (+0000) Subject: Persistency works much better now. New command: status - history-like X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=d519fdaae5ce6533cfaa65d0e9715b2bc1c8ae46;p=egate.git Persistency works much better now. New command: status - history-like --- diff --git a/kernel/Makefile b/kernel/Makefile index 05f8b6f..6fafa73 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,7 +2,10 @@ # Europagate, 1995 # # $Log: Makefile,v $ -# Revision 1.16 1995/04/19 07:30:56 adam +# Revision 1.17 1995/04/19 10:46:17 adam +# Persistency works much better now. New command: status - history-like +# +# Revision 1.16 1995/04/19 07:30:56 adam # First work on Z39.50 persistence. # # Revision 1.15 1995/04/17 11:27:29 quinn @@ -56,11 +59,11 @@ # SHELL=/bin/sh -ZPRE=/home/proj/zdist/zdist102b1-1/libz3950 -ZINC=-I$(ZPRE) -ZLIB=$(ZPRE)/libz3950.a +#ZPRE=/home/proj/zdist/zdist102b1-1/libz3950 +#ZINC=-I$(ZPRE) +#ZLIB=$(ZPRE)/libz3950.a -#ZLIB=../../yaz/lib/libyaz.a +ZLIB=../../yaz/lib/libyaz.a INCLUDE=-I../include #CFLAGS=-g -Wall diff --git a/kernel/kernel.h b/kernel/kernel.h index dc2adc4..ef5d82f 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: kernel.h,v $ - * Revision 1.13 1995/04/19 07:31:04 adam + * Revision 1.14 1995/04/19 10:46:18 adam + * Persistency works much better now. New command: status - history-like + * + * Revision 1.13 1995/04/19 07:31:04 adam * First work on Z39.50 persistence. * * Revision 1.12 1995/04/17 09:34:29 adam @@ -68,6 +71,7 @@ struct gw_user_set { char *database; /* database(s) in which we search */ struct ccl_rpn_node *rpn; /* rpn request */ int present_flag; /* present in target (presistency) */ + char *search_str; /* find request string */ struct gw_user_set *prev; }; @@ -108,7 +112,8 @@ void read_kernel_res (void); struct gw_user_set *user_set_add (const char *name, int hits, const char *database, struct ccl_rpn_node *rpn, - int present_flag); + int present_flag, + const char *search_str); struct gw_user_set *user_set_search (const char *name); void user_set_init (void); diff --git a/kernel/lang.dk.res b/kernel/lang.dk.res index 5fcb52c..fa14969 100644 --- a/kernel/lang.dk.res +++ b/kernel/lang.dk.res @@ -1,5 +1,5 @@ # Email gateway - resources for danish conversation -# $Id: lang.dk.res,v 1.6 1995/03/01 14:32:25 adam Exp $ +# $Id: lang.dk.res,v 1.7 1995/04/19 10:46:18 adam Exp $ # # Beskeder gw.msg.subject: Din forespørgsel @@ -9,7 +9,7 @@ gw.msg.z39errcode: Z39.50 fejl kode gw.msg.connect: Forbindelse oprettet til server gw.msg.databases: Databaser til stede gw.msg.database: Valgte databaser -gw.msg.records: %d poster modtaget +gw.msg.records: %d poster modtaget fra sæt %s # Fejlmeddelelser gw.err.no.database: Database skal vælges inden find-forespørgsel diff --git a/kernel/lang.uk.res b/kernel/lang.uk.res index 21716fc..c6c269b 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.5 1995/03/01 14:32:25 adam Exp $ +# $Id: lang.uk.res,v 1.6 1995/04/19 10:46:18 adam Exp $ # # Messages gw.msg.subject: Your Z39.50 Query @@ -9,7 +9,7 @@ gw.msg.z39errcode: Z39.50 error code gw.msg.connect: Connection established to target gw.msg.databases: Known databases gw.msg.database: Selected databases -gw.msg.msg.records: %d records found +gw.msg.records: %d records found in set %s # Error messages gw.err.no.database: You must choose database before issuing a find-query diff --git a/kernel/main.c b/kernel/main.c index f638c4b..a8fadfb 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: main.c,v $ - * Revision 1.16 1995/04/19 07:31:07 adam + * Revision 1.17 1995/04/19 10:46:18 adam + * Persistency works much better now. New command: status - history-like + * + * Revision 1.16 1995/04/19 07:31:07 adam * First work on Z39.50 persistence. * * Revision 1.15 1995/04/17 09:34:30 adam @@ -208,6 +211,9 @@ int main (int argc, char **argv) fprintf (stderr, " -i id Set IPC userid\n"); exit (1); case 'd': + gw_log_level (GW_LOG_ALL & ~RES_DEBUG); + break; + case 'D': gw_log_level (GW_LOG_ALL); break; case 't': @@ -342,7 +348,8 @@ int main (int argc, char **argv) struct gw_user_set *user_set_add (const char *name, int hits, const char *database, struct ccl_rpn_node *rpn, - int present_flag) + int present_flag, + const char *search_str) { struct gw_user_set *s; @@ -354,6 +361,7 @@ struct gw_user_set *user_set_add (const char *name, int hits, s->database = gw_strdup (database); s->rpn = rpn; s->present_flag = present_flag; + s->search_str = gw_strdup (search_str); s->prev = info.sets; info.sets = s; return s; diff --git a/kernel/persist.c b/kernel/persist.c index e341536..219024f 100644 --- a/kernel/persist.c +++ b/kernel/persist.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: persist.c,v $ - * Revision 1.1 1995/04/19 07:31:10 adam + * Revision 1.2 1995/04/19 10:46:19 adam + * Persistency works much better now. New command: status - history-like + * + * Revision 1.1 1995/04/19 07:31:10 adam * First work on Z39.50 persistence. * */ @@ -17,6 +20,17 @@ #include "kernel.h" +static int fgetsx (char *buf, int size, FILE *inf) +{ + char *cp; + + if (!fgets (buf, size, inf)) + return 0; + if ((cp = strchr (buf, '\n'))) + *cp = '\0'; + return 1; +} + static int set_change; static int obtain_set (ZASS zass, struct gw_user_set *set) @@ -32,6 +46,7 @@ static int obtain_set (ZASS zass, struct gw_user_set *set) set_change = 1; set->present_flag = 1; set->hits = p->num; + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s researched", set->name); return 0; } @@ -55,9 +70,17 @@ static int obtain_sets (ZASS zass, struct ccl_rpn_node *rpn, case CCL_RPN_SET: set = user_set_search (rpn->u.setname); if (!set) + { + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s not there at all", + rpn->u.setname); return 1; + } if (set->present_flag) + { + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s already there", + rpn->u.setname); return 0; + } } return obtain_set (zass, set); } @@ -87,9 +110,12 @@ const struct zass_presentent *zass_p_present (ZASS zass, return NULL; if (!set->present_flag) { - int r = obtain_set (zass, set); - if (r) - return NULL; + const struct zass_searchent *p; + + p = zass_p_search (zass, set->rpn, result_set, set->database, + info.sets); + if (!p) + return NULL; } return zass_present (zass, (char*) result_set, offset, number); } @@ -98,13 +124,11 @@ struct ccl_rpn_node *load_rpn (char *buf, FILE *inf) { struct ccl_rpn_node *rpn; struct ccl_rpn_attr **attrp; - char *cp; int type, value, no_read; + char *cp; - if (!fgets (buf, 1024, inf)) + if (!fgetsx (buf, 1024, inf)) return NULL; - if ((cp = strchr (buf, '\n'))) - *cp = '\0'; switch (*buf) { case 'A': @@ -147,7 +171,7 @@ struct ccl_rpn_node *load_rpn (char *buf, FILE *inf) rpn->u.t.term = gw_strdup (buf+2); attrp = &rpn->u.t.attr_list; - if (!fgets (buf, 1024, inf)) + if (!fgetsx (buf, 1024, inf)) return NULL; cp = buf; while (sscanf (cp, "%d %d%n", &type, &value, &no_read) > 1) @@ -189,33 +213,46 @@ int load_p_state (int userid) "Couldn't open %s", fname); return -1; } - gw_log (GW_LOG_FATAL, KERNEL_LOG, + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Reading persistence file %s", fname); - if (!fgets (fline, 1024, inf)) + + if (!fgetsx (fline, 1024, inf)) return -1; if (sscanf (fline, "%s", info.target) != 1) *info.target = '\0'; - gw_log (GW_LOG_FATAL, KERNEL_LOG, - "Reading persistence file %s (2)", fname); read_kernel_res (); - gw_log (GW_LOG_FATAL, KERNEL_LOG, "reopen_target start"); + + if (!fgetsx (fline, 1024, inf)) + return -1; + free (info.database); + info.database = gw_strdup (fline); + + if (!fgetsx (fline, 1024, inf)) + return -1; + if (sscanf (fline, "%d", &info.setno) != 1) + return -1; + gw_log (GW_LOG_DEBUG, KERNEL_LOG, + "Reading persistence file %s (2)", fname); reopen_target (); - gw_log (GW_LOG_FATAL, KERNEL_LOG, "reopen_target end"); - while (fgets (fline, 1024, inf)) + while (fgetsx (fline, 1024, inf)) { - gw_log (GW_LOG_FATAL, KERNEL_LOG, + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Reading persistence file %s (3)", fname); if (sscanf (fline, "%s %d %s", resultname, &hits, database) != 3) return -1; - gw_log (GW_LOG_FATAL, KERNEL_LOG, + if (!fgetsx (fline, 1024, inf)) /* search string */ + return -1; + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Adding %s, %d hits, database %s", resultname, hits, database); - set = user_set_add (resultname, hits, database, NULL, 0); + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Search string %s", fline); + set = user_set_add (resultname, hits, database, NULL, 0, fline); set->rpn = load_rpn (fline, inf); ccl_pr_tree (set->rpn, stderr); - fgets (fline, 1024, inf); + fgetsx (fline, 1024, inf); } fclose (inf); + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Finished reading %s", fname); return 0; } @@ -256,11 +293,21 @@ static void save_rpn (struct ccl_rpn_node *rpn, FILE *of) } } +static void save_sets (FILE *of, struct gw_user_set *sp) +{ + if (!sp) + return; + save_sets (of, sp->prev); + fprintf (of, "%s %d %s\n%s\n", sp->name, sp->hits, sp->database, + sp->search_str); + save_rpn (sp->rpn, of); + fprintf (of, "X\n"); +} + int save_p_state (int userid) { FILE *of; char fname[128]; - struct gw_user_set *sp; sprintf (fname, "persist.%d", userid); @@ -272,14 +319,8 @@ int save_p_state (int userid) return -1; } gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Writing persistence file %s", fname); - fprintf (of, "%s\n", info.target); - for (sp = info.sets; sp; sp = sp->prev) - { - fprintf (of, "%s %d %s\n", sp->name, sp->hits, sp->database); - save_rpn (sp->rpn, of); - fprintf (of, "X\n"); - } + fprintf (of, "%s\n%s\n%d\n", info.target, info.database, info.setno); + save_sets (of, info.sets); fclose (of); return 0; } - diff --git a/kernel/urp.c b/kernel/urp.c index 032392c..0c6c333 100644 --- a/kernel/urp.c +++ b/kernel/urp.c @@ -2,7 +2,10 @@ * Europagate, 1995 * * $Log: urp.c,v $ - * Revision 1.26 1995/04/19 07:31:12 adam + * Revision 1.27 1995/04/19 10:46:19 adam + * Persistency works much better now. New command: status - history-like + * + * Revision 1.26 1995/04/19 07:31:12 adam * First work on Z39.50 persistence. * * Revision 1.25 1995/04/17 09:34:33 adam @@ -137,9 +140,12 @@ int reopen_target (void) const char *v; if (info.zass) gw_log (GW_LOG_WARN, KERNEL_LOG, "Zass free..."); + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reopen_target"); info.zass = zass_open (info.hostname, info.port); if (!info.zass) { + gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Cannot connect to target %s:%d", + info.hostname, info.port); fprintf (reply_fd, "%s %s:%d\n", gw_res_get (info.kernel_res, "gw.err.connect", "Cannot connect to target"), @@ -166,6 +172,10 @@ int reopen_target (void) gw_res_get (info.kernel_res, "gw.msg.database", "Selected databases"), info.database); + if (info.setno >= 0) + fprintf (reply_fd, "set=%d\n", info.setno); + else + fprintf (reply_fd, "set=Default\n"); return 0; } @@ -321,7 +331,7 @@ static void display_diag_error (int code, const char *addinfo) gw_res_get (info.kernel_res, str, ""), addinfo); } -static int exec_find (struct ccl_token *list) +static int exec_find (struct ccl_token *list, const char *search_str) { const struct zass_searchent *p; struct gw_user_set *us; @@ -381,7 +391,7 @@ static int exec_find (struct ccl_token *list) } fprintf (reply_fd, "%d %s\n", p->num, gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)")); - us = user_set_add (setname, p->num, info.database, rpn, 1); + us = user_set_add (setname, p->num, info.database, rpn, 1, search_str); fprintf (reply_fd, "Result-set %s created\n", setname); if (info.setno >= 0) info.setno++; @@ -401,6 +411,22 @@ static int exec_target (struct ccl_token *list) return reopen_target (); } +static void exec_status_r (struct gw_user_set *sp) +{ + if (!sp) + return; + exec_status_r (sp->prev); + fprintf (reply_fd, "%6s %7d %12.12s %.50s\n", sp->name, sp->hits, + sp->database, sp->search_str); +} + +static int exec_status (struct ccl_token *list) +{ + fprintf (reply_fd, " Name Hits Database Find\n"); + exec_status_r (info.sets); + return 0; +} + static int exec_base (struct ccl_token *list) { struct ccl_token *li = list; @@ -478,8 +504,8 @@ static void present (const char *set, int offset, int number, } fprintf (reply_fd, gw_res_get (info.kernel_res, "gw.msg.records", - "Got %d records"), - zp->num); + "Got %d records from set %s"), + zp->num, set); fprintf (reply_fd, "\n"); for (i = 0, pp = zp->records; pp; pp = pp->next, i++) { @@ -722,16 +748,24 @@ static int exec_command (const char *str) "command ignored")); return 0; } +#if 0 + 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"); +#endif switch (no) { case 1: - return exec_find (cmd->next); + return exec_find (cmd->next, str); case 2: return exec_show (cmd->next); case 3: return exec_base (cmd->next); case 4: return exec_help (cmd->next); + case 7: + return exec_status (cmd->next); case 9: return exec_target (cmd->next); default: @@ -799,10 +833,6 @@ int urp_start (int continuation, struct str_queue *queue) 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; }