- Z_GDU *p = z_get_HTTP_Request(odr);
- const char *host = url;
- const char *cp0 = strstr(host, "://");
- const char *cp1 = 0;
- if (cp0)
- cp0 = cp0+3;
- else
- cp0 = host;
-
- cp1 = strchr(cp0, '/');
- if (!cp1)
- cp1 = cp0 + strlen(cp0);
-
- if (cp0 && cp1)
- {
- char *h = (char*) odr_malloc(odr, cp1 - cp0 + 1);
- memcpy (h, cp0, cp1 - cp0);
- h[cp1-cp0] = '\0';
- z_HTTP_header_add(odr, &p->u.HTTP_Request->headers, "Host", h);
- }
- p->u.HTTP_Request->path = odr_strdup(odr, *cp1 ? cp1 : "/");
- return p;
-}
-
-static WRBUF get_url(const char *uri, WRBUF username, WRBUF password,
- int *code)
-{
- int number_of_redirects = 0;
- WRBUF result = 0;
- ODR out = odr_createmem(ODR_ENCODE);
- ODR in = odr_createmem(ODR_DECODE);
-
- while (1)
+ // 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));
+
+ 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();
+ if (proxy.length())
+ yaz_url_set_proxy(url_p, proxy.c_str());
+
+ Z_HTTP_Response *http_response = yaz_url_exec(url_p,
+ url_template.c_str(),
+ "GET",
+ http_headers,
+ 0, /* content buf */
+ 0 /* content_len */
+ );
+ if (http_response && http_response->code == 200 &&
+ http_response->content_buf)