session_shared: allow max sessions to be given
[metaproxy-moved-to-github.git] / src / filter_sru_to_z3950.cpp
index a95f40b..2b62986 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2011 Index Data
+   Copyright (C) 2005-2012 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
@@ -116,7 +116,8 @@ yf::SRUtoZ3950::~SRUtoZ3950()
 {  // must have a destructor because of boost::scoped_ptr
 }
 
-void yf::SRUtoZ3950::configure(const xmlNode *xmlnode, bool test_only)
+void yf::SRUtoZ3950::configure(const xmlNode *xmlnode, bool test_only,
+                               const char *path)
 {
     m_p->configure(xmlnode);
 }
@@ -210,6 +211,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
         return;
     }
     
+    bool enable_package_log = false;
     std::string zurl;
     Z_SRW_extra_arg *arg;
 
@@ -222,7 +224,18 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
         {
             package.origin().set_max_sockets(atoi(arg->value));
         }
-
+        else if (!strcmp(arg->name, "x-session-id"))
+        {
+            package.origin().set_custom_session(arg->value);
+        }
+        else if (!strcmp(arg->name, "x-log-enable"))
+        {
+            if (*arg->value == '1')
+            {
+                enable_package_log = true;
+                package.log_enable();
+            }
+        }
     assert(sru_pdu_req);
 
     // filter acts as sink for SRU explain requests
@@ -284,6 +297,25 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
                                YAZ_SRW_UNSUPP_OPERATION, "unknown");
     }
 
+    if (enable_package_log)
+    {
+        std::string l;
+        package.log_reset(l);
+        if (l.length())
+        {
+            WRBUF w = wrbuf_alloc();
+            
+            wrbuf_puts(w, "<log>\n");
+            wrbuf_xmlputs(w, l.c_str());
+            wrbuf_puts(w, "</log>");
+            
+            sru_pdu_res->extraResponseData_len = wrbuf_len(w);
+            sru_pdu_res->extraResponseData_buf =
+                odr_strdup(odr_en, wrbuf_cstr(w));
+            wrbuf_destroy(w);
+        }
+    }
+    
     // build and send SRU response
     mp_util::build_sru_response(package, odr_en, soap, 
                                 sru_pdu_res, charset, stylesheet);
@@ -464,6 +496,9 @@ bool yf::SRUtoZ3950::Impl::z3950_search_request(mp::Package &package,
     Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_searchRequest);
     Z_SearchRequest *z_searchRequest = apdu->u.searchRequest;
 
+    // RecordSyntax will always be XML
+    z_searchRequest->preferredRecordSyntax
+        = odr_oiddup(odr_en, yaz_oid_recsyn_xml);
 
     if (!mp_util::set_databases_from_zurl(odr_en, zurl,
                                           &z_searchRequest->num_databaseNames,