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