2 * Copyright (c) 1995-2003, Index Data
3 * See the file LICENSE for details.
5 * $Id: ber_any.c,v 1.25 2003-05-20 17:22:54 adam Exp $
13 int ber_any(ODR o, Odr_any **p)
20 if ((res = completeBER(o->bp, odr_max(o))) <= 0) /* FIX THIS */
22 odr_seterror(o, OPROTO, 2);
25 (*p)->buf = (unsigned char *)odr_malloc(o, res);
26 memcpy((*p)->buf, o->bp, res);
27 (*p)->len = (*p)->size = res;
31 if (odr_write(o, (*p)->buf, (*p)->len) < 0)
34 default: odr_seterror(o, OOTHER, 3); return 0;
39 * Return length of BER-package or 0.
41 int completeBER(const unsigned char *buf, int len)
43 int res, ll, zclass, tag, cons;
44 const unsigned char *b = buf;
48 if (!buf[0] && !buf[1])
50 if ((res = ber_dectag(b, &zclass, &tag, &cons, len)) <= 0)
56 if ((res = ber_declen(b, &ll, len)) <= 0)
63 return (len >= ll ? ll + (b-buf) : 0);
66 /* constructed - cycle through children */
69 if (*b == 0 && *(b + 1) == 0)
71 if (!(res = completeBER(b, len)))