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