Minor fix.
[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.19  1998-03-31 15:13:19  adam
8  * Development towards compiled ASN.1.
9  *
10  * Revision 1.18  1998/03/31 11:07:44  adam
11  * Furhter work on UNIverse resource report.
12  * Added Extended Services handling in frontend server.
13  *
14  * Revision 1.17  1998/03/20 14:46:06  adam
15  * Added UNIverse Resource Reports.
16  *
17  * Revision 1.16  1998/02/11 11:53:32  adam
18  * Changed code so that it compiles as C++.
19  *
20  * Revision 1.15  1998/02/10 15:31:46  adam
21  * Implemented date and time structure. Changed the Update Extended
22  * Service.
23  *
24  * Revision 1.14  1998/01/05 09:04:57  adam
25  * Fixed bugs in encoders/decoders - Not operator (!) missing.
26  *
27  * Revision 1.13  1997/05/14 06:53:22  adam
28  * C++ support.
29  *
30  * Revision 1.12  1997/04/30 08:52:02  quinn
31  * Null
32  *
33  * Revision 1.11  1996/10/10  12:35:13  quinn
34  * Added Update extended service.
35  *
36  * Revision 1.10  1996/10/09  15:54:55  quinn
37  * Added SearchInfoReport
38  *
39  * Revision 1.9  1996/06/10  08:53:36  quinn
40  * Added Summary,OPAC,ResourceReport
41  *
42  * Revision 1.8  1996/02/20  12:51:44  quinn
43  * Completed SCAN. Fixed problems with EXTERNAL.
44  *
45  * Revision 1.7  1995/10/12  10:34:38  quinn
46  * Added Espec-1.
47  *
48  * Revision 1.6  1995/09/29  17:11:55  quinn
49  * Smallish
50  *
51  * Revision 1.5  1995/09/27  15:02:42  quinn
52  * Modified function heads & prototypes.
53  *
54  * Revision 1.4  1995/08/29  11:17:16  quinn
55  * *** empty log message ***
56  *
57  * Revision 1.3  1995/08/21  09:10:18  quinn
58  * Smallish fixes to suppport new formats.
59  *
60  * Revision 1.2  1995/08/17  12:45:00  quinn
61  * Fixed minor problems with GRS-1. Added support in c&s.
62  *
63  * Revision 1.1  1995/08/15  13:37:41  quinn
64  * Improved EXTERNAL
65  *
66  *
67  */
68
69 #include <proto.h>
70
71 /*
72  * The table below should be moved to the ODR structure itself and
73  * be an image of the association context: To help
74  * map indirect references when they show up. 
75  */
76 static Z_ext_typeent type_table[] =
77 {
78     {VAL_SUTRS, Z_External_sutrs, (Odr_fun) z_SUTRS},
79     {VAL_EXPLAIN, Z_External_explainRecord, (Odr_fun)z_ExplainRecord},
80     {VAL_RESOURCE1, Z_External_resourceReport1, (Odr_fun)z_ResourceReport1},
81     {VAL_RESOURCE2, Z_External_resourceReport2, (Odr_fun)z_ResourceReport2},
82     {VAL_PROMPT1, Z_External_promptObject1, (Odr_fun)z_PromptObject1 },
83     {VAL_GRS1, Z_External_grs1, (Odr_fun)z_GenericRecord},
84     {VAL_EXTENDED, Z_External_extendedService, (Odr_fun)z_TaskPackage},
85 #ifdef ASN_COMPILED
86     {VAL_ITEMORDER, Z_External_itemOrder, (Odr_fun)z_IOItemOrder},
87 #else
88     {VAL_ITEMORDER, Z_External_itemOrder, (Odr_fun)z_ItemOrder},
89 #endif
90     {VAL_DIAG1, Z_External_diag1, (Odr_fun)z_DiagnosticFormat},
91     {VAL_ESPEC1, Z_External_espec1, (Odr_fun)z_Espec1},
92     {VAL_SUMMARY, Z_External_summary, (Odr_fun)z_BriefBib},
93     {VAL_OPAC, Z_External_OPAC, (Odr_fun)z_OPACRecord},
94     {VAL_SEARCHRES1, Z_External_searchResult1, (Odr_fun)z_SearchInfoReport},
95     {VAL_DBUPDATE, Z_External_update, (Odr_fun)z_IUUpdate},
96     {VAL_DATETIME, Z_External_dateTime, (Odr_fun)z_DateTime},
97     {VAL_UNIVERSE_REPORT, Z_External_universeReport, (Odr_fun)z_UniverseReport},
98     {VAL_NONE, 0, 0}
99 };
100
101 Z_ext_typeent *z_ext_getentbyref(oid_value val)
102 {
103     Z_ext_typeent *i;
104
105     for (i = type_table; i->dref != VAL_NONE; i++)
106         if (i->dref == val)
107             return i;
108     return 0;
109 }
110
111 int z_External(ODR o, Z_External **p, int opt)
112 {
113     oident *oid;
114     Z_ext_typeent *type;
115
116     static Odr_arm arm[] =
117     {
118         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single, (Odr_fun)odr_any},
119         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet, (Odr_fun)odr_octetstring},
120         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary, (Odr_fun)odr_bitstring},
121
122         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs, (Odr_fun)z_SUTRS},
123         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
124             (Odr_fun)z_ExplainRecord},
125         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
126             (Odr_fun)z_ResourceReport1},
127         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
128             (Odr_fun)z_ResourceReport2},
129         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
130             (Odr_fun)z_PromptObject1},
131         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1, (Odr_fun)z_GenericRecord},
132         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_extendedService,
133             (Odr_fun)z_TaskPackage},
134 #ifdef ASN_COMPILED
135         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder, (Odr_fun)z_IOItemOrder},
136 #else
137         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_itemOrder, (Odr_fun)z_ItemOrder},
138 #endif
139         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_diag1, (Odr_fun)z_DiagnosticFormat},
140         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_espec1, (Odr_fun)z_Espec1},
141         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_summary, (Odr_fun)z_BriefBib},
142         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_OPAC, (Odr_fun)z_OPACRecord},
143         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_searchResult1,
144             (Odr_fun)z_SearchInfoReport},
145         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_update, (Odr_fun)z_IUUpdate},
146         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_dateTime, (Odr_fun)z_DateTime},
147         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_universeReport,
148          (Odr_fun)z_UniverseReport},
149         {-1, -1, -1, -1, 0}
150     };
151
152     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
153     if (!odr_sequence_begin(o, p, sizeof(**p)))
154         return opt && odr_ok(o);
155     if (!(odr_oid(o, &(*p)->direct_reference, 1) &&
156         odr_integer(o, &(*p)->indirect_reference, 1) &&
157         odr_graphicstring(o, &(*p)->descriptor, 1)))
158         return 0;
159     /*
160      * Do we know this beast?
161      */
162     if (o->direction == ODR_DECODE && (*p)->direct_reference &&
163         (oid = oid_getentbyoid((*p)->direct_reference)) &&
164         (type = z_ext_getentbyref(oid->value)))
165     {
166         int zclass, tag, cons;
167
168         /*
169          * We know it. If it's represented as an ASN.1 type, bias the CHOICE.
170          */
171         if (!odr_peektag(o, &zclass, &tag, &cons))
172             return opt && odr_ok(o);
173         if (zclass == ODR_CONTEXT && tag == 0 && cons == 1)
174             odr_choice_bias(o, type->what);
175     }
176     return
177         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
178         odr_sequence_end(o);
179 }