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