- /* convert response record to XML somehow */
- if (rec->which == Z_External_octet && oid
- && !oid_oidcmp(oid, yaz_oid_recsyn_xml))
- {
- /* xml already */
- rdoc = xmlParseMemory((char*) rec->u.octet_aligned->buf,
- rec->u.octet_aligned->len);
- if (!rdoc)
- {
- yaz_log(YLOG_FATAL, "Non-wellformed XML received from %s",
- db->url);
- return 0;
- }
- }
- else if (rec->which == Z_External_OPAC)
- {
- if (!sdb->yaz_marc)
- {
- yaz_log(YLOG_WARN, "MARC decoding not configured");
- return 0;
- }
- else
- {
- /* OPAC gets converted to XML too */
- WRBUF wrbuf_opac = wrbuf_alloc();
- /* MARCXML inside the OPAC XML. Charset is in effect because we
- use the yaz_marc handle */
- yaz_marc_xml(sdb->yaz_marc, YAZ_MARC_MARCXML);
- yaz_opac_decode_wrbuf(sdb->yaz_marc, rec->u.opac, wrbuf_opac);
-
- rdoc = xmlParseMemory((char*) wrbuf_buf(wrbuf_opac),
- wrbuf_len(wrbuf_opac));
- if (!rdoc)
- {
- yaz_log(YLOG_WARN, "Unable to parse OPAC XML");
- /* Was used to debug bug #1348 */
-#if 0
- FILE *f = fopen("/tmp/opac.xml.txt", "wb");
- if (f)
- {
- fwrite(wrbuf_buf(wrbuf_opac), 1, wrbuf_len(wrbuf_opac), f);
- fclose(f);
- }
-#endif
- }
- wrbuf_destroy(wrbuf_opac);
- }
- }
- else if (oid && yaz_oid_is_iso2709(oid))
- {
- /* ISO2709 gets converted to MARCXML */
- if (!sdb->yaz_marc)
- {
- yaz_log(YLOG_WARN, "MARC decoding not configured");
- return 0;
- }
- else
- {
- xmlNode *res;
- char *buf;
- int len;
-
- if (rec->which != Z_External_octet)
- {
- yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s",
- db->url);
- return 0;
- }
- buf = (char*) rec->u.octet_aligned->buf;
- len = rec->u.octet_aligned->len;
- if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0)
- {
- yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url);
- return 0;
- }
-
- if (yaz_marc_write_xml(sdb->yaz_marc, &res,
- "http://www.loc.gov/MARC21/slim", 0, 0) < 0)
- {
- yaz_log(YLOG_WARN, "Failed to encode as XML %s",
- db->url);
- return 0;
- }
- rdoc = xmlNewDoc((xmlChar *) "1.0");
- xmlDocSetRootElement(rdoc, res);
- }
- }
- else