+
+ /* Check if the user has access to all databases (Seb) */
+ /* You could argue that this should happen later, after we have
+ * determined that the database(s) exist. */
+ if (zh->dbaccesslist) {
+ for (i = 0; i < num_bases; i++) {
+ const char *db = basenames[i];
+ char *p, *pp;
+ for (p = zh->dbaccesslist; p && *p; p = pp) {
+ int len;
+ if ((pp = strchr(p, '+'))) {
+ len = pp - p;
+ pp++;
+ }
+ else
+ len = strlen(p);
+ if (len == strlen(db) && !strncmp(db, p, len))
+ break;
+ }
+ if (!p) {
+ zh->errCode = YAZ_BIB1_ACCESS_TO_SPECIFIED_DATABASE_DENIED;
+ return ZEBRA_FAIL;
+ }
+ }
+ }
+
+ for (i = 0; i < zh->num_basenames; i++)
+ xfree(zh->basenames[i]);
+ xfree(zh->basenames);
+
+ zh->num_basenames = num_bases;
+ zh->basenames = xmalloc(zh->num_basenames * sizeof(*zh->basenames));
+ for (i = 0; i < zh->num_basenames; i++)
+ zh->basenames[i] = xstrdup(basenames[i]);
+
+ cp = strrchr(basenames[0], '/');
+ if (cp)
+ {
+ len = cp - basenames[0];
+ new_reg = xmalloc(len + 1);
+ memcpy(new_reg, basenames[0], len);
+ new_reg[len] = '\0';
+ }
+ else
+ new_reg = xstrdup("");
+ for (i = 1; i<num_bases; i++)
+ {
+ const char *cp1;
+
+ cp1 = strrchr(basenames[i], '/');
+ if (cp)
+ {
+ if (!cp1)
+ {
+ zh->errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
+ return -1;
+ }
+ if (len != cp1 - basenames[i] ||
+ memcmp(basenames[i], new_reg, len))
+ {
+ zh->errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
+ return -1;
+ }
+ }
+ else
+ {
+ if (cp1)
+ {
+ zh->errCode = YAZ_BIB1_COMBI_OF_SPECIFIED_DATABASES_UNSUPP;
+ return ZEBRA_FAIL;
+ }
+ }
+ }
+ zebra_select_register(zh, new_reg);
+ xfree(new_reg);
+ if (!zh->res)
+ {
+ zh->errCode = YAZ_BIB1_DATABASE_UNAVAILABLE;
+ return ZEBRA_FAIL;
+ }
+ if (!zh->lock_normal || !zh->lock_shadow)
+ {
+ zh->errCode = YAZ_BIB1_TEMPORARY_SYSTEM_ERROR;
+ return ZEBRA_FAIL;
+ }
+ return ZEBRA_OK;
+}
+
+ZEBRA_RES zebra_set_approx_limit(ZebraHandle zh, zint approx_limit)
+{
+ if (approx_limit == 0)
+ approx_limit = DEFAULT_APPROX_LIMIT;
+ zh->approx_limit = approx_limit;
+ return ZEBRA_OK;
+}
+
+void zebra_set_partial_result(ZebraHandle zh)
+{
+ zh->partial_result = 1;
+}
+
+
+ZEBRA_RES zebra_set_break_handler(ZebraHandle zh,
+ int (*f)(void *client_data),
+ void *client_data)
+{
+ zh->break_handler_func = f;
+ zh->break_handler_data = client_data;
+ return ZEBRA_OK;
+}
+
+ZEBRA_RES zebra_search_RPN_x(ZebraHandle zh, ODR o, Z_RPNQuery *query,
+ const char *setname, zint *hits,
+ int *estimated_hit_count,
+ int *partial_resultset)
+{
+ ZEBRA_RES r;
+
+ ZEBRA_CHECK_HANDLE(zh);
+
+ assert(o);
+ assert(query);
+ assert(hits);
+ assert(setname);
+ yaz_log(log_level, "zebra_search_rpn");
+
+ zh->partial_result = 0;
+
+ if (zebra_begin_read(zh) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+
+ r = resultSetAddRPN(zh, odr_extract_mem(o), query,
+ zh->num_basenames, zh->basenames, setname,
+ hits, estimated_hit_count);
+
+ *partial_resultset = zh->partial_result;
+ zebra_end_read(zh);
+ return r;
+}
+
+ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
+ const char *setname, zint *hits)
+{
+ int estimated_hit_count;
+ int partial_resultset;
+ return zebra_search_RPN_x(zh, o, query, setname, hits,
+ &estimated_hit_count,
+ &partial_resultset);
+}
+
+ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
+ const char *setname,
+ Z_RecordComposition *comp,
+ const Odr_oid *input_format, int num_recs,
+ ZebraRetrievalRecord *recs)
+{
+ ZebraMetaRecord *poset;
+ int i;
+ ZEBRA_RES ret = ZEBRA_OK;
+ zint *pos_array;
+
+ ZEBRA_CHECK_HANDLE(zh);
+ assert(stream);
+ assert(setname);
+ assert(recs);
+ assert(num_recs>0);
+
+ yaz_log(log_level, "zebra_records_retrieve n=%d", num_recs);
+
+ if (!zh->res)
+ {
+ zebra_setError(zh, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ setname);
+ return ZEBRA_FAIL;
+ }
+
+ if (zebra_begin_read(zh) == ZEBRA_FAIL)
+ return ZEBRA_FAIL;
+
+ pos_array = (zint *) xmalloc(num_recs * sizeof(*pos_array));
+ for (i = 0; i<num_recs; i++)
+ pos_array[i] = recs[i].position;
+ poset = zebra_meta_records_create(zh, setname, num_recs, pos_array);
+ if (!poset)
+ {
+ yaz_log(YLOG_DEBUG, "zebraPosSetCreate error");
+ zebra_setError(zh, YAZ_BIB1_SPECIFIED_RESULT_SET_DOES_NOT_EXIST,
+ setname);
+ ret = ZEBRA_FAIL;
+ }
+ else