Client uses prefix query notation.
[yaz-moved-to-github.git] / odr / ber_bool.c
1 /*
2  * Copyright (c) 1995, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: ber_bool.c,v $
7  * Revision 1.6  1995-05-16 08:50:43  quinn
8  * License, documentation, and memory fixes
9  *
10  * Revision 1.5  1995/04/18  08:15:14  quinn
11  * Added dynamic memory allocation on encoding (whew). Code is now somewhat
12  * neater. We'll make the same change for decoding one day.
13  *
14  * Revision 1.4  1995/03/21  10:17:27  quinn
15  * Fixed little bug in decoder.
16  *
17  * Revision 1.3  1995/03/08  12:12:06  quinn
18  * Added better error checking.
19  *
20  * Revision 1.2  1995/02/09  15:51:45  quinn
21  * Works better now.
22  *
23  * Revision 1.1  1995/02/02  16:21:51  quinn
24  * First kick.
25  *
26  */
27
28 #include <stdio.h>
29 #include <odr.h>
30
31
32 int ber_boolean(ODR o, int *val)
33 {
34     int res, len;
35
36     switch (o->direction)
37     {
38         case ODR_ENCODE:
39             if (ber_enclen(o, 1, 1, 1) != 1)
40                 return 0;
41             if (odr_putc(o, *val) < 0)
42                 return 0;
43 #ifdef ODR_DEBUG
44             fprintf(stderr, "[val=%d]\n", *val);
45 #endif
46             return 1;
47         case ODR_DECODE:
48             if ((res = ber_declen(o->bp, &len)) < 0)
49             {
50                 o->error = OPROTO;
51                 return 0;
52             }
53             if (len != 1)
54             {
55                 o->error = OPROTO;
56                 return 0;
57             }
58             o->bp+= res;
59             o->left -= res;
60             *val = *o->bp;
61             o->bp++;
62             o->left--;
63 #ifdef ODR_DEBUG
64             fprintf(stderr, "[val=%d]\n", *val);
65 #endif
66             return 1;
67         case ODR_PRINT:
68             return 1;
69         default: o->error = OOTHER; return 0;
70     }
71 }