1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements BER ANY encoding and decoding.
10 * This source file implements BER encoding and decoding of
21 int ber_any(ODR o, Odr_any **p)
28 if ((res = completeBER(o->bp, odr_max(o))) <= 0) /* FIX THIS */
30 odr_seterror(o, OPROTO, 2);
33 (*p)->buf = (char *)odr_malloc(o, res);
34 memcpy((*p)->buf, o->bp, res);
42 if (odr_write2(o, (*p)->buf, (*p)->len) < 0)
45 default: odr_seterror(o, OOTHER, 3); return 0;
49 #define BER_ANY_DEBUG 0
51 int completeBER_n(const char *buf, int len, int level)
53 int res, ll, zclass, tag, cons;
59 yaz_log(YLOG_LOG, "completeBER lev=%d len=%d", level, len);
65 if (!buf[0] && !buf[1])
67 if ((res = ber_dectag(b, &zclass, &tag, &cons, len)) <= 0)
72 res = ber_declen(b, &ll, len);
76 yaz_log(YLOG_LOG, "<<<<<<<<< return1 lev=%d res=%d", level, res);
78 return -1; /* error */
83 yaz_log(YLOG_LOG, "<<<<<<<<< return2 lev=%d res=%d", level, res);
85 return 0; /* incomplete length */
90 { /* definite length */
94 yaz_log(YLOG_LOG, "<<<<<<<<< return5 lev=%d len=%d ll=%d",
101 /* indefinite length */
103 { /* if primitive, it's an error */
105 yaz_log(YLOG_LOG, "<<<<<<<<< return6 lev=%d ll=%d len=%d res=%d",
106 level, ll, len, res);
108 return -1; /* error */
110 /* constructed - cycle through children */
113 if (b[0] == 0 && b[1] == 0)
115 res = completeBER_n(b, len, level+1);
123 return (b - buf) + 2;
126 int completeBER(const char *buf, int len)
128 int res = completeBER_n(buf, len, 0);
130 yaz_log(YLOG_LOG, "completeBER len=%d res=%d", len, res);
139 * c-file-style: "Stroustrup"
140 * indent-tabs-mode: nil
142 * vim: shiftwidth=4 tabstop=8 expandtab