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