From: Adam Dickmeiss Date: Thu, 30 Jun 2011 15:40:29 +0000 (+0200) Subject: Beginnings of url recipe handling X-Git-Tag: v1.3.14~13 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=a5fe7e6104de3fccbbbe7cb57253b261b0ac6ecc;p=metaproxy-moved-to-github.git Beginnings of url recipe handling --- diff --git a/include/metaproxy/xmlutil.hpp b/include/metaproxy/xmlutil.hpp index ab3556d..ff265ef 100644 --- a/include/metaproxy/xmlutil.hpp +++ b/include/metaproxy/xmlutil.hpp @@ -51,6 +51,7 @@ namespace metaproxy_1 { void check_empty(const xmlNode *node); + void url_recipe_handle(xmlDoc *doc, std::string recipe); } class XMLError : public std::runtime_error { public: diff --git a/src/Makefile.am b/src/Makefile.am index 0f756ea..903c637 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,6 +53,7 @@ libmetaproxy_la_SOURCES = \ sru_util.cpp sru_util.hpp \ thread_pool_observer.cpp thread_pool_observer.hpp \ torus.cpp torus.hpp \ + url_recipe.cpp \ util.cpp \ xmlutil.cpp diff --git a/src/filter_zoom.cpp b/src/filter_zoom.cpp index 35512ca..39b5624 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; @@ -400,6 +402,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 @@ -866,6 +873,12 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start, if (rec_buf) { + xmlDoc *doc = xmlParseMemory(rec_buf, rec_len); + mp::xml::url_recipe_handle(doc, b->sptr->urlRecipe); + xmlFreeDoc(doc); + } + if (rec_buf) + { npr = (Z_NamePlusRecord *) odr_malloc(odr, sizeof(*npr)); npr->databaseName = odr_database; npr->which = Z_NamePlusRecord_databaseRecord; diff --git a/src/url_recipe.cpp b/src/url_recipe.cpp new file mode 100644 index 0000000..bba6a41 --- /dev/null +++ b/src/url_recipe.cpp @@ -0,0 +1,101 @@ +/* This file is part of Metaproxy. + Copyright (C) 2005-2011 Index Data + +Metaproxy is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include + +#include + +namespace mp = metaproxy_1; +// Doxygen doesn't like mp::xml, so we use this instead +namespace mp_xml = metaproxy_1::xml; + +void mp_xml::url_recipe_handle(xmlDoc *doc, std::string recipe) +{ + if (recipe.length() == 0) + return; + std::string result; + + size_t p0 = 0, p1 = 0; + for (;;) + { + p1 = recipe.find_first_of("${", p0); + if (p1 == std::string::npos) + { + result += recipe.substr(p0); + break; + } + result += recipe.substr(p0, p1 - p0); + + int step = 0; // 0=variable, 1=pattern, 2=replacement, 3=mode + std::string variable; + std::string pattern; + std::string replacement; + std::string mode; + p0 = p1+2; + while (p0 < recipe.length() && step < 5) + { + char c = recipe[p0]; + if (c == '}') + step = 5; + else if (step == 0) + { + if (c == '[') + step = 1; + else + variable += c; + } + else if (step == 1) + { + if (c == '/') + step = 2; + else + pattern += c; + } + else if (step == 2) + { + if (c == '/') + step = 3; + else + replacement += c; + } + else if (step == 3) + { + if (c == ']') + step = 4; + else + mode += c; + } + p0++; + } + if (variable.length()) + { + ; + } + } +} + + +/* + * Local variables: + * c-basic-offset: 4 + * c-file-style: "Stroustrup" + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +