2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: odr_cons.c,v 1.24 2003-01-06 08:20:27 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)) < 0)
39 if (o->op->stackp == ODR_MAX_STACK - 1)
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 */
58 else if (o->direction == ODR_DECODE)
60 if ((res = ber_declen(o->bp, &o->op->stack[o->op->stackp].len)) < 0)
62 o->op->stack[o->op->stackp].lenlen = res;
65 else if (o->direction == ODR_PRINT)
68 fprintf(o->print, "{\n");
76 o->op->stack[o->op->stackp].base = o->bp;
77 o->op->stack[o->op->stackp].base_offset = odr_tell(o);
81 int odr_constructed_more(ODR o)
85 if (o->op->stackp < 0)
87 if (o->op->stack[o->op->stackp].len >= 0)
88 return o->bp - o->op->stack[o->op->stackp].base < o->op->stack[o->op->stackp].len;
90 return (!(*o->bp == 0 && *(o->bp + 1) == 0));
93 int odr_constructed_end(ODR o)
100 if (o->op->stackp < 0)
105 switch (o->direction)
108 if (o->op->stack[o->op->stackp].len < 0)
110 if (*o->bp++ == 0 && *(o->bp++) == 0)
121 else if (o->bp - o->op->stack[o->op->stackp].base !=
122 o->op->stack[o->op->stackp].len)
131 odr_seek(o, ODR_S_SET, o->op->stack[o->op->stackp].len_offset);
132 if ((res = ber_enclen(o, pos - o->op->stack[o->op->stackp].base_offset,
133 o->op->stack[o->op->stackp].lenlen, 1)) < 0)
138 odr_seek(o, ODR_S_END, 0);
139 if (res == 0) /* indefinite encoding */
142 fprintf(stderr, "[cons_end(%d): indefinite]", o->op->stackp);
144 if (odr_putc(o, 0) < 0 || odr_putc(o, 0) < 0)
150 fprintf(stderr, "[cons_end(%d): definite]", o->op->stackp);
159 fprintf(o->print, "}\n");