1 /* Gateway kernel - Z39.50 Persistence
5 * Revision 1.1 1995/04/19 07:31:10 adam
6 * First work on Z39.50 persistence.
20 static int set_change;
22 static int obtain_set (ZASS zass, struct gw_user_set *set)
24 const struct zass_searchent *p;
26 p = zass_search (zass, set->rpn, set->name, set->database);
31 if (p->num != set->hits)
33 set->present_flag = 1;
38 static int obtain_sets (ZASS zass, struct ccl_rpn_node *rpn,
39 struct gw_user_set *sets)
41 struct gw_user_set *set;
50 if ((r=obtain_sets (zass, rpn->u.p[0], sets)))
52 return obtain_sets (zass, rpn->u.p[1], sets);
56 set = user_set_search (rpn->u.setname);
59 if (set->present_flag)
62 return obtain_set (zass, set);
65 const struct zass_searchent *zass_p_search (ZASS zass,
66 struct ccl_rpn_node *rpn,
67 const char *result_set,
69 struct gw_user_set *sets)
74 r = obtain_sets (zass, rpn, sets);
77 return zass_search (zass, rpn, (char*) result_set, (char*) database);
80 const struct zass_presentent *zass_p_present (ZASS zass,
81 const char *result_set, int offset, int number)
83 struct gw_user_set *set;
85 set = user_set_search (result_set);
88 if (!set->present_flag)
90 int r = obtain_set (zass, set);
94 return zass_present (zass, (char*) result_set, offset, number);
97 struct ccl_rpn_node *load_rpn (char *buf, FILE *inf)
99 struct ccl_rpn_node *rpn;
100 struct ccl_rpn_attr **attrp;
102 int type, value, no_read;
104 if (!fgets (buf, 1024, inf))
106 if ((cp = strchr (buf, '\n')))
111 rpn = malloc (sizeof (*rpn));
114 rpn->kind = CCL_RPN_AND;
115 rpn->u.p[0] = load_rpn (buf, inf);
116 rpn->u.p[1] = load_rpn (buf, inf);
119 rpn = malloc (sizeof (*rpn));
122 rpn->kind = CCL_RPN_OR;
123 rpn->u.p[0] = load_rpn (buf, inf);
124 rpn->u.p[1] = load_rpn (buf, inf);
127 rpn = malloc (sizeof (*rpn));
130 rpn->kind = CCL_RPN_NOT;
131 rpn->u.p[0] = load_rpn (buf, inf);
132 rpn->u.p[1] = load_rpn (buf, inf);
135 rpn = malloc (sizeof (*rpn));
138 rpn->kind = CCL_RPN_PROX;
139 rpn->u.p[0] = load_rpn (buf, inf);
140 rpn->u.p[1] = load_rpn (buf, inf);
143 rpn = malloc (sizeof (*rpn));
146 rpn->kind = CCL_RPN_TERM;
148 rpn->u.t.term = gw_strdup (buf+2);
149 attrp = &rpn->u.t.attr_list;
150 if (!fgets (buf, 1024, inf))
153 while (sscanf (cp, "%d %d%n", &type, &value, &no_read) > 1)
155 *attrp = malloc (sizeof(**attrp));
156 (*attrp)->type = type;
157 (*attrp)->value = value;
158 attrp = &(*attrp)->next;
164 rpn = malloc (sizeof (*rpn));
167 rpn->kind = CCL_RPN_SET;
168 rpn->u.setname = gw_strdup (buf+2);
173 int load_p_state (int userid)
181 struct gw_user_set *set;
183 sprintf (fname, "persist.%d", userid);
185 inf = fopen (fname, "r");
188 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
189 "Couldn't open %s", fname);
192 gw_log (GW_LOG_FATAL, KERNEL_LOG,
193 "Reading persistence file %s", fname);
194 if (!fgets (fline, 1024, inf))
196 if (sscanf (fline, "%s", info.target) != 1)
198 gw_log (GW_LOG_FATAL, KERNEL_LOG,
199 "Reading persistence file %s (2)", fname);
201 gw_log (GW_LOG_FATAL, KERNEL_LOG, "reopen_target start");
203 gw_log (GW_LOG_FATAL, KERNEL_LOG, "reopen_target end");
204 while (fgets (fline, 1024, inf))
206 gw_log (GW_LOG_FATAL, KERNEL_LOG,
207 "Reading persistence file %s (3)", fname);
208 if (sscanf (fline, "%s %d %s", resultname, &hits, database) != 3)
210 gw_log (GW_LOG_FATAL, KERNEL_LOG,
211 "Adding %s, %d hits, database %s",
212 resultname, hits, database);
213 set = user_set_add (resultname, hits, database, NULL, 0);
214 set->rpn = load_rpn (fline, inf);
215 ccl_pr_tree (set->rpn, stderr);
216 fgets (fline, 1024, inf);
222 static void save_rpn (struct ccl_rpn_node *rpn, FILE *of)
224 struct ccl_rpn_attr *attr;
230 save_rpn (rpn->u.p[0], of);
231 save_rpn (rpn->u.p[1], of);
235 save_rpn (rpn->u.p[0], of);
236 save_rpn (rpn->u.p[1], of);
240 save_rpn (rpn->u.p[0], of);
241 save_rpn (rpn->u.p[1], of);
245 save_rpn (rpn->u.p[0], of);
246 save_rpn (rpn->u.p[1], of);
249 fprintf (of, "T %s\n", rpn->u.t.term);
250 for (attr = rpn->u.t.attr_list; attr; attr = attr->next)
251 fprintf (of, "%d %d ", attr->type, attr->value);
255 fprintf (of, "S %s\n", rpn->u.setname);
259 int save_p_state (int userid)
263 struct gw_user_set *sp;
265 sprintf (fname, "persist.%d", userid);
267 of = fopen (fname, "w");
270 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
271 "Couldn't open %s", fname);
274 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Writing persistence file %s", fname);
275 fprintf (of, "%s\n", info.target);
276 for (sp = info.sets; sp; sp = sp->prev)
278 fprintf (of, "%s %d %s\n", sp->name, sp->hits, sp->database);
279 save_rpn (sp->rpn, of);