3 * Copyright (C) 1994, Index Data I/S
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.2 1995-04-18 08:14:37 quinn
9 * Added dynamic memory allocation on encoding
11 * Revision 1.1 1995/03/30 09:39:41 quinn
12 * Moved .h files to include directory
14 * Revision 1.15 1995/03/29 15:39:57 quinn
15 * Fixed bugs in the bitmask operations
17 * Revision 1.14 1995/03/27 08:33:15 quinn
18 * Added more OID utilities.
20 * Revision 1.13 1995/03/17 10:17:44 quinn
21 * Added memory management.
23 * Revision 1.12 1995/03/14 10:27:38 quinn
24 * Modified makefile to use common lib
25 * Beginning to add memory management to odr
27 * Revision 1.11 1995/03/10 11:44:41 quinn
28 * Fixed serious stack-bug in odr_cons_begin
30 * Revision 1.10 1995/03/08 12:12:16 quinn
31 * Added better error checking.
33 * Revision 1.9 1995/03/07 10:10:00 quinn
34 * Added some headers for Adam.
36 * Revision 1.8 1995/03/07 09:23:16 quinn
37 * Installing top-level API and documentation.
39 * Revision 1.7 1995/02/10 15:55:29 quinn
42 * Revision 1.6 1995/02/09 15:51:47 quinn
45 * Revision 1.5 1995/02/07 17:52:59 quinn
46 * A damn mess, but now things work, I think.
48 * Revision 1.4 1995/02/06 16:45:03 quinn
51 * Revision 1.3 1995/02/03 17:04:36 quinn
52 * *** empty log message ***
54 * Revision 1.2 1995/02/02 20:38:50 quinn
57 * Revision 1.1 1995/02/02 16:21:53 quinn
76 #define ODR_IMPLICIT 0
77 #define ODR_EXPLICIT 1
82 #define ODR_UNIVERSAL 0
83 #define ODR_APPLICATION 1
92 #define ODR_BITSTRING 3
93 #define ODR_OCTETSTRING 4
97 #define ODR_EXTERNAL 8
100 #define ODR_SEQUENCE 16
102 #define ODR_NUMERICSTRING 18
103 #define ODR_PRINTABLESTRING 19
104 #define ODR_GRAPHICSTRING 25
105 #define ODR_VISIBLESTRING 26
108 * odr stream directions
114 typedef struct odr_oct
121 typedef Odr_oct Odr_any;
123 typedef struct odr_bitmask
125 #define ODR_BITMASK_SIZE 256
126 unsigned char bits[ODR_BITMASK_SIZE];
130 #define ODR_OID_SIZE 100
131 typedef int Odr_oid; /* terminate by -1 */
133 typedef struct odr_constack
135 unsigned char *base; /* starting point of data */
137 int len; /* length of data, if known, else -1
139 unsigned char *lenb; /* where to encode length */
141 int lenlen; /* length of length-field */
144 struct odr_memblock; /* defined in odr_mem.c */
150 typedef struct odr_ecblock
152 int can_grow; /* are we allowed to reallocate */
153 unsigned char *buf; /* memory handle */
154 int pos; /* current position */
155 int top; /* top of buffer */
156 int size; /* current buffer size */
162 int direction; /* the direction of this stream */
164 int error; /* current error state (0==OK) */
165 unsigned char *buf; /* for encoding or decoding */
166 int buflen; /* size of buffer for encoding, len for decoding */
167 unsigned char *bp; /* position in buffer */
168 int left; /* bytes remaining in buffer */
170 odr_ecblock ecb; /* memory control block */
172 int t_class; /* implicit tagging (-1==default tag) */
175 FILE *print; /* output file for direction print */
176 int indent; /* current indent level for printing */
178 struct odr_memblock *mem;
180 /* stack for constructed types */
181 #define ODR_MAX_STACK 50
182 int stackp; /* top of stack (-1 == initial state) */
183 odr_constack stack[ODR_MAX_STACK];
186 typedef int (*Odr_fun)();
188 typedef struct odr_arm
205 #define OUNEXPECTED 5
211 extern char *odr_errlist[];
213 int odr_geterror(ODR o);
214 void odr_perror(ODR o, char *message);
215 void odr_setprint(ODR o, FILE *file);
216 ODR odr_createmem(int direction);
217 void odr_reset(ODR o);
218 void odr_destroy(ODR o);
219 void odr_setbuf(ODR o, char *buf, int len);
220 char *odr_getbuf(ODR o, int *len);
221 void *odr_malloc(ODR o, int size);
223 #define odr_implicit(o, t, p, cl, tg, opt)\
224 (odr_implicit_settag((o), cl, tg), t ((o), (p), opt) )
226 #define odr_explicit(o, t, p, cl, tg, opt)\
227 ((int) (odr_constructed_begin((o), (p), (cl), (tg)) ? \
228 t ((o), (p), (opt)) &&\
229 odr_constructed_end(o) : opt))
231 #define ODR_MASK_ZERO(mask)\
232 ((void) (memset((mask)->bits, 0, ODR_BITMASK_SIZE),\
235 #define ODR_MASK_SET(mask, num)\
236 (((mask)->bits[(num) >> 3] |= 0X80 >> ((num) & 0X07)),\
237 (mask)->top < (num) >> 3 ? ((mask)->top = (num) >> 3) : 0)
239 #define ODR_MASK_CLEAR(mask, num)\
240 ((mask)->bits[(num) >> 3] &= ~(0X80 >> ((num) & 0X07)))
242 #define ODR_MASK_GET(mask, num) ( ((num) >> 3 <= (mask)->top) ? \
243 ((mask)->bits[(num) >> 3] & (0X80 >> ((num) & 0X07)) ? 1 : 0) : 0)
246 * write a single character at the current position - grow buffer if
248 * (no, we're not usually this anal about our macros, but this one is
249 * next to unreadable without some indentation :)
251 #define odr_putc(o, c) \
254 (o)->ecb.pos < (o)->ecb.size ? \
256 (o)->ecb.buf[(o)->ecb.pos++] = (c), \
260 odr_grow_block(&(o)->ecb, 1) == 0 ? \
262 (o)->ecb.buf[(o)->ecb.pos++] = (c), \
266 (o)->error = OSPACE, \
272 (o)->ecb.pos > (o)->ecb.top ? \
274 (o)->ecb.top = (o)->ecb.pos, \
282 #define odr_tell(o) ((o)->ecb.pos)