1 /* Gateway kernel - Z39.50 Persistence
5 * Revision 1.7 1995/05/03 16:34:19 adam
6 * CCL def command, i.e. user definitions - saved as resource files.
8 * Revision 1.6 1995/05/03 07:37:44 adam
9 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
10 * are used when possible.
12 * Revision 1.5 1995/05/02 15:26:00 adam
13 * Monitor observes death of child (email kernel). The number
14 * of simultanous processes is controlled now. Email requests are
15 * queued if necessary. This scheme should only be forced if no kernels
18 * Revision 1.4 1995/04/20 16:10:46 adam
19 * Modified to work with non-blocking zass-api. Not using non-blocking
22 * Revision 1.3 1995/04/19 13:19:09 adam
23 * New command: account - for authentication.
25 * Revision 1.2 1995/04/19 10:46:19 adam
26 * Persistency works much better now. New command: status - history-like
28 * Revision 1.1 1995/04/19 07:31:10 adam
29 * First work on Z39.50 persistence.
43 static int fgetsx (char *buf, int size, FILE *inf)
47 if (!fgets (buf, size, inf))
49 if ((cp = strchr (buf, '\n')))
54 static int set_change;
56 static int obtain_set (ZASS zass, struct gw_user_set *set)
58 const struct zass_searchent *p;
60 p = zass_search (zass, set->rpn, set->name, set->database, NULL);
65 if (p->num != set->hits)
67 set->present_flag = 1;
69 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s researched", set->name);
73 static int obtain_sets (ZASS zass, struct ccl_rpn_node *rpn,
74 struct gw_user_set *sets)
76 struct gw_user_set *set;
85 if ((r=obtain_sets (zass, rpn->u.p[0], sets)))
87 return obtain_sets (zass, rpn->u.p[1], sets);
91 set = user_set_search (rpn->u.setname);
94 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s not there at all",
98 if (set->present_flag)
100 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s already there",
105 return obtain_set (zass, set);
108 const struct zass_searchent *zass_p_search (ZASS zass,
109 struct ccl_rpn_node *rpn,
110 const char *result_set,
111 const char *database,
112 struct gw_user_set *sets)
117 r = obtain_sets (zass, rpn, sets);
120 return zass_search (zass, rpn, (char*) result_set, (char*) database, NULL);
123 const struct zass_presentent *zass_p_present (ZASS zass,
124 const char *result_set, int offset, int number)
126 struct gw_user_set *set;
128 set = user_set_search (result_set);
131 if (!set->present_flag)
133 const struct zass_searchent *p;
135 p = zass_p_search (zass, set->rpn, result_set, set->database,
140 return zass_present (zass, (char*) result_set, offset, number, NULL);
143 struct ccl_rpn_node *load_rpn (char *buf, FILE *inf)
145 struct ccl_rpn_node *rpn;
146 struct ccl_rpn_attr **attrp;
147 int type, value, no_read;
150 if (!fgetsx (buf, 1024, inf))
152 rpn = malloc (sizeof (*rpn));
158 rpn->kind = CCL_RPN_AND;
159 rpn->u.p[0] = load_rpn (buf, inf);
160 rpn->u.p[1] = load_rpn (buf, inf);
163 rpn->kind = CCL_RPN_OR;
164 rpn->u.p[0] = load_rpn (buf, inf);
165 rpn->u.p[1] = load_rpn (buf, inf);
168 rpn->kind = CCL_RPN_NOT;
169 rpn->u.p[0] = load_rpn (buf, inf);
170 rpn->u.p[1] = load_rpn (buf, inf);
173 rpn->kind = CCL_RPN_PROX;
174 rpn->u.p[0] = load_rpn (buf, inf);
175 rpn->u.p[1] = load_rpn (buf, inf);
178 rpn->kind = CCL_RPN_TERM;
180 rpn->u.t.term = gw_strdup (buf+2);
181 attrp = &rpn->u.t.attr_list;
182 if (!fgetsx (buf, 1024, inf))
185 while (sscanf (cp, "%d %d%n", &type, &value, &no_read) > 1)
187 *attrp = malloc (sizeof(**attrp));
188 (*attrp)->type = type;
189 (*attrp)->value = value;
190 attrp = &(*attrp)->next;
196 rpn->kind = CCL_RPN_SET;
197 rpn->u.setname = gw_strdup (buf+2);
206 int load_p_state (int userid)
214 struct gw_user_set *set;
216 sprintf (fname, "user.%d.p", userid);
218 inf = fopen (fname, "r");
221 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
222 "Couldn't open %s", fname);
225 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
226 "Reading persistence file %s", fname);
228 if (!fgetsx (fline, 1024, inf))
230 if (sscanf (fline, "%s", info.target) != 1)
234 if (!fgetsx (fline, 1024, inf))
236 if (sscanf (fline, "%s", info.account) != 1)
237 *info.account = '\0';
239 if (!fgetsx (fline, 1024, inf))
241 free (info.database);
242 info.database = gw_strdup (fline);
244 if (!fgetsx (fline, 1024, inf))
246 if (sscanf (fline, "%d", &info.setno) != 1)
248 if (!fgetsx (fline, 1024, inf))
250 if (sscanf (fline, "%d", &info.next_position) != 1)
252 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
253 "Reading persistence file %s (2)", fname);
257 while (fgetsx (fline, 1024, inf))
259 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
260 "Reading persistence file %s (3)", fname);
261 if (sscanf (fline, "%s %d %s", resultname, &hits, database) != 3)
263 if (!fgetsx (fline, 1024, inf)) /* search string */
265 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
266 "Adding %s, %d hits, database %s",
267 resultname, hits, database);
268 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Search string %s", fline);
269 set = user_set_add (resultname, hits, database, NULL, 0, fline);
270 set->rpn = load_rpn (fline, inf);
271 ccl_pr_tree (set->rpn, stderr);
272 fgetsx (fline, 1024, inf);
275 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Finished reading %s", fname);
279 static void save_rpn (struct ccl_rpn_node *rpn, FILE *of)
281 struct ccl_rpn_attr *attr;
287 save_rpn (rpn->u.p[0], of);
288 save_rpn (rpn->u.p[1], of);
292 save_rpn (rpn->u.p[0], of);
293 save_rpn (rpn->u.p[1], of);
297 save_rpn (rpn->u.p[0], of);
298 save_rpn (rpn->u.p[1], of);
302 save_rpn (rpn->u.p[0], of);
303 save_rpn (rpn->u.p[1], of);
306 fprintf (of, "T %s\n", rpn->u.t.term);
307 for (attr = rpn->u.t.attr_list; attr; attr = attr->next)
308 fprintf (of, "%d %d ", attr->type, attr->value);
312 fprintf (of, "S %s\n", rpn->u.setname);
316 static void save_sets (FILE *of, struct gw_user_set *sp)
320 save_sets (of, sp->prev);
321 fprintf (of, "%s %d %s\n%s\n", sp->name, sp->hits, sp->database,
323 save_rpn (sp->rpn, of);
327 int save_p_state (int userid)
332 sprintf (fname, "user.%d.p", userid);
334 of = fopen (fname, "w");
337 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
338 "Couldn't open %s", fname);
341 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Writing persistence file %s", fname);
342 fprintf (of, "%s\n%s\n%s\n%d\n%d\n", info.target, info.account,
343 info.database, info.setno, info.next_position);
344 save_sets (of, info.sets);
349 void del_p_state (int userid)
353 sprintf (fname, "user.%d.p", userid);