2 * Copyright (C) 1995-2002, Index Data
5 * $Id: zebraapi.c,v 1.58 2002-04-23 18:07:17 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, 1, 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 static int zebra_begin_read (ZebraHandle zh);
54 static void zebra_end_read (ZebraHandle zh);
56 ZebraHandle zebra_open (ZebraService zs)
63 zh = (ZebraHandle) xmalloc (sizeof(*zh));
64 yaz_log (LOG_LOG, "zebra_open zs=%p returns %p", zs, zh);
67 zh->reg = 0; /* no register attached yet */
74 zh->reg_name = xstrdup ("");
76 zh->num_basenames = 0;
84 zh->admin_databaseName = 0;
86 zh->shadow_enable = 1;
88 zebra_mutex_cond_lock (&zs->session_lock);
90 zh->next = zs->sessions;
93 zebra_mutex_cond_unlock (&zs->session_lock);
98 ZebraService zebra_start (const char *configName)
102 yaz_log (LOG_LOG, "zebra_start %s", configName);
104 if (!(res = res_open (configName, 0)))
105 yaz_log (LOG_WARN, "Cannot read resources `%s'", configName);
108 ZebraService zh = xmalloc (sizeof(*zh));
110 yaz_log (LOG_LOG, "Read resources `%s'", configName);
112 zh->global_res = res;
113 zh->configName = xstrdup(configName);
118 zebra_mutex_cond_init (&zh->session_lock);
119 if (!res_get (zh->global_res, "passwd"))
120 zh->passwd_db = NULL;
123 zh->passwd_db = passwd_db_open ();
125 logf (LOG_WARN|LOG_ERRNO, "passwd_db_open failed");
127 passwd_db_file (zh->passwd_db,
128 res_get (zh->global_res, "passwd"));
130 zh->path_root = res_get (zh->global_res, "root");
137 struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
138 int rw, int useshadow, Res res,
139 const char *reg_path)
141 struct zebra_register *reg;
142 int record_compression = REC_COMPRESS_NONE;
143 char *recordCompression = 0;
145 reg = xmalloc (sizeof(*reg));
148 reg->name = xstrdup (name);
155 yaz_log (LOG_LOG, "zebra_register_open rw = %d useshadow=%d p=%p",
158 reg->dh = data1_create ();
161 reg->bfs = bfs_create (res_get (res, "register"), reg_path);
164 data1_destroy(reg->dh);
168 bf_cache (reg->bfs, res_get (res, "shadow"));
169 data1_set_tabpath (reg->dh, res_get(res, "profilePath"));
170 data1_set_tabroot (reg->dh, reg_path);
171 reg->recTypes = recTypes_init (reg->dh);
172 recTypes_default_handlers (reg->recTypes);
174 reg->zebra_maps = zebra_maps_open (res, reg_path);
175 reg->rank_classes = NULL;
179 reg->keys.buf_max = 0;
194 zebraRankInstall (reg, rank1_class);
196 recordCompression = res_get_def (res, "recordCompression", "none");
197 if (!strcmp (recordCompression, "none"))
198 record_compression = REC_COMPRESS_NONE;
199 if (!strcmp (recordCompression, "bzip2"))
200 record_compression = REC_COMPRESS_BZIP2;
202 if (!(reg->records = rec_open (reg->bfs, rw, record_compression)))
204 logf (LOG_WARN, "rec_open");
209 reg->matchDict = dict_open (reg->bfs, GMATCH_DICT, 20, 1, 0);
211 if (!(reg->dict = dict_open (reg->bfs, FNAME_DICT, 40, rw, 0)))
213 logf (LOG_WARN, "dict_open");
216 if (!(reg->sortIdx = sortIdx_open (reg->bfs, rw)))
218 logf (LOG_WARN, "sortIdx_open");
221 if (res_get_match (res, "isam", "s", ISAM_DEFAULT))
223 struct ISAMS_M_s isams_m;
224 if (!(reg->isams = isams_open (reg->bfs, FNAME_ISAMS, rw,
225 key_isams_m(res, &isams_m))))
227 logf (LOG_WARN, "isams_open");
231 if (res_get_match (res, "isam", "i", ISAM_DEFAULT))
233 if (!(reg->isam = is_open (reg->bfs, FNAME_ISAM, key_compare, rw,
234 sizeof (struct it_key), res)))
236 logf (LOG_WARN, "is_open");
240 if (res_get_match (res, "isam", "c", ISAM_DEFAULT))
242 struct ISAMC_M_s isamc_m;
243 if (!(reg->isamc = isc_open (reg->bfs, FNAME_ISAMC,
244 rw, key_isamc_m(res, &isamc_m))))
246 logf (LOG_WARN, "isc_open");
250 if (res_get_match (res, "isam", "d", ISAM_DEFAULT))
252 struct ISAMD_M_s isamd_m;
254 if (!(reg->isamd = isamd_open (reg->bfs, FNAME_ISAMD,
255 rw, key_isamd_m(res, &isamd_m))))
257 logf (LOG_WARN, "isamd_open");
261 if (res_get_match (res, "isam", "b", ISAM_DEFAULT))
263 struct ISAMC_M_s isamc_m;
265 if (!(reg->isamb = isamb_open (reg->bfs, "isamb",
266 rw, key_isamc_m(res, &isamc_m))))
268 logf (LOG_WARN, "isamb_open");
272 reg->zei = zebraExplain_open (reg->records, reg->dh,
277 logf (LOG_WARN, "Cannot obtain EXPLAIN information");
281 yaz_log (LOG_LOG, "zebra_register_open ok p=%p", reg);
285 void zebra_admin_shutdown (ZebraHandle zh)
287 zebra_mutex_cond_lock (&zh->service->session_lock);
288 zh->service->stop_flag = 1;
289 zebra_mutex_cond_unlock (&zh->service->session_lock);
292 void zebra_admin_start (ZebraHandle zh)
294 ZebraService zs = zh->service;
296 zebra_mutex_cond_lock (&zs->session_lock);
297 zebra_mutex_cond_unlock (&zs->session_lock);
300 static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
302 yaz_log(LOG_LOG, "zebra_register_close p=%p", reg);
307 zebraExplain_close (reg->zei, 0);
308 dict_close (reg->dict);
310 dict_close (reg->matchDict);
311 sortIdx_close (reg->sortIdx);
313 isams_close (reg->isams);
315 is_close (reg->isam);
317 isc_close (reg->isamc);
319 isamd_close (reg->isamd);
321 isamb_close (reg->isamb);
322 rec_close (®->records);
325 recTypes_destroy (reg->recTypes);
326 zebra_maps_close (reg->zebra_maps);
327 zebraRankDestroy (reg);
328 bfs_destroy (reg->bfs);
329 data1_destroy (reg->dh);
331 xfree (reg->key_buf);
334 yaz_log (LOG_LOG, "zebra_register_close 2");
337 void zebra_stop(ZebraService zs)
341 yaz_log (LOG_LOG, "zebra_stop");
343 zebra_mutex_cond_lock (&zs->session_lock);
346 zebra_close (zs->sessions);
349 zebra_mutex_cond_unlock (&zs->session_lock);
351 zebra_mutex_cond_destroy (&zs->session_lock);
354 passwd_db_close (zs->passwd_db);
356 res_close (zs->global_res);
357 xfree (zs->configName);
358 xfree (zs->path_root);
362 void zebra_close (ZebraHandle zh)
365 struct zebra_session **sp;
371 yaz_log (LOG_LOG, "zebra_close zh=%p", zh);
374 resultSetDestroy (zh, -1, 0, 0);
378 zebra_register_close (zh->service, zh->reg);
379 zebra_close_res (zh);
381 xfree (zh->admin_databaseName);
382 zebra_mutex_cond_lock (&zs->session_lock);
383 zebra_lock_destroy (zh->lock_normal);
384 zebra_lock_destroy (zh->lock_shadow);
396 // if (!zs->sessions && zs->stop_flag)
397 // zebra_register_deactivate(zs);
398 zebra_mutex_cond_unlock (&zs->session_lock);
399 xfree (zh->reg_name);
403 struct map_baseinfo {
409 char **new_basenames;
413 static Res zebra_open_res (ZebraHandle zh)
419 sprintf (fname, "%.200s/zebra.cfg", zh->path_reg);
420 res = res_open (fname, zh->service->global_res);
422 res = zh->service->global_res;
424 else if (*zh->reg_name == 0)
426 res = zh->service->global_res;
430 yaz_log (LOG_WARN, "no register root specified");
431 return 0; /* no path for register - fail! */
436 static void zebra_close_res (ZebraHandle zh)
438 if (zh->res != zh->service->global_res)
443 static int zebra_select_register (ZebraHandle zh, const char *new_reg)
445 if (zh->res && strcmp (zh->reg_name, new_reg) == 0)
449 assert (zh->reg == 0);
450 assert (*zh->reg_name == 0);
456 resultSetInvalidate (zh);
457 zebra_register_close (zh->service, zh->reg);
462 xfree (zh->reg_name);
463 zh->reg_name = xstrdup (new_reg);
465 xfree (zh->path_reg);
467 if (zh->service->path_root)
469 zh->path_reg = xmalloc (strlen(zh->service->path_root) +
470 strlen(zh->reg_name) + 3);
471 strcpy (zh->path_reg, zh->service->path_root);
474 strcat (zh->path_reg, "/");
475 strcat (zh->path_reg, zh->reg_name);
478 zh->res = zebra_open_res (zh);
481 zebra_lock_destroy (zh->lock_normal);
485 zebra_lock_destroy (zh->lock_shadow);
491 const char *lock_area =res_get (zh->res, "lockDir");
493 if (!lock_area && zh->path_reg)
494 res_put (zh->res, "lockDir", zh->path_reg);
495 sprintf (fname, "norm.%s.LCK", zh->reg_name);
497 zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
499 sprintf (fname, "shadow.%s.LCK", zh->reg_name);
501 zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
507 void map_basenames_func (void *vp, const char *name, const char *value)
509 struct map_baseinfo *p = (struct map_baseinfo *) vp;
511 char fromdb[128], todb[8][128];
514 sscanf (value, "%127s %127s %127s %127s %127s %127s %127s %127s %127s",
515 fromdb, todb[0], todb[1], todb[2], todb[3], todb[4],
516 todb[5], todb[6], todb[7]);
520 for (i = 0; i<p->num_bases; i++)
521 if (p->basenames[i] && !strcmp (p->basenames[i], fromdb))
524 for (i = 0; i < no; i++)
526 if (p->new_num_bases == p->new_num_max)
528 p->new_basenames[(p->new_num_bases)++] =
529 nmem_strdup (p->mem, todb[i]);
535 void map_basenames (ZebraHandle zh, ODR stream,
536 int *num_bases, char ***basenames)
538 struct map_baseinfo info;
539 struct map_baseinfo *p = &info;
543 info.num_bases = *num_bases;
544 info.basenames = *basenames;
545 info.new_num_max = 128;
546 info.new_num_bases = 0;
547 info.new_basenames = (char **)
548 odr_malloc (stream, sizeof(*info.new_basenames) * info.new_num_max);
549 info.mem = stream->mem;
551 res_trav (zh->service->global_res, "mapdb", &info, map_basenames_func);
553 for (i = 0; i<p->num_bases; i++)
554 if (p->basenames[i] && p->new_num_bases < p->new_num_max)
556 p->new_basenames[(p->new_num_bases)++] =
557 nmem_strdup (p->mem, p->basenames[i]);
559 *num_bases = info.new_num_bases;
560 *basenames = info.new_basenames;
561 for (i = 0; i<*num_bases; i++)
562 logf (LOG_LOG, "base %s", (*basenames)[i]);
565 int zebra_select_database (ZebraHandle zh, const char *basename)
567 return zebra_select_databases (zh, 1, &basename);
570 int zebra_select_databases (ZebraHandle zh, int num_bases,
571 const char **basenames)
583 for (i = 0; i < zh->num_basenames; i++)
584 xfree (zh->basenames[i]);
585 xfree (zh->basenames);
587 zh->num_basenames = num_bases;
588 zh->basenames = xmalloc (zh->num_basenames * sizeof(*zh->basenames));
589 for (i = 0; i < zh->num_basenames; i++)
590 zh->basenames[i] = xstrdup (basenames[i]);
592 cp = strrchr(basenames[0], '/');
595 len = cp - basenames[0];
596 new_reg = xmalloc (len + 1);
597 memcpy (new_reg, basenames[0], len);
601 new_reg = xstrdup ("");
602 for (i = 1; i<num_bases; i++)
606 cp1 = strrchr (basenames[i], '/');
614 if (len != cp1 - basenames[i] ||
615 memcmp (basenames[i], new_reg, len))
630 zebra_select_register (zh, new_reg);
640 void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream,
641 Z_RPNQuery *query, const char *setname, int *hits)
646 if (zebra_begin_read (zh))
648 resultSetAddRPN (zh, decode, stream, query,
649 zh->num_basenames, zh->basenames, setname);
656 void zebra_records_retrieve (ZebraHandle zh, ODR stream,
657 const char *setname, Z_RecordComposition *comp,
658 oid_value input_format, int num_recs,
659 ZebraRetrievalRecord *recs)
667 zh->errString = odr_strdup (stream, setname);
671 if (zebra_begin_read (zh))
674 pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
675 for (i = 0; i<num_recs; i++)
676 pos_array[i] = recs[i].position;
677 poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
680 logf (LOG_DEBUG, "zebraPosSetCreate error");
682 zh->errString = nmem_strdup (stream->mem, setname);
686 for (i = 0; i<num_recs; i++)
691 recs[i].format = VAL_SUTRS;
692 recs[i].len = strlen(poset[i].term);
693 recs[i].buf = poset[i].term;
694 recs[i].base = poset[i].db;
696 else if (poset[i].sysno)
699 zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
700 stream, input_format, comp,
701 &recs[i].format, &recs[i].buf,
704 recs[i].errString = NULL;
710 sprintf (num_str, "%d", pos_array[i]);
712 zh->errString = odr_strdup (stream, num_str);
716 zebraPosSetDestroy (zh, poset, num_recs);
722 void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
723 oid_value attributeset,
724 int *position, int *num_entries, ZebraScanEntry **entries,
727 if (zebra_begin_read (zh))
733 rpn_scan (zh, stream, zapt, attributeset,
734 zh->num_basenames, zh->basenames, position,
735 num_entries, entries, is_partial);
739 void zebra_sort (ZebraHandle zh, ODR stream,
740 int num_input_setnames, const char **input_setnames,
741 const char *output_setname, Z_SortKeySpecList *sort_sequence,
744 if (zebra_begin_read (zh))
746 resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
747 output_setname, sort_sequence, sort_status);
751 int zebra_deleleResultSet(ZebraHandle zh, int function,
752 int num_setnames, char **setnames,
756 if (zebra_begin_read(zh))
757 return Z_DeleteStatus_systemProblemAtTarget;
760 case Z_DeleteRequest_list:
761 resultSetDestroy (zh, num_setnames, setnames, statuses);
763 case Z_DeleteRequest_all:
764 resultSetDestroy (zh, -1, 0, statuses);
768 status = Z_DeleteStatus_success;
769 for (i = 0; i<num_setnames; i++)
770 if (statuses[i] == Z_DeleteStatus_resultSetDidNotExist)
771 status = statuses[i];
775 int zebra_errCode (ZebraHandle zh)
780 const char *zebra_errString (ZebraHandle zh)
782 return diagbib1_str (zh->errCode);
785 char *zebra_errAdd (ZebraHandle zh)
787 return zh->errString;
790 int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
792 ZebraService zs = zh->service;
793 if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
795 logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS");
799 logf(LOG_APP,"AUTHFAIL:%s", user?user:"ANONYMOUS");
803 void zebra_admin_import_begin (ZebraHandle zh, const char *database)
805 zebra_begin_trans (zh);
806 xfree (zh->admin_databaseName);
807 zh->admin_databaseName = xstrdup(database);
810 void zebra_admin_import_end (ZebraHandle zh)
812 zebra_end_trans (zh);
815 void zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
819 for (i = 0; i<segment->num_segmentRecords; i++)
821 Z_NamePlusRecord *npr = segment->segmentRecords[i];
822 const char *databaseName = npr->databaseName;
825 databaseName = zh->admin_databaseName;
826 printf ("--------------%d--------------------\n", i);
827 if (npr->which == Z_NamePlusRecord_intermediateFragment)
829 Z_FragmentSyntax *fragment = npr->u.intermediateFragment;
830 if (fragment->which == Z_FragmentSyntax_notExternallyTagged)
832 Odr_oct *oct = fragment->u.notExternallyTagged;
833 printf ("%.*s", (oct->len > 100 ? 100 : oct->len) ,
837 extract_rec_in_mem (zh, "grs.sgml",
845 0 /* match criteria */);
851 void zebra_admin_create (ZebraHandle zh, const char *database)
855 zebra_begin_trans (zh);
858 /* announce database */
859 if (zebraExplain_newDatabase (zh->reg->zei, database, 0
860 /* explainDatabase */))
863 zh->errString = "Database already exist";
865 zebra_end_trans (zh);
868 int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
869 const char *input_str, int input_len,
870 char *output_str, int output_len)
873 if (!zh->reg->zebra_maps)
875 wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "",
876 input_str, input_len);
879 if (wrbuf_len(wrbuf) >= output_len)
881 if (wrbuf_len(wrbuf))
882 memcpy (output_str, wrbuf_buf(wrbuf), wrbuf_len(wrbuf));
883 output_str[wrbuf_len(wrbuf)] = '\0';
884 return wrbuf_len(wrbuf);
888 void zebra_set_state (ZebraHandle zh, int val, int seqno)
890 char state_fname[256];
895 sprintf (state_fname, "state.%s.LCK", zh->reg_name);
896 fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
897 f = fopen (fname, "w");
899 yaz_log (LOG_LOG, "%c %d %ld", val, seqno, p);
900 fprintf (f, "%c %d %ld\n", val, seqno, p);
905 void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
907 char state_fname[256];
911 sprintf (state_fname, "state.%s.LCK", zh->reg_name);
912 fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
913 f = fopen (fname, "r");
919 fscanf (f, "%c %d", val, seqno);
925 static int zebra_begin_read (ZebraHandle zh)
935 if (zh->trans_no != 1)
937 zebra_flush_reg (zh);
949 zebra_get_state (zh, &val, &seqno);
955 else if (seqno != zh->reg->seqno)
957 yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d",
958 seqno, zh->reg->seqno);
961 else if (zh->reg->last_val != val)
963 yaz_log (LOG_LOG, "reopen last cur/old %d/%d",
964 val, zh->reg->last_val);
971 zebra_lock_r (zh->lock_shadow);
973 zebra_lock_r (zh->lock_normal);
976 zebra_register_close (zh->service, zh->reg);
977 zh->reg = zebra_register_open (zh->service, zh->reg_name,
978 0, val == 'c' ? 1 : 0,
979 zh->res, zh->path_reg);
985 zh->reg->last_val = val;
986 zh->reg->seqno = seqno;
991 static void zebra_end_read (ZebraHandle zh)
995 if (zh->trans_no != 0)
1000 logf (LOG_LOG, "user/system: %ld/%ld",
1001 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
1002 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
1006 zebra_unlock (zh->lock_normal);
1007 zebra_unlock (zh->lock_shadow);
1010 void zebra_begin_trans (ZebraHandle zh)
1015 const char *rval = 0;
1020 if (zh->trans_no != 1)
1025 yaz_log (LOG_LOG, "zebra_begin_trans");
1027 zh->records_inserted = 0;
1028 zh->records_updated = 0;
1029 zh->records_deleted = 0;
1030 zh->records_processed = 0;
1032 #if HAVE_SYS_TIMES_H
1037 if (zh->shadow_enable)
1038 rval = res_get (zh->res, "shadow");
1040 for (pass = 0; pass < 2; pass++)
1044 zebra_lock_r (zh->lock_normal);
1045 zebra_lock_w (zh->lock_shadow);
1049 zebra_lock_w (zh->lock_normal);
1050 zebra_lock_w (zh->lock_shadow);
1053 zebra_get_state (zh, &val, &seqno);
1056 yaz_log (LOG_LOG, "previous transaction didn't finish commit");
1057 zebra_unlock (zh->lock_shadow);
1058 zebra_unlock (zh->lock_normal);
1062 else if (val == 'd')
1066 BFiles bfs = bfs_create (res_get (zh->res, "shadow"),
1068 yaz_log (LOG_LOG, "previous transaction didn't reach commit");
1069 bf_commitClean (bfs, rval);
1074 yaz_log (LOG_WARN, "your previous transaction didn't finish");
1081 yaz_log (LOG_FATAL, "zebra_begin_trans couldn't finish commit");
1085 zebra_set_state (zh, 'd', seqno);
1087 zh->reg = zebra_register_open (zh->service, zh->reg_name,
1088 1, rval ? 1 : 0, zh->res,
1091 zh->reg->seqno = seqno;
1094 void zebra_end_trans (ZebraHandle zh)
1101 if (zh->trans_no != 0)
1104 yaz_log (LOG_LOG, "zebra_end_trans");
1105 rval = res_get (zh->res, "shadow");
1107 zebra_flush_reg (zh);
1109 zebra_register_close (zh->service, zh->reg);
1113 yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
1114 zh->records_processed, zh->records_inserted,
1115 zh->records_updated, zh->records_deleted);
1117 zebra_get_state (zh, &val, &seqno);
1120 BFiles bfs = bfs_create (rval, zh->path_reg);
1121 yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val);
1122 bf_commitClean (bfs, rval);
1127 zebra_set_state (zh, 'o', seqno);
1129 zebra_unlock (zh->lock_shadow);
1130 zebra_unlock (zh->lock_normal);
1132 #if HAVE_SYS_TIMES_H
1134 logf (LOG_LOG, "user/system: %ld/%ld",
1135 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
1136 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
1141 void zebra_repository_update (ZebraHandle zh)
1143 zebra_begin_trans (zh);
1144 logf (LOG_LOG, "updating %s", zh->rGroup.path);
1145 repositoryUpdate (zh);
1146 zebra_end_trans (zh);
1149 void zebra_repository_delete (ZebraHandle zh)
1151 logf (LOG_LOG, "deleting %s", zh->rGroup.path);
1152 repositoryDelete (zh);
1155 void zebra_repository_show (ZebraHandle zh)
1157 repositoryShow (zh);
1160 int zebra_commit (ZebraHandle zh)
1172 rval = res_get (zh->res, "shadow");
1175 logf (LOG_WARN, "Cannot perform commit");
1176 logf (LOG_WARN, "No shadow area defined");
1180 zebra_lock_w (zh->lock_normal);
1181 zebra_lock_r (zh->lock_shadow);
1183 bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
1185 zebra_get_state (zh, &val, &seqno);
1188 bf_cache (bfs, rval);
1189 if (bf_commitExists (bfs))
1191 zebra_set_state (zh, 'c', seqno);
1193 logf (LOG_LOG, "commit start");
1197 bf_commitExec (bfs);
1201 logf (LOG_LOG, "commit clean");
1202 bf_commitClean (bfs, rval);
1204 zebra_set_state (zh, 'o', seqno);
1208 logf (LOG_LOG, "nothing to commit");
1212 zebra_unlock (zh->lock_shadow);
1213 zebra_unlock (zh->lock_normal);
1217 int zebra_init (ZebraHandle zh)
1227 rval = res_get (zh->res, "shadow");
1229 bfs = bfs_create (res_get (zh->service->global_res, "register"),
1232 bf_cache (bfs, rval);
1236 zebra_set_state (zh, 'o', 0);
1240 int zebra_compact (ZebraHandle zh)
1248 bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
1254 int zebra_record_insert (ZebraHandle zh, const char *buf, int len)
1257 zebra_begin_trans (zh);
1258 extract_rec_in_mem (zh, "grs.sgml",
1260 "Default", /* database */
1261 0 /* delete_flag */,
1266 0 /* match criteria */);
1267 zebra_end_trans (zh);
1271 void zebra_set_group (ZebraHandle zh, struct recordGroup *rg)
1273 memcpy (&zh->rGroup, rg, sizeof(*rg));
1276 void zebra_result (ZebraHandle zh, int *code, char **addinfo)
1278 *code = zh->errCode;
1279 *addinfo = zh->errString;
1282 void zebra_shadow_enable (ZebraHandle zh, int value)
1284 zh->shadow_enable = value;