+ else if (enable_pz2_retrieval)
+ {
+ char rec_type_str[100];
+ const char *record_encoding = 0;
+
+ if (b->sptr->record_encoding.length())
+ record_encoding = b->sptr->record_encoding.c_str();
+ else if (assume_marc8_charset)
+ record_encoding = "marc8";
+
+ strcpy(rec_type_str, b->sptr->use_turbomarc ? "txml" : "xml");
+ if (record_encoding)
+ {
+ strcat(rec_type_str, "; charset=");
+ strcat(rec_type_str, record_encoding);
+ }
+
+ package.log("zoom", YLOG_LOG, "Getting record of type %s",
+ rec_type_str);
+ int rec_len;
+ xmlChar *xmlrec_buf = 0;
+ const char *rec_buf = ZOOM_record_get(recs[i], rec_type_str,
+ &rec_len);
+ if (!rec_buf && !npr)
+ {
+ std::string addinfo("ZOOM_record_get failed for type ");
+
+ int error = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ addinfo += rec_type_str;
+ log_diagnostic(package, error, addinfo.c_str());
+ npr = zget_surrogateDiagRec(odr, odr_database,
+ error, addinfo.c_str());
+ }
+ else
+ {
+ package.log_write(rec_buf, rec_len);
+ package.log_write("\r\n", 2);
+ }
+
+ if (rec_buf && b->xsp && enable_pz2_transform)
+ {
+ xmlDoc *rec_doc = xmlParseMemory(rec_buf, rec_len);
+ if (!rec_doc)
+ {
+ const char *addinfo = "xml parse failed for record";
+ int error = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ log_diagnostic(package, error, addinfo);
+ npr = zget_surrogateDiagRec(
+ odr, odr_database, error, addinfo);
+ }
+ else
+ {
+ xmlDoc *rec_res =
+ xsltApplyStylesheet(b->xsp, rec_doc, 0);
+
+ if (rec_res)
+ {
+ xsltSaveResultToString(&xmlrec_buf, &rec_len,
+ rec_res, b->xsp);
+ rec_buf = (const char *) xmlrec_buf;
+ package.log("zoom", YLOG_LOG, "xslt successful");
+ package.log_write(rec_buf, rec_len);
+
+ xmlFreeDoc(rec_res);
+ }
+ if (!rec_buf)
+ {
+ std::string addinfo;
+ int error =
+ YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+
+ addinfo = "xslt apply failed for "
+ + b->sptr->transform_xsl_fname;
+ log_diagnostic(package, error, addinfo.c_str());
+ npr = zget_surrogateDiagRec(
+ odr, odr_database, error, addinfo.c_str());
+ }
+ xmlFreeDoc(rec_doc);
+ }
+ }
+
+ if (rec_buf && b->enable_cproxy)
+ {
+ xmlDoc *doc = xmlParseMemory(rec_buf, rec_len);
+ std::string res =
+ mp::xml::url_recipe_handle(doc, b->sptr->urlRecipe);
+ if (res.length() && b->content_session_id.length())
+ {
+ size_t off = res.find_first_of("://");
+ if (off != std::string::npos)
+ {
+ char tmp[1024];
+ sprintf(tmp, "%s.%s/",
+ b->content_session_id.c_str(),
+ m_p->content_proxy_server.c_str());
+ res.insert(off + 3, tmp);
+ }
+ }
+ if (res.length())
+ {
+ xmlNode *ptr = xmlDocGetRootElement(doc);
+ while (ptr && ptr->type != XML_ELEMENT_NODE)
+ ptr = ptr->next;
+ xmlNode *c =
+ xmlNewChild(ptr, 0, BAD_CAST "metadata", 0);
+ xmlNewProp(c, BAD_CAST "type", BAD_CAST
+ "generated-url");
+ xmlNode * t = xmlNewText(BAD_CAST res.c_str());
+ xmlAddChild(c, t);
+
+ if (xmlrec_buf)
+ xmlFree(xmlrec_buf);
+
+ xmlDocDumpMemory(doc, &xmlrec_buf, &rec_len);
+ rec_buf = (const char *) xmlrec_buf;
+ }
+ xmlFreeDoc(doc);
+ }
+ if (!npr)
+ {
+ if (!rec_buf)
+ npr = zget_surrogateDiagRec(
+ odr, odr_database,
+ YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
+ rec_type_str);
+ else
+ {
+ npr = (Z_NamePlusRecord *)
+ odr_malloc(odr, sizeof(*npr));
+ npr->databaseName = odr_database;
+ npr->which = Z_NamePlusRecord_databaseRecord;
+ npr->u.databaseRecord =
+ z_ext_record_xml(odr, rec_buf, rec_len);
+ }
+ }
+ if (xmlrec_buf)
+ xmlFree(xmlrec_buf);
+ }