+
+ /* only accept XML and SUTRS requests from now */
+ if (oid_oidcmp(input_format, yaz_oid_recsyn_xml)
+ && oid_oidcmp(input_format, yaz_oid_recsyn_sutrs))
+ {
+ yaz_log(YLOG_WARN, "unsupported format for element set zebra::%s",
+ elemsetname);
+ return YAZ_BIB1_NO_SYNTAXES_AVAILABLE_FOR_THIS_REQUEST;
+ }
+
+
+ /* processing special elementsetnames zebra::meta:: */
+ if (elemsetname && 0 == strcmp(elemsetname, "meta"))
+ {
+ int ret = 0;
+ WRBUF wrbuf = wrbuf_alloc();
+ RecordAttr *recordAttr = rec_init_attr(zh->reg->zei, rec);
+
+ if (!oid_oidcmp(input_format, yaz_oid_recsyn_xml))
+ {
+ *output_format = input_format;
+
+ wrbuf_printf(wrbuf, ZEBRA_XML_HEADER_STR
+ " sysno=\"" ZINT_FORMAT "\"", sysno);
+ retrieve_puts_attr(wrbuf, "base", rec->info[recInfo_databaseName]);
+ retrieve_puts_attr(wrbuf, "file", rec->info[recInfo_filename]);
+ retrieve_puts_attr(wrbuf, "type", rec->info[recInfo_fileType]);
+ if (score >= 0)
+ retrieve_puts_attr_int(wrbuf, "score", score);
+
+ wrbuf_printf(wrbuf,
+ " rank=\"" ZINT_FORMAT "\""
+ " size=\"%i\""
+ " set=\"zebra::%s\"/>\n",
+ recordAttr->staticrank,
+ recordAttr->recordSize,
+ elemsetname);
+ }
+ else if (!oid_oidcmp(input_format, yaz_oid_recsyn_sutrs))
+ {
+ *output_format = input_format;
+ wrbuf_printf(wrbuf, "sysno " ZINT_FORMAT "\n", sysno);
+ retrieve_puts_str(wrbuf, "base", rec->info[recInfo_databaseName]);
+ retrieve_puts_str(wrbuf, "file", rec->info[recInfo_filename]);
+ retrieve_puts_str(wrbuf, "type", rec->info[recInfo_fileType]);
+ if (score >= 0)
+ retrieve_puts_int(wrbuf, "score", score);
+
+ wrbuf_printf(wrbuf,
+ "rank " ZINT_FORMAT "\n"
+ "size %i\n"
+ "set zebra::%s\n",
+ recordAttr->staticrank,
+ recordAttr->recordSize,
+ elemsetname);
+ }
+ *rec_lenp = wrbuf_len(wrbuf);
+ if (*rec_lenp)
+ *rec_bufp = odr_strdup(odr, wrbuf_cstr(wrbuf));
+ else
+ ret = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+
+ wrbuf_destroy(wrbuf);
+ rec_free(&rec);
+ return ret;
+ }
+
+ /* processing special elementsetnames zebra::index:: */
+ if (elemsetname && 0 == strncmp(elemsetname, "index", 5))
+ {
+ int ret = zebra_special_index_fetch(zh, sysno, odr, rec,
+ elemsetname + 5,
+ input_format, output_format,
+ rec_bufp, rec_lenp);
+
+ rec_free(&rec);
+ return ret;
+ }
+
+ if (rec)
+ rec_free(&rec);
+ return YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
+}
+
+
+int zebra_record_fetch(ZebraHandle zh, const char *setname,
+ zint sysno, int score,
+ ODR odr,
+ const Odr_oid *input_format, Z_RecordComposition *comp,
+ const Odr_oid **output_format,
+ char **rec_bufp, int *rec_lenp, char **basenamep,
+ char **addinfo)
+{
+ Record rec;
+ char *fname, *file_type, *basename;
+ const char *elemsetname;
+ struct ZebraRecStream stream;
+ RecordAttr *recordAttr;
+ void *clientData;
+ int return_code = 0;
+ zint sysnos[10];
+ int no_sysnos = 10;
+ ZEBRA_RES res;
+
+ res = zebra_result_recid_to_sysno(zh, setname, sysno, sysnos, &no_sysnos);
+ if (res != ZEBRA_OK)
+ return ZEBRA_FAIL;
+
+ sysno = sysnos[0];
+ *basenamep = 0;
+ *addinfo = 0;
+ elemsetname = yaz_get_esn(comp);
+
+ /* processing zebra special elementset names of form 'zebra:: */
+ if (elemsetname && 0 == strncmp(elemsetname, "zebra::", 7))
+ return zebra_special_fetch(zh, setname, sysno, score, odr,
+ elemsetname + 7,
+ input_format, output_format,
+ rec_bufp, rec_lenp);
+
+
+ /* processing all other element set names */
+ rec = rec_get(zh->reg->records, sysno);
+ if (!rec)
+ {
+ yaz_log(YLOG_WARN, "rec_get fail on sysno=" ZINT_FORMAT, sysno);
+ *basenamep = 0;
+ return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ }
+
+
+ recordAttr = rec_init_attr(zh->reg->zei, rec);
+
+ file_type = rec->info[recInfo_fileType];
+ fname = rec->info[recInfo_filename];
+ basename = rec->info[recInfo_databaseName];
+ *basenamep = (char *) odr_malloc(odr, strlen(basename)+1);
+ strcpy(*basenamep, basename);
+
+ yaz_log(YLOG_DEBUG, "retrieve localno=" ZINT_FORMAT " score=%d",
+ sysno, score);
+
+ return_code = zebra_create_record_stream(zh, &rec, &stream);
+
+ if (rec)