3 * Copyright (C) 1994, Index Data I/S
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.1 1995-03-30 09:39:41 quinn
9 * Moved .h files to include directory
11 * Revision 1.15 1995/03/29 15:39:57 quinn
12 * Fixed bugs in the bitmask operations
14 * Revision 1.14 1995/03/27 08:33:15 quinn
15 * Added more OID utilities.
17 * Revision 1.13 1995/03/17 10:17:44 quinn
18 * Added memory management.
20 * Revision 1.12 1995/03/14 10:27:38 quinn
21 * Modified makefile to use common lib
22 * Beginning to add memory management to odr
24 * Revision 1.11 1995/03/10 11:44:41 quinn
25 * Fixed serious stack-bug in odr_cons_begin
27 * Revision 1.10 1995/03/08 12:12:16 quinn
28 * Added better error checking.
30 * Revision 1.9 1995/03/07 10:10:00 quinn
31 * Added some headers for Adam.
33 * Revision 1.8 1995/03/07 09:23:16 quinn
34 * Installing top-level API and documentation.
36 * Revision 1.7 1995/02/10 15:55:29 quinn
39 * Revision 1.6 1995/02/09 15:51:47 quinn
42 * Revision 1.5 1995/02/07 17:52:59 quinn
43 * A damn mess, but now things work, I think.
45 * Revision 1.4 1995/02/06 16:45:03 quinn
48 * Revision 1.3 1995/02/03 17:04:36 quinn
49 * *** empty log message ***
51 * Revision 1.2 1995/02/02 20:38:50 quinn
54 * Revision 1.1 1995/02/02 16:21:53 quinn
73 #define ODR_IMPLICIT 0
74 #define ODR_EXPLICIT 1
79 #define ODR_UNIVERSAL 0
80 #define ODR_APPLICATION 1
89 #define ODR_BITSTRING 3
90 #define ODR_OCTETSTRING 4
94 #define ODR_EXTERNAL 8
97 #define ODR_SEQUENCE 16
99 #define ODR_NUMERICSTRING 18
100 #define ODR_PRINTABLESTRING 19
101 #define ODR_GRAPHICSTRING 25
102 #define ODR_VISIBLESTRING 26
105 * odr stream directions
111 typedef struct odr_oct
118 typedef Odr_oct Odr_any;
120 typedef struct odr_bitmask
122 #define ODR_BITMASK_SIZE 256
123 unsigned char bits[ODR_BITMASK_SIZE];
127 #define ODR_OID_SIZE 100
128 typedef int Odr_oid; /* terminate by -1 */
130 typedef struct odr_constack
132 unsigned char *base; /* starting point of data */
133 int len; /* length of data, if known, else -1
135 unsigned char *lenb; /* where to encode length */
136 int lenlen; /* length of length-field */
139 struct odr_memblock; /* defined in odr_mem.c */
143 int direction; /* the direction of this stream */
145 int error; /* current error state (0==OK) */
146 unsigned char *buf; /* for encoding or decoding */
147 int buflen; /* size of buffer for encoding, len for decoding */
148 unsigned char *bp; /* position in buffer */
149 int left; /* bytes remaining in buffer */
151 int t_class; /* implicit tagging (-1==default tag) */
154 FILE *print; /* output file for direction print */
155 int indent; /* current indent level for printing */
157 struct odr_memblock *mem;
159 /* stack for constructed types */
160 #define ODR_MAX_STACK 50
161 int stackp; /* top of stack (-1 == initial state) */
162 odr_constack stack[ODR_MAX_STACK];
165 typedef int (*Odr_fun)();
167 typedef struct odr_arm
184 #define OUNEXPECTED 5
190 extern char *odr_errlist[];
192 int odr_geterror(ODR o);
193 void odr_perror(ODR o, char *message);
194 void odr_setprint(ODR o, FILE *file);
195 ODR odr_createmem(int direction);
196 void odr_reset(ODR o);
197 void odr_destroy(ODR o);
198 void odr_setbuf(ODR o, char *buf, int len);
199 char *odr_getbuf(ODR o, int *len);
200 void *odr_malloc(ODR o, int size);
202 #define odr_implicit(o, t, p, cl, tg, opt)\
203 (odr_implicit_settag((o), cl, tg), t ((o), (p), opt) )
205 #define odr_explicit(o, t, p, cl, tg, opt)\
206 ((int) (odr_constructed_begin((o), (p), (cl), (tg)) ? \
207 t ((o), (p), (opt)) &&\
208 odr_constructed_end(o) : opt))
210 #define ODR_MASK_ZERO(mask)\
211 ((void) (memset((mask)->bits, 0, ODR_BITMASK_SIZE),\
214 #define ODR_MASK_SET(mask, num)\
215 (((mask)->bits[(num) >> 3] |= 0X80 >> ((num) & 0X07)),\
216 (mask)->top < (num) >> 3 ? ((mask)->top = (num) >> 3) : 0)
218 #define ODR_MASK_CLEAR(mask, num)\
219 ((mask)->bits[(num) >> 3] &= ~(0X80 >> ((num) & 0X07)))
221 #define ODR_MASK_GET(mask, num) ( ((num) >> 3 <= (mask)->top) ? \
222 ((mask)->bits[(num) >> 3] & (0X80 >> ((num) & 0X07)) ? 1 : 0) : 0)