SRW, CQL, 2003
[yaz-moved-to-github.git] / odr / ber_bool.c
1 /*
2  * Copyright (c) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Id: ber_bool.c,v 1.13 2003-01-06 08:20:27 adam Exp $
7  */
8
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <stdio.h>
14 #include "odr-priv.h"
15
16 int ber_boolean(ODR o, int *val)
17 {
18     int res, len;
19
20     switch (o->direction)
21     {
22     case ODR_ENCODE:
23         if (ber_enclen(o, 1, 1, 1) != 1)
24             return 0;
25         if (odr_putc(o, *val) < 0)
26             return 0;
27 #ifdef ODR_DEBUG
28         fprintf(stderr, "[val=%d]\n", *val);
29 #endif
30         return 1;
31     case ODR_DECODE:
32         if ((res = ber_declen(o->bp, &len)) < 0)
33         {
34             o->error = OPROTO;
35             return 0;
36         }
37         if (len != 1)
38         {
39             o->error = OPROTO;
40             return 0;
41         }
42         o->bp+= res;
43         *val = *o->bp;
44         o->bp++;
45 #ifdef ODR_DEBUG
46         fprintf(stderr, "[val=%d]\n", *val);
47 #endif
48         return 1;
49     case ODR_PRINT:
50         return 1;
51     default: o->error = OOTHER; return 0;
52     }
53 }