* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* $Id: odr.h,v 1.25 2007-01-03 08:42:14 adam Exp $ */
+/* $Id: odr.h,v 1.26 2007-03-19 21:08:13 adam Exp $ */
/**
* \file odr.h
#define ODR_S_CUR 1
#define ODR_S_END 2
-typedef struct odr
+typedef struct odr *ODR;
+
+/** ODR handle and the public structs */
+struct odr
{
int direction; /* the direction of this stream */
- int error; /* current error state (0==OK) */
+ int error; /* current error state (0==OK) */
- int can_grow; /* are we allowed to reallocate */
unsigned char *buf; /* memory handle */
+ int top; /* top of buffer (max pos when encoding) */
int size; /* current buffer size (encoding+decoding) */
int pos; /* current position (encoding) */
- int top; /* top of buffer (max pos when encoding) */
const unsigned char *bp; /* position in buffer (decoding) */
- int t_class; /* implicit tagging (-1==default tag) */
- int t_tag;
-
- int enable_bias; /* force choice enable flag */
- int choice_bias; /* force choice */
- int lenlen; /* force length-of-lenght (odr_setlen()) */
-
- FILE *print; /* output file handler for direction print */
- int indent; /* current indent level for printing */
-
NMEM mem; /* memory handle for decoding (primarily) */
struct Odr_private *op;
-} *ODR;
+};
typedef int (*Odr_fun)(ODR, char **, int, const char *);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: ber_tag.c,v 1.7 2007-01-03 08:42:15 adam Exp $
+ * $Id: ber_tag.c,v 1.8 2007-03-19 21:08:13 adam Exp $
*/
/**
if (o->direction == ODR_DECODE)
*pp = 0;
- o->t_class = -1;
+ o->op->t_class = -1;
if (ODR_STACK_EMPTY(o))
{
odr_seek(o, ODR_S_SET, 0);
struct odr_constack *stack_first; /** first member of allocated stack */
struct odr_constack *stack_top; /** top of stack */
-
const char **tmp_names_buf; /** array returned by odr_get_element_path */
int tmp_names_sz; /** size of tmp_names_buf */
void (*stream_write)(ODR o, void *handle, int type,
const char *buf, int len);
void (*stream_close)(void *handle);
+
+ int can_grow; /* are we allowed to reallocate */
+ int t_class; /* implicit tagging (-1==default tag) */
+ int t_tag;
+
+ int enable_bias; /* force choice enable flag */
+ int choice_bias; /* force choice */
+ int lenlen; /* force length-of-lenght (odr_setlen()) */
+ FILE *print; /* output file handler for direction print */
+ int indent; /* current indent level for printing */
};
#define ODR_STACK_POP(x) (x)->op->stack_top = (x)->op->stack_top->prev
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr.c,v 1.15 2007-02-23 10:15:01 adam Exp $
+ * $Id: odr.c,v 1.16 2007-03-19 21:08:13 adam Exp $
*
*/
const char *buf, int len),
void (*stream_close)(void *handle))
{
- o->print = (FILE*) handle;
+ o->op->print = (FILE*) handle;
o->op->stream_write = stream_write;
o->op->stream_close = stream_close;
}
if (!(o = (ODR)xmalloc(sizeof(*o))))
return 0;
+ o->op = (struct Odr_private *) xmalloc (sizeof(*o->op));
o->direction = direction;
o->buf = 0;
o->size = o->pos = o->top = 0;
- o->can_grow = 1;
+ o->op->can_grow = 1;
o->mem = nmem_create();
- o->enable_bias = 1;
- o->op = (struct Odr_private *) xmalloc (sizeof(*o->op));
+ o->op->enable_bias = 1;
o->op->odr_ber_tag.lclass = -1;
o->op->iconv_handle = 0;
odr_setprint(o, stderr);
o->bp = o->buf;
odr_seek(o, ODR_S_SET, 0);
o->top = 0;
- o->t_class = -1;
- o->t_tag = -1;
- o->indent = 0;
+ o->op->t_class = -1;
+ o->op->t_tag = -1;
+ o->op->indent = 0;
o->op->stack_first = 0;
o->op->stack_top = 0;
o->op->tmp_names_sz = 0;
o->op->tmp_names_buf = 0;
nmem_reset(o->mem);
- o->choice_bias = -1;
- o->lenlen = 1;
+ o->op->choice_bias = -1;
+ o->op->lenlen = 1;
if (o->op->iconv_handle != 0)
yaz_iconv(o->op->iconv_handle, 0, 0, 0, 0);
yaz_log (log_level, "odr_reset o=%p", o);
void odr_destroy(ODR o)
{
nmem_destroy(o->mem);
- if (o->buf && o->can_grow)
+ if (o->buf && o->op->can_grow)
xfree(o->buf);
if (o->op->stream_close)
- o->op->stream_close(o->print);
+ o->op->stream_close(o->op->print);
if (o->op->iconv_handle != 0)
yaz_iconv_close (o->op->iconv_handle);
xfree(o->op);
o->bp = (unsigned char *) buf;
o->buf = (unsigned char *) buf;
- o->can_grow = can_grow;
+ o->op->can_grow = can_grow;
o->top = o->pos = 0;
o->size = len;
}
va_start(ap, fmt);
yaz_vsnprintf(buf, sizeof(buf), fmt, ap);
- o->op->stream_write(o, o->print, ODR_VISIBLESTRING, buf, strlen(buf));
+ o->op->stream_write(o, o->op->print, ODR_VISIBLESTRING, buf, strlen(buf));
va_end(ap);
}
/*
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_bit.c,v 1.6 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_bit.c,v 1.7 2007-03-19 21:08:13 adam Exp $
*/
/**
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_BITSTRING;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_BITSTRING;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_bool.c,v 1.6 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_bool.c,v 1.7 2007-03-19 21:08:13 adam Exp $
*/
/**
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_BOOLEAN;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_BOOLEAN;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_choice.c,v 1.7 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_choice.c,v 1.8 2007-03-19 21:08:13 adam Exp $
*/
/**
int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp,
const char *name)
{
- int i, cl = -1, tg, cn, *which = (int *)whichp, bias = o->choice_bias;
+ int i, cl = -1, tg, cn, *which = (int *)whichp, bias = o->op->choice_bias;
if (o->error)
return 0;
*which = -1;
*(char**)p = 0;
}
- o->choice_bias = -1;
+ o->op->choice_bias = -1;
if (o->direction == ODR_PRINT)
{
void odr_choice_bias(ODR o, int what)
{
- if (o->enable_bias)
- o->choice_bias = what;
+ if (o->op->enable_bias)
+ o->op->choice_bias = what;
}
void odr_choice_enable_bias (ODR o, int mode)
{
- o->enable_bias = mode;
+ o->op->enable_bias = mode;
}
/*
* Local variables:
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_cons.c,v 1.8 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_cons.c,v 1.9 2007-03-19 21:08:13 adam Exp $
*
*/
void odr_setlenlen(ODR o, int len)
{
- o->lenlen = len;
+ o->op->lenlen = len;
}
int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
{
int res;
int cons = 1;
- int lenlen = o->lenlen;
+ int lenlen = o->op->lenlen;
if (o->error)
return 0;
- o->lenlen = 1; /* reset lenlen */
- if (o->t_class < 0)
+ o->op->lenlen = 1; /* reset lenlen */
+ if (o->op->t_class < 0)
{
- o->t_class = zclass;
- o->t_tag = tag;
+ o->op->t_class = zclass;
+ o->op->t_tag = tag;
}
- if ((res = ber_tag(o, xxp, o->t_class, o->t_tag, &cons, 1, name)) < 0)
+ res = ber_tag(o, xxp, o->op->t_class, o->op->t_tag, &cons, 1, name);
+ if (res < 0)
return 0;
if (!res || !cons)
return 0;
{
odr_prname(o, name);
odr_printf(o, "{\n");
- o->indent++;
+ o->op->indent++;
}
else
{
return 1;
case ODR_PRINT:
ODR_STACK_POP(o);
- o->indent--;
+ o->op->indent--;
odr_prname(o, 0);
odr_printf(o, "}\n");
return 1;
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_enum.c,v 1.6 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_enum.c,v 1.7 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_enum.c
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_ENUM;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_ENUM;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_int.c,v 1.6 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_int.c,v 1.7 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_int.c
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_INTEGER;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_INTEGER;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_mem.c,v 1.8 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_mem.c,v 1.9 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_mem.c
{
int togrow;
- if (!b->can_grow)
+ if (!b->op->can_grow)
return -1;
if (!b->size)
togrow = 1024;
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_null.c,v 1.7 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_null.c,v 1.8 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_null.c
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_NULL;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_NULL;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_oct.c,v 1.10 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_oct.c,v 1.11 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_oct.c
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_OCTETSTRING;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_OCTETSTRING;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
odr_prname(o, name);
odr_printf(o, "OCTETSTRING(len=%d) ", (*p)->len);
- o->op->stream_write(o, o->print, ODR_OCTETSTRING,
+ o->op->stream_write(o, o->op->print, ODR_OCTETSTRING,
(char*) (*p)->buf, (*p)->len);
odr_printf(o, "\n");
return 1;
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_OCTETSTRING;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_OCTETSTRING;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_OCTETSTRING;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_OCTETSTRING;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_oid.c,v 1.8 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_oid.c,v 1.9 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_oid.c
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_OID;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_OID;
}
- if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt, name)) < 0)
+ res = ber_tag(o, p, o->op->t_class, o->op->t_tag, &cons, opt, name);
+ if (res < 0)
return 0;
if (!res)
return odr_missing(o, opt, name);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_seq.c,v 1.6 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_seq.c,v 1.7 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_seq.c
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_SEQUENCE;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_SEQUENCE;
}
if (o->direction == ODR_DECODE)
*pp = 0;
- if (odr_constructed_begin(o, p, o->t_class, o->t_tag, name))
+ if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
{
if (o->direction == ODR_DECODE && size)
*pp = (char *)odr_malloc(o, size);
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = ODR_UNIVERSAL;
- o->t_tag = ODR_SET;
+ o->op->t_class = ODR_UNIVERSAL;
+ o->op->t_tag = ODR_SET;
}
if (o->direction == ODR_DECODE)
*pp = 0;
- if (odr_constructed_begin(o, p, o->t_class, o->t_tag, name))
+ if (odr_constructed_begin(o, p, o->op->t_class, o->op->t_tag, name))
{
if (o->direction == ODR_DECODE && size)
*pp = (char *)odr_malloc(o, size);
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_tag.c,v 1.6 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_tag.c,v 1.7 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_tag.c
{
if (o->error)
return 0;
- if (o->t_class < 0)
+ if (o->op->t_class < 0)
{
- o->t_class = zclass;
- o->t_tag = tag;
+ o->op->t_class = zclass;
+ o->op->t_tag = tag;
}
return 1;
}
*pp = (char *)odr_malloc(o, size);
else if (!*pp)
{
- o->t_class = -1;
+ o->op->t_class = -1;
return 0;
}
return 1;
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: odr_util.c,v 1.9 2007-01-03 08:42:15 adam Exp $
+ * $Id: odr_util.c,v 1.10 2007-03-19 21:08:13 adam Exp $
*/
/**
* \file odr_util.c
void odr_prname(ODR o, const char *name)
{
if (name)
- odr_printf(o, "%*s%s ", o->indent*4, "", name);
+ odr_printf(o, "%*s%s ", o->op->indent*4, "", name);
else
- odr_printf(o, "%*s", o->indent*4, "");
+ odr_printf(o, "%*s", o->op->indent*4, "");
}
int odp_more_chunks(ODR o, const unsigned char *base, int len)