+
+
+int zebra_special_fetch(ZebraHandle zh, SYSNO sysno, ODR odr,
+ const char *elemsetname,
+ oid_value input_format,
+ oid_value *output_format,
+ char **rec_bufp, int *rec_lenp)
+{
+ Record rec;
+
+ /* only accept XML and SUTRS requests */
+ if (input_format != VAL_TEXT_XML
+ && input_format != VAL_SUTRS){
+ yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s",
+ elemsetname);
+ return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ }
+
+ /* processing zebra::meta::sysno elemset without fetching binary data */
+ if (elemsetname && 0 == strcmp(elemsetname, "meta::sysno"))
+ {
+ char rec_str[128];
+ if (input_format == VAL_SUTRS){
+ sprintf(rec_str, ZINT_FORMAT, sysno);
+ *output_format = VAL_SUTRS;
+ }
+ else if (input_format == VAL_TEXT_XML){
+ sprintf(rec_str, "<record xmlns="
+ "\"http://www.indexdata.com/zebra/\""
+ " sysno=\"" ZINT_FORMAT "\""
+ " set=\"zebra::%s\">\n",
+ sysno, elemsetname);
+ *output_format = VAL_TEXT_XML;
+ }
+ *rec_lenp = strlen(rec_str);
+ if (*rec_lenp){
+ *rec_bufp = odr_strdup(odr, rec_str);
+ return 0;
+ } else {
+ return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ }
+ }
+
+ /* fetching binary record up for all other display elementsets */
+ rec = rec_get(zh->reg->records, sysno);
+ if (!rec){
+ yaz_log(YLOG_DEBUG, "rec_get fail on sysno=" ZINT_FORMAT, sysno);
+ return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ }
+
+ /* processing special elementsetnames zebra::index:: */
+ if (elemsetname && 0 == strncmp(elemsetname, "index::", 7)){
+
+ int ret = zebra_special_index_fetch(zh, sysno, odr, rec,
+ elemsetname + 7,
+ input_format, output_format,
+ rec_bufp, rec_lenp);
+
+ rec_free(&rec);
+ return ret;
+ }
+
+ /* processing special elementsetnames zebra::data */
+ if (elemsetname && 0 == strcmp(elemsetname, "data")){
+ struct ZebraRecStream stream;
+ RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, rec);
+ zebra_create_record_stream(zh, &rec, &stream);
+ *output_format = VAL_SUTRS;
+ *rec_lenp = recordAttr->recordSize;
+ *rec_bufp = (char *) odr_malloc(odr, *rec_lenp);
+ stream.readf(&stream, *rec_bufp, *rec_lenp);
+ stream.destroy(&stream);
+ rec_free(&rec);
+ return 0;
+ }
+
+ if (rec)
+ rec_free(&rec);
+ return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+}
+