Fixed bugs in encoders/decoders - Not operator (!) missing.
[yaz-moved-to-github.git] / asn / prt-ext.c
1 /*
2  * Copyright (c) 1995-1998, Index Data.
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: prt-ext.c,v $
7  * Revision 1.14  1998-01-05 09:04:57  adam
8  * Fixed bugs in encoders/decoders - Not operator (!) missing.
9  *
10  * Revision 1.13  1997/05/14 06:53:22  adam
11  * C++ support.
12  *
13  * Revision 1.12  1997/04/30 08:52:02  quinn
14  * Null
15  *
16  * Revision 1.11  1996/10/10  12:35:13  quinn
17  * Added Update extended service.
18  *
19  * Revision 1.10  1996/10/09  15:54:55  quinn
20  * Added SearchInfoReport
21  *
22  * Revision 1.9  1996/06/10  08:53:36  quinn
23  * Added Summary,OPAC,ResourceReport
24  *
25  * Revision 1.8  1996/02/20  12:51:44  quinn
26  * Completed SCAN. Fixed problems with EXTERNAL.
27  *
28  * Revision 1.7  1995/10/12  10:34:38  quinn
29  * Added Espec-1.
30  *
31  * Revision 1.6  1995/09/29  17:11:55  quinn
32  * Smallish
33  *
34  * Revision 1.5  1995/09/27  15:02:42  quinn
35  * Modified function heads & prototypes.
36  *
37  * Revision 1.4  1995/08/29  11:17:16  quinn
38  * *** empty log message ***
39  *
40  * Revision 1.3  1995/08/21  09:10:18  quinn
41  * Smallish fixes to suppport new formats.
42  *
43  * Revision 1.2  1995/08/17  12:45:00  quinn
44  * Fixed minor problems with GRS-1. Added support in c&s.
45  *
46  * Revision 1.1  1995/08/15  13:37:41  quinn
47  * Improved EXTERNAL
48  *
49  *
50  */
51
52 #include <proto.h>
53
54 /*
55  * The table below should be moved to the ODR structure itself and
56  * be an image of the association context: To help
57  * map indirect references when they show up. 
58  */
59 static Z_ext_typeent type_table[] =
60 {
61     {VAL_SUTRS, Z_External_sutrs, z_SUTRS},
62     {VAL_EXPLAIN, Z_External_explainRecord, z_ExplainRecord},
63     {VAL_RESOURCE1, Z_External_resourceReport1, z_ResourceReport1},
64     {VAL_RESOURCE2, Z_External_resourceReport2, z_ResourceReport2},
65     {VAL_PROMPT1, Z_External_promptObject1, z_PromptObject1 },
66     {VAL_GRS1, Z_External_grs1, z_GenericRecord},
67     {VAL_EXTENDED, Z_External_extendedService, z_TaskPackage},
68     {VAL_ITEMORDER, Z_External_itemOrder, z_ItemOrder},
69     {VAL_DIAG1, Z_External_diag1, z_DiagnosticFormat},
70     {VAL_ESPEC1, Z_External_espec1, z_Espec1},
71     {VAL_SUMMARY, Z_External_summary, z_BriefBib},
72     {VAL_OPAC, Z_External_OPAC, z_OPACRecord},
73     {VAL_SEARCHRES1, Z_External_searchResult1, z_SearchInfoReport},
74     {VAL_DBUPDATE, Z_External_update, z_IUUpdate},
75     {VAL_NONE, 0, 0}
76 };
77
78 Z_ext_typeent *z_ext_getentbyref(oid_value val)
79 {
80     Z_ext_typeent *i;
81
82     for (i = type_table; i->dref != VAL_NONE; i++)
83         if (i->dref == val)
84             return i;
85     return 0;
86 }
87
88 int z_External(ODR o, Z_External **p, int opt)
89 {
90     oident *oid;
91     Z_ext_typeent *type;
92
93     static Odr_arm arm[] =
94     {
95         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single, odr_any},
96         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet, odr_octetstring},
97         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary, odr_bitstring},
98
99         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs, z_SUTRS},
100         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
101             z_ExplainRecord},
102         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
103             z_ResourceReport1},
104         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
105             z_ResourceReport2},
106         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
107             z_PromptObject1},
108         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1, z_GenericRecord},
109         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
110             z_TaskPackage},
111         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder, z_ItemOrder},
112         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_diag1, z_DiagnosticFormat},
113         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_espec1, z_Espec1},
114         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_summary, z_BriefBib},
115         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_OPAC, z_OPACRecord},
116         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_searchResult1,
117             z_SearchInfoReport},
118         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update, z_IUUpdate},
119         {-1, -1, -1, -1, 0}
120     };
121
122     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
123     if (!odr_sequence_begin(o, p, sizeof(**p)))
124         return opt && odr_ok(o);
125     if (!(odr_oid(o, &(*p)->direct_reference, 1) &&
126         odr_integer(o, &(*p)->indirect_reference, 1) &&
127         odr_graphicstring(o, &(*p)->descriptor, 1)))
128         return 0;
129     /*
130      * Do we know this beast?
131      */
132     if (o->direction == ODR_DECODE && (*p)->direct_reference &&
133         (oid = oid_getentbyoid((*p)->direct_reference)) &&
134         (type = z_ext_getentbyref(oid->value)))
135     {
136         int zclass, tag, cons;
137
138         /*
139          * We know it. If it's represented as an ASN.1 type, bias the CHOICE.
140          */
141         if (!odr_peektag(o, &zclass, &tag, &cons))
142             return opt && odr_ok(o);
143         if (zclass == ODR_CONTEXT && tag == 0 && cons == 1)
144             odr_choice_bias(o, type->what);
145     }
146     return
147         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
148         odr_sequence_end(o);
149 }