From e02b5659eaac4f86f7bf97779a5f0dcf9f6bf86a Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Tue, 15 Aug 1995 13:37:41 +0000 Subject: [PATCH] Improved EXTERNAL --- asn/prt-ext.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/prt-ext.h | 61 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 asn/prt-ext.c create mode 100644 include/prt-ext.h diff --git a/asn/prt-ext.c b/asn/prt-ext.c new file mode 100644 index 0000000..ae50510 --- /dev/null +++ b/asn/prt-ext.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 1995, Index Data. + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: prt-ext.c,v $ + * Revision 1.1 1995-08-15 13:37:41 quinn + * Improved EXTERNAL + * + * + */ + +#include + +int z_External(ODR o, Z_External **p, int opt) +{ + oident *oid; + + static Odr_arm arm[] = + { + {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single, odr_any}, + {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet, odr_octetstring}, + {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary, odr_bitstring}, + + {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_SUTRS, z_SUTRS}, + {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord, + z_ExplainRecord}, + {-1, -1, -1, -1, 0} + }; + /* + * The table below should be moved to the ODR structure itself and + * be an image of the association context: To help + * map indirect references when they show up. + */ + static struct + { + oid_value dref; + int what; /* discriminator value for the external CHOICE */ + } tab[] = + { + {VAL_SUTRS, Z_External_SUTRS}, + {VAL_EXPLAIN, Z_External_explainRecord}, + {VAL_NONE, 0} + }; + + odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL); + if (!odr_sequence_begin(o, p, sizeof(**p))) + return opt && odr_ok(o); + if (!(odr_oid(o, &(*p)->direct_reference, 1) && + odr_integer(o, &(*p)->indirect_reference, 1) && + odr_graphicstring(o, &(*p)->descriptor, 1))) + return 0; + /* + * Do we know this beast? + */ + if (o->direction == ODR_DECODE && (*p)->direct_reference && + (oid = oid_getentbyoid((*p)->direct_reference))) + { + int i; + + for (i = 0; tab[i].dref != VAL_NONE; i++) + if (oid->value == tab[i].dref) + { + odr_choice_bias(o, tab[i].what); + break; + } + } + return + odr_choice(o, arm, &(*p)->u, &(*p)->which) && + odr_sequence_end(o); +} diff --git a/include/prt-ext.h b/include/prt-ext.h new file mode 100644 index 0000000..a04b2e3 --- /dev/null +++ b/include/prt-ext.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 1995, 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, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of Index Data or the individual authors may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR + * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + */ + +/* + * Biased-choice External for Z39.50. + */ + +struct Z_External +{ + Odr_oid *direct_reference; + int *indirect_reference; + char *descriptor; + enum + { + /* Generic types */ + Z_External_single = 0, + Z_External_octet, + Z_External_arbitrary, + + /* Specific types */ + Z_External_SUTRS, + Z_External_explainRecord + } which; + union + { + /* Generic types */ + Odr_any *single_ASN1_type; + Odr_oct *octet_aligned; + Odr_bitmask *arbitrary; + + /* Specific types */ + Z_SUTRS *sutrs; + Z_ExplainRecord *explainRecord; + } u; +}; + +int z_External(ODR o, Z_External **p, int opt); -- 1.7.10.4