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