From 3e8a6d354cf280b4a157796bae8d4ea713784247 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 26 May 1999 14:47:12 +0000 Subject: [PATCH] Implemented z_ext_record. --- asn/prt-ext.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++- include/prt-ext.h | 4 ++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/asn/prt-ext.c b/asn/prt-ext.c index 29aadd3..3206d87 100644 --- a/asn/prt-ext.c +++ b/asn/prt-ext.c @@ -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; +} + diff --git a/include/prt-ext.h b/include/prt-ext.h index 5038d42..7ae8da2 100644 --- a/include/prt-ext.h +++ b/include/prt-ext.h @@ -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 } -- 1.7.10.4