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