+ Record rec;
+
+ /* set output variables before processing possible error states */
+ /* *rec_lenp = 0; */
+
+
+
+ /* processing zebra::meta::sysno elemset without fetching binary data */
+ if (elemsetname && 0 == strcmp(elemsetname, "meta::sysno"))
+ {
+ int ret = 0;
+ WRBUF wrbuf = wrbuf_alloc();
+ if (input_format == VAL_SUTRS)
+ {
+ wrbuf_printf(wrbuf, ZINT_FORMAT, sysno);
+ *output_format = VAL_SUTRS;
+ }
+ else if (input_format == VAL_TEXT_XML)
+ {
+ wrbuf_printf(wrbuf, ZEBRA_XML_HEADER_STR
+ " sysno=\"" ZINT_FORMAT "\"/>\n",
+ sysno);
+ *output_format = VAL_TEXT_XML;
+ }
+ *rec_lenp = wrbuf_len(wrbuf);
+ if (*rec_lenp)
+ *rec_bufp = odr_strdup(odr, wrbuf_buf(wrbuf));
+ else
+ ret = YAZ_BIB1_NO_SYNTAXES_AVAILABLE_FOR_THIS_REQUEST;
+ wrbuf_free(wrbuf, 1);
+ return ret;
+ }
+
+ /* processing special elementsetname zebra::index:: for sort elements */
+ if (elemsetname && 0 == strncmp(elemsetname, "index", 5))
+ {
+ int ret = zebra_special_sort_fetch(zh, sysno, odr,
+ elemsetname + 5,
+ input_format, output_format,
+ rec_bufp, rec_lenp);
+ if (ret != -1)
+ return ret;
+ /* not a sort index so we continue to get the full record */
+ }
+
+
+ /* fetching binary record up for all other display elementsets */
+ rec = rec_get(zh->reg->records, sysno);
+ if (!rec)
+ {
+ yaz_log(YLOG_WARN, "rec_get fail on sysno=" ZINT_FORMAT, sysno);
+ return YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ }
+
+ /* 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 = input_format;
+ *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;
+ }
+
+ /* only accept XML and SUTRS requests from now */
+ 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_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 (input_format == VAL_TEXT_XML)
+ {
+ *output_format = VAL_TEXT_XML;
+
+ 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 (input_format == VAL_SUTRS)
+ {
+ *output_format = VAL_SUTRS;
+ 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_buf(wrbuf));
+ else
+ ret = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+
+ wrbuf_free(wrbuf, 1);
+ 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_;