2 * Copyright (C) 1995-1998, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1998-06-22 11:36:47 adam
8 * Added authentication check facility to zebra.
10 * Revision 1.5 1998/06/13 00:14:08 adam
13 * Revision 1.4 1998/06/12 12:22:12 adam
16 * Revision 1.3 1998/05/27 16:57:44 adam
17 * Zebra returns surrogate diagnostic for single records when
20 * Revision 1.2 1998/05/20 10:12:19 adam
21 * Implemented automatic EXPLAIN database maintenance.
22 * Modified Zebra to work with ASN.1 compiled version of YAZ.
24 * Revision 1.1 1998/03/05 08:45:13 adam
25 * New result set model and modular ranking system. Moved towards
26 * descent server API. System information stored as "SGML" records.
41 static int zebra_register_lock (ZebraHandle zh)
44 int state = zebra_server_lock_get_state(zh, &lastChange);
54 zebra_server_lock (zh, state);
58 if (zh->registerState == state)
60 if (zh->registerChange >= lastChange)
62 logf (LOG_LOG, "Register completely updated since last access");
64 else if (zh->registerState == -1)
65 logf (LOG_LOG, "Reading register using state %d pid=%ld", state,
68 logf (LOG_LOG, "Register has changed state from %d to %d",
69 zh->registerState, state);
70 zh->registerChange = lastChange;
73 zebraExplain_close (zh->zei, 0, 0);
74 dict_close (zh->dict);
75 sortIdx_close (zh->sortIdx);
79 isc_close (zh->isamc);
80 rec_close (&zh->records);
82 bf_cache (zh->bfs, state ? res_get (zh->res, "shadow") : NULL);
83 zh->registerState = state;
84 zh->records = rec_open (zh->bfs, 0);
85 if (!(zh->dict = dict_open (zh->bfs, FNAME_DICT, 40, 0)))
87 if (!(zh->sortIdx = sortIdx_open (zh->bfs, 0)))
91 if (!res_get_match (zh->res, "isam", "i", NULL))
93 if (!(zh->isamc = isc_open (zh->bfs, FNAME_ISAMC,
94 0, key_isamc_m(zh->res))))
100 if (!(zh->isam = is_open (zh->bfs, FNAME_ISAM, key_compare, 0,
101 sizeof (struct it_key), zh->res)))
104 zh->zei = zebraExplain_open (zh->records, zh->dh, zh->res, 0, 0, 0);
109 static void zebra_register_unlock (ZebraHandle zh)
111 static int waitSec = -1;
115 logf (LOG_LOG, "user/system: %ld/%ld",
116 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
117 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
121 char *s = res_get (zh->res, "debugRequestWait");
132 if (zh->registerState != -1)
133 zebra_server_unlock (zh, zh->registerState);
136 ZebraHandle zebra_open (const char *configName)
138 ZebraHandle zh = xmalloc (sizeof(*zh));
140 if (!(zh->res = res_open (configName)))
142 logf (LOG_WARN, "Failed to read resources `%s'", configName);
145 zebra_server_lock_init (zh);
146 zh->dh = data1_create ();
147 zh->bfs = bfs_create (res_get (zh->res, "register"));
148 bf_lockDir (zh->bfs, res_get (zh->res, "lockDir"));
149 data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath"));
151 zh->registerState = -1; /* trigger open of registers! */
152 zh->registerChange = 0;
155 zh->zebra_maps = zebra_maps_open (zh->res);
156 zh->rank_classes = NULL;
160 zebraRankInstall (zh, rank1_class);
162 if (!res_get (zh->res, "passwd"))
163 zh->passwd_db = NULL;
166 zh->passwd_db = passwd_db_open ();
168 logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
170 passwd_db_file (zh->passwd_db, res_get (zh->res, "passwd"));
172 zh->bfs = bfs_create (res_get (zh->res, "register"));
173 bf_lockDir (zh->bfs, res_get (zh->res, "lockDir"));
174 data1_set_tabpath (zh->dh, res_get(zh->res, "profilePath"));
179 void zebra_close (ZebraHandle zh)
183 resultSetDestroy (zh);
184 zebraExplain_close (zh->zei, 0, 0);
185 dict_close (zh->dict);
186 sortIdx_close (zh->sortIdx);
190 isc_close (zh->isamc);
191 rec_close (&zh->records);
192 zebra_register_unlock (zh);
194 zebra_maps_close (zh->zebra_maps);
195 zebraRankDestroy (zh);
196 bfs_destroy (zh->bfs);
197 data1_destroy (zh->dh);
198 zebra_server_lock_destroy (zh);
201 passwd_db_close (zh->passwd_db);
206 void zebra_search_rpn (ZebraHandle zh, ODR stream,
207 Z_RPNQuery *query, int num_bases, char **basenames,
210 zebra_register_lock (zh);
212 zh->errString = NULL;
214 rpn_search (zh, stream, query, num_bases, basenames, setname);
215 zebra_register_unlock (zh);
218 void zebra_records_retrieve (ZebraHandle zh, ODR stream,
219 const char *setname, Z_RecordComposition *comp,
220 oid_value input_format, int num_recs,
221 ZebraRetrievalRecord *recs)
227 zh->errString = NULL;
228 pos_array = xmalloc (num_recs * sizeof(*pos_array));
229 for (i = 0; i<num_recs; i++)
230 pos_array[i] = recs[i].position;
232 zebra_register_lock (zh);
234 poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
237 logf (LOG_DEBUG, "zebraPosSetCreate error");
242 for (i = 0; i<num_recs; i++)
247 logf (LOG_DEBUG, "Out of range. pos=%d", pos_array[i]);
252 zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
253 stream, input_format, comp,
254 &recs[i].format, &recs[i].buf,
257 recs[i].errString = NULL;
260 zebraPosSetDestroy (zh, poset, num_recs);
262 zebra_register_unlock (zh);
266 void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
267 oid_value attributeset,
268 int num_bases, char **basenames,
269 int *position, int *num_entries, ZebraScanEntry **entries,
273 zh->errString = NULL;
274 zebra_register_lock (zh);
275 rpn_scan (zh, stream, zapt, attributeset,
276 num_bases, basenames, position,
277 num_entries, entries, is_partial);
278 zebra_register_unlock (zh);
281 void zebra_sort (ZebraHandle zh, ODR stream,
282 int num_input_setnames, char **input_setnames,
283 char *output_setname, Z_SortKeySpecList *sort_sequence,
287 zh->errString = NULL;
288 zebra_register_lock (zh);
289 resultSetSort (zh, stream, num_input_setnames, input_setnames,
290 output_setname, sort_sequence, sort_status);
291 zebra_register_unlock (zh);
294 int zebra_errCode (ZebraHandle zh)
299 const char *zebra_errString (ZebraHandle zh)
301 return diagbib1_str (zh->errCode);
304 char *zebra_errAdd (ZebraHandle zh)
306 return zh->errString;
309 int zebra_hits (ZebraHandle zh)
314 int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
316 if (!zh->passwd_db || !passwd_db_auth (zh->passwd_db, user, pass))
321 void zebra_setDB (ZebraHandle zh, int num_bases, char **basenames)
326 void zebra_setRecordType (ZebraHandle zh, const char *type)
331 void zebra_setGroup (ZebraHandle zh, const char *group)
336 void zebra_admin (ZebraHandle zh, const char *command)