Use Odr_oid for OIDs. Requires YAZ 3.0.2
[metaproxy-moved-to-github.git] / src / gduutil.cpp
index 2d4164d..47014d6 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: gduutil.cpp,v 1.15 2006-10-04 14:04:00 marc Exp $
-   Copyright (c) 2005-2006, Index Data.
+/* $Id: gduutil.cpp,v 1.20 2007-04-13 09:57:51 adam Exp $
+   Copyright (c) 2005-2007, Index Data.
 
    See the LICENSE file for details
 */
@@ -8,6 +8,7 @@
 #include "util.hpp"
 
 #include <yaz/wrbuf.h>
+#include <yaz/oid_db.h>
 #include <yaz/querytowrbuf.h>
 
 #include <iostream>
@@ -129,7 +130,8 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                 = zapdu.u.initRequest;
 
             Z_IdAuthentication *a = ir->idAuthentication;
-            if (a && a->which == Z_IdAuthentication_idPass )
+            if (a && a->which == Z_IdAuthentication_idPass 
+                &&  a->u.idPass->userId)
                 os << a->u.idPass->userId << " ";
             //<< ":" << a->u.idPass->groupId << " ";
             else
@@ -144,10 +146,13 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                 else
                     os << "-" << " " ;
 
-            os << (ir->implementationId) << " "
-                //<< ir->referenceId << " "
-               << (ir->implementationName) << " "
-               << (ir->implementationVersion);
+            if (ir->implementationId)
+                os << (ir->implementationId) << " ";
+            //<< ir->referenceId << " "
+            if (ir->implementationName)
+                os<< (ir->implementationName) << " ";
+            if (ir->implementationVersion)
+                os << (ir->implementationVersion) << " ";
         }
         break;
     case Z_APDU_initResponse:
@@ -155,12 +160,16 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
         {
             Z_InitResponse *ir 
                 = zapdu.u.initResponse;
-            if (ir->result && *(ir->result))
-                os << "OK" << " "
-                   << (ir->implementationId) << " "
+            if (ir->result && *(ir->result)){
+                os << "OK" << " ";
+                if (ir->implementationId)
+                     os << (ir->implementationId) << " ";
                     //<< ir->referenceId << " "
-                   << (ir->implementationName) << " "
-                   << (ir->implementationVersion) << " ";
+                if (ir->implementationName)
+                      os<< (ir->implementationName) << " ";
+                if (ir->implementationVersion)
+                     os << (ir->implementationVersion) << " ";
+            }
             else
                 os << "DIAG";
         }
@@ -182,8 +191,8 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                          
             WRBUF wr = wrbuf_alloc();
             yaz_query_to_wrbuf(wr, sr->query);
-            os << wrbuf_buf(wr);
-            wrbuf_free(wr, 1);
+            os << wrbuf_cstr(wr);
+            wrbuf_destroy(wr);
         }
         break;
     case Z_APDU_searchResponse:
@@ -233,12 +242,19 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
             else
                 os << " -";
             if (pr->preferredRecordSyntax)
-                //os << " " << pr->preferredRecordSyntax;
-                os << " " <<(oid_getentbyoid(pr->preferredRecordSyntax))->desc;
+            {
+                char oid_name_str[OID_STR_MAX];
+                const char *oid_name = yaz_oid_to_string_buf(
+                    pr->preferredRecordSyntax, 0, oid_name_str);
+                    
+                os << " " << oid_name;
+            }
             else
                 os << " -";
-            if (pr->recordComposition)
-                os << " " << mp_util::record_composition_to_esn(pr->recordComposition);
+            const char * msg = 0;
+            if (pr->recordComposition 
+                && (msg = mp_util::record_composition_to_esn(pr->recordComposition)))
+                os << " " << msg;
             else
                 os << " -";
         }
@@ -333,9 +349,10 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                 if (sr->termListAndStartPoint)
                 {
                     WRBUF wr = wrbuf_alloc();
-                    yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, VAL_NONE);
-                    os << wrbuf_buf(wr);
-                    wrbuf_free(wr, 1);
+                    yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, 
+                                      sr->attributeSet);
+                    os << wrbuf_cstr(wr);
+                    wrbuf_destroy(wr);
                 }
                 else
                     os << " -";