friend class Impl;
friend class Frontend;
std::string zurl;
- WRBUF m_apdu_wrbuf;
+ mp::wrbuf m_apdu_wrbuf;
ZOOM_connection m_connection;
ZOOM_resultset m_resultset;
std::string m_frontend_database;
const char *element_set_name,
bool &enable_pz2_retrieval,
bool &enable_pz2_transform,
+ bool &enable_record_transform,
bool &assume_marc8_charset);
Z_Records *get_records(Package &package,
std::string element_raw;
std::string proxy;
xsltStylesheetPtr explain_xsp;
+ xsltStylesheetPtr record_xsp;
std::map<std::string,SearchablePtr> s_map;
+ std::string zoom_timeout;
};
}
}
yf::Zoom::Backend::Backend()
{
- m_apdu_wrbuf = wrbuf_alloc();
m_connection = ZOOM_connection_create(0);
ZOOM_connection_save_apdu_wrbuf(m_connection, m_apdu_wrbuf);
m_resultset = 0;
xmlFreeDoc(explain_doc);
ZOOM_connection_destroy(m_connection);
ZOOM_resultset_destroy(m_resultset);
- wrbuf_destroy(m_apdu_wrbuf);
}
int *error, char **addinfo,
ODR odr)
{
- ZOOM_connection_connect(m_connection, zurl.c_str(), 0);
+ ZOOM_connection_connect(m_connection, zurl.length() ? zurl.c_str() : 0, 0);
get_zoom_error(error, addinfo, odr);
}
piggyback = true;
use_turbomarc = true;
sortStrategy = "embed";
- urlRecipe = "${md-electronic-url}";
ccl_bibset = ccl_qual_dup(base);
}
}
yf::Zoom::Impl::Impl() :
- apdu_log(false), element_transform("pz2") , element_raw("raw")
+ apdu_log(false), element_transform("pz2") , element_raw("raw"),
+ zoom_timeout("40")
{
bibset = ccl_qual_mk();
explain_xsp = 0;
+ record_xsp = 0;
srand((unsigned int) time(0));
}
const char *path)
{
std::string explain_xslt_fname;
+ std::string record_xslt_fname;
content_tmp_file = "/tmp/cf.XXXXXX.p";
if (path && *path)
proxy = mp::xml::get_text(attr->children);
else if (!strcmp((const char *) attr->name, "explain_xsl"))
explain_xslt_fname = mp::xml::get_text(attr->children);
+ else if (!strcmp((const char *) attr->name, "record_xsl"))
+ record_xslt_fname = mp::xml::get_text(attr->children);
else
throw mp::filter::FilterException(
"Bad attribute " + std::string((const char *)
attr->name));
}
}
+ else if (!strcmp((const char *) ptr->name, "zoom"))
+ {
+ const struct _xmlAttr *attr;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "timeout"))
+ zoom_timeout = mp::xml::get_text(attr->children);
+ else
+ throw mp::filter::FilterException(
+ "Bad attribute " + std::string((const char *)
+ attr->name));
+ }
+ }
else
{
throw mp::filter::FilterException
}
}
+
+ if (record_xslt_fname.length())
+ {
+ const char *path = 0;
+
+ if (xsldir.length())
+ path = xsldir.c_str();
+ else
+ path = file_path.c_str();
+
+ char fullpath[1024];
+ char *cp = yaz_filepath_resolve(record_xslt_fname.c_str(),
+ path, 0, fullpath);
+ if (!cp)
+ {
+ throw mp::filter::FilterException
+ ("Cannot read XSLT " + record_xslt_fname);
+ }
+
+ xmlDoc *xsp_doc = xmlParseFile(cp);
+ if (!xsp_doc)
+ {
+ throw mp::filter::FilterException
+ ("Cannot parse XSLT " + record_xslt_fname);
+ }
+
+ record_xsp = xsltParseStylesheetDoc(xsp_doc);
+ if (!record_xsp)
+ {
+ xmlFreeDoc(xsp_doc);
+ throw mp::filter::FilterException
+ ("Cannot parse XSLT " + record_xslt_fname);
+
+ }
+ }
}
bool yf::Zoom::Frontend::create_content_session(mp::Package &package,
return false;
}
b->content_session_id.assign(xx, 6);
- WRBUF w = wrbuf_alloc();
+ mp::wrbuf w;
wrbuf_puts(w, "#content_proxy\n");
wrbuf_printf(w, "connector: %s\n", b->sptr->contentConnector.c_str());
if (authentication.length())
if (realm.length())
wrbuf_printf(w, "realm: %s\n", realm.c_str());
- fwrite(wrbuf_buf(w), 1, wrbuf_len(w), file);
+ fwrite(w.buf(), 1, w.len(), file);
fclose(file);
package.log("zoom", YLOG_LOG, "content file: %s", fname);
xfree(fname);
- wrbuf_destroy(w);
}
return true;
}
std::list<BackendPtr>::const_iterator map_it;
if (m_backend && !m_backend->enable_explain &&
m_backend->m_frontend_database == database)
+ {
+ m_backend->connect("", error, addinfo, odr);
return m_backend;
+ }
std::string input_args;
std::string torus_db;
if (!doc)
{
*error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
- *addinfo = odr_strdup(odr, database.c_str());
+ *addinfo = odr_strdup(odr, torus_db.c_str());
BackendPtr b;
return b;
}
if (!sptr)
{
*error = YAZ_BIB1_DATABASE_DOES_NOT_EXIST;
- *addinfo = odr_strdup(odr, database.c_str());
+ *addinfo = odr_strdup(odr, torus_db.c_str());
BackendPtr b;
return b;
}
if (sptr->query_encoding.length())
b->set_option("rpnCharset", sptr->query_encoding);
- b->set_option("timeout", "40");
+ b->set_option("timeout", m_p->zoom_timeout.c_str());
if (m_p->apdu_log)
b->set_option("apdulog", "1");
const char *element_set_name,
bool &enable_pz2_retrieval,
bool &enable_pz2_transform,
+ bool &enable_record_transform,
bool &assume_marc8_charset)
-
{
char oid_name_str[OID_STR_MAX];
const char *syntax_name = 0;
if (preferredRecordSyntax &&
- !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml)
- && element_set_name)
+ !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml))
{
- if (!strcmp(element_set_name, m_p->element_transform.c_str()))
+ if (element_set_name &&
+ !strcmp(element_set_name, m_p->element_transform.c_str()))
{
enable_pz2_retrieval = true;
enable_pz2_transform = true;
}
- else if (!strcmp(element_set_name, m_p->element_raw.c_str()))
+ else if (element_set_name &&
+ !strcmp(element_set_name, m_p->element_raw.c_str()))
{
enable_pz2_retrieval = true;
}
+ else if (m_p->record_xsp)
+ {
+ enable_pz2_retrieval = true;
+ enable_pz2_transform = true;
+ enable_record_transform = true;
+ }
}
if (enable_pz2_retrieval)
bool enable_pz2_retrieval = false; // whether target profile is used
bool enable_pz2_transform = false; // whether XSLT is used as well
bool assume_marc8_charset = false;
+ bool enable_record_transform = false;
prepare_elements(b, preferredRecordSyntax,
element_set_name,
enable_pz2_retrieval,
enable_pz2_transform,
+ enable_record_transform,
assume_marc8_charset);
package.log("zoom", YLOG_LOG, "pz2_retrieval: %s . pz2_transform: %s",
}
if (i > 0)
{ // only return records if no error and at least one record
+
+ const char *xsl_parms[3];
+ mp::wrbuf cproxy_host;
+
+ if (b->enable_cproxy && b->content_session_id.length())
+ {
+ wrbuf_printf(cproxy_host, "\"%s.%s/\"",
+ b->content_session_id.c_str(),
+ m_p->content_proxy_server.c_str());
+ xsl_parms[0] = "cproxyhost";
+ xsl_parms[1] = wrbuf_cstr(cproxy_host);
+ xsl_parms[2] = 0;
+ }
+ else
+ {
+ xsl_parms[0] = 0;
+ }
+
char *odr_database = odr_strdup(odr,
b->m_frontend_database.c_str());
Z_NamePlusRecordList *npl = (Z_NamePlusRecordList *)
}
else
{
- xmlDoc *rec_res =
- xsltApplyStylesheet(b->xsp, rec_doc, 0);
+ // first stage XSLT - per target
+ xsltStylesheetPtr xsp = b->xsp;
+ xmlDoc *rec_res = xsltApplyStylesheet(xsp, rec_doc,
+ xsl_parms);
+ // insert generated-url
+ if (rec_res)
+ {
+ std::string res =
+ mp::xml::url_recipe_handle(rec_res,
+ b->sptr->urlRecipe);
+ if (res.length())
+ {
+ xmlNode *ptr = xmlDocGetRootElement(rec_res);
+ 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);
+ }
+ }
+ // second stage XSLT - common
+ if (rec_res && m_p->record_xsp &&
+ enable_record_transform)
+ {
+ xmlDoc *tmp_doc = rec_res;
+ xsp = m_p->record_xsp;
+ rec_res = xsltApplyStylesheet(xsp, tmp_doc,
+ xsl_parms);
+ xmlFreeDoc(tmp_doc);
+ }
+ // get result out of it
if (rec_res)
{
xsltSaveResultToString(&xmlrec_buf, &rec_len,
- rec_res, b->xsp);
+ rec_res, 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 && 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)
bool enable_pz2_retrieval = false;
bool enable_pz2_transform = false;
+ bool enable_record_transform = false;
bool assume_marc8_charset = false;
prepare_elements(b, sr->preferredRecordSyntax, 0 /*element_set_name */,
enable_pz2_retrieval,
enable_pz2_transform,
+ enable_record_transform,
assume_marc8_charset);
Odr_int hits = 0;
Z_Query *query = sr->query;
- WRBUF ccl_wrbuf = 0;
- WRBUF pqf_wrbuf = 0;
+ mp::wrbuf ccl_wrbuf;
+ mp::wrbuf pqf_wrbuf;
std::string sortkeys;
if (query->which == Z_Query_type_1 || query->which == Z_Query_type_101)
{
// RPN
- pqf_wrbuf = wrbuf_alloc();
yaz_rpnquery_to_wrbuf(pqf_wrbuf, query->u.type_1);
}
else if (query->which == Z_Query_type_2)
{
// CCL
- ccl_wrbuf = wrbuf_alloc();
wrbuf_write(ccl_wrbuf, (const char *) query->u.type_2->buf,
query->u.type_2->len);
}
return;
}
- WRBUF sru_sortkeys_wrbuf = wrbuf_alloc();
+ mp::wrbuf sru_sortkeys_wrbuf;
if (cql_sortby_to_sortkeys(cn, wrbuf_vp_puts, sru_sortkeys_wrbuf))
{
error = YAZ_BIB1_ILLEGAL_SORT_RELATION;
log_diagnostic(package, error, addinfo);
apdu_res = odr.create_searchResponse(apdu_req, error, addinfo);
package.response() = apdu_res;
- wrbuf_destroy(sru_sortkeys_wrbuf);
cql_parser_destroy(cp);
return;
}
- WRBUF sort_spec_wrbuf = wrbuf_alloc();
+ mp::wrbuf sort_spec_wrbuf;
yaz_srw_sortkeys_to_sort_spec(wrbuf_cstr(sru_sortkeys_wrbuf),
sort_spec_wrbuf);
- wrbuf_destroy(sru_sortkeys_wrbuf);
-
- ccl_wrbuf = wrbuf_alloc();
wrbuf_puts(ccl_wrbuf, ccl_buf);
yaz_tok_cfg_t tc = yaz_tok_cfg_create();
}
}
yaz_tok_parse_destroy(tp);
- wrbuf_destroy(sort_spec_wrbuf);
-
cql_parser_destroy(cp);
}
else
return;
}
- if (ccl_wrbuf)
+ if (ccl_wrbuf.len())
{
// CCL to PQF
- assert(pqf_wrbuf == 0);
+ assert(pqf_wrbuf.len() == 0);
int cerror, cpos;
struct ccl_rpn_node *cn;
package.log("zoom", YLOG_LOG, "CCL: %s", wrbuf_cstr(ccl_wrbuf));
cn = ccl_find_str(b->sptr->ccl_bibset, wrbuf_cstr(ccl_wrbuf),
&cerror, &cpos);
- wrbuf_destroy(ccl_wrbuf);
if (!cn)
{
- char *addinfo = odr_strdup(odr, ccl_err_msg(cerror));
+ char *addinfo = odr_strdup_null(odr, ccl_err_msg(cerror));
error = YAZ_BIB1_MALFORMED_QUERY;
switch (cerror)
package.response() = apdu_res;
return;
}
- pqf_wrbuf = wrbuf_alloc();
ccl_pquery(pqf_wrbuf, cn);
package.log("zoom", YLOG_LOG, "RPN: %s", wrbuf_cstr(pqf_wrbuf));
ccl_rpn_delete(cn);
}
- assert(pqf_wrbuf);
+ assert(pqf_wrbuf.len());
ZOOM_query q = ZOOM_query_create();
ZOOM_query_sortby2(q, b->sptr->sortStrategy.c_str(), sortkeys.c_str());
int status = 0;
Z_RPNQuery *zquery;
zquery = p_query_rpn(odr, wrbuf_cstr(pqf_wrbuf));
- WRBUF wrb = wrbuf_alloc();
+ mp::wrbuf wrb;
if (!strcmp(b->get_option("sru"), "solr"))
{
}
ZOOM_query_destroy(q);
- wrbuf_destroy(wrb);
- wrbuf_destroy(pqf_wrbuf);
if (status)
{
error = YAZ_BIB1_MALFORMED_QUERY;
package.log("zoom", YLOG_LOG, "search PQF: %s", wrbuf_cstr(pqf_wrbuf));
b->search(q, &hits, &error, &addinfo, odr);
ZOOM_query_destroy(q);
- wrbuf_destroy(pqf_wrbuf);
}
if (error && proxy_step)