source: trunk/gsdl/packages/yaz/odr/ber_bit.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 1995-2000, Index Data
3 * See the file LICENSE for details.
4 * Sebastian Hammer, Adam Dickmeiss
5 *
6 * $Log$
7 * Revision 1.1 2000/08/03 03:11:12 johnmcp
8 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
9 *
10 * Revision 1.12 2000/02/29 13:44:55 adam
11 * Check for config.h (currently not generated).
12 *
13 * Revision 1.11 2000/01/31 13:15:21 adam
14 * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
15 * that some characters are not surrounded by spaces in resulting term.
16 * ILL-code updates.
17 *
18 * Revision 1.10 1999/11/30 13:47:11 adam
19 * Improved installation. Moved header files to include/yaz.
20 *
21 * Revision 1.9 1999/04/20 09:56:48 adam
22 * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
23 * Modified all encoders/decoders to reflect this change.
24 *
25 * Revision 1.8 1999/01/08 11:23:21 adam
26 * Added const modifier to some of the BER/ODR encoding routines.
27 *
28 * Revision 1.7 1995/09/29 17:12:16 quinn
29 * Smallish
30 *
31 * Revision 1.6 1995/09/27 15:02:54 quinn
32 * Modified function heads & prototypes.
33 *
34 * Revision 1.5 1995/05/16 08:50:43 quinn
35 * License, documentation, and memory fixes
36 *
37 * Revision 1.4 1995/04/18 08:15:13 quinn
38 * Added dynamic memory allocation on encoding (whew). Code is now somewhat
39 * neater. We'll make the same change for decoding one day.
40 *
41 * Revision 1.3 1995/03/08 12:12:04 quinn
42 * Added better error checking.
43 *
44 * Revision 1.2 1995/02/03 17:04:31 quinn
45 * *** empty log message ***
46 *
47 * Revision 1.1 1995/02/02 20:38:49 quinn
48 * Updates.
49 *
50 *
51 */
52#if HAVE_CONFIG_H
53#include <config.h>
54#endif
55
56#include <yaz/odr.h>
57
58int ber_bitstring(ODR o, Odr_bitmask *p, int cons)
59{
60 int res, len;
61 const unsigned char *base;
62
63 switch (o->direction)
64 {
65 case ODR_DECODE:
66 if ((res = ber_declen(o->bp, &len)) < 0)
67 {
68 o->error = OPROTO;
69 return 0;
70 }
71 o->bp += res;
72 if (cons) /* fetch component strings */
73 {
74 base = o->bp;
75 while (odp_more_chunks(o, base, len))
76 if (!odr_bitstring(o, &p, 0, 0))
77 return 0;
78 return 1;
79 }
80 /* primitive bitstring */
81 if (len < 0)
82 {
83 o->error = OOTHER;
84 return 0;
85 }
86 if (len == 0)
87 return 1;
88 if (len - 1 > ODR_BITMASK_SIZE)
89 {
90 o->error = OOTHER;
91 return 0;
92 }
93 o->bp++; /* silently ignore the unused-bits field */
94 len--;
95 memcpy(p->bits + p->top + 1, o->bp, len);
96 p->top += len;
97 o->bp += len;
98 return 1;
99 case ODR_ENCODE:
100 if ((res = ber_enclen(o, p->top + 2, 5, 0)) < 0)
101 return 0;
102 if (odr_putc(o, 0) < 0) /* no unused bits here */
103 return 0;
104 if (p->top < 0)
105 return 1;
106 if (odr_write(o, p->bits, p->top + 1) < 0)
107 return 0;
108 return 1;
109 case ODR_PRINT: return 1;
110 default: o->error = OOTHER; return 0;
111 }
112}
Note: See TracBrowser for help on using the repository browser.