6b615d5250a73e7563a5afa41fd80d94f6405d21
[yaz-moved-to-github.git] / src / odr_bit.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2009 Index Data
3  * See the file LICENSE for details.
4  */
5
6 /**
7  * \file odr_bit.c
8  * \brief Implements ODR BITSTRING codec
9  */
10
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14
15 #include <string.h>
16 #include "odr-priv.h"
17
18 /*
19  * Top level bitstring string en/decoder.
20  * Returns 1 on success, 0 on error.
21  */
22 int odr_bitstring(ODR o, Odr_bitmask **p, int opt, const char *name)
23 {
24     int res, cons = 0;
25
26     if (o->error)
27         return 0;
28     if (o->op->t_class < 0)
29     {
30         o->op->t_class = ODR_UNIVERSAL;
31         o->op->t_tag = ODR_BITSTRING;
32     }
33     res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
34     if (res < 0)
35         return 0;
36     if (!res)
37         return odr_missing(o, opt, name);
38     if (o->direction == ODR_PRINT)
39     {
40         odr_prname(o, name);
41         odr_printf(o, "BITSTRING(len=%d)\n",(*p)->top + 1);
42         return 1;
43     }
44     if (o->direction == ODR_DECODE)
45     {
46         *p = (Odr_bitmask *)odr_malloc(o, sizeof(Odr_bitmask));
47         memset((*p)->bits, 0, ODR_BITMASK_SIZE);
48         (*p)->top = -1;
49     }
50 #if 0
51     /* ignoring the cons helps with at least one target. 
52      * http://bugzilla.indexdata.dk/cgi-bin/bugzilla/show_bug.cgi?id=24
53      */
54     return ber_bitstring(o, *p, 0);
55 #else
56     return ber_bitstring(o, *p, cons);
57 #endif
58 }
59 /*
60  * Local variables:
61  * c-basic-offset: 4
62  * c-file-style: "Stroustrup"
63  * indent-tabs-mode: nil
64  * End:
65  * vim: shiftwidth=4 tabstop=8 expandtab
66  */
67