zoom: warn if %query is not defined and Explain is used
[metaproxy-moved-to-github.git] / src / filter_z3950_client.cpp
index 2ebe770..fe3049e 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
@@ -55,6 +55,7 @@ namespace metaproxy_1 {
             void failNotify();
             void timeoutNotify();
             void recv_GDU(Z_GDU *gdu, int len);
+            void fixup_nsd(ODR odr, Z_Records *records);
             yazpp_1::IPDU_Observer* sessionNotify(
                 yazpp_1::IPDU_Observable *the_PDU_Observable,
                 int fd);
@@ -168,12 +169,50 @@ void yf::Z3950Client::Assoc::timeoutNotify()
     }
 }
 
+void yf::Z3950Client::Assoc::fixup_nsd(ODR odr, Z_Records *records)
+{
+    if (records && records->which == Z_Records_NSD)
+    {
+        Z_DefaultDiagFormat *nsd = records->u.nonSurrogateDiagnostic;
+       std::string addinfo;
+        
+        // should really check for nsd->which.. But union has two members
+        // containing almost same data
+        //  char *v2Addinfo;
+       //  Z_InternationalString *v3Addinfo;
+
+        if (nsd->u.v2Addinfo)
+        {
+            addinfo.assign(nsd->u.v2Addinfo);
+            addinfo += " ";
+        }
+        addinfo += "(backend=" + m_host + ")";
+        nsd->u.v2Addinfo = odr_strdup(odr, addinfo.c_str());
+    }
+}
+
 void yf::Z3950Client::Assoc::recv_GDU(Z_GDU *gdu, int len)
 {
     m_waiting = false;
 
     if (m_package)
+    { 
+        mp::odr odr; // must be in scope for response() = assignment
+        if (gdu && gdu->which == Z_GDU_Z3950)
+        {
+            Z_APDU *apdu = gdu->u.z3950;
+            switch (apdu->which)
+            {
+            case Z_APDU_searchResponse:
+                fixup_nsd(odr, apdu->u.searchResponse->records);
+                break;
+            case Z_APDU_presentResponse:
+                fixup_nsd(odr, apdu->u.presentResponse->records);
+                break;
+            }
+        }
         m_package->response() = gdu;
+    }
 }
 
 yazpp_1::IPDU_Observer *yf::Z3950Client::Assoc::sessionNotify(