Added GRS-1.
[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.2  1995-08-17 12:45:00  quinn
8  * Fixed minor problems with GRS-1. Added support in c&s.
9  *
10  * Revision 1.1  1995/08/15  13:37:41  quinn
11  * Improved EXTERNAL
12  *
13  *
14  */
15
16 #include <proto.h>
17
18 int z_External(ODR o, Z_External **p, int opt)
19 {
20     oident *oid;
21
22     static Odr_arm arm[] =
23     {
24         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_single, odr_any},
25         {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_External_octet, odr_octetstring},
26         {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_External_arbitrary, odr_bitstring},
27
28         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_sutrs, z_SUTRS},
29         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_explainRecord,
30             z_ExplainRecord},
31         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport1,
32             z_ResourceReport1},
33         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_resourceReport2,
34             z_ResourceReport2},
35         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_promptObject1,
36             z_PromptObject1},
37         {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_External_grs1, z_GenericRecord},
38         {-1, -1, -1, -1, 0}
39     };
40     /*
41      * The table below should be moved to the ODR structure itself and
42      * be an image of the association context: To help
43      * map indirect references when they show up. 
44      */
45     static struct
46     {
47         oid_value dref;
48         int what;          /* discriminator value for the external CHOICE */
49     } tab[] =
50     {
51         {VAL_SUTRS, Z_External_sutrs},
52         {VAL_EXPLAIN, Z_External_explainRecord},
53         {VAL_RESOURCE1, Z_External_resourceReport1},
54         {VAL_RESOURCE2, Z_External_resourceReport2},
55         {VAL_PROMPT1, Z_External_promptObject1},
56         {VAL_GRS1, Z_External_grs1},
57         {VAL_NONE, 0}
58     };
59
60     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
61     if (!odr_sequence_begin(o, p, sizeof(**p)))
62         return opt && odr_ok(o);
63     if (!(odr_oid(o, &(*p)->direct_reference, 1) &&
64         odr_integer(o, &(*p)->indirect_reference, 1) &&
65         odr_graphicstring(o, &(*p)->descriptor, 1)))
66         return 0;
67     /*
68      * Do we know this beast?
69      */
70     if (o->direction == ODR_DECODE && (*p)->direct_reference &&
71         (oid = oid_getentbyoid((*p)->direct_reference)))
72     {
73         int i;
74
75         for (i = 0; tab[i].dref != VAL_NONE; i++)
76             if (oid->value == tab[i].dref)
77             {
78                 odr_choice_bias(o, tab[i].what);
79                 break;
80             }
81     }
82     return
83         odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
84         odr_sequence_end(o);
85 }