* Europagate, 1995
*
* $Log: kernel.h,v $
- * Revision 1.12 1995/04/17 09:34:29 adam
+ * 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
* Timeout (idletime) adjustable. Minor changes in kernel.
*
* Revision 1.11 1995/03/28 11:42:34 adam
#define LINE_MAX 1024
struct gw_user_set {
- char *name; /* name of result set */
- int hits; /* -1 on error */
+ char *name; /* name of result set */
+ int hits; /* -1 on error */
+ char *database; /* database(s) in which we search */
+ struct ccl_rpn_node *rpn; /* rpn request */
+ int present_flag; /* present in target (presistency) */
struct gw_user_set *prev;
};
int command_no;
char from_str[LINE_MAX+1];
const char *reply_fname;
+ int setno;
#if USE_FML
Fml fml;
#endif
void read_kernel_res (void);
-struct gw_user_set *user_set_add (const char *name, int hits);
+struct gw_user_set *user_set_add (const char *name, int hits,
+ const char *database,
+ struct ccl_rpn_node *rpn,
+ int present_flag);
struct gw_user_set *user_set_search (const char *name);
void user_set_init (void);
int lgets (char *buf, int max, int fd);
+const struct zass_searchent *zass_p_search (ZASS zass,
+ struct ccl_rpn_node *rpn,
+ const char *result_set,
+ const char *database,
+ struct gw_user_set *sets);
+const struct zass_presentent *zass_p_present (ZASS zass,
+ const char *result_set,
+ int offset, int number);
+
+int load_p_state (int userid);
+int save_p_state (int userid);
+int reopen_target (void);
+
#define KERNEL_LOG "kernel"
* Europagate, 1995
*
* $Log: main.c,v $
- * Revision 1.15 1995/04/17 09:34:30 adam
+ * 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
* Timeout (idletime) adjustable. Minor changes in kernel.
*
* Revision 1.14 1995/03/28 11:42:34 adam
{
gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds",
timeout);
+ if (info.zass)
+ save_p_state (userid);
break;
}
if (FD_ISSET (gip_fd, &set_r))
while (lgets (line_buf, sizeof(line_buf)-1, gip_fd))
str_queue_enq (queue, line_buf);
urp_start (continuation, queue);
+ if (!continuation)
+ load_p_state (userid);
urp_command (queue);
urp_end ();
while (str_queue_deq (queue, 0, 0))
info.override_hostname = NULL;
info.databases = NULL;
info.database = NULL;
+ info.setno = -1;
#if USE_FML
info.fml = NULL;
#endif
else
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)
+ {
+ read_kernel_res ();
kernel_events (queue, userid);
+ }
else
{
char line_buf[512];
+ read_kernel_res ();
while (lgets (line_buf, sizeof(line_buf)-1, 0))
str_queue_enq (queue, line_buf);
urp_start (0, queue);
return 0;
}
-struct gw_user_set *user_set_add (const char *name, int hits)
+struct gw_user_set *user_set_add (const char *name, int hits,
+ const char *database,
+ struct ccl_rpn_node *rpn,
+ int present_flag)
{
struct gw_user_set *s;
s->name = gw_strdup (name);
s->hits = hits;
+ s->database = gw_strdup (database);
+ s->rpn = rpn;
+ s->present_flag = present_flag;
s->prev = info.sets;
info.sets = s;
return s;
for (s = info.sets; s; s = s1)
{
free (s->name);
+ free (s->database);
+ ccl_rpn_delete (s->rpn);
s1 = s->prev;
free (s);
}
if (info.override_hostname)
strncpy (info.hostname, info.override_hostname,
sizeof(info.hostname)-1);
+ v = gw_res_get (info.kernel_res, "gw.result.set", NULL);
+ info.setno = v ? -1 : 0;
#if USE_FML
if (!info.fml)
{
--- /dev/null
+/* Gateway kernel - Z39.50 Persistence
+ * Europagate, 1995
+ *
+ * $Log: persist.c,v $
+ * Revision 1.1 1995/04/19 07:31:10 adam
+ * First work on Z39.50 persistence.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "kernel.h"
+
+static int set_change;
+
+static int obtain_set (ZASS zass, struct gw_user_set *set)
+{
+ const struct zass_searchent *p;
+
+ p = zass_search (zass, set->rpn, set->name, set->database);
+ if (!p)
+ return 2;
+ if (p->errcode != -1)
+ return 3;
+ if (p->num != set->hits)
+ set_change = 1;
+ set->present_flag = 1;
+ set->hits = p->num;
+ return 0;
+}
+
+static int obtain_sets (ZASS zass, struct ccl_rpn_node *rpn,
+ struct gw_user_set *sets)
+{
+ struct gw_user_set *set;
+ int r;
+
+ switch (rpn->kind)
+ {
+ case CCL_RPN_AND:
+ case CCL_RPN_OR:
+ case CCL_RPN_NOT:
+ case CCL_RPN_PROX:
+ if ((r=obtain_sets (zass, rpn->u.p[0], sets)))
+ return r;
+ return obtain_sets (zass, rpn->u.p[1], sets);
+ case CCL_RPN_TERM:
+ return 0;
+ case CCL_RPN_SET:
+ set = user_set_search (rpn->u.setname);
+ if (!set)
+ return 1;
+ if (set->present_flag)
+ return 0;
+ }
+ return obtain_set (zass, set);
+}
+
+const struct zass_searchent *zass_p_search (ZASS zass,
+ struct ccl_rpn_node *rpn,
+ const char *result_set,
+ const char *database,
+ struct gw_user_set *sets)
+{
+ int r;
+
+ set_change = 0;
+ r = obtain_sets (zass, rpn, sets);
+ if (r)
+ return NULL;
+ return zass_search (zass, rpn, (char*) result_set, (char*) database);
+}
+
+const struct zass_presentent *zass_p_present (ZASS zass,
+ const char *result_set, int offset, int number)
+{
+ struct gw_user_set *set;
+
+ set = user_set_search (result_set);
+ if (!set)
+ return NULL;
+ if (!set->present_flag)
+ {
+ int r = obtain_set (zass, set);
+ if (r)
+ return NULL;
+ }
+ return zass_present (zass, (char*) result_set, offset, number);
+}
+
+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;
+
+ if (!fgets (buf, 1024, inf))
+ return NULL;
+ if ((cp = strchr (buf, '\n')))
+ *cp = '\0';
+ switch (*buf)
+ {
+ case 'A':
+ rpn = malloc (sizeof (*rpn));
+ if (!rpn)
+ return NULL;
+ rpn->kind = CCL_RPN_AND;
+ rpn->u.p[0] = load_rpn (buf, inf);
+ rpn->u.p[1] = load_rpn (buf, inf);
+ break;
+ case 'O':
+ rpn = malloc (sizeof (*rpn));
+ if (!rpn)
+ return NULL;
+ rpn->kind = CCL_RPN_OR;
+ rpn->u.p[0] = load_rpn (buf, inf);
+ rpn->u.p[1] = load_rpn (buf, inf);
+ break;
+ case 'N':
+ rpn = malloc (sizeof (*rpn));
+ if (!rpn)
+ return NULL;
+ rpn->kind = CCL_RPN_NOT;
+ rpn->u.p[0] = load_rpn (buf, inf);
+ rpn->u.p[1] = load_rpn (buf, inf);
+ break;
+ case 'P':
+ rpn = malloc (sizeof (*rpn));
+ if (!rpn)
+ return NULL;
+ rpn->kind = CCL_RPN_PROX;
+ rpn->u.p[0] = load_rpn (buf, inf);
+ rpn->u.p[1] = load_rpn (buf, inf);
+ break;
+ case 'T':
+ rpn = malloc (sizeof (*rpn));
+ if (!rpn)
+ return NULL;
+ rpn->kind = CCL_RPN_TERM;
+
+ rpn->u.t.term = gw_strdup (buf+2);
+ attrp = &rpn->u.t.attr_list;
+ if (!fgets (buf, 1024, inf))
+ return NULL;
+ cp = buf;
+ while (sscanf (cp, "%d %d%n", &type, &value, &no_read) > 1)
+ {
+ *attrp = malloc (sizeof(**attrp));
+ (*attrp)->type = type;
+ (*attrp)->value = value;
+ attrp = &(*attrp)->next;
+ cp += no_read;
+ }
+ *attrp = NULL;
+ break;
+ case 'S':
+ rpn = malloc (sizeof (*rpn));
+ if (!rpn)
+ return NULL;
+ rpn->kind = CCL_RPN_SET;
+ rpn->u.setname = gw_strdup (buf+2);
+ }
+ return rpn;
+}
+
+int load_p_state (int userid)
+{
+ FILE *inf;
+ char fname[128];
+ char fline[1025];
+ char database[1024];
+ char resultname[32];
+ int hits;
+ struct gw_user_set *set;
+
+ sprintf (fname, "persist.%d", userid);
+
+ inf = fopen (fname, "r");
+ if (!inf)
+ {
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
+ "Couldn't open %s", fname);
+ return -1;
+ }
+ gw_log (GW_LOG_FATAL, KERNEL_LOG,
+ "Reading persistence file %s", fname);
+ if (!fgets (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");
+ reopen_target ();
+ gw_log (GW_LOG_FATAL, KERNEL_LOG, "reopen_target end");
+ while (fgets (fline, 1024, inf))
+ {
+ gw_log (GW_LOG_FATAL, 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,
+ "Adding %s, %d hits, database %s",
+ resultname, hits, database);
+ set = user_set_add (resultname, hits, database, NULL, 0);
+ set->rpn = load_rpn (fline, inf);
+ ccl_pr_tree (set->rpn, stderr);
+ fgets (fline, 1024, inf);
+ }
+ fclose (inf);
+ return 0;
+}
+
+static void save_rpn (struct ccl_rpn_node *rpn, FILE *of)
+{
+ struct ccl_rpn_attr *attr;
+
+ switch (rpn->kind)
+ {
+ case CCL_RPN_AND:
+ fprintf (of, "A\n");
+ save_rpn (rpn->u.p[0], of);
+ save_rpn (rpn->u.p[1], of);
+ break;
+ case CCL_RPN_OR:
+ fprintf (of, "O\n");
+ save_rpn (rpn->u.p[0], of);
+ save_rpn (rpn->u.p[1], of);
+ break;
+ case CCL_RPN_NOT:
+ fprintf (of, "N\n");
+ save_rpn (rpn->u.p[0], of);
+ save_rpn (rpn->u.p[1], of);
+ break;
+ case CCL_RPN_PROX:
+ fprintf (of, "P\n");
+ save_rpn (rpn->u.p[0], of);
+ save_rpn (rpn->u.p[1], of);
+ break;
+ case CCL_RPN_TERM:
+ fprintf (of, "T %s\n", rpn->u.t.term);
+ for (attr = rpn->u.t.attr_list; attr; attr = attr->next)
+ fprintf (of, "%d %d ", attr->type, attr->value);
+ fprintf (of, "\n");
+ break;
+ case CCL_RPN_SET:
+ fprintf (of, "S %s\n", rpn->u.setname);
+ }
+}
+
+int save_p_state (int userid)
+{
+ FILE *of;
+ char fname[128];
+ struct gw_user_set *sp;
+
+ sprintf (fname, "persist.%d", userid);
+
+ of = fopen (fname, "w");
+ if (!of)
+ {
+ gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
+ "Couldn't open %s", fname);
+ 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");
+ }
+ fclose (of);
+ return 0;
+}
+
* Europagate, 1995
*
* $Log: urp.c,v $
- * Revision 1.25 1995/04/17 09:34:33 adam
+ * 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
* Timeout (idletime) adjustable. Minor changes in kernel.
*
* Revision 1.24 1995/03/28 11:42:35 adam
return 1;
}
-static int reopen_target (void)
+int reopen_target (void)
{
const char *v;
if (info.zass)
{
const struct zass_searchent *p;
struct gw_user_set *us;
+ char setname[32];
struct ccl_rpn_node *rpn;
int error;
const char *pos;
- us = user_set_add ("Default", -1);
+ if (info.setno == -1)
+ strcpy (setname, "Default");
+ else
+ sprintf (setname, "%d", info.setno);
rpn = ccl_find (info.bibset, list, &error, &pos);
if (!rpn)
{
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Searching in database %s",
info.database );
assert (info.zass);
- p = zass_search (info.zass, rpn, "Default", info.database );
+ fprintf (reply_fd, "Searching in database %s\n", info.database);
+ p = zass_p_search (info.zass, rpn, setname, info.database, info.sets);
if (!p)
+ {
+ fprintf (reply_fd, "Search fail\n");
return -1;
+ }
if (p->errcode != -1)
{
display_diag_error (p->errcode, p->errstring);
}
fprintf (reply_fd, "%d %s\n", p->num,
gw_res_get (info.kernel_res, "gw.msg.hits", "hit(s)"));
- us->hits = p->num;
+ us = user_set_add (setname, p->num, info.database, rpn, 1);
+ fprintf (reply_fd, "Result-set %s created\n", setname);
+ if (info.setno >= 0)
+ info.setno++;
return 0;
}
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present in set %s", set);
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "present of %d records from offset %d",
number, offset);
- zp = zass_present(info.zass, (char *) set, offset, number);
+ zp = zass_p_present(info.zass, (char *) set, offset, number);
if (zp)
{
int i;