Implemented z_ext_record.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 26 May 1999 14:47:12 +0000 (14:47 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 26 May 1999 14:47:12 +0000 (14:47 +0000)
asn/prt-ext.c
include/prt-ext.h

index 29aadd3..3206d87 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: prt-ext.c,v $
- * Revision 1.20  1999-04-20 09:56:48  adam
+ * Revision 1.21  1999-05-26 14:47:12  adam
+ * Implemented z_ext_record.
+ *
+ * Revision 1.20  1999/04/20 09:56:48  adam
  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
  * Modified all encoders/decoders to reflect this change.
  *
@@ -194,3 +197,78 @@ int z_External(ODR o, Z_External **p, int opt, const char *name)
        odr_sequence_end(o);
 }
 
+Z_External *z_ext_record(ODR o, int format, const char *buf, int len)
+{
+    Z_External *thisext;
+    oident recform;
+    int oid[OID_SIZE];
+
+    thisext = (Z_External *) odr_malloc(o, sizeof(*thisext));
+    thisext->descriptor = 0;
+    thisext->indirect_reference = 0;
+
+    recform.proto = PROTO_Z3950;
+    recform.oclass = CLASS_RECSYN;
+    recform.value = (enum oid_value) format;
+    if (!oid_ent_to_oid(&recform, oid))
+       return 0;
+    thisext->direct_reference = odr_oiddup(o, oid);
+    thisext->indirect_reference = 0;
+    thisext->descriptor = 0;
+    
+    if (len < 0) /* Structured data */
+    {
+       switch (format)
+       {
+       case VAL_SUTRS:
+           thisext->which = Z_External_sutrs;
+           break;
+       case VAL_GRS1:
+           thisext->which = Z_External_grs1;
+           break;
+       case VAL_EXPLAIN:
+           thisext->which = Z_External_explainRecord;
+           break;
+       case VAL_SUMMARY:
+           thisext->which = Z_External_summary;
+           break;
+       case VAL_OPAC:
+           thisext->which = Z_External_OPAC;
+           break;
+       default:
+           return 0;
+       }
+       
+       /*
+        * We cheat on the pointers here. Obviously, the record field
+        * of the backend-fetch structure should have been a union for
+        * correctness, but we're stuck with this for backwards
+        * compatibility.
+        */
+       thisext->u.grs1 = (Z_GenericRecord*) buf;
+    }
+    else if (format == VAL_SUTRS) /* SUTRS is a single-ASN.1-type */
+    {
+       Odr_oct *sutrs = (Odr_oct *)odr_malloc(o, sizeof(*sutrs));
+       
+       thisext->which = Z_External_sutrs;
+       thisext->u.sutrs = sutrs;
+       sutrs->buf = (unsigned char *)odr_malloc(o, len);
+       sutrs->len = sutrs->size = len;
+       memcpy(sutrs->buf, buf, len);
+    }
+    else
+    {
+       thisext->which = Z_External_octet;
+       if (!(thisext->u.octet_aligned = (Odr_oct *)
+             odr_malloc(o, sizeof(Odr_oct))))
+           return 0;
+       if (!(thisext->u.octet_aligned->buf = (unsigned char *)
+             odr_malloc(o, len)))
+           return 0;
+       memcpy(thisext->u.octet_aligned->buf, buf, len);
+       thisext->u.octet_aligned->len = thisext->u.octet_aligned->size = len;
+    }
+    return thisext;
+}
+
index 5038d42..7ae8da2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995-1998, Index Data.
+ * Copyright (c) 1995-1999, Index Data.
  *
  * Permission to use, copy, modify, distribute, and sell this software and
  * its documentation, in whole or in part, for any purpose, is hereby granted,
@@ -106,6 +106,8 @@ struct Z_External
 
 YAZ_EXPORT int z_External(ODR o, Z_External **p, int opt, const char *name);
 YAZ_EXPORT Z_ext_typeent *z_ext_getentbyref(oid_value val);
+YAZ_EXPORT Z_External *z_ext_record(ODR o, int format, const char *buf,
+                                   int len);
 
 #ifdef __cplusplus
 }