Do not use z_ext_getentbyref
[yazpp-moved-to-github.git] / src / yaz-my-client.cpp
index c310895..f9a9462 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1998-2004, Index Data.
  * See the file LICENSE for details.
  * 
- * $Id: yaz-my-client.cpp,v 1.21 2005-06-25 15:53:19 adam Exp $
+ * $Id: yaz-my-client.cpp,v 1.26 2007-04-10 12:14:04 adam Exp $
  */
 
 #include <stdlib.h>
@@ -10,9 +10,9 @@
 #include <yaz/options.h>
 #include <yaz/diagbib1.h>
 #include <yaz/marcdisp.h>
-#include <yaz++/ir-assoc.h>
-#include <yaz++/pdu-assoc.h>
-#include <yaz++/socket-manager.h>
+#include <yazpp/ir-assoc.h>
+#include <yazpp/pdu-assoc.h>
+#include <yazpp/socket-manager.h>
 
 extern "C" {
 #if HAVE_READLINE_READLINE_H
@@ -57,7 +57,7 @@ public:
     void timeoutNotify();
     char *get_cookie (Z_OtherInformation **oi);
     int processCommand(const char *cmd);
-    const char *MyClient::getCommand();
+    const char *getCommand();
     int cmd_open(char *host);
     int cmd_connect(char *host);
     int cmd_quit(char *args);
@@ -296,37 +296,9 @@ void MyClient::recv_record(Z_DatabaseRecord *record, int offset,
         if (ent)
             printf("%s\n", ent->desc);
     }
-    /* Check if this is a known, ASN.1 type tucked away in an octet string */
-    Z_ext_typeent *etype = z_ext_getentbyref(ent->value);
-    if (ent && (r->which == Z_External_octet || r->which == Z_External_single)
-        && (etype = z_ext_getentbyref(ent->value)))
-
-    {
-        void *rr;
-        /*
-         * Call the given decoder to process the record.
-         */
-        odr_setbuf(odr_decode(), (char*)record->u.octet_aligned->buf,
-                   record->u.octet_aligned->len, 0);
-        if (!(*etype->fun)(odr_decode(), (char **)&rr, 0, 0))
-        {
-            odr_perror(odr_decode(), "Decoding constructed record.");
-            fprintf(stderr, "[Near %d]\n", odr_offset(odr_decode()));
-            fprintf(stderr, "Packet dump:\n---------\n");
-            odr_dumpBER(stderr, (char*)record->u.octet_aligned->buf,
-                        record->u.octet_aligned->len);
-            fprintf(stderr, "---------\n");
-        }
-        if (etype->what == Z_External_sutrs)
-        {
-            Z_SUTRS *sutrs = (Z_SUTRS *) rr;
-            recv_textRecord ((int) VAL_SUTRS, (const char *) sutrs->buf,
-                             (size_t) sutrs->len);
-        }
-        return;
-    }
     if (r->which == Z_External_octet && record->u.octet_aligned->len)
     {
+        yaz_marc_t mt = yaz_marc_create();
         switch (ent->value)
         {
         case VAL_ISO2709:
@@ -351,13 +323,20 @@ void MyClient::recv_record(Z_DatabaseRecord *record, int offset,
         case VAL_SIGLEMARC:
         case VAL_ISDSMARC:
         case VAL_RUSMARC:
-            marc_display((char*) record->u.octet_aligned->buf,0);
+            const char *result_buf;
+            size_t result_size;
+            yaz_marc_decode_buf(mt, (const char *)
+                                record->u.octet_aligned->buf,
+                                record->u.octet_aligned->len,
+                                &result_buf, &result_size);
+            fwrite(result_buf, 1, result_size, stdout);
             break;
         default:
             recv_textRecord((int) ent->value,
                             (const char *) record->u.octet_aligned->buf,
                             (size_t) record->u.octet_aligned->len);
         }
+        yaz_marc_destroy(mt);
     }
     else if (ent && ent->value == VAL_SUTRS && r->which == Z_External_sutrs)
         recv_textRecord((int) VAL_SUTRS, (const char *) r->u.sutrs->buf,