Possible compatibility problems with earlier versions marked with '*'.
+Added odr_set_stream which is is a more generic to odr_setprint.
+odr_set_stream takes a stream handle, pointer to puts function and
+pointer to close function. The close function - if non-NULL - will be
+called during odr_destroy.
+
--- 2.0.23 2004/08/11
Fix buffer overrun in CQL parser when dealing with proximity (%).
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
- * $Id: odr.h,v 1.14 2003-11-26 16:24:04 mike Exp $
+ * $Id: odr.h,v 1.15 2004-08-11 12:15:38 adam Exp $
*/
#ifndef ODR_H
int choice_bias; /* force choice */
int lenlen; /* force length-of-lenght (odr_setlen()) */
- FILE *print; /* output file for direction print */
+ FILE *print; /* output file handler for direction print */
int indent; /* current indent level for printing */
NMEM mem; /* memory handle for decoding (primarily) */
YAZ_EXPORT int odr_set_charset(ODR o, const char *to, const char *from);
+YAZ_EXPORT void odr_set_stream(ODR o, void *handle,
+ void (*stream_puts)(void *handle,
+ const char *strz),
+ void (*stream_close)(void *handle));
+
+YAZ_EXPORT void odr_printf(ODR o, const char *fmt, ...);
+
YAZ_END_CDECL
#include <yaz/xmalloc.h>
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*
- * $Id: odr-priv.h,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr-priv.h,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#ifndef ODR_PRIV_H
yaz_iconv_t iconv_handle;
int error_id;
char element[80];
+ void (*stream_puts)(void *handle, const char *strz);
+ void (*stream_close)(void *handle);
};
/* Private macro.
/*
- * Copyright (c) 1995-2003, Index Data
+ * Copyright (c) 1995-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: odr.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*
*/
#if HAVE_CONFIG_H
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <yaz/xmalloc.h>
#include "odr-priv.h"
}
}
+void odr_FILE_puts(void *handle, const char *strz)
+{
+ fputs(strz, (FILE*) handle);
+}
+
+void odr_FILE_close(void *handle)
+{
+ FILE *f = (FILE *) handle;
+ if (f && f != stderr && f != stdout)
+ fclose(f);
+}
+
void odr_setprint(ODR o, FILE *file)
{
- o->print = file;
+ odr_set_stream(o, file, odr_FILE_puts, odr_FILE_close);
+}
+
+void odr_set_stream(ODR o, void *handle,
+ void (*stream_puts)(void *handle, const char *strz),
+ void (*stream_close)(void *handle))
+{
+ o->print = handle;
+ o->op->stream_puts = stream_puts;
+ o->op->stream_close = stream_close;
}
int odr_set_charset(ODR o, const char *to, const char *from)
ODR odr_createmem(int direction)
{
- ODR r;
+ ODR o;
- if (!(r = (ODR)xmalloc(sizeof(*r))))
+ if (!(o = (ODR)xmalloc(sizeof(*o))))
return 0;
- r->direction = direction;
- r->print = stderr;
- r->buf = 0;
- r->size = r->pos = r->top = 0;
- r->can_grow = 1;
- r->mem = nmem_create();
- r->enable_bias = 1;
- r->op = (struct Odr_private *) xmalloc (sizeof(*r->op));
- r->op->odr_ber_tag.lclass = -1;
- r->op->iconv_handle = 0;
- odr_reset(r);
- yaz_log (LOG_DEBUG, "odr_createmem dir=%d o=%p", direction, r);
- return r;
+ o->direction = direction;
+ o->buf = 0;
+ o->size = o->pos = o->top = 0;
+ o->can_grow = 1;
+ o->mem = nmem_create();
+ o->enable_bias = 1;
+ o->op = (struct Odr_private *) xmalloc (sizeof(*o->op));
+ o->op->odr_ber_tag.lclass = -1;
+ o->op->iconv_handle = 0;
+ odr_setprint(o, stderr);
+ odr_reset(o);
+ yaz_log (LOG_DEBUG, "odr_createmem dir=%d o=%p", direction, o);
+ return o;
}
void odr_reset(ODR o)
nmem_destroy(o->mem);
if (o->buf && o->can_grow)
xfree(o->buf);
- if (o->print && o->print != stderr)
- fclose(o->print);
+ if (o->op->stream_close)
+ o->op->stream_close(o->print);
if (o->op->iconv_handle != 0)
yaz_iconv_close (o->op->iconv_handle);
xfree(o->op);
return (char*) o->buf;
}
+void odr_printf(ODR o, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[4096];
+
+ va_start(ap, fmt);
+#ifdef WIN32
+ _vsnprintf(buf, sizeof(buf)-1, fmt, ap);
+#else
+#if HAVE_VSNPRINTF
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+#else
+ vsprintf(buf, fmt, ap);
+#endif
+#endif
+ o->op->stream_puts(o->print, buf);
+ va_end(ap);
+}
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_any.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_any.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "ANY (len=%d)\n", (*p)->len);
+ odr_printf(o, "ANY (len=%d)\n", (*p)->len);
return 1;
}
if (o->direction == ODR_DECODE)
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_bit.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_bit.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "BITSTRING(len=%d)\n",(*p)->top + 1);
+ odr_printf(o, "BITSTRING(len=%d)\n",(*p)->top + 1);
return 1;
}
if (o->direction == ODR_DECODE)
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_bool.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_bool.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "%s\n", (**p ? "TRUE" : "FALSE"));
+ odr_printf(o, "%s\n", (**p ? "TRUE" : "FALSE"));
return 1;
}
if (cons)
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_choice.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_choice.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (name)
{
odr_prname(o, name);
- fprintf (o->print, "choice\n");
+ odr_printf(o, "choice\n");
}
}
for (i = 0; arm[i].fun; i++)
* Copyright (c) 1995-2003, Index Data
* See the file LICENSE for details.
*
- * $Id: odr_cons.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_cons.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*
*/
#if HAVE_CONFIG_H
else if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "{\n");
+ odr_printf(o, "{\n");
o->indent++;
}
else
o->op->stackp--;
o->indent--;
odr_prname(o, 0);
- fprintf(o->print, "}\n");
+ odr_printf(o, "}\n");
return 1;
default:
odr_seterror(o, OOTHER, 38);
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_enum.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_enum.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "%d\n", **p);
+ odr_printf(o, "%d\n", **p);
return 1;
}
if (cons)
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_int.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_int.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "%d\n", **p);
+ odr_printf(o, "%d\n", **p);
return 1;
}
if (cons)
* Copyright (c) 1995-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: odr_null.c,v 1.2 2004-03-09 20:49:04 adam Exp $
+ * $Id: odr_null.c,v 1.3 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "NULL\n");
+ odr_printf(o, "NULL\n");
return 1;
}
if (cons)
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_oct.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_oct.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
{
int i;
odr_prname(o, name);
- fprintf(o->print, "OCTETSTRING(len=%d)", (*p)->len);
+ odr_printf(o, "OCTETSTRING(len=%d)", (*p)->len);
for (i = 0; i<(*p)->len; i++)
{
if (i < 5 || i > ((*p)->len - 4))
{
- fprintf (o->print, " %02X", (*p)->buf[i]);
+ odr_printf(o, " %02X", (*p)->buf[i]);
}
else if (i == 5)
- fprintf (o->print, " .. ");
+ odr_printf(o, " .. ");
}
- fprintf(o->print, "\n");
+ odr_printf(o, "\n");
return 1;
}
if (o->direction == ODR_DECODE)
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "'%s'\n", *p);
+ odr_printf(o, "'%s'\n", *p);
return 1;
}
t = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); /* wrapper for octstring */
if (o->direction == ODR_PRINT)
{
odr_prname(o, name);
- fprintf(o->print, "'%s'\n", *p);
+ odr_printf(o, "'%s'\n", *p);
return 1;
}
t = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); /* wrapper for octstring */
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
- * $Id: odr_oid.c,v 1.1 2003-10-27 12:21:33 adam Exp $
+ * $Id: odr_oid.c,v 1.2 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
int i;
odr_prname(o, name);
- fprintf(o->print, "OID:");
+ odr_printf(o, "OID:");
for (i = 0; (*p)[i] > -1; i++)
- fprintf(o->print, " %d", (*p)[i]);
- fprintf(o->print, "\n");
+ odr_printf(o, " %d", (*p)[i]);
+ odr_printf(o, "\n");
return 1;
}
if (o->direction == ODR_DECODE)
* Copyright (c) 1995-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: odr_util.c,v 1.3 2004-01-05 14:46:52 adam Exp $
+ * $Id: odr_util.c,v 1.4 2004-08-11 12:15:38 adam Exp $
*/
#if HAVE_CONFIG_H
#include <config.h>
void odr_prname(ODR o, const char *name)
{
if (name)
- fprintf (o->print, "%*s%s ", o->indent*4, "", name);
+ odr_printf(o, "%*s%s ", o->indent*4, "", name);
else
- fprintf (o->print, "%*s", o->indent*4, "");
+ odr_printf(o, "%*s", o->indent*4, "");
}
int odp_more_chunks(ODR o, const unsigned char *base, int len)
* Copyright (c) 2002-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: zgdu.c,v 1.9 2004-02-25 12:59:56 adam Exp $
+ * $Id: zgdu.c,v 1.10 2004-08-11 12:15:38 adam Exp $
*/
#include <ctype.h>
(*p)->u.HTTP_Response->content_len);
if (o->direction == ODR_PRINT)
{
- fprintf(o->print, "-- HTTP response:\n%.*s\n", o->top - top0,
- o->buf + top0);
- fprintf(o->print, "-- \n");
+ odr_printf(o, "-- HTTP response:\n%.*s\n", o->top - top0,
+ o->buf + top0);
+ odr_printf(o, "-- \n");
}
break;
case Z_GDU_HTTP_Request:
(*p)->u.HTTP_Request->content_len);
if (o->direction == ODR_PRINT)
{
- fprintf(o->print, "-- HTTP request:\n%.*s\n", o->top - top0,
+ odr_printf(o, "-- HTTP request:\n%.*s\n", o->top - top0,
o->buf + top0);
- fprintf(o->print, "-- \n");
+ odr_printf(o, "-- \n");
}
break;
case Z_GDU_Z3950: