Fix Metaproxy stops logging after check config failed MP-590
[metaproxy-moved-to-github.git] / src / sru_util.cpp
index 8c10681..d9e8730 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2013 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
@@ -131,6 +131,7 @@ bool mp_util::build_sru_explain(metaproxy_1::Package &package,
         xmlDocDumpFormatMemory(doc, &xmlbuff, &xmlbuffsz, 1);
 
         explain_xml.assign((const char*)xmlbuff, 0, xmlbuffsz);
+        xmlFree(xmlbuff);
     }
 
 
@@ -227,10 +228,10 @@ bool mp_util::build_sru_response(mp::Package &package,
 Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package,
                                         mp::odr &odr_de,
                                         mp::odr &odr_en,
-                                        Z_SRW_PDU *sru_pdu_res,
+                                        Z_SRW_diagnostic **diagnostic,
+                                        int *num_diagnostic,
                                         Z_SOAP **soap,
-                                        char *charset,
-                                        char *stylesheet)
+                                        char *charset)
 {
     Z_GDU *zgdu_req = package.request().get();
     Z_SRW_PDU *sru_pdu_req = 0;
@@ -251,15 +252,8 @@ Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package,
     // closing connection if we did not ...
     if (0 == yaz_sru_decode(http_req, &sru_pdu_req, soap,
                             odr_de, &charset,
-                            &(sru_pdu_res->u.response->diagnostics),
-                            &(sru_pdu_res->u.response->num_diagnostics)))
+                            diagnostic, num_diagnostic))
     {
-        if (sru_pdu_res->u.response->num_diagnostics)
-        {
-            //sru_pdu_res = sru_pdu_res_exp;
-            package.session().close();
-            return 0;
-        }
         return sru_pdu_req;
     }
     else if (0 == yaz_srw_decode(http_req, &sru_pdu_req, soap,
@@ -281,6 +275,7 @@ mp_util::check_sru_query_exists(mp::Package &package,
                                 Z_SRW_PDU *sru_pdu_res,
                                 Z_SRW_searchRetrieveRequest const *sr_req)
 {
+#ifdef Z_SRW_query_type_cql
     if ((sr_req->query_type == Z_SRW_query_type_cql && !sr_req->query.cql))
     {
         yaz_add_srw_diagnostic(odr_en,
@@ -313,6 +308,22 @@ mp_util::check_sru_query_exists(mp::Package &package,
                                "PQF query is empty");
         return false;
     }
+#else
+    if (!sr_req->query)
+    {
+        yaz_add_srw_diagnostic(odr_en,
+                               &(sru_pdu_res->u.response->diagnostics),
+                               &(sru_pdu_res->u.response->num_diagnostics),
+                               YAZ_SRW_MANDATORY_PARAMETER_NOT_SUPPLIED,
+                               "query");
+        yaz_add_srw_diagnostic(odr_en,
+                               &(sru_pdu_res->u.response->diagnostics),
+                               &(sru_pdu_res->u.response->num_diagnostics),
+                               YAZ_SRW_QUERY_SYNTAX_ERROR,
+                               "CQL query is empty");
+        return false;
+    }
+#endif
     return true;
 }
 
@@ -365,6 +376,7 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu)
                 else
                     os << " -";
 
+#ifdef Z_SRW_query_type_cql
                 switch (sr->query_type){
                 case Z_SRW_query_type_cql:
                     os << " CQL";
@@ -380,6 +392,10 @@ std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu)
                         os << " " << sr->query.pqf;
                     break;
                 }
+#else
+                os << " " << (sr->queryType ? sr->queryType : "cql")
+                   << " " << sr->query;
+#endif
             }
         }
         break;