92e0363d8119262b2b0eb3d8011454bdca874943
[yaz-moved-to-github.git] / src / odr_use.c
1 /*
2  * Copyright (c) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: odr_use.c,v 1.1 2003-10-27 12:21:34 adam Exp $
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "odr-priv.h"
13
14 int odr_external(ODR o, Odr_external **p, int opt, const char *name)
15 {
16     Odr_external *pp;
17     static Odr_arm arm[] =
18     {
19         {ODR_EXPLICIT, ODR_CONTEXT, 0, ODR_EXTERNAL_single, 
20          (Odr_fun)odr_any, "single"},
21         {ODR_IMPLICIT, ODR_CONTEXT, 1, ODR_EXTERNAL_octet,
22          (Odr_fun)odr_octetstring, "octet"},
23         {ODR_IMPLICIT, ODR_CONTEXT, 2, ODR_EXTERNAL_arbitrary,
24          (Odr_fun)odr_bitstring, "arbitrary"},
25         {-1, -1, -1, -1, 0, 0}
26     };
27
28     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
29     if (!odr_sequence_begin(o, p, sizeof(Odr_external), name))
30         return odr_missing(o, opt, name);
31     pp = *p;
32     return
33         odr_oid(o, &pp->direct_reference, 1, "direct") &&
34         odr_integer(o, &pp->indirect_reference, 1, "indirect") &&
35         odr_graphicstring(o, &pp->descriptor, 1, "descriptor") &&
36         odr_choice(o, arm, &pp->u, &pp->which, 0) &&
37         odr_sequence_end(o);
38 }
39
40 int odr_visiblestring(ODR o, char **p, int opt, const char *name)
41 {
42     return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL,
43                             ODR_VISIBLESTRING, opt, name);
44 }    
45
46 /*
47  * a char may not be sufficient to hold a general string, but we'll deal
48  * with that once we start looking more closely at UniCode & co.
49  */
50 int odr_generalstring(ODR o, char **p, int opt, const char *name)
51 {
52     return odr_implicit_tag(o, odr_iconv_string, p, ODR_UNIVERSAL,
53                             ODR_GENERALSTRING,opt, name);
54 }    
55
56 int odr_graphicstring(ODR o, char **p, int opt, const char *name)
57 {
58     return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL,
59                         ODR_GRAPHICSTRING, opt, name);
60 }    
61
62 int odr_generalizedtime(ODR o, char **p, int opt, const char *name)
63 {
64     return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL,
65                             ODR_GENERALIZEDTIME, opt, name);
66 }