3 * Copyright (C) 1994, Index Data I/S
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.3 1995-05-15 11:55:54 quinn
9 * Work on asynchronous activity.
11 * Revision 1.2 1995/04/18 08:14:37 quinn
12 * Added dynamic memory allocation on encoding
14 * Revision 1.1 1995/03/30 09:39:41 quinn
15 * Moved .h files to include directory
17 * Revision 1.15 1995/03/29 15:39:57 quinn
18 * Fixed bugs in the bitmask operations
20 * Revision 1.14 1995/03/27 08:33:15 quinn
21 * Added more OID utilities.
23 * Revision 1.13 1995/03/17 10:17:44 quinn
24 * Added memory management.
26 * Revision 1.12 1995/03/14 10:27:38 quinn
27 * Modified makefile to use common lib
28 * Beginning to add memory management to odr
30 * Revision 1.11 1995/03/10 11:44:41 quinn
31 * Fixed serious stack-bug in odr_cons_begin
33 * Revision 1.10 1995/03/08 12:12:16 quinn
34 * Added better error checking.
36 * Revision 1.9 1995/03/07 10:10:00 quinn
37 * Added some headers for Adam.
39 * Revision 1.8 1995/03/07 09:23:16 quinn
40 * Installing top-level API and documentation.
42 * Revision 1.7 1995/02/10 15:55:29 quinn
45 * Revision 1.6 1995/02/09 15:51:47 quinn
48 * Revision 1.5 1995/02/07 17:52:59 quinn
49 * A damn mess, but now things work, I think.
51 * Revision 1.4 1995/02/06 16:45:03 quinn
54 * Revision 1.3 1995/02/03 17:04:36 quinn
55 * *** empty log message ***
57 * Revision 1.2 1995/02/02 20:38:50 quinn
60 * Revision 1.1 1995/02/02 16:21:53 quinn
79 #define ODR_IMPLICIT 0
80 #define ODR_EXPLICIT 1
85 #define ODR_UNIVERSAL 0
86 #define ODR_APPLICATION 1
95 #define ODR_BITSTRING 3
96 #define ODR_OCTETSTRING 4
100 #define ODR_EXTERNAL 8
103 #define ODR_SEQUENCE 16
105 #define ODR_NUMERICSTRING 18
106 #define ODR_PRINTABLESTRING 19
107 #define ODR_GRAPHICSTRING 25
108 #define ODR_VISIBLESTRING 26
111 * odr stream directions
117 typedef struct odr_oct
124 typedef Odr_oct Odr_any;
126 typedef struct odr_bitmask
128 #define ODR_BITMASK_SIZE 256
129 unsigned char bits[ODR_BITMASK_SIZE];
133 #define ODR_OID_SIZE 100
134 typedef int Odr_oid; /* terminate by -1 */
136 typedef struct odr_constack
138 unsigned char *base; /* starting point of data */
140 int len; /* length of data, if known, else -1
142 unsigned char *lenb; /* where to encode length */
144 int lenlen; /* length of length-field */
147 struct odr_memblock; /* defined in odr_mem.c */
148 typedef struct odr_memblock *ODR_MEM;
154 typedef struct odr_ecblock
156 int can_grow; /* are we allowed to reallocate */
157 unsigned char *buf; /* memory handle */
158 int pos; /* current position */
159 int top; /* top of buffer */
160 int size; /* current buffer size */
166 int direction; /* the direction of this stream */
168 int error; /* current error state (0==OK) */
169 unsigned char *buf; /* for encoding or decoding */
170 int buflen; /* size of buffer for encoding, len for decoding */
171 unsigned char *bp; /* position in buffer */
172 int left; /* bytes remaining in buffer */
174 odr_ecblock ecb; /* memory control block */
176 int t_class; /* implicit tagging (-1==default tag) */
179 FILE *print; /* output file for direction print */
180 int indent; /* current indent level for printing */
182 struct odr_memblock *mem;
184 /* stack for constructed types */
185 #define ODR_MAX_STACK 50
186 int stackp; /* top of stack (-1 == initial state) */
187 odr_constack stack[ODR_MAX_STACK];
190 typedef int (*Odr_fun)();
192 typedef struct odr_arm
209 #define OUNEXPECTED 5
215 extern char *odr_errlist[];
217 int odr_geterror(ODR o);
218 void odr_perror(ODR o, char *message);
219 void odr_setprint(ODR o, FILE *file);
220 ODR odr_createmem(int direction);
221 void odr_reset(ODR o);
222 void odr_destroy(ODR o);
223 void odr_setbuf(ODR o, char *buf, int len, int can_grow);
224 char *odr_getbuf(ODR o, int *len, int *size);
225 void *odr_malloc(ODR o, int size);
226 ODR_MEM odr_extract_mem(ODR o);
227 void odr_release_mem(ODR_MEM p);
229 #define odr_implicit(o, t, p, cl, tg, opt)\
230 (odr_implicit_settag((o), cl, tg), t ((o), (p), opt) )
232 #define odr_explicit(o, t, p, cl, tg, opt)\
233 ((int) (odr_constructed_begin((o), (p), (cl), (tg)) ? \
234 t ((o), (p), (opt)) &&\
235 odr_constructed_end(o) : opt))
237 #define ODR_MASK_ZERO(mask)\
238 ((void) (memset((mask)->bits, 0, ODR_BITMASK_SIZE),\
241 #define ODR_MASK_SET(mask, num)\
242 (((mask)->bits[(num) >> 3] |= 0X80 >> ((num) & 0X07)),\
243 (mask)->top < (num) >> 3 ? ((mask)->top = (num) >> 3) : 0)
245 #define ODR_MASK_CLEAR(mask, num)\
246 ((mask)->bits[(num) >> 3] &= ~(0X80 >> ((num) & 0X07)))
248 #define ODR_MASK_GET(mask, num) ( ((num) >> 3 <= (mask)->top) ? \
249 ((mask)->bits[(num) >> 3] & (0X80 >> ((num) & 0X07)) ? 1 : 0) : 0)
252 * write a single character at the current position - grow buffer if
254 * (no, we're not usually this anal about our macros, but this one is
255 * next to unreadable without some indentation :)
257 #define odr_putc(o, c) \
260 (o)->ecb.pos < (o)->ecb.size ? \
262 (o)->ecb.buf[(o)->ecb.pos++] = (c), \
266 odr_grow_block(&(o)->ecb, 1) == 0 ? \
268 (o)->ecb.buf[(o)->ecb.pos++] = (c), \
272 (o)->error = OSPACE, \
278 (o)->ecb.pos > (o)->ecb.top ? \
280 (o)->ecb.top = (o)->ecb.pos, \
288 #define odr_tell(o) ((o)->ecb.pos)
289 #define odr_ok(o) (!(o)->ecb.error)
291 #define ODR_MAXNAME 256