1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2012 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <metaproxy/xmlutil.hpp>
22 #include <yaz/wrbuf.h>
25 #include <metaproxy/util.hpp>
28 namespace mp = metaproxy_1;
30 xmlDoc *mp::get_searchable(mp::Package &package,
31 std::string url_template, const std::string &db,
32 const std::string &query,
33 const std::string &realm,
34 const std::string &proxy)
36 // http://mk2.indexdata.com/torus2/searchable/records/?query=udb%3d%db
38 // http://mk2.indexdata.com/torus2/searchable/records/?query=%query
42 found = url_template.find("%query");
43 if (found != std::string::npos)
44 url_template.replace(found, 6, mp::util::uri_encode(query));
49 package.log("zoom", YLOG_WARN,
50 "%query not defined in <torus url=\"..\"");
55 found = url_template.find("%db");
56 if (found != std::string::npos)
57 url_template.replace(found, 3, mp::util::uri_encode(db));
59 found = url_template.find("%realm");
60 if (found != std::string::npos)
61 url_template.replace(found, 6, mp::util::uri_encode(realm));
63 Z_HTTP_Header *http_headers = 0;
66 z_HTTP_header_add(odr, &http_headers, "Accept","application/xml");
68 yaz_url_t url_p = yaz_url_create();
70 yaz_url_set_proxy(url_p, proxy.c_str());
72 Z_HTTP_Response *http_response = yaz_url_exec(url_p,
79 if (http_response && http_response->code == 200 &&
80 http_response->content_buf)
82 package.log("zoom", YLOG_LOG, "Torus: %s OK", url_template.c_str());
83 doc = xmlParseMemory(http_response->content_buf,
84 http_response->content_len);
89 package.log("zoom", YLOG_WARN, "Torus: %s FAIL", url_template.c_str());
92 package.log("zoom", YLOG_LOG, "HTTP code: %d", http_response->code);
96 if (http_response && http_response->content_buf)
98 package.log("zoom", YLOG_LOG, "HTTP content");
99 package.log_write(http_response->content_buf,
100 http_response->content_len);
102 yaz_url_destroy(url_p);
109 * c-file-style: "Stroustrup"
110 * indent-tabs-mode: nil
112 * vim: shiftwidth=4 tabstop=8 expandtab