Modified Data1-system to use nmem
[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.7  1995-10-12 10:34:38  quinn
8  * Added Espec-1.
9  *
10  * Revision 1.6  1995/09/29  17:11:55  quinn
11  * Smallish
12  *
13  * Revision 1.5  1995/09/27  15:02:42  quinn
14  * Modified function heads & prototypes.
15  *
16  * Revision 1.4  1995/08/29  11:17:16  quinn
17  * *** empty log message ***
18  *
19  * Revision 1.3  1995/08/21  09:10:18  quinn
20  * Smallish fixes to suppport new formats.
21  *
22  * Revision 1.2  1995/08/17  12:45:00  quinn
23  * Fixed minor problems with GRS-1. Added support in c&s.
24  *
25  * Revision 1.1  1995/08/15  13:37:41  quinn
26  * Improved EXTERNAL
27  *
28  *
29  */
30
31 #include <proto.h>
32
33 int z_External(ODR o, Z_External **p, int opt)
34 {
35    oident *oid;
36
37     static Odr_arm arm[] =
38     {
39         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single, odr_any},
40         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet, odr_octetstring},
41         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary, odr_bitstring},
42
43         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs, z_SUTRS},
44         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
45             z_ExplainRecord},
46         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
47             z_ResourceReport1},
48         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
49             z_ResourceReport2},
50         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
51             z_PromptObject1},
52         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1, z_GenericRecord},
53         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
54             z_TaskPackage},
55         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder, z_ItemOrder},
56         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_diag1, z_DiagnosticFormat},
57         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_espec1, z_Espec1},
58         {-1, -1, -1, -1, 0}
59     };
60     /*
61      * The table below should be moved to the ODR structure itself and
62      * be an image of the association context: To help
63      * map indirect references when they show up. 
64      */
65     static struct
66     {
67         oid_value dref;
68         int what;          /* discriminator value for the external CHOICE */
69     } tab[] =
70     {
71         {VAL_SUTRS, Z_External_sutrs},
72         {VAL_EXPLAIN, Z_External_explainRecord},
73         {VAL_RESOURCE1, Z_External_resourceReport1},
74         {VAL_RESOURCE2, Z_External_resourceReport2},
75         {VAL_PROMPT1, Z_External_promptObject1},
76         {VAL_GRS1, Z_External_grs1},
77         {VAL_EXTENDED, Z_External_extendedService},
78         {VAL_ITEMORDER, Z_External_itemOrder},
79         {VAL_DIAG1, Z_External_diag1},
80         {VAL_ESPEC1, Z_External_espec1},
81         {VAL_NONE, 0}
82     };
83
84     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
85     if (!odr_sequence_begin(o, p, sizeof(**p)))
86         return opt && odr_ok(o);
87     if (!(odr_oid(o, &(*p)->direct_reference, 1) &&
88         odr_integer(o, &(*p)->indirect_reference, 1) &&
89         odr_graphicstring(o, &(*p)->descriptor, 1)))
90         return 0;
91     /*
92      * Do we know this beast?
93      */
94     if (o->direction == ODR_DECODE && (*p)->direct_reference &&
95         (oid = oid_getentbyoid((*p)->direct_reference)))
96     {
97         int i;
98
99         for (i = 0; tab[i].dref != VAL_NONE; i++)
100             if (oid->value == tab[i].dref)
101             {
102                 odr_choice_bias(o, tab[i].what);
103                 break;
104             }
105     }
106     return
107         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
108         odr_sequence_end(o);
109 }