Header updates
[yaz-moved-to-github.git] / src / odr_use.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2011 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file odr_use.c
7  * \brief Implements misc ODR types.
8  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include "odr-priv.h"
14
15 int odr_external(ODR o, Odr_external **p, int opt, const char *name)
16 {
17     Odr_external *pp;
18     static Odr_arm arm[] =
19     {
20         {ODR_EXPLICIT, ODR_CONTEXT, 0, ODR_EXTERNAL_single, 
21          (Odr_fun)odr_any, "single"},
22         {ODR_IMPLICIT, ODR_CONTEXT, 1, ODR_EXTERNAL_octet,
23          (Odr_fun)odr_octetstring, "octet"},
24         {ODR_IMPLICIT, ODR_CONTEXT, 2, ODR_EXTERNAL_arbitrary,
25          (Odr_fun)odr_bitstring, "arbitrary"},
26         {-1, -1, -1, -1, 0, 0}
27     };
28
29     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
30     if (!odr_sequence_begin(o, p, sizeof(Odr_external), name))
31         return odr_missing(o, opt, name);
32     pp = *p;
33     return
34         odr_oid(o, &pp->direct_reference, 1, "direct") &&
35         odr_integer(o, &pp->indirect_reference, 1, "indirect") &&
36         odr_graphicstring(o, &pp->descriptor, 1, "descriptor") &&
37         odr_choice(o, arm, &pp->u, &pp->which, 0) &&
38         odr_sequence_end(o);
39 }
40
41 int odr_visiblestring(ODR o, char **p, int opt, const char *name)
42 {
43     return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL,
44                             ODR_VISIBLESTRING, opt, name);
45 }    
46
47 /*
48  * a char may not be sufficient to hold a general string, but we'll deal
49  * with that once we start looking more closely at UniCode & co.
50  */
51 int odr_generalstring(ODR o, char **p, int opt, const char *name)
52 {
53     return odr_implicit_tag(o, odr_iconv_string, p, ODR_UNIVERSAL,
54                             ODR_GENERALSTRING,opt, name);
55 }    
56
57 int odr_graphicstring(ODR o, char **p, int opt, const char *name)
58 {
59     return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL,
60                         ODR_GRAPHICSTRING, opt, name);
61 }    
62
63 int odr_generalizedtime(ODR o, char **p, int opt, const char *name)
64 {
65     return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL,
66                             ODR_GENERALIZEDTIME, opt, name);
67 }
68 /*
69  * Local variables:
70  * c-basic-offset: 4
71  * c-file-style: "Stroustrup"
72  * indent-tabs-mode: nil
73  * End:
74  * vim: shiftwidth=4 tabstop=8 expandtab
75  */
76