2 * Copyright (C) 1995-2002, Index Data
5 * $Id: zebraapi.c,v 1.62 2002-07-15 11:50:45 adam Exp $
18 #include <yaz/diagbib1.h>
22 static Res zebra_open_res (ZebraHandle zh);
23 static void zebra_close_res (ZebraHandle zh);
25 static void zebra_chdir (ZebraService zh)
27 const char *dir = res_get (zh->global_res, "chdir");
30 logf (LOG_DEBUG, "chdir %s", dir);
38 static void zebra_flush_reg (ZebraHandle zh)
40 zebraExplain_flush (zh->reg->zei, zh);
42 extract_flushWriteKeys (zh);
43 zebra_index_merge (zh);
46 static struct zebra_register *zebra_register_open (ZebraService zs,
48 int rw, int useshadow,
50 const char *reg_path);
51 static void zebra_register_close (ZebraService zs, struct zebra_register *reg);
53 ZebraHandle zebra_open (ZebraService zs)
60 zh = (ZebraHandle) xmalloc (sizeof(*zh));
61 yaz_log (LOG_LOG, "zebra_open zs=%p returns %p", zs, zh);
64 zh->reg = 0; /* no register attached yet */
71 zh->reg_name = xstrdup ("");
73 zh->num_basenames = 0;
81 zh->admin_databaseName = 0;
83 zh->shadow_enable = 1;
85 zebra_mutex_cond_lock (&zs->session_lock);
87 zh->next = zs->sessions;
90 zebra_mutex_cond_unlock (&zs->session_lock);
95 ZebraService zebra_start (const char *configName)
99 yaz_log (LOG_LOG, "zebra_start %s", configName);
101 if (!(res = res_open (configName, 0)))
102 yaz_log (LOG_WARN, "Cannot read resources `%s'", configName);
105 ZebraService zh = xmalloc (sizeof(*zh));
107 yaz_log (LOG_LOG, "Read resources `%s'", configName);
109 zh->global_res = res;
110 zh->configName = xstrdup(configName);
115 zebra_mutex_cond_init (&zh->session_lock);
116 if (!res_get (zh->global_res, "passwd"))
117 zh->passwd_db = NULL;
120 zh->passwd_db = passwd_db_open ();
122 logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
124 passwd_db_file (zh->passwd_db,
125 res_get (zh->global_res, "passwd"));
127 zh->path_root = res_get (zh->global_res, "root");
134 struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
135 int rw, int useshadow, Res res,
136 const char *reg_path)
138 struct zebra_register *reg;
139 int record_compression = REC_COMPRESS_NONE;
140 char *recordCompression = 0;
142 reg = xmalloc (sizeof(*reg));
145 reg->name = xstrdup (name);
152 yaz_log (LOG_LOG, "zebra_register_open rw = %d useshadow=%d p=%p",
155 reg->dh = data1_create ();
158 reg->bfs = bfs_create (res_get (res, "register"), reg_path);
161 data1_destroy(reg->dh);
165 bf_cache (reg->bfs, res_get (res, "shadow"));
166 data1_set_tabpath (reg->dh, res_get(res, "profilePath"));
167 data1_set_tabroot (reg->dh, reg_path);
168 reg->recTypes = recTypes_init (reg->dh);
169 recTypes_default_handlers (reg->recTypes);
171 reg->zebra_maps = zebra_maps_open (res, reg_path);
172 reg->rank_classes = NULL;
176 reg->keys.buf_max = 0;
191 zebraRankInstall (reg, rank1_class);
193 recordCompression = res_get_def (res, "recordCompression", "none");
194 if (!strcmp (recordCompression, "none"))
195 record_compression = REC_COMPRESS_NONE;
196 if (!strcmp (recordCompression, "bzip2"))
197 record_compression = REC_COMPRESS_BZIP2;
199 if (!(reg->records = rec_open (reg->bfs, rw, record_compression)))
201 logf (LOG_WARN, "rec_open");
206 reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0);
208 if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0)))
210 logf (LOG_WARN, "dict_open");
213 if (!(reg->sortIdx = sortIdx_open (reg->bfs, rw)))
215 logf (LOG_WARN, "sortIdx_open");
218 if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
220 struct ISAMS_M_s isams_m;
221 if (!(reg->isams = isams_open (reg->bfs, FNAME_ISAMS, rw,
222 key_isams_m(res, &isams_m))))
224 logf (LOG_WARN, "isams_open");
228 if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
230 if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw,
231 sizeof (struct it_key), res)))
233 logf (LOG_WARN, "is_open");
237 if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
239 struct ISAMC_M_s isamc_m;
240 if (!(reg->isamc = isc_open (reg->bfs, FNAME_ISAMC,
241 rw, key_isamc_m(res, &isamc_m))))
243 logf (LOG_WARN, "isc_open");
247 if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
249 struct ISAMD_M_s isamd_m;
251 if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD,
252 rw, key_isamd_m(res, &isamd_m))))
254 logf (LOG_WARN, "isamd_open");
258 if (res_get_match (res, "isam", "b", ISAM_DEFAULT))
260 struct ISAMC_M_s isamc_m;
262 if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
263 rw, key_isamc_m(res, &isamc_m), 0)))
265 logf (LOG_WARN, "isamb_open");
269 if (res_get_match (res, "isam", "bc", ISAM_DEFAULT))
271 struct ISAMC_M_s isamc_m;
273 if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
274 rw, key_isamc_m(res, &isamc_m), 1)))
276 logf (LOG_WARN, "isamb_open");
280 if (res_get_match (res, "isam", "null", ISAM_DEFAULT))
282 struct ISAMC_M_s isamc_m;
284 if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
285 rw, key_isamc_m(res, &isamc_m), -1)))
287 logf (LOG_WARN, "isamb_open");
291 reg->zei = zebraExplain_open (reg->records, reg->dh,
296 logf (LOG_WARN, "Cannot obtain EXPLAIN information");
300 yaz_log (LOG_LOG, "zebra_register_open ok p=%p", reg);
304 void zebra_admin_shutdown (ZebraHandle zh)
306 zebra_mutex_cond_lock (&zh->service->session_lock);
307 zh->service->stop_flag = 1;
308 zebra_mutex_cond_unlock (&zh->service->session_lock);
311 void zebra_admin_start (ZebraHandle zh)
313 ZebraService zs = zh->service;
315 zebra_mutex_cond_lock (&zs->session_lock);
316 zebra_mutex_cond_unlock (&zs->session_lock);
319 static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
321 yaz_log(LOG_LOG, "zebra_register_close p=%p", reg);
326 zebraExplain_close (reg->zei);
327 dict_close (reg->dict);
329 dict_close (reg->matchDict);
330 sortIdx_close (reg->sortIdx);
332 isams_close (reg->isams);
334 is_close (reg->isam);
336 isc_close (reg->isamc);
338 isamd_close (reg->isamd);
340 isamb_close (reg->isamb);
341 rec_close (®->records);
344 recTypes_destroy (reg->recTypes);
345 zebra_maps_close (reg->zebra_maps);
346 zebraRankDestroy (reg);
347 bfs_destroy (reg->bfs);
348 data1_destroy (reg->dh);
350 xfree (reg->key_buf);
353 yaz_log (LOG_LOG, "zebra_register_close 2");
356 void zebra_stop(ZebraService zs)
360 yaz_log (LOG_LOG, "zebra_stop");
362 zebra_mutex_cond_lock (&zs->session_lock);
365 zebra_close (zs->sessions);
368 zebra_mutex_cond_unlock (&zs->session_lock);
370 zebra_mutex_cond_destroy (&zs->session_lock);
373 passwd_db_close (zs->passwd_db);
375 res_close (zs->global_res);
376 xfree (zs->configName);
377 xfree (zs->path_root);
381 void zebra_close (ZebraHandle zh)
384 struct zebra_session **sp;
390 yaz_log (LOG_LOG, "zebra_close zh=%p", zh);
393 resultSetDestroy (zh, -1, 0, 0);
397 zebra_register_close (zh->service, zh->reg);
398 zebra_close_res (zh);
400 xfree (zh->admin_databaseName);
401 zebra_mutex_cond_lock (&zs->session_lock);
402 zebra_lock_destroy (zh->lock_normal);
403 zebra_lock_destroy (zh->lock_shadow);
415 // if (!zs->sessions && zs->stop_flag)
416 // zebra_register_deactivate(zs);
417 zebra_mutex_cond_unlock (&zs->session_lock);
418 xfree (zh->reg_name);
422 struct map_baseinfo {
428 char **new_basenames;
432 static Res zebra_open_res (ZebraHandle zh)
438 sprintf (fname, "%.200s/zebra.cfg", zh->path_reg);
439 res = res_open (fname, zh->service->global_res);
441 res = zh->service->global_res;
443 else if (*zh->reg_name == 0)
445 res = zh->service->global_res;
449 yaz_log (LOG_WARN, "no register root specified");
450 return 0; /* no path for register - fail! */
455 static void zebra_close_res (ZebraHandle zh)
457 if (zh->res != zh->service->global_res)
462 static int zebra_select_register (ZebraHandle zh, const char *new_reg)
464 if (zh->res && strcmp (zh->reg_name, new_reg) == 0)
468 assert (zh->reg == 0);
469 assert (*zh->reg_name == 0);
475 resultSetInvalidate (zh);
476 zebra_register_close (zh->service, zh->reg);
481 xfree (zh->reg_name);
482 zh->reg_name = xstrdup (new_reg);
484 xfree (zh->path_reg);
486 if (zh->service->path_root)
488 zh->path_reg = xmalloc (strlen(zh->service->path_root) +
489 strlen(zh->reg_name) + 3);
490 strcpy (zh->path_reg, zh->service->path_root);
493 strcat (zh->path_reg, "/");
494 strcat (zh->path_reg, zh->reg_name);
497 zh->res = zebra_open_res (zh);
500 zebra_lock_destroy (zh->lock_normal);
504 zebra_lock_destroy (zh->lock_shadow);
510 const char *lock_area =res_get (zh->res, "lockDir");
512 if (!lock_area && zh->path_reg)
513 res_put (zh->res, "lockDir", zh->path_reg);
514 sprintf (fname, "norm.%s.LCK", zh->reg_name);
516 zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
518 sprintf (fname, "shadow.%s.LCK", zh->reg_name);
520 zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
526 void map_basenames_func (void *vp, const char *name, const char *value)
528 struct map_baseinfo *p = (struct map_baseinfo *) vp;
530 char fromdb[128], todb[8][128];
533 sscanf (value, "%127s %127s %127s %127s %127s %127s %127s %127s %127s",
534 fromdb, todb[0], todb[1], todb[2], todb[3], todb[4],
535 todb[5], todb[6], todb[7]);
539 for (i = 0; i<p->num_bases; i++)
540 if (p->basenames[i] && !strcmp (p->basenames[i], fromdb))
543 for (i = 0; i < no; i++)
545 if (p->new_num_bases == p->new_num_max)
547 p->new_basenames[(p->new_num_bases)++] =
548 nmem_strdup (p->mem, todb[i]);
554 void map_basenames (ZebraHandle zh, ODR stream,
555 int *num_bases, char ***basenames)
557 struct map_baseinfo info;
558 struct map_baseinfo *p = &info;
562 info.num_bases = *num_bases;
563 info.basenames = *basenames;
564 info.new_num_max = 128;
565 info.new_num_bases = 0;
566 info.new_basenames = (char **)
567 odr_malloc (stream, sizeof(*info.new_basenames) * info.new_num_max);
568 info.mem = stream->mem;
570 res_trav (zh->service->global_res, "mapdb", &info, map_basenames_func);
572 for (i = 0; i<p->num_bases; i++)
573 if (p->basenames[i] && p->new_num_bases < p->new_num_max)
575 p->new_basenames[(p->new_num_bases)++] =
576 nmem_strdup (p->mem, p->basenames[i]);
578 *num_bases = info.new_num_bases;
579 *basenames = info.new_basenames;
580 for (i = 0; i<*num_bases; i++)
581 logf (LOG_LOG, "base %s", (*basenames)[i]);
584 int zebra_select_database (ZebraHandle zh, const char *basename)
586 return zebra_select_databases (zh, 1, &basename);
589 int zebra_select_databases (ZebraHandle zh, int num_bases,
590 const char **basenames)
602 for (i = 0; i < zh->num_basenames; i++)
603 xfree (zh->basenames[i]);
604 xfree (zh->basenames);
606 zh->num_basenames = num_bases;
607 zh->basenames = xmalloc (zh->num_basenames * sizeof(*zh->basenames));
608 for (i = 0; i < zh->num_basenames; i++)
609 zh->basenames[i] = xstrdup (basenames[i]);
611 cp = strrchr(basenames[0], '/');
614 len = cp - basenames[0];
615 new_reg = xmalloc (len + 1);
616 memcpy (new_reg, basenames[0], len);
620 new_reg = xstrdup ("");
621 for (i = 1; i<num_bases; i++)
625 cp1 = strrchr (basenames[i], '/');
633 if (len != cp1 - basenames[i] ||
634 memcmp (basenames[i], new_reg, len))
649 zebra_select_register (zh, new_reg);
659 void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream,
660 Z_RPNQuery *query, const char *setname, int *hits)
665 if (zebra_begin_read (zh))
667 resultSetAddRPN (zh, decode, stream, query,
668 zh->num_basenames, zh->basenames, setname);
675 void zebra_records_retrieve (ZebraHandle zh, ODR stream,
676 const char *setname, Z_RecordComposition *comp,
677 oid_value input_format, int num_recs,
678 ZebraRetrievalRecord *recs)
686 zh->errString = odr_strdup (stream, setname);
692 if (zebra_begin_read (zh))
695 pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
696 for (i = 0; i<num_recs; i++)
697 pos_array[i] = recs[i].position;
698 poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
701 logf (LOG_DEBUG, "zebraPosSetCreate error");
703 zh->errString = nmem_strdup (stream->mem, setname);
707 for (i = 0; i<num_recs; i++)
712 recs[i].format = VAL_SUTRS;
713 recs[i].len = strlen(poset[i].term);
714 recs[i].buf = poset[i].term;
715 recs[i].base = poset[i].db;
717 else if (poset[i].sysno)
720 zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
721 stream, input_format, comp,
722 &recs[i].format, &recs[i].buf,
725 recs[i].errString = NULL;
731 sprintf (num_str, "%d", pos_array[i]);
733 zh->errString = odr_strdup (stream, num_str);
737 zebraPosSetDestroy (zh, poset, num_recs);
743 void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
744 oid_value attributeset,
745 int *position, int *num_entries, ZebraScanEntry **entries,
748 if (zebra_begin_read (zh))
754 rpn_scan (zh, stream, zapt, attributeset,
755 zh->num_basenames, zh->basenames, position,
756 num_entries, entries, is_partial);
760 void zebra_sort (ZebraHandle zh, ODR stream,
761 int num_input_setnames, const char **input_setnames,
762 const char *output_setname, Z_SortKeySpecList *sort_sequence,
765 if (zebra_begin_read (zh))
767 resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
768 output_setname, sort_sequence, sort_status);
772 int zebra_deleleResultSet(ZebraHandle zh, int function,
773 int num_setnames, char **setnames,
777 if (zebra_begin_read(zh))
778 return Z_DeleteStatus_systemProblemAtTarget;
781 case Z_DeleteRequest_list:
782 resultSetDestroy (zh, num_setnames, setnames, statuses);
784 case Z_DeleteRequest_all:
785 resultSetDestroy (zh, -1, 0, statuses);
789 status = Z_DeleteStatus_success;
790 for (i = 0; i<num_setnames; i++)
791 if (statuses[i] == Z_DeleteStatus_resultSetDidNotExist)
792 status = statuses[i];
796 int zebra_errCode (ZebraHandle zh)
801 const char *zebra_errString (ZebraHandle zh)
803 return diagbib1_str (zh->errCode);
806 char *zebra_errAdd (ZebraHandle zh)
808 return zh->errString;
811 int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
813 ZebraService zs = zh->service;
814 if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
816 logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS");
820 logf(LOG_APP,"AUTHFAIL:%s", user?user:"ANONYMOUS");
824 void zebra_admin_import_begin (ZebraHandle zh, const char *database)
826 zebra_begin_trans (zh);
827 xfree (zh->admin_databaseName);
828 zh->admin_databaseName = xstrdup(database);
831 void zebra_admin_import_end (ZebraHandle zh)
833 zebra_end_trans (zh);
836 void zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
840 for (i = 0; i<segment->num_segmentRecords; i++)
842 Z_NamePlusRecord *npr = segment->segmentRecords[i];
843 const char *databaseName = npr->databaseName;
846 databaseName = zh->admin_databaseName;
847 printf ("--------------%d--------------------\n", i);
848 if (npr->which == Z_NamePlusRecord_intermediateFragment)
850 Z_FragmentSyntax *fragment = npr->u.intermediateFragment;
851 if (fragment->which == Z_FragmentSyntax_notExternallyTagged)
853 Odr_oct *oct = fragment->u.notExternallyTagged;
854 printf ("%.*s", (oct->len > 100 ? 100 : oct->len) ,
858 extract_rec_in_mem (zh, "grs.sgml",
866 0 /* match criteria */);
872 void zebra_admin_create (ZebraHandle zh, const char *database)
876 zebra_begin_trans (zh);
879 /* announce database */
880 if (zebraExplain_newDatabase (zh->reg->zei, database, 0
881 /* explainDatabase */))
884 zh->errString = "Database already exist";
886 zebra_end_trans (zh);
889 int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
890 const char *input_str, int input_len,
891 char *output_str, int output_len)
894 if (!zh->reg->zebra_maps)
896 wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "",
897 input_str, input_len);
900 if (wrbuf_len(wrbuf) >= output_len)
902 if (wrbuf_len(wrbuf))
903 memcpy (output_str, wrbuf_buf(wrbuf), wrbuf_len(wrbuf));
904 output_str[wrbuf_len(wrbuf)] = '\0';
905 return wrbuf_len(wrbuf);
909 void zebra_set_state (ZebraHandle zh, int val, int seqno)
911 char state_fname[256];
916 sprintf (state_fname, "state.%s.LCK", zh->reg_name);
917 fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
918 f = fopen (fname, "w");
920 yaz_log (LOG_LOG, "%c %d %ld", val, seqno, p);
921 fprintf (f, "%c %d %ld\n", val, seqno, p);
926 void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
928 char state_fname[256];
932 sprintf (state_fname, "state.%s.LCK", zh->reg_name);
933 fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
934 f = fopen (fname, "r");
940 fscanf (f, "%c %d", val, seqno);
946 int zebra_begin_read (ZebraHandle zh)
956 if (zh->trans_no != 1)
958 zebra_flush_reg (zh);
970 zebra_get_state (zh, &val, &seqno);
976 else if (seqno != zh->reg->seqno)
978 yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d",
979 seqno, zh->reg->seqno);
982 else if (zh->reg->last_val != val)
984 yaz_log (LOG_LOG, "reopen last cur/old %d/%d",
985 val, zh->reg->last_val);
992 zebra_lock_r (zh->lock_shadow);
994 zebra_lock_r (zh->lock_normal);
997 zebra_register_close (zh->service, zh->reg);
998 zh->reg = zebra_register_open (zh->service, zh->reg_name,
999 0, val == 'c' ? 1 : 0,
1000 zh->res, zh->path_reg);
1006 zh->reg->last_val = val;
1007 zh->reg->seqno = seqno;
1012 void zebra_end_read (ZebraHandle zh)
1016 if (zh->trans_no != 0)
1019 #if HAVE_SYS_TIMES_H
1021 logf (LOG_LOG, "user/system: %ld/%ld",
1022 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
1023 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
1027 zebra_unlock (zh->lock_normal);
1028 zebra_unlock (zh->lock_shadow);
1031 void zebra_begin_trans (ZebraHandle zh)
1036 const char *rval = 0;
1041 if (zh->trans_no != 1)
1046 yaz_log (LOG_LOG, "zebra_begin_trans");
1048 zh->records_inserted = 0;
1049 zh->records_updated = 0;
1050 zh->records_deleted = 0;
1051 zh->records_processed = 0;
1053 #if HAVE_SYS_TIMES_H
1058 if (zh->shadow_enable)
1059 rval = res_get (zh->res, "shadow");
1061 for (pass = 0; pass < 2; pass++)
1065 zebra_lock_r (zh->lock_normal);
1066 zebra_lock_w (zh->lock_shadow);
1070 zebra_lock_w (zh->lock_normal);
1071 zebra_lock_w (zh->lock_shadow);
1074 zebra_get_state (zh, &val, &seqno);
1077 yaz_log (LOG_LOG, "previous transaction didn't finish commit");
1078 zebra_unlock (zh->lock_shadow);
1079 zebra_unlock (zh->lock_normal);
1083 else if (val == 'd')
1087 BFiles bfs = bfs_create (res_get (zh->res, "shadow"),
1089 yaz_log (LOG_LOG, "previous transaction didn't reach commit");
1090 bf_commitClean (bfs, rval);
1095 yaz_log (LOG_WARN, "your previous transaction didn't finish");
1102 yaz_log (LOG_FATAL, "zebra_begin_trans couldn't finish commit");
1106 zebra_set_state (zh, 'd', seqno);
1108 zh->reg = zebra_register_open (zh->service, zh->reg_name,
1109 1, rval ? 1 : 0, zh->res,
1112 zh->reg->seqno = seqno;
1115 void zebra_end_trans (ZebraHandle zh)
1122 if (zh->trans_no != 0)
1125 yaz_log (LOG_LOG, "zebra_end_trans");
1126 rval = res_get (zh->res, "shadow");
1128 zebraExplain_runNumberIncrement (zh->reg->zei, 1);
1130 zebra_flush_reg (zh);
1132 zebra_register_close (zh->service, zh->reg);
1136 yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
1137 zh->records_processed, zh->records_inserted,
1138 zh->records_updated, zh->records_deleted);
1140 zebra_get_state (zh, &val, &seqno);
1143 BFiles bfs = bfs_create (rval, zh->path_reg);
1144 yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val);
1145 bf_commitClean (bfs, rval);
1150 zebra_set_state (zh, 'o', seqno);
1152 zebra_unlock (zh->lock_shadow);
1153 zebra_unlock (zh->lock_normal);
1155 #if HAVE_SYS_TIMES_H
1157 logf (LOG_LOG, "user/system: %ld/%ld",
1158 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
1159 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
1164 void zebra_repository_update (ZebraHandle zh)
1166 zebra_begin_trans (zh);
1167 logf (LOG_LOG, "updating %s", zh->rGroup.path);
1168 repositoryUpdate (zh);
1169 zebra_end_trans (zh);
1172 void zebra_repository_delete (ZebraHandle zh)
1174 logf (LOG_LOG, "deleting %s", zh->rGroup.path);
1175 repositoryDelete (zh);
1178 void zebra_repository_show (ZebraHandle zh)
1180 repositoryShow (zh);
1183 int zebra_commit (ZebraHandle zh)
1195 rval = res_get (zh->res, "shadow");
1198 logf (LOG_WARN, "Cannot perform commit");
1199 logf (LOG_WARN, "No shadow area defined");
1203 zebra_lock_w (zh->lock_normal);
1204 zebra_lock_r (zh->lock_shadow);
1206 bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
1208 zebra_get_state (zh, &val, &seqno);
1211 bf_cache (bfs, rval);
1212 if (bf_commitExists (bfs))
1214 zebra_set_state (zh, 'c', seqno);
1216 logf (LOG_LOG, "commit start");
1217 bf_commitExec (bfs);
1221 logf (LOG_LOG, "commit clean");
1222 bf_commitClean (bfs, rval);
1224 zebra_set_state (zh, 'o', seqno);
1228 logf (LOG_LOG, "nothing to commit");
1232 zebra_unlock (zh->lock_shadow);
1233 zebra_unlock (zh->lock_normal);
1237 int zebra_init (ZebraHandle zh)
1247 rval = res_get (zh->res, "shadow");
1249 bfs = bfs_create (res_get (zh->service->global_res, "register"),
1252 bf_cache (bfs, rval);
1256 zebra_set_state (zh, 'o', 0);
1260 int zebra_compact (ZebraHandle zh)
1268 bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
1274 int zebra_record_insert (ZebraHandle zh, const char *buf, int len)
1277 zebra_begin_trans (zh);
1278 extract_rec_in_mem (zh, "grs.sgml",
1280 "Default", /* database */
1281 0 /* delete_flag */,
1286 0 /* match criteria */);
1287 zebra_end_trans (zh);
1291 void zebra_set_group (ZebraHandle zh, struct recordGroup *rg)
1293 memcpy (&zh->rGroup, rg, sizeof(*rg));
1296 void zebra_result (ZebraHandle zh, int *code, char **addinfo)
1298 *code = zh->errCode;
1299 *addinfo = zh->errString;
1302 void zebra_shadow_enable (ZebraHandle zh, int value)
1304 zh->shadow_enable = value;