f0750737e2bcdffcd4ffa398e219f28d28f4e02a
[yaz-moved-to-github.git] / asn / prt-ext.c
1 /*
2  * Copyright (c) 1995, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: prt-ext.c,v $
7  * Revision 1.3  1995-08-21 09:10:18  quinn
8  * Smallish fixes to suppport new formats.
9  *
10  * Revision 1.2  1995/08/17  12:45:00  quinn
11  * Fixed minor problems with GRS-1. Added support in c&s.
12  *
13  * Revision 1.1  1995/08/15  13:37:41  quinn
14  * Improved EXTERNAL
15  *
16  *
17  */
18
19 #include <proto.h>
20
21 int z_External(ODR o, Z_External **p, int opt)
22 {
23     oident *oid;
24
25     static Odr_arm arm[] =
26     {
27         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single, odr_any},
28         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet, odr_octetstring},
29         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary, odr_bitstring},
30
31         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs, z_SUTRS},
32         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
33             z_ExplainRecord},
34         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
35             z_ResourceReport1},
36         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
37             z_ResourceReport2},
38         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
39             z_PromptObject1},
40         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1, z_GenericRecord},
41         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
42             z_TaskPackage},
43         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder, z_ItemOrder},
44         {-1, -1, -1, -1, 0}
45     };
46     /*
47      * The table below should be moved to the ODR structure itself and
48      * be an image of the association context: To help
49      * map indirect references when they show up. 
50      */
51     static struct
52     {
53         oid_value dref;
54         int what;          /* discriminator value for the external CHOICE */
55     } tab[] =
56     {
57         {VAL_SUTRS, Z_External_sutrs},
58         {VAL_EXPLAIN, Z_External_explainRecord},
59         {VAL_RESOURCE1, Z_External_resourceReport1},
60         {VAL_RESOURCE2, Z_External_resourceReport2},
61         {VAL_PROMPT1, Z_External_promptObject1},
62         {VAL_GRS1, Z_External_grs1},
63         {VAL_NONE, 0}
64     };
65
66     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
67     if (!odr_sequence_begin(o, p, sizeof(**p)))
68         return opt && odr_ok(o);
69     if (!(odr_oid(o, &(*p)->direct_reference, 1) &&
70         odr_integer(o, &(*p)->indirect_reference, 1) &&
71         odr_graphicstring(o, &(*p)->descriptor, 1)))
72         return 0;
73     /*
74      * Do we know this beast?
75      */
76     if (o->direction == ODR_DECODE && (*p)->direct_reference &&
77         (oid = oid_getentbyoid((*p)->direct_reference)))
78     {
79         int i;
80
81         for (i = 0; tab[i].dref != VAL_NONE; i++)
82             if (oid->value == tab[i].dref)
83             {
84                 odr_choice_bias(o, tab[i].what);
85                 break;
86             }
87     }
88     return
89         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
90         odr_sequence_end(o);
91 }