X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftorus.cpp;h=54008503652adabb28439d04dca85c377f3cab25;hb=586d78659d671683f33ec55f4a7d32b28e345ccd;hp=d2ebd9f82a8691ae84ad9b53a63e75471e8d6245;hpb=6bbc073d4048f6bbff75e165b7539b9adbe22559;p=metaproxy-moved-to-github.git diff --git a/src/torus.cpp b/src/torus.cpp index d2ebd9f..5400850 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) 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 @@ -29,13 +29,21 @@ namespace mp = metaproxy_1; 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) + const std::string &proxy, + std::string &addinfo) { - // 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, 3, mp::util::uri_encode(db)); @@ -46,7 +54,7 @@ xmlDoc *mp::get_searchable(mp::Package &package, 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(); @@ -60,20 +68,36 @@ xmlDoc *mp::get_searchable(mp::Package &package, 0, /* content buf */ 0 /* content_len */ ); - if (http_response && http_response->code == 200 && + if (http_response && http_response->code == 200 && http_response->content_buf) { - package.log("zoom", YLOG_LOG, "Torus: %s OK", url_template.c_str()); 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()); + addinfo = "Torus: XML parse failed"; + } } else { - package.log("zoom", YLOG_WARN, "Torus: %s FAIL", url_template.c_str()); + addinfo = "Torus: "; if (http_response) { - package.log("zoom", YLOG_LOG, "HTTP code: %d", http_response->code); + package.log("zoom", YLOG_WARN, "Torus: %s FAIL. HTTP code %d", + url_template.c_str(), http_response->code); + addinfo += std::string(http_response->content_buf, + http_response->content_len); + } + else + { + addinfo += "unknown error"; + package.log("zoom", YLOG_WARN, "Torus: %s FAIL. No HTTP response", + url_template.c_str()); } }