Added cs_get_SSL. yaz-client-ssl prints peer info
[yaz-moved-to-github.git] / src / odr_bit.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_bit.c,v 1.1 2003-10-27 12:21:33 adam Exp $
7  */
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include <string.h>
13 #include "odr-priv.h"
14
15 /*
16  * Top level bitstring string en/decoder.
17  * Returns 1 on success, 0 on error.
18  */
19 int odr_bitstring(ODR o, Odr_bitmask **p, int opt, const char *name)
20 {
21     int res, cons = 0;
22
23     if (o->error)
24         return 0;
25     if (o->t_class < 0)
26     {
27         o->t_class = ODR_UNIVERSAL;
28         o->t_tag = ODR_BITSTRING;
29     }
30     if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
31         return 0;
32     if (!res)
33         return odr_missing(o, opt, name);
34     if (o->direction == ODR_PRINT)
35     {
36         odr_prname(o, name);
37         fprintf(o->print, "BITSTRING(len=%d)\n",(*p)->top + 1);
38         return 1;
39     }
40     if (o->direction == ODR_DECODE)
41     {
42         *p = (Odr_bitmask *)odr_malloc(o, sizeof(Odr_bitmask));
43         memset((*p)->bits, 0, ODR_BITMASK_SIZE);
44         (*p)->top = -1;
45     }
46 #if 0
47     /* ignoring the cons helps with at least one target. 
48      * http://bugzilla.indexdata.dk/cgi-bin/bugzilla/show_bug.cgi?id=24
49      */
50     return ber_bitstring(o, *p, 0);
51 #else
52     return ber_bitstring(o, *p, cons);
53 #endif
54 }