1 /* Gateway kernel - Z39.50 Persistence
5 * Revision 1.6 1995/05/03 07:37:44 adam
6 * CCL commands stop/continue implemented. New functions gw_res_{int,bool}
7 * are used when possible.
9 * Revision 1.5 1995/05/02 15:26:00 adam
10 * Monitor observes death of child (email kernel). The number
11 * of simultanous processes is controlled now. Email requests are
12 * queued if necessary. This scheme should only be forced if no kernels
15 * Revision 1.4 1995/04/20 16:10:46 adam
16 * Modified to work with non-blocking zass-api. Not using non-blocking
19 * Revision 1.3 1995/04/19 13:19:09 adam
20 * New command: account - for authentication.
22 * Revision 1.2 1995/04/19 10:46:19 adam
23 * Persistency works much better now. New command: status - history-like
25 * Revision 1.1 1995/04/19 07:31:10 adam
26 * First work on Z39.50 persistence.
40 static int fgetsx (char *buf, int size, FILE *inf)
44 if (!fgets (buf, size, inf))
46 if ((cp = strchr (buf, '\n')))
51 static int set_change;
53 static int obtain_set (ZASS zass, struct gw_user_set *set)
55 const struct zass_searchent *p;
57 p = zass_search (zass, set->rpn, set->name, set->database, NULL);
62 if (p->num != set->hits)
64 set->present_flag = 1;
66 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s researched", set->name);
70 static int obtain_sets (ZASS zass, struct ccl_rpn_node *rpn,
71 struct gw_user_set *sets)
73 struct gw_user_set *set;
82 if ((r=obtain_sets (zass, rpn->u.p[0], sets)))
84 return obtain_sets (zass, rpn->u.p[1], sets);
88 set = user_set_search (rpn->u.setname);
91 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s not there at all",
95 if (set->present_flag)
97 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Set %s already there",
102 return obtain_set (zass, set);
105 const struct zass_searchent *zass_p_search (ZASS zass,
106 struct ccl_rpn_node *rpn,
107 const char *result_set,
108 const char *database,
109 struct gw_user_set *sets)
114 r = obtain_sets (zass, rpn, sets);
117 return zass_search (zass, rpn, (char*) result_set, (char*) database, NULL);
120 const struct zass_presentent *zass_p_present (ZASS zass,
121 const char *result_set, int offset, int number)
123 struct gw_user_set *set;
125 set = user_set_search (result_set);
128 if (!set->present_flag)
130 const struct zass_searchent *p;
132 p = zass_p_search (zass, set->rpn, result_set, set->database,
137 return zass_present (zass, (char*) result_set, offset, number, NULL);
140 struct ccl_rpn_node *load_rpn (char *buf, FILE *inf)
142 struct ccl_rpn_node *rpn;
143 struct ccl_rpn_attr **attrp;
144 int type, value, no_read;
147 if (!fgetsx (buf, 1024, inf))
149 rpn = malloc (sizeof (*rpn));
155 rpn->kind = CCL_RPN_AND;
156 rpn->u.p[0] = load_rpn (buf, inf);
157 rpn->u.p[1] = load_rpn (buf, inf);
160 rpn->kind = CCL_RPN_OR;
161 rpn->u.p[0] = load_rpn (buf, inf);
162 rpn->u.p[1] = load_rpn (buf, inf);
165 rpn->kind = CCL_RPN_NOT;
166 rpn->u.p[0] = load_rpn (buf, inf);
167 rpn->u.p[1] = load_rpn (buf, inf);
170 rpn->kind = CCL_RPN_PROX;
171 rpn->u.p[0] = load_rpn (buf, inf);
172 rpn->u.p[1] = load_rpn (buf, inf);
175 rpn->kind = CCL_RPN_TERM;
177 rpn->u.t.term = gw_strdup (buf+2);
178 attrp = &rpn->u.t.attr_list;
179 if (!fgetsx (buf, 1024, inf))
182 while (sscanf (cp, "%d %d%n", &type, &value, &no_read) > 1)
184 *attrp = malloc (sizeof(**attrp));
185 (*attrp)->type = type;
186 (*attrp)->value = value;
187 attrp = &(*attrp)->next;
193 rpn->kind = CCL_RPN_SET;
194 rpn->u.setname = gw_strdup (buf+2);
203 int load_p_state (int userid)
211 struct gw_user_set *set;
213 sprintf (fname, "persist.%d", userid);
215 inf = fopen (fname, "r");
218 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
219 "Couldn't open %s", fname);
222 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
223 "Reading persistence file %s", fname);
225 if (!fgetsx (fline, 1024, inf))
227 if (sscanf (fline, "%s", info.target) != 1)
231 if (!fgetsx (fline, 1024, inf))
233 if (sscanf (fline, "%s", info.account) != 1)
234 *info.account = '\0';
236 if (!fgetsx (fline, 1024, inf))
238 free (info.database);
239 info.database = gw_strdup (fline);
241 if (!fgetsx (fline, 1024, inf))
243 if (sscanf (fline, "%d", &info.setno) != 1)
245 if (!fgetsx (fline, 1024, inf))
247 if (sscanf (fline, "%d", &info.next_position) != 1)
249 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
250 "Reading persistence file %s (2)", fname);
254 while (fgetsx (fline, 1024, inf))
256 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
257 "Reading persistence file %s (3)", fname);
258 if (sscanf (fline, "%s %d %s", resultname, &hits, database) != 3)
260 if (!fgetsx (fline, 1024, inf)) /* search string */
262 gw_log (GW_LOG_DEBUG, KERNEL_LOG,
263 "Adding %s, %d hits, database %s",
264 resultname, hits, database);
265 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Search string %s", fline);
266 set = user_set_add (resultname, hits, database, NULL, 0, fline);
267 set->rpn = load_rpn (fline, inf);
268 ccl_pr_tree (set->rpn, stderr);
269 fgetsx (fline, 1024, inf);
272 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Finished reading %s", fname);
276 static void save_rpn (struct ccl_rpn_node *rpn, FILE *of)
278 struct ccl_rpn_attr *attr;
284 save_rpn (rpn->u.p[0], of);
285 save_rpn (rpn->u.p[1], of);
289 save_rpn (rpn->u.p[0], of);
290 save_rpn (rpn->u.p[1], of);
294 save_rpn (rpn->u.p[0], of);
295 save_rpn (rpn->u.p[1], of);
299 save_rpn (rpn->u.p[0], of);
300 save_rpn (rpn->u.p[1], of);
303 fprintf (of, "T %s\n", rpn->u.t.term);
304 for (attr = rpn->u.t.attr_list; attr; attr = attr->next)
305 fprintf (of, "%d %d ", attr->type, attr->value);
309 fprintf (of, "S %s\n", rpn->u.setname);
313 static void save_sets (FILE *of, struct gw_user_set *sp)
317 save_sets (of, sp->prev);
318 fprintf (of, "%s %d %s\n%s\n", sp->name, sp->hits, sp->database,
320 save_rpn (sp->rpn, of);
324 int save_p_state (int userid)
329 sprintf (fname, "persist.%d", userid);
331 of = fopen (fname, "w");
334 gw_log (GW_LOG_WARN|GW_LOG_ERRNO, KERNEL_LOG,
335 "Couldn't open %s", fname);
338 gw_log (GW_LOG_DEBUG, KERNEL_LOG, "Writing persistence file %s", fname);
339 fprintf (of, "%s\n%s\n%s\n%d\n%d\n", info.target, info.account,
340 info.database, info.setno, info.next_position);
341 save_sets (of, info.sets);
346 void del_p_state (int userid)
350 sprintf (fname, "persist.%d", userid);