+ ASSERTZH;
+ yaz_log(LOG_API,"zebra_result");
+ *code = zh->errCode;
+ *addinfo = zh->errString;
+ return 0;
+}
+
+int zebra_shadow_enable (ZebraHandle zh, int value)
+{
+ ASSERTZH;
+ yaz_log(LOG_API,"zebra_shadow_enable");
+ zh->errCode=0;
+ zh->shadow_enable = value;
+ return 0;
+}
+
+int zebra_record_encoding (ZebraHandle zh, const char *encoding)
+{
+ ASSERTZH;
+ yaz_log(LOG_API,"zebra_record_encoding");
+ zh->errCode=0;
+ xfree (zh->record_encoding);
+
+ /*
+ * Fixme!
+ * Something about charset aliases. Oleg???
+ */
+
+ if (zh->iconv_to_utf8 != 0)
+ yaz_iconv_close(zh->iconv_to_utf8);
+ if (zh->iconv_from_utf8 != 0)
+ yaz_iconv_close(zh->iconv_from_utf8);
+
+ zh->record_encoding = xstrdup (encoding);
+
+ logf(LOG_DEBUG, "Reset record encoding: %s", encoding);
+
+ zh->iconv_to_utf8 =
+ yaz_iconv_open ("UTF-8", encoding);
+ if (zh->iconv_to_utf8 == 0)
+ yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported", encoding);
+ zh->iconv_from_utf8 =
+ yaz_iconv_open (encoding, "UTF-8");
+ if (zh->iconv_to_utf8 == 0)
+ yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported", encoding);
+
+ return 0;
+}
+
+int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
+{
+ ASSERTZH;
+ yaz_log(LOG_API,"zebra_set_resource %s:%s",name,value);
+ zh->errCode=0;
+ res_set(zh->res, name, value);
+ return 0;
+}
+
+const char *zebra_get_resource(ZebraHandle zh,
+ const char *name, const char *defaultvalue)
+{
+ const char *v;
+ ASSERTZH;
+ v= res_get_def( zh->res, name, (char *)defaultvalue);
+ zh->errCode=0;
+ yaz_log(LOG_API,"zebra_get_resource %s:%s",name,v);
+ return v;
+}
+
+/* moved from zebra_api_ext.c by pop */
+/* FIXME: Should this really be public??? -Heikki */
+
+int zebra_trans_no (ZebraHandle zh)
+{
+ ASSERTZH;
+ yaz_log(LOG_API,"zebra_trans_no");
+ return zh->trans_no;
+}
+
+int zebra_get_shadow_enable (ZebraHandle zh)
+{
+ yaz_log(LOG_API,"zebra_get_shadow_enable");
+ return (zh->shadow_enable);
+}
+
+int zebra_set_shadow_enable (ZebraHandle zh, int value)
+{
+ yaz_log(LOG_API,"zebra_set_shadow_enable %d",value);
+ zh->shadow_enable = value;
+ return 0;
+}
+
+/* almost the same as zebra_records_retrieve ... but how did it work?
+ I mean for multiple records ??? CHECK ??? */
+void api_records_retrieve (ZebraHandle zh, ODR stream,
+ const char *setname, Z_RecordComposition *comp,
+ oid_value input_format, int num_recs,
+ ZebraRetrievalRecord *recs)
+{
+ ZebraPosSet poset;
+ int i, *pos_array;
+ yaz_log(LOG_API,"api_records_retrieve s=%s n=%d",setname,num_recs);
+
+ if (!zh->res)
+ {
+ zh->errCode = 30;
+ zh->errString = odr_strdup (stream, setname);
+ return;
+ }
+
+ zh->errCode = 0;
+
+ if (zebra_begin_read (zh))
+ return;
+
+ pos_array = (int *) xmalloc (num_recs * sizeof(*pos_array));
+ for (i = 0; i<num_recs; i++)
+ pos_array[i] = recs[i].position;
+ poset = zebraPosSetCreate (zh, setname, num_recs, pos_array);
+ if (!poset)
+ {
+ logf (LOG_DEBUG, "zebraPosSetCreate error");
+ zh->errCode = 30;
+ zh->errString = nmem_strdup (stream->mem, setname);
+ }
+ else
+ {
+ for (i = 0; i<num_recs; i++)
+ {
+ if (poset[i].term)
+ {
+ recs[i].errCode = 0;
+ recs[i].format = VAL_SUTRS;
+ recs[i].len = strlen(poset[i].term);
+ recs[i].buf = poset[i].term;
+ recs[i].base = poset[i].db;
+ recs[i].sysno = 0;
+
+ }
+ else if (poset[i].sysno)
+ {
+ /* changed here ??? CHECK ??? */
+ char *b;
+ recs[i].errCode =
+ zebra_record_fetch (zh, poset[i].sysno, poset[i].score,
+ stream, input_format, comp,
+ &recs[i].format,
+ &b,
+ &recs[i].len,
+ &recs[i].base);
+ recs[i].buf = (char *) odr_malloc(stream,recs[i].len);
+ memcpy(recs[i].buf, b, recs[i].len);
+ recs[i].errString = 0; /* Hmmm !!! we should get this */
+ recs[i].sysno = poset[i].sysno;
+ recs[i].score = poset[i].score;
+ }
+ else
+ {
+ char num_str[20];
+
+ sprintf (num_str, "%d", pos_array[i]);
+ zh->errCode = 13;
+ zh->errString = odr_strdup (stream, num_str);
+ break;
+ }
+
+ }
+ zebraPosSetDestroy (zh, poset, num_recs);
+ }
+ zebra_end_read (zh);
+ xfree (pos_array);