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