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