zoom: simplify cproxyhost XSLT parm passing
[metaproxy-moved-to-github.git] / src / gduutil.cpp
index 6fc6d07..0f1ebd8 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Metaproxy.
-   Copyright (C) 2005-2008 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
@@ -17,23 +17,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #include "gduutil.hpp"
-#include "util.hpp"
+#include <metaproxy/util.hpp>
 
 #include <yaz/wrbuf.h>
 #include <yaz/oid_db.h>
 #include <yaz/querytowrbuf.h>
 
 #include <iostream>
-#include <list>
 
 namespace mp = metaproxy_1;
 
 // Doxygen doesn't like mp::gdu, so we use this instead
 namespace mp_util = metaproxy_1::util;
 
-
-
-
 std::ostream& std::operator<<(std::ostream& os,  Z_GDU& zgdu)
 {
     if (zgdu.which == Z_GDU_Z3950)
@@ -66,7 +62,6 @@ std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Request& httpreq)
     return os;
 }
 
-
 std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Response& httpres)
 {
     os << httpres.code << " ";
@@ -76,7 +71,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_HTTP_Response& httpres)
 
 std::ostream& std::operator<<(std::ostream& os, Z_Records & rs)
 {
-    switch(rs.which) {
+    switch (rs.which)
+    {
     case Z_Records_DBOSD :
         break;
     case Z_Records_NSD:
@@ -96,7 +92,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_Records & rs)
 
 std::ostream& std::operator<<(std::ostream& os, Z_DiagRec& dr)
 {
-    switch(dr.which) {
+    switch (dr.which)
+    {
     case Z_DiagRec_defaultFormat:
         if (dr.u.defaultFormat)
             os << *(dr.u.defaultFormat);
@@ -116,7 +113,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_DefaultDiagFormat& ddf)
     if (ddf.condition)
         os << *(ddf.condition) << " ";
 
-    switch(ddf.which) {
+    switch (ddf.which)
+    {
     case Z_DefaultDiagFormat_v2Addinfo:
         os << ddf.u.v2Addinfo;
         break;
@@ -139,7 +137,7 @@ static void dump_opt_string(std::ostream& os, const char *s)
         os << "-";
 }
 
-static void dump_opt_int(std::ostream& os, const int *i)
+static void dump_opt_int(std::ostream& os, const Odr_int *i)
 {
     os << " ";
     if (i)
@@ -228,29 +226,31 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                 os << "-";
 
             os << " ";
-            WRBUF wr = wrbuf_alloc();
+            mp::wrbuf wr;
             yaz_query_to_wrbuf(wr, sr->query);
             os << wrbuf_cstr(wr);
-            wrbuf_destroy(wr);
         }
         break;
     case Z_APDU_searchResponse:
         os << " " << "searchResponse ";
         {
-            Z_SearchResponse *sr 
-                = zapdu.u.searchResponse;
-            if (sr->searchStatus && *(sr->searchStatus))
-            {
+            Z_SearchResponse *sr = zapdu.u.searchResponse;
+            if (!sr->searchStatus)
+                os << "Unknown";
+            else if (*sr->searchStatus)
                 os << "OK";
+            else
+                os << "Failure";
+            if (sr->records && sr->records->which != Z_Records_DBOSD)
+            {
+                os << " DIAG " << *sr->records;
+            }
+            else
+            {
                 dump_opt_int(os, sr->resultCount);
                 dump_opt_int(os, sr->numberOfRecordsReturned);
                 dump_opt_int(os, sr->nextResultSetPosition);
             }
-            else 
-                if (sr->records)
-                    os << "DIAG " << *(sr->records);
-                else
-                    os << "ERROR";
         }
         break;
     case Z_APDU_presentRequest:
@@ -281,30 +281,35 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
         {
             Z_PresentResponse *pr 
                 = zapdu.u.presentResponse;
-            if ((pr->presentStatus) && !*(pr->presentStatus))
+            if (!pr->presentStatus)
+                os << "Unknown";
+            else
             {
-                os << "OK";
-                //<< pr->referenceId << " "
-                if (pr->numberOfRecordsReturned)
-                    os << " " << *(pr->numberOfRecordsReturned);
-                else
-                    os << " -";
-                if (pr->nextResultSetPosition)
-                    os << " " << *(pr->nextResultSetPosition);
-                else
-                    os << " -";
+                switch (*pr->presentStatus)
+                {
+                case Z_PresentStatus_success:
+                    os << "OK"; break;
+                case Z_PresentStatus_partial_1:
+                    os << "Partial-1"; break;
+                case Z_PresentStatus_partial_2:
+                    os << "Partial-2"; break;
+                case Z_PresentStatus_partial_3:
+                    os << "Partial-3"; break;
+                case Z_PresentStatus_partial_4:
+                    os << "Partial-4"; break;
+                case Z_PresentStatus_failure:
+                    os << "Failure"; break;
+                default:
+                    os << "Unknown"; break;
+                }
             }
+            if (pr->records && pr->records->which != Z_Records_DBOSD)
+                os << " DIAG " << *pr->records;
             else
-                if (pr->records)
-                    os << "DIAG " << *(pr->records);
-                else
-                    os << "ERROR";
-
-            //os << "DIAG" << " "
-            //<< "-" << " "
-            //<< pr->referenceId << " "
-            //<< *(pr->numberOfRecordsReturned) << " "
-            //<< *(pr->nextResultSetPosition);
+            {
+                dump_opt_int(os, pr->numberOfRecordsReturned);
+                dump_opt_int(os, pr->nextResultSetPosition);
+            }
         }
         break;
     case Z_APDU_deleteResultSetRequest:
@@ -337,8 +342,7 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
     case Z_APDU_scanRequest:
         os << " " << "scanRequest" << " ";
         { 
-            Z_ScanRequest *sr 
-                = zapdu.u.scanRequest;
+            Z_ScanRequest *sr = zapdu.u.scanRequest;
                         
             if (sr)
             {
@@ -355,11 +359,10 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                 os << " ";
                 if (sr->termListAndStartPoint)
                 {
-                    WRBUF wr = wrbuf_alloc();
+                    mp::wrbuf wr;
                     yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, 
                                       sr->attributeSet);
                     os << wrbuf_cstr(wr);
-                    wrbuf_destroy(wr);
                 }
                 else
                     os << "-";
@@ -369,17 +372,15 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
     case Z_APDU_scanResponse:
         os << " " << "scanResponse" << " ";
         {
-            Z_ScanResponse *sr 
-                = zapdu.u.scanResponse;
+            Z_ScanResponse *sr = zapdu.u.scanResponse;
             if (sr)
             {
                 if (!sr->scanStatus)
-                {
                     os << "OK";
-                }
                 else
                 {
-                    switch (*(sr->scanStatus)){
+                    switch (*sr->scanStatus)
+                    {
                     case Z_Scan_success:
                         os << "OK";
                         break;
@@ -468,48 +469,49 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
         break;
     case Z_APDU_extendedServicesResponse:
         os << " " << "extendedServicesResponse";
-         { 
-             Z_ExtendedServicesResponse *er 
-                 = zapdu.u.extendedServicesResponse;
-             if (er)
-             {
-                 if (er->operationStatus)
-                 {
-                     os << " ";
-                     switch (*(er->operationStatus)){
-                     case Z_ExtendedServicesResponse_done:
-                         os << "OK";
-                         break;
-                     case Z_ExtendedServicesResponse_accepted:
-                         os << "ACCEPT";
-                         break;
-                     case Z_ExtendedServicesResponse_failure:
-                         if (er->num_diagnostics)
-                             os << "DIAG " << **(er->diagnostics);
-                         else
-                             os << "ERROR";
-                         break;
-                     default:
-                         os << "unknown";
-                     }
-                 }
-                 else
-                     os << " -";
-             }
-         }
+        { 
+            Z_ExtendedServicesResponse *er 
+                = zapdu.u.extendedServicesResponse;
+            if (er)
+            {
+                if (er->operationStatus)
+                {
+                    os << " ";
+                    switch (*er->operationStatus)
+                    {
+                    case Z_ExtendedServicesResponse_done:
+                        os << "OK";
+                        break;
+                    case Z_ExtendedServicesResponse_accepted:
+                        os << "ACCEPT";
+                        break;
+                    case Z_ExtendedServicesResponse_failure:
+                        if (er->num_diagnostics)
+                            os << "DIAG " << **(er->diagnostics);
+                        else
+                            os << "ERROR";
+                        break;
+                    default:
+                        os << "unknown";
+                    }
+                }
+                else
+                    os << " -";
+            }
+        }
         break;
     case Z_APDU_close:
         os  << " " << "close" << " ";
         { 
-            Z_Close  *c 
-                = zapdu.u.close;
+            Z_Close *c = zapdu.u.close;
             if (c)
             {
                 if (c->closeReason)
                 {
                     os << *(c->closeReason) << " ";
 
-                    switch (*(c->closeReason)) {
+                    switch (*c->closeReason)
+                    {
                     case Z_Close_finished:
                         os << "finished";
                         break;