Log diagnostics regardless of searchStatus
[metaproxy-moved-to-github.git] / src / gduutil.cpp
index 7fd718f..e6574d6 100644 (file)
@@ -1,7 +1,5 @@
-/* $Id: gduutil.cpp,v 1.22 2007-05-22 13:03:32 adam Exp $
-   Copyright (c) 2005-2007, Index Data.
-
-This file is part of Metaproxy.
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2010 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
@@ -14,13 +12,12 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Metaproxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+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>
@@ -142,7 +139,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)
@@ -240,20 +237,23 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
     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:
@@ -284,30 +284,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:
@@ -572,8 +577,9 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+