virt_db reports init diagnostics when rejected
[metaproxy-moved-to-github.git] / src / torus.cpp
index 924781a..d603621 100644 (file)
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/zgdu.h>
 #include <yaz/srw.h>
 #include <yaz/comstack.h>
-
+#include <metaproxy/util.hpp>
 #include "torus.hpp"
 
 namespace mp = metaproxy_1;
@@ -148,40 +148,20 @@ static WRBUF get_url(const char *uri, WRBUF username, WRBUF password,
 }
 
 
-mp::Torus::Torus()
-{
-    doc = 0;
-}
-
-mp::Torus::~Torus()
-{
-    if (doc)
-        xmlFreeDoc(doc);
-}
-
-void mp::Torus::read_searchables(std::string url)
+xmlDoc *mp::get_searchable(std::string url_template, const std::string &db)
 {
-    if (doc)
-    {
-        xmlFreeDoc(doc);
-        doc = 0;
-    }
-    if (url.length() == 0)
-        return;
+    // http://newmk2.indexdata.com/torus2/searchable.ebsco/records/?query=udb=aberdeenUni
+    xmlDoc *doc = 0;
+    size_t found;
 
+    found = url_template.find("%db");
+    if (found != std::string::npos)
+        url_template.replace(found, found+3, mp::util::uri_encode(db));
     int code;
-    WRBUF w = get_url(url.c_str(), 0, 0, &code);
+    WRBUF w = get_url(url_template.c_str(), 0, 0, &code);
     if (code == 200)
-    {
         doc = xmlParseMemory(wrbuf_buf(w), wrbuf_len(w));
-        if (doc)
-            yaz_log(YLOG_LOG, "xmlParseMemory OK");
-    }
     wrbuf_destroy(w);
-}
-
-xmlDoc *mp::Torus::get_doc()
-{
     return doc;
 }