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