2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: odr_cons.c,v 1.26 2003-05-20 19:55:30 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);
47 fprintf(stderr, "[cons_begin(%d)]", o->op->stackp);
49 if (o->direction == ODR_ENCODE)
51 static unsigned char dummy[sizeof(int)+1];
53 o->op->stack[o->op->stackp].lenlen = lenlen;
55 if (odr_write(o, dummy, lenlen) < 0) /* dummy */
61 else if (o->direction == ODR_DECODE)
63 if ((res = ber_declen(o->bp, &o->op->stack[o->op->stackp].len,
66 odr_seterror(o, OOTHER, 31);
70 o->op->stack[o->op->stackp].lenlen = res;
72 if (o->op->stack[o->op->stackp].len > odr_max(o))
74 odr_seterror(o, OOTHER, 32);
79 else if (o->direction == ODR_PRINT)
82 fprintf(o->print, "{\n");
87 odr_seterror(o, OOTHER, 33);
91 o->op->stack[o->op->stackp].base = o->bp;
92 o->op->stack[o->op->stackp].base_offset = odr_tell(o);
96 int odr_constructed_more(ODR o)
100 if (o->op->stackp < 0)
102 if (o->op->stack[o->op->stackp].len >= 0)
103 return o->bp - o->op->stack[o->op->stackp].base < o->op->stack[o->op->stackp].len;
105 return (!(*o->bp == 0 && *(o->bp + 1) == 0));
108 int odr_constructed_end(ODR o)
115 if (o->op->stackp < 0)
117 odr_seterror(o, OOTHER, 34);
120 switch (o->direction)
123 if (o->op->stack[o->op->stackp].len < 0)
125 if (*o->bp++ == 0 && *(o->bp++) == 0)
132 odr_seterror(o, OOTHER, 35);
136 else if (o->bp - o->op->stack[o->op->stackp].base !=
137 o->op->stack[o->op->stackp].len)
139 odr_seterror(o, OCONLEN, 36);
146 odr_seek(o, ODR_S_SET, o->op->stack[o->op->stackp].len_offset);
147 if ((res = ber_enclen(o, pos - o->op->stack[o->op->stackp].base_offset,
148 o->op->stack[o->op->stackp].lenlen, 1)) < 0)
150 odr_seterror(o, OLENOV, 37);
153 odr_seek(o, ODR_S_END, 0);
154 if (res == 0) /* indefinite encoding */
157 fprintf(stderr, "[cons_end(%d): indefinite]", o->op->stackp);
159 if (odr_putc(o, 0) < 0 || odr_putc(o, 0) < 0)
165 fprintf(stderr, "[cons_end(%d): definite]", o->op->stackp);
174 fprintf(o->print, "}\n");
177 odr_seterror(o, OOTHER, 38);