6161b33b637b172792c31cc32475198d697b2a4d
[yaz-moved-to-github.git] / odr / ber_bool.c
1 /*
2  * Copyright (C) 1994, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: ber_bool.c,v $
7  * Revision 1.4  1995-03-21 10:17:27  quinn
8  * Fixed little bug in decoder.
9  *
10  * Revision 1.3  1995/03/08  12:12:06  quinn
11  * Added better error checking.
12  *
13  * Revision 1.2  1995/02/09  15:51:45  quinn
14  * Works better now.
15  *
16  * Revision 1.1  1995/02/02  16:21:51  quinn
17  * First kick.
18  *
19  */
20
21 #include <stdio.h>
22 #include <odr.h>
23
24
25 int ber_boolean(ODR o, int *val)
26 {
27     int res, len;
28
29     switch (o->direction)
30     {
31         case ODR_ENCODE:
32             if (!o->left)
33             {
34                 o->error = OSPACE;
35                 return 0;
36             }
37             if (ber_enclen(o->bp, 1, 1, 1) != 1)
38             {
39                 o->error = OOTHER;
40                 return 0;
41             }
42             o->bp++;
43             o->left--;
44             *(o->bp++) = (unsigned char) *val;
45 #ifdef ODR_DEBUG
46             fprintf(stderr, "[val=%d]\n", *val);
47 #endif
48             o->left--;
49             return 1;
50         case ODR_DECODE:
51             if ((res = ber_declen(o->bp, &len)) < 0)
52             {
53                 o->error = OPROTO;
54                 return 0;
55             }
56             if (len != 1)
57             {
58                 o->error = OPROTO;
59                 return 0;
60             }
61             o->bp+= res;
62             o->left -= res;
63             *val = *o->bp;
64             o->bp++;
65             o->left--;
66 #ifdef ODR_DEBUG
67             fprintf(stderr, "[val=%d]\n", *val);
68 #endif
69             return 1;
70         case ODR_PRINT:
71             return 1;
72         default: o->error = OOTHER; return 0;
73     }
74 }