X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftorus.cpp;h=828e4ac02efc92658dde21311a830d81ebffe3ac;hb=d89b94329401b771c440dc6aafd72b9309a8b0ad;hp=e715614be4d829930396e0eebf707d6171e7cd59;hpb=cf16212cc3ea5a38f40b49779814eaeba57e69c0;p=metaproxy-moved-to-github.git diff --git a/src/torus.cpp b/src/torus.cpp index e715614..828e4ac 100644 --- a/src/torus.cpp +++ b/src/torus.cpp @@ -1,5 +1,5 @@ /* This file is part of Metaproxy. - Copyright (C) 2005-2011 Index Data + Copyright (C) 2005-2013 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 @@ -20,26 +20,40 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include #include #include #include "torus.hpp" namespace mp = metaproxy_1; -xmlDoc *mp::get_searchable(std::string url_template, const std::string &db, +xmlDoc *mp::get_searchable(mp::Package &package, + std::string url_template, const std::string &db, + const std::string &query, + const std::string &realm, const std::string &proxy) { - // http://newmk2.indexdata.com/torus2/searchable.ebsco/records/?query=udb=aberdeenUni + // http://mk2.indexdata.com/torus2/searchable/records/?query=udb%3d%db + // or + // http://mk2.indexdata.com/torus2/searchable/records/?query=%query xmlDoc *doc = 0; size_t found; + found = url_template.find("%query"); + if (found != std::string::npos) + url_template.replace(found, 6, mp::util::uri_encode(query)); + found = url_template.find("%db"); if (found != std::string::npos) - url_template.replace(found, found+3, mp::util::uri_encode(db)); + url_template.replace(found, 3, mp::util::uri_encode(db)); + + found = url_template.find("%realm"); + if (found != std::string::npos) + url_template.replace(found, 6, mp::util::uri_encode(realm)); Z_HTTP_Header *http_headers = 0; mp::odr odr; - + z_HTTP_header_add(odr, &http_headers, "Accept","application/xml"); yaz_url_t url_p = yaz_url_create(); @@ -53,9 +67,36 @@ xmlDoc *mp::get_searchable(std::string url_template, const std::string &db, 0, /* content buf */ 0 /* content_len */ ); - if (http_response->code == 200 && http_response->content_buf) + if (http_response && http_response->code == 200 && + http_response->content_buf) + { doc = xmlParseMemory(http_response->content_buf, http_response->content_len); + if (doc) + package.log("zoom", YLOG_LOG, "Torus: %s OK", + url_template.c_str()); + else + package.log("zoom", YLOG_WARN, "Torus: %s FAIL. XML parse failed", + url_template.c_str()); + } + else + { + if (http_response) + { + package.log("zoom", YLOG_WARN, "Torus: %s FAIL. HTTP code %d", + url_template.c_str(), http_response->code); + } + else + package.log("zoom", YLOG_WARN, "Torus: %s FAIL. No HTTP response", + url_template.c_str()); + } + + if (http_response && http_response->content_buf) + { + package.log("zoom", YLOG_LOG, "HTTP content"); + package.log_write(http_response->content_buf, + http_response->content_len); + } yaz_url_destroy(url_p); return doc; }