2 * Copyright (c) 1995-2004, Index Data
3 * See the file LICENSE for details.
5 * $Id: odr_cons.c,v 1.3 2004-08-13 07:30:06 adam Exp $
14 void odr_setlenlen(ODR o, int len)
19 int odr_constructed_begin(ODR o, void *p, int zclass, int tag,
24 int lenlen = o->lenlen;
28 o->lenlen = 1; /* reset lenlen */
34 if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, 1, name)) < 0)
39 if (o->op->stackp == ODR_MAX_STACK - 1)
41 odr_seterror(o, OSTACK, 30);
44 o->op->stack[++(o->op->stackp)].lenb = o->bp;
45 o->op->stack[o->op->stackp].len_offset = odr_tell(o);
46 o->op->stack_names[o->op->stackp] = name ? name : "?";
47 o->op->stack_names[o->op->stackp + 1] = 0;
49 fprintf(stderr, "[cons_begin(%d)]", o->op->stackp);
51 if (o->direction == ODR_ENCODE)
53 static unsigned char dummy[sizeof(int)+1];
55 o->op->stack[o->op->stackp].lenlen = lenlen;
57 if (odr_write(o, dummy, lenlen) < 0) /* dummy */
59 o->op->stack_names[o->op->stackp] = 0;
64 else if (o->direction == ODR_DECODE)
66 if ((res = ber_declen(o->bp, &o->op->stack[o->op->stackp].len,
69 odr_seterror(o, OOTHER, 31);
70 o->op->stack_names[o->op->stackp] = 0;
74 o->op->stack[o->op->stackp].lenlen = res;
76 if (o->op->stack[o->op->stackp].len > odr_max(o))
78 odr_seterror(o, OOTHER, 32);
79 o->op->stack_names[o->op->stackp] = 0;
84 else if (o->direction == ODR_PRINT)
92 odr_seterror(o, OOTHER, 33);
93 o->op->stack_names[o->op->stackp] = 0;
97 o->op->stack[o->op->stackp].base = o->bp;
98 o->op->stack[o->op->stackp].base_offset = odr_tell(o);
102 int odr_constructed_more(ODR o)
106 if (o->op->stackp < 0)
108 if (o->op->stack[o->op->stackp].len >= 0)
109 return o->bp - o->op->stack[o->op->stackp].base < o->op->stack[o->op->stackp].len;
111 return (!(*o->bp == 0 && *(o->bp + 1) == 0));
114 int odr_constructed_end(ODR o)
121 if (o->op->stackp < 0)
123 odr_seterror(o, OOTHER, 34);
126 o->op->stack_names[o->op->stackp] = 0;
127 switch (o->direction)
130 if (o->op->stack[o->op->stackp].len < 0)
132 if (*o->bp++ == 0 && *(o->bp++) == 0)
139 odr_seterror(o, OOTHER, 35);
143 else if (o->bp - o->op->stack[o->op->stackp].base !=
144 o->op->stack[o->op->stackp].len)
146 odr_seterror(o, OCONLEN, 36);
153 odr_seek(o, ODR_S_SET, o->op->stack[o->op->stackp].len_offset);
154 if ((res = ber_enclen(o, pos - o->op->stack[o->op->stackp].base_offset,
155 o->op->stack[o->op->stackp].lenlen, 1)) < 0)
157 odr_seterror(o, OLENOV, 37);
160 odr_seek(o, ODR_S_END, 0);
161 if (res == 0) /* indefinite encoding */
164 fprintf(stderr, "[cons_end(%d): indefinite]", o->op->stackp);
166 if (odr_putc(o, 0) < 0 || odr_putc(o, 0) < 0)
172 fprintf(stderr, "[cons_end(%d): definite]", o->op->stackp);
181 odr_printf(o, "}\n");
184 odr_seterror(o, OOTHER, 38);