2 * Copyright (C) 1995-2002, Index Data
5 * $Id: zebraapi.c,v 1.60 2002-05-07 11:05:19 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))))
265 logf (LOG_WARN, "isamb_open");
269 reg->zei = zebraExplain_open (reg->records, reg->dh,
274 logf (LOG_WARN, "Cannot obtain EXPLAIN information");
278 yaz_log (LOG_LOG, "zebra_register_open ok p=%p", reg);
282 void zebra_admin_shutdown (ZebraHandle zh)
284 zebra_mutex_cond_lock (&zh->service->session_lock);
285 zh->service->stop_flag = 1;
286 zebra_mutex_cond_unlock (&zh->service->session_lock);
289 void zebra_admin_start (ZebraHandle zh)
291 ZebraService zs = zh->service;
293 zebra_mutex_cond_lock (&zs->session_lock);
294 zebra_mutex_cond_unlock (&zs->session_lock);
297 static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
299 yaz_log(LOG_LOG, "zebra_register_close p=%p", reg);
304 zebraExplain_close (reg->zei);
305 dict_close (reg->dict);
307 dict_close (reg->matchDict);
308 sortIdx_close (reg->sortIdx);
310 isams_close (reg->isams);
312 is_close (reg->isam);
314 isc_close (reg->isamc);
316 isamd_close (reg->isamd);
318 isamb_close (reg->isamb);
319 rec_close (®->records);
322 recTypes_destroy (reg->recTypes);
323 zebra_maps_close (reg->zebra_maps);
324 zebraRankDestroy (reg);
325 bfs_destroy (reg->bfs);
326 data1_destroy (reg->dh);
328 xfree (reg->key_buf);
331 yaz_log (LOG_LOG, "zebra_register_close 2");
334 void zebra_stop(ZebraService zs)
338 yaz_log (LOG_LOG, "zebra_stop");
340 zebra_mutex_cond_lock (&zs->session_lock);
343 zebra_close (zs->sessions);
346 zebra_mutex_cond_unlock (&zs->session_lock);
348 zebra_mutex_cond_destroy (&zs->session_lock);
351 passwd_db_close (zs->passwd_db);
353 res_close (zs->global_res);
354 xfree (zs->configName);
355 xfree (zs->path_root);
359 void zebra_close (ZebraHandle zh)
362 struct zebra_session **sp;
368 yaz_log (LOG_LOG, "zebra_close zh=%p", zh);
371 resultSetDestroy (zh, -1, 0, 0);
375 zebra_register_close (zh->service, zh->reg);
376 zebra_close_res (zh);
378 xfree (zh->admin_databaseName);
379 zebra_mutex_cond_lock (&zs->session_lock);
380 zebra_lock_destroy (zh->lock_normal);
381 zebra_lock_destroy (zh->lock_shadow);
393 // if (!zs->sessions && zs->stop_flag)
394 // zebra_register_deactivate(zs);
395 zebra_mutex_cond_unlock (&zs->session_lock);
396 xfree (zh->reg_name);
400 struct map_baseinfo {
406 char **new_basenames;
410 static Res zebra_open_res (ZebraHandle zh)
416 sprintf (fname, "%.200s/zebra.cfg", zh->path_reg);
417 res = res_open (fname, zh->service->global_res);
419 res = zh->service->global_res;
421 else if (*zh->reg_name == 0)
423 res = zh->service->global_res;
427 yaz_log (LOG_WARN, "no register root specified");
428 return 0; /* no path for register - fail! */
433 static void zebra_close_res (ZebraHandle zh)
435 if (zh->res != zh->service->global_res)
440 static int zebra_select_register (ZebraHandle zh, const char *new_reg)
442 if (zh->res && strcmp (zh->reg_name, new_reg) == 0)
446 assert (zh->reg == 0);
447 assert (*zh->reg_name == 0);
453 resultSetInvalidate (zh);
454 zebra_register_close (zh->service, zh->reg);
459 xfree (zh->reg_name);
460 zh->reg_name = xstrdup (new_reg);
462 xfree (zh->path_reg);
464 if (zh->service->path_root)
466 zh->path_reg = xmalloc (strlen(zh->service->path_root) +
467 strlen(zh->reg_name) + 3);
468 strcpy (zh->path_reg, zh->service->path_root);
471 strcat (zh->path_reg, "/");
472 strcat (zh->path_reg, zh->reg_name);
475 zh->res = zebra_open_res (zh);
478 zebra_lock_destroy (zh->lock_normal);
482 zebra_lock_destroy (zh->lock_shadow);
488 const char *lock_area =res_get (zh->res, "lockDir");
490 if (!lock_area && zh->path_reg)
491 res_put (zh->res, "lockDir", zh->path_reg);
492 sprintf (fname, "norm.%s.LCK", zh->reg_name);
494 zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
496 sprintf (fname, "shadow.%s.LCK", zh->reg_name);
498 zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
504 void map_basenames_func (void *vp, const char *name, const char *value)
506 struct map_baseinfo *p = (struct map_baseinfo *) vp;
508 char fromdb[128], todb[8][128];
511 sscanf (value, "%127s %127s %127s %127s %127s %127s %127s %127s %127s",
512 fromdb, todb[0], todb[1], todb[2], todb[3], todb[4],
513 todb[5], todb[6], todb[7]);
517 for (i = 0; i<p->num_bases; i++)
518 if (p->basenames[i] && !strcmp (p->basenames[i], fromdb))
521 for (i = 0; i < no; i++)
523 if (p->new_num_bases == p->new_num_max)
525 p->new_basenames[(p->new_num_bases)++] =
526 nmem_strdup (p->mem, todb[i]);
532 void map_basenames (ZebraHandle zh, ODR stream,
533 int *num_bases, char ***basenames)
535 struct map_baseinfo info;
536 struct map_baseinfo *p = &info;
540 info.num_bases = *num_bases;
541 info.basenames = *basenames;
542 info.new_num_max = 128;
543 info.new_num_bases = 0;
544 info.new_basenames = (char **)
545 odr_malloc (stream, sizeof(*info.new_basenames) * info.new_num_max);
546 info.mem = stream->mem;
548 res_trav (zh->service->global_res, "mapdb", &info, map_basenames_func);
550 for (i = 0; i<p->num_bases; i++)
551 if (p->basenames[i] && p->new_num_bases < p->new_num_max)
553 p->new_basenames[(p->new_num_bases)++] =
554 nmem_strdup (p->mem, p->basenames[i]);
556 *num_bases = info.new_num_bases;
557 *basenames = info.new_basenames;
558 for (i = 0; i<*num_bases; i++)
559 logf (LOG_LOG, "base %s", (*basenames)[i]);
562 int zebra_select_database (ZebraHandle zh, const char *basename)
564 return zebra_select_databases (zh, 1, &basename);
567 int zebra_select_databases (ZebraHandle zh, int num_bases,
568 const char **basenames)
580 for (i = 0; i < zh->num_basenames; i++)
581 xfree (zh->basenames[i]);
582 xfree (zh->basenames);
584 zh->num_basenames = num_bases;
585 zh->basenames = xmalloc (zh->num_basenames * sizeof(*zh->basenames));
586 for (i = 0; i < zh->num_basenames; i++)
587 zh->basenames[i] = xstrdup (basenames[i]);
589 cp = strrchr(basenames[0], '/');
592 len = cp - basenames[0];
593 new_reg = xmalloc (len + 1);
594 memcpy (new_reg, basenames[0], len);
598 new_reg = xstrdup ("");
599 for (i = 1; i<num_bases; i++)
603 cp1 = strrchr (basenames[i], '/');
611 if (len != cp1 - basenames[i] ||
612 memcmp (basenames[i], new_reg, len))
627 zebra_select_register (zh, new_reg);
637 void zebra_search_rpn (ZebraHandle zh, ODR decode, ODR stream,
638 Z_RPNQuery *query, const char *setname, int *hits)
643 if (zebra_begin_read (zh))
645 resultSetAddRPN (zh, decode, stream, query,
646 zh->num_basenames, zh->basenames, setname);
653 void zebra_records_retrieve (ZebraHandle zh, ODR stream,
654 const char *setname, Z_RecordComposition *comp,
655 oid_value input_format, int num_recs,
656 ZebraRetrievalRecord *recs)
664 zh->errString = odr_strdup (stream, setname);
668 if (zebra_begin_read (zh))
671 pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
672 for (i = 0; i<num_recs; i++)
673 pos_array[i] = recs[i].position;
674 poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
677 logf (LOG_DEBUG, "zebraPosSetCreate error");
679 zh->errString = nmem_strdup (stream->mem, setname);
683 for (i = 0; i<num_recs; i++)
688 recs[i].format = VAL_SUTRS;
689 recs[i].len = strlen(poset[i].term);
690 recs[i].buf = poset[i].term;
691 recs[i].base = poset[i].db;
693 else if (poset[i].sysno)
696 zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
697 stream, input_format, comp,
698 &recs[i].format, &recs[i].buf,
701 recs[i].errString = NULL;
707 sprintf (num_str, "%d", pos_array[i]);
709 zh->errString = odr_strdup (stream, num_str);
713 zebraPosSetDestroy (zh, poset, num_recs);
719 void zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
720 oid_value attributeset,
721 int *position, int *num_entries, ZebraScanEntry **entries,
724 if (zebra_begin_read (zh))
730 rpn_scan (zh, stream, zapt, attributeset,
731 zh->num_basenames, zh->basenames, position,
732 num_entries, entries, is_partial);
736 void zebra_sort (ZebraHandle zh, ODR stream,
737 int num_input_setnames, const char **input_setnames,
738 const char *output_setname, Z_SortKeySpecList *sort_sequence,
741 if (zebra_begin_read (zh))
743 resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
744 output_setname, sort_sequence, sort_status);
748 int zebra_deleleResultSet(ZebraHandle zh, int function,
749 int num_setnames, char **setnames,
753 if (zebra_begin_read(zh))
754 return Z_DeleteStatus_systemProblemAtTarget;
757 case Z_DeleteRequest_list:
758 resultSetDestroy (zh, num_setnames, setnames, statuses);
760 case Z_DeleteRequest_all:
761 resultSetDestroy (zh, -1, 0, statuses);
765 status = Z_DeleteStatus_success;
766 for (i = 0; i<num_setnames; i++)
767 if (statuses[i] == Z_DeleteStatus_resultSetDidNotExist)
768 status = statuses[i];
772 int zebra_errCode (ZebraHandle zh)
777 const char *zebra_errString (ZebraHandle zh)
779 return diagbib1_str (zh->errCode);
782 char *zebra_errAdd (ZebraHandle zh)
784 return zh->errString;
787 int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
789 ZebraService zs = zh->service;
790 if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
792 logf(LOG_APP,"AUTHOK:%s", user?user:"ANONYMOUS");
796 logf(LOG_APP,"AUTHFAIL:%s", user?user:"ANONYMOUS");
800 void zebra_admin_import_begin (ZebraHandle zh, const char *database)
802 zebra_begin_trans (zh);
803 xfree (zh->admin_databaseName);
804 zh->admin_databaseName = xstrdup(database);
807 void zebra_admin_import_end (ZebraHandle zh)
809 zebra_end_trans (zh);
812 void zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
816 for (i = 0; i<segment->num_segmentRecords; i++)
818 Z_NamePlusRecord *npr = segment->segmentRecords[i];
819 const char *databaseName = npr->databaseName;
822 databaseName = zh->admin_databaseName;
823 printf ("--------------%d--------------------\n", i);
824 if (npr->which == Z_NamePlusRecord_intermediateFragment)
826 Z_FragmentSyntax *fragment = npr->u.intermediateFragment;
827 if (fragment->which == Z_FragmentSyntax_notExternallyTagged)
829 Odr_oct *oct = fragment->u.notExternallyTagged;
830 printf ("%.*s", (oct->len > 100 ? 100 : oct->len) ,
834 extract_rec_in_mem (zh, "grs.sgml",
842 0 /* match criteria */);
848 void zebra_admin_create (ZebraHandle zh, const char *database)
852 zebra_begin_trans (zh);
855 /* announce database */
856 if (zebraExplain_newDatabase (zh->reg->zei, database, 0
857 /* explainDatabase */))
860 zh->errString = "Database already exist";
862 zebra_end_trans (zh);
865 int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
866 const char *input_str, int input_len,
867 char *output_str, int output_len)
870 if (!zh->reg->zebra_maps)
872 wrbuf = zebra_replace(zh->reg->zebra_maps, reg_id, "",
873 input_str, input_len);
876 if (wrbuf_len(wrbuf) >= output_len)
878 if (wrbuf_len(wrbuf))
879 memcpy (output_str, wrbuf_buf(wrbuf), wrbuf_len(wrbuf));
880 output_str[wrbuf_len(wrbuf)] = '\0';
881 return wrbuf_len(wrbuf);
885 void zebra_set_state (ZebraHandle zh, int val, int seqno)
887 char state_fname[256];
892 sprintf (state_fname, "state.%s.LCK", zh->reg_name);
893 fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
894 f = fopen (fname, "w");
896 yaz_log (LOG_LOG, "%c %d %ld", val, seqno, p);
897 fprintf (f, "%c %d %ld\n", val, seqno, p);
902 void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
904 char state_fname[256];
908 sprintf (state_fname, "state.%s.LCK", zh->reg_name);
909 fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
910 f = fopen (fname, "r");
916 fscanf (f, "%c %d", val, seqno);
922 int zebra_begin_read (ZebraHandle zh)
932 if (zh->trans_no != 1)
934 zebra_flush_reg (zh);
946 zebra_get_state (zh, &val, &seqno);
952 else if (seqno != zh->reg->seqno)
954 yaz_log (LOG_LOG, "reopen seqno cur/old %d/%d",
955 seqno, zh->reg->seqno);
958 else if (zh->reg->last_val != val)
960 yaz_log (LOG_LOG, "reopen last cur/old %d/%d",
961 val, zh->reg->last_val);
968 zebra_lock_r (zh->lock_shadow);
970 zebra_lock_r (zh->lock_normal);
973 zebra_register_close (zh->service, zh->reg);
974 zh->reg = zebra_register_open (zh->service, zh->reg_name,
975 0, val == 'c' ? 1 : 0,
976 zh->res, zh->path_reg);
982 zh->reg->last_val = val;
983 zh->reg->seqno = seqno;
988 void zebra_end_read (ZebraHandle zh)
992 if (zh->trans_no != 0)
997 logf (LOG_LOG, "user/system: %ld/%ld",
998 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
999 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
1003 zebra_unlock (zh->lock_normal);
1004 zebra_unlock (zh->lock_shadow);
1007 void zebra_begin_trans (ZebraHandle zh)
1012 const char *rval = 0;
1017 if (zh->trans_no != 1)
1022 yaz_log (LOG_LOG, "zebra_begin_trans");
1024 zh->records_inserted = 0;
1025 zh->records_updated = 0;
1026 zh->records_deleted = 0;
1027 zh->records_processed = 0;
1029 #if HAVE_SYS_TIMES_H
1034 if (zh->shadow_enable)
1035 rval = res_get (zh->res, "shadow");
1037 for (pass = 0; pass < 2; pass++)
1041 zebra_lock_r (zh->lock_normal);
1042 zebra_lock_w (zh->lock_shadow);
1046 zebra_lock_w (zh->lock_normal);
1047 zebra_lock_w (zh->lock_shadow);
1050 zebra_get_state (zh, &val, &seqno);
1053 yaz_log (LOG_LOG, "previous transaction didn't finish commit");
1054 zebra_unlock (zh->lock_shadow);
1055 zebra_unlock (zh->lock_normal);
1059 else if (val == 'd')
1063 BFiles bfs = bfs_create (res_get (zh->res, "shadow"),
1065 yaz_log (LOG_LOG, "previous transaction didn't reach commit");
1066 bf_commitClean (bfs, rval);
1071 yaz_log (LOG_WARN, "your previous transaction didn't finish");
1078 yaz_log (LOG_FATAL, "zebra_begin_trans couldn't finish commit");
1082 zebra_set_state (zh, 'd', seqno);
1084 zh->reg = zebra_register_open (zh->service, zh->reg_name,
1085 1, rval ? 1 : 0, zh->res,
1088 zh->reg->seqno = seqno;
1091 void zebra_end_trans (ZebraHandle zh)
1098 if (zh->trans_no != 0)
1101 yaz_log (LOG_LOG, "zebra_end_trans");
1102 rval = res_get (zh->res, "shadow");
1104 zebraExplain_runNumberIncrement (zh->reg->zei, 1);
1106 zebra_flush_reg (zh);
1108 zebra_register_close (zh->service, zh->reg);
1112 yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
1113 zh->records_processed, zh->records_inserted,
1114 zh->records_updated, zh->records_deleted);
1116 zebra_get_state (zh, &val, &seqno);
1119 BFiles bfs = bfs_create (rval, zh->path_reg);
1120 yaz_log (LOG_LOG, "deleting shadow stuff val=%c", val);
1121 bf_commitClean (bfs, rval);
1126 zebra_set_state (zh, 'o', seqno);
1128 zebra_unlock (zh->lock_shadow);
1129 zebra_unlock (zh->lock_normal);
1131 #if HAVE_SYS_TIMES_H
1133 logf (LOG_LOG, "user/system: %ld/%ld",
1134 (long) (zh->tms2.tms_utime - zh->tms1.tms_utime),
1135 (long) (zh->tms2.tms_stime - zh->tms1.tms_stime));
1140 void zebra_repository_update (ZebraHandle zh)
1142 zebra_begin_trans (zh);
1143 logf (LOG_LOG, "updating %s", zh->rGroup.path);
1144 repositoryUpdate (zh);
1145 zebra_end_trans (zh);
1148 void zebra_repository_delete (ZebraHandle zh)
1150 logf (LOG_LOG, "deleting %s", zh->rGroup.path);
1151 repositoryDelete (zh);
1154 void zebra_repository_show (ZebraHandle zh)
1156 repositoryShow (zh);
1159 int zebra_commit (ZebraHandle zh)
1171 rval = res_get (zh->res, "shadow");
1174 logf (LOG_WARN, "Cannot perform commit");
1175 logf (LOG_WARN, "No shadow area defined");
1179 zebra_lock_w (zh->lock_normal);
1180 zebra_lock_r (zh->lock_shadow);
1182 bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
1184 zebra_get_state (zh, &val, &seqno);
1187 bf_cache (bfs, rval);
1188 if (bf_commitExists (bfs))
1190 zebra_set_state (zh, 'c', seqno);
1192 logf (LOG_LOG, "commit start");
1196 bf_commitExec (bfs);
1200 logf (LOG_LOG, "commit clean");
1201 bf_commitClean (bfs, rval);
1203 zebra_set_state (zh, 'o', seqno);
1207 logf (LOG_LOG, "nothing to commit");
1211 zebra_unlock (zh->lock_shadow);
1212 zebra_unlock (zh->lock_normal);
1216 int zebra_init (ZebraHandle zh)
1226 rval = res_get (zh->res, "shadow");
1228 bfs = bfs_create (res_get (zh->service->global_res, "register"),
1231 bf_cache (bfs, rval);
1235 zebra_set_state (zh, 'o', 0);
1239 int zebra_compact (ZebraHandle zh)
1247 bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
1253 int zebra_record_insert (ZebraHandle zh, const char *buf, int len)
1256 zebra_begin_trans (zh);
1257 extract_rec_in_mem (zh, "grs.sgml",
1259 "Default", /* database */
1260 0 /* delete_flag */,
1265 0 /* match criteria */);
1266 zebra_end_trans (zh);
1270 void zebra_set_group (ZebraHandle zh, struct recordGroup *rg)
1272 memcpy (&zh->rGroup, rg, sizeof(*rg));
1275 void zebra_result (ZebraHandle zh, int *code, char **addinfo)
1277 *code = zh->errCode;
1278 *addinfo = zh->errString;
1281 void zebra_shadow_enable (ZebraHandle zh, int value)
1283 zh->shadow_enable = value;