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