X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_zoom.cpp;h=b6258987adab498b33ecb6066f60c864236da447;hb=4bfec20c393570a81471c644fad6268eed3dba29;hp=d381d4335978b8135b81cd6f14b79561e94cec5a;hpb=b8cb28040e138df63ebb91b9fb27560143883c8b;p=metaproxy-moved-to-github.git diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index d381d43..b625898 100644 --- a/src/filter_zoom.cpp +++ b/src/filter_zoom.cpp @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include "torus.hpp" #include @@ -60,6 +61,7 @@ namespace metaproxy_1 { std::string element_set; std::string record_encoding; std::string transform_xsl_fname; + std::string urlRecipe; bool use_turbomarc; bool piggyback; CCL_bibset ccl_bibset; @@ -152,7 +154,8 @@ yf::Zoom::~Zoom() { // must have a destructor because of boost::scoped_ptr } -void yf::Zoom::configure(const xmlNode *xmlnode, bool test_only) +void yf::Zoom::configure(const xmlNode *xmlnode, bool test_only, + const char *path) { m_p->configure(xmlnode, test_only); } @@ -400,6 +403,11 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr) s->transform_xsl_fname = mp::xml::get_text(ptr); } else if (!strcmp((const char *) ptr->name, + "urlRecipe")) + { + s->urlRecipe = mp::xml::get_text(ptr); + } + else if (!strcmp((const char *) ptr->name, "useTurboMarc")) { ; // useTurboMarc is ignored @@ -530,6 +538,7 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( if (m_backend && m_backend->m_frontend_database == database) return m_backend; + const char *sru_proxy = 0; std::string db_args; std::string torus_db; size_t db_arg_pos = database.find(','); @@ -628,19 +637,34 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( { // A CF target b->set_option("user", sptr->cfAuth.c_str()); - if (authentication.length() && db_args.length() == 0) + if (db_args.length() == 0) { - // no database (auth) args specified already.. and the - // Torus authentication has it.. Generate the args that CF - // understands.. - size_t found = authentication.find('/'); - if (found != std::string::npos) + if (authentication.length()) + { + // no database (auth) args specified already.. and the + // Torus authentication has it.. Generate the args that CF + // understands.. + size_t found = authentication.find('/'); + if (found != std::string::npos) + { + db_args += "user=" + mp::util::uri_encode(authentication.substr(0, found)) + + "&password=" + mp::util::uri_encode(authentication.substr(found+1)); + } + else + db_args += "user=" + mp::util::uri_encode(authentication); + } + if (sptr->cfProxy.length()) { - db_args += "user=" + mp::util::uri_encode(authentication.substr(0, found)) - + "&password=" + mp::util::uri_encode(authentication.substr(found+1)); + if (db_args.length()) + db_args += "&"; + db_args += "proxy=" + mp::util::uri_encode(sptr->cfProxy); } - else - db_args += "user=" + mp::util::uri_encode(authentication); + } + if (sptr->cfSubDb.length()) + { + if (db_args.length()) + db_args += "&"; + db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb); } } else @@ -664,6 +688,8 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( param_user = value; else if (!strcmp(name, "password")) param_password = value; + else if (!strcmp(name, "proxy")) + sru_proxy = value; else { BackendPtr notfound; @@ -692,18 +718,9 @@ yf::Zoom::BackendPtr yf::Zoom::Frontend::get_backend_from_databases( b->set_option("user", authentication.c_str()); } } - if (sptr->cfProxy.length()) - { - if (db_args.length()) - db_args += "&"; - db_args += "proxy=" + mp::util::uri_encode(sptr->cfProxy); - } - if (sptr->cfSubDb.length()) - { - if (db_args.length()) - db_args += "&"; - db_args += "subdatabase=" + mp::util::uri_encode(sptr->cfSubDb); - } + + if (sru_proxy) + b->set_option("proxy", sru_proxy); std::string url; if (sptr->sru.length()) @@ -743,6 +760,7 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, Z_Records *records = 0; 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; if (start < 0 || number_to_present <= 0) return records; @@ -774,7 +792,14 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, if (enable_pz2_retrieval) { if (b->sptr->request_syntax.length()) + { syntax_name = b->sptr->request_syntax.c_str(); + const Odr_oid *syntax_oid = + yaz_string_to_oid(yaz_oid_std(), CLASS_RECSYN, syntax_name); + if (!oid_oidcmp(syntax_oid, yaz_oid_recsyn_usmarc) + || !oid_oidcmp(syntax_oid, yaz_oid_recsyn_opac)) + assume_marc8_charset = true; + } } else if (preferredRecordSyntax) syntax_name = @@ -825,19 +850,22 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, else if (enable_pz2_retrieval) { char rec_type_str[100]; + const char *record_encoding = 0; - strcpy(rec_type_str, b->sptr->use_turbomarc ? - "txml" : "xml"); - // prevent buffer overflow ... - if (b->sptr->record_encoding.length() > 0 && - b->sptr->record_encoding.length() < - (sizeof(rec_type_str)-20)) + 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, b->sptr->record_encoding.c_str()); + strcat(rec_type_str, record_encoding); } int rec_len; + xmlChar *xmlrec_buf = 0; const char *rec_buf = ZOOM_record_get(recs[i], rec_type_str, &rec_len); if (rec_buf && b->xsp && enable_pz2_transform) @@ -849,13 +877,39 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, rec_res = xsltApplyStylesheet(b->xsp, rec_doc, 0); if (rec_res) - xsltSaveResultToString((xmlChar **) &rec_buf, &rec_len, + xsltSaveResultToString(&xmlrec_buf, &rec_len, rec_res, b->xsp); + rec_buf = (const char *) xmlrec_buf; + xmlFreeDoc(rec_doc); + xmlFreeDoc(rec_res); } } if (rec_buf) { + xmlDoc *doc = xmlParseMemory(rec_buf, rec_len); + std::string res = + mp::xml::url_recipe_handle(doc, b->sptr->urlRecipe); + if (res.length()) + { + xmlNode *ptr = xmlDocGetRootElement(doc); + while (ptr && ptr->type != XML_ELEMENT_NODE) + ptr = ptr->next; + xmlNode *c = + xmlNewChild(ptr, 0, BAD_CAST "generated-url", 0); + 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 (rec_buf) + { npr = (Z_NamePlusRecord *) odr_malloc(odr, sizeof(*npr)); npr->databaseName = odr_database; npr->which = Z_NamePlusRecord_databaseRecord; @@ -869,6 +923,8 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS, rec_type_str); } + if (xmlrec_buf) + xmlFree(xmlrec_buf); } else {