From: Adam Dickmeiss Date: Thu, 25 Jul 2002 12:51:08 +0000 (+0000) Subject: iconv conversions for ODR X-Git-Tag: YAZ.1.8.8~11 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=569f86b4615c2731727be2a0ff898d36f9725819;p=yaz-moved-to-github.git iconv conversions for ODR --- diff --git a/include/yaz/odr.h b/include/yaz/odr.h index abd1d73..895d635 100644 --- a/include/yaz/odr.h +++ b/include/yaz/odr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-2001, Index Data. + * Copyright (c) 1995-2002, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: odr.h,v 1.5 2001-09-24 21:51:55 adam Exp $ + * $Id: odr.h,v 1.6 2002-07-25 12:51:08 adam Exp $ */ #ifndef ODR_H @@ -121,13 +121,6 @@ typedef struct odr_constack #define ODR_S_CUR 1 #define ODR_S_END 2 -typedef struct { /* used to be statics in ber_tag... */ - int lclass; - int ltag; - int br; - int lcons; -} Odr_ber_tag; - typedef struct odr { int direction; /* the direction of this stream */ @@ -155,12 +148,7 @@ typedef struct odr NMEM mem; /* memory handle for decoding (primarily) */ - /* stack for constructed types */ -#define ODR_MAX_STACK 50 - int stackp; /* top of stack (-1 == initial state) */ - odr_constack stack[ODR_MAX_STACK]; - - Odr_ber_tag odr_ber_tag; + struct Odr_private *op; } *ODR; typedef int (*Odr_fun)(ODR, char **, int, const char *); @@ -239,42 +227,6 @@ YAZ_EXPORT Odr_null *odr_nullval(void); #define ODR_MASK_GET(mask, num) ( ((num) >> 3 <= (mask)->top) ? \ ((mask)->bits[(num) >> 3] & (0X80 >> ((num) & 0X07)) ? 1 : 0) : 0) -/* Private macro. - * write a single character at the current position - grow buffer if - * necessary. - * (no, we're not usually this anal about our macros, but this baby is - * next to unreadable without some indentation :) - */ -#define odr_putc(o, c) \ -( \ - ( \ - (o)->pos < (o)->size ? \ - ( \ - (o)->buf[(o)->pos++] = (c), \ - 0 \ - ) : \ - ( \ - odr_grow_block((o), 1) == 0 ? \ - ( \ - (o)->buf[(o)->pos++] = (c), \ - 0 \ - ) : \ - ( \ - (o)->error = OSPACE, \ - -1 \ - ) \ - ) \ - ) == 0 ? \ - ( \ - (o)->pos > (o)->top ? \ - ( \ - (o)->top = (o)->pos, \ - 0 \ - ) : \ - 0 \ - ) : \ - -1 \ -) \ #define odr_tell(o) ((o)->pos) #define odr_offset(o) ((o)->bp - (o)->buf) @@ -320,6 +272,7 @@ YAZ_EXPORT int odr_oid(ODR o, Odr_oid **p, int opt, const char *name); YAZ_EXPORT int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp, const char *name); YAZ_EXPORT int odr_cstring(ODR o, char **p, int opt, const char *name); +YAZ_EXPORT int odr_iconv_string(ODR o, char **p, int opt, const char *name); YAZ_EXPORT int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num, const char *name); YAZ_EXPORT int odr_set_of(ODR o, Odr_fun type, void *p, int *num, @@ -371,6 +324,9 @@ YAZ_EXPORT int odr_graphicstring(ODR o, char **p, int opt, const char *name); YAZ_EXPORT int odr_generalizedtime(ODR o, char **p, int opt, const char *name); + +YAZ_EXPORT int odr_set_charset(ODR o, const char *to, const char *from); + YAZ_END_CDECL #include diff --git a/odr/Makefile.am b/odr/Makefile.am index 81ab9aa..37ef25b 100644 --- a/odr/Makefile.am +++ b/odr/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.5 2002-04-15 09:44:44 adam Exp $ +## $Id: Makefile.am,v 1.6 2002-07-25 12:51:08 adam Exp $ noinst_LTLIBRARIES = libodr.la @@ -10,5 +10,5 @@ libodr_la_SOURCES = odr_bool.c ber_bool.c ber_len.c ber_tag.c odr_util.c \ odr_null.c ber_null.c odr_int.c ber_int.c odr_tag.c odr_cons.c \ odr_seq.c odr_oct.c ber_oct.c odr_bit.c ber_bit.c odr_oid.c \ ber_oid.c odr_use.c odr_choice.c odr_any.c ber_any.c odr.c odr_mem.c \ - dumpber.c odr_enum.c + dumpber.c odr_enum.c odr-priv.h diff --git a/odr/ber_any.c b/odr/ber_any.c index 9ca2cb2..6ae67d0 100644 --- a/odr/ber_any.c +++ b/odr/ber_any.c @@ -1,70 +1,13 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Log: ber_any.c,v $ - * Revision 1.18 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.17 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.16 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.15 1999/01/08 11:23:20 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.14 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.13 1997/05/14 06:53:56 adam - * C++ support. - * - * Revision 1.12 1995/09/29 17:12:15 quinn - * Smallish - * - * Revision 1.11 1995/09/27 15:02:54 quinn - * Modified function heads & prototypes. - * - * Revision 1.10 1995/05/16 08:50:42 quinn - * License, documentation, and memory fixes - * - * Revision 1.9 1995/04/18 08:15:12 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.8 1995/04/17 09:37:42 quinn - * *** empty log message *** - * - * Revision 1.7 1995/03/17 10:17:39 quinn - * Added memory management. - * - * Revision 1.6 1995/03/08 12:12:02 quinn - * Added better error checking. - * - * Revision 1.5 1995/02/14 20:39:54 quinn - * Fixed bugs in completeBER and (serious one in) ber_oid. - * - * Revision 1.4 1995/02/14 11:54:33 quinn - * Adjustments. - * - * Revision 1.3 1995/02/10 18:57:24 quinn - * More in the way of error-checking. - * - * Revision 1.2 1995/02/10 15:55:28 quinn - * Bug fixes, mostly. - * - * Revision 1.1 1995/02/09 15:51:45 quinn - * Works better now. - * + * $Id: ber_any.c,v 1.19 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int ber_any(ODR o, Odr_any **p) { diff --git a/odr/ber_bit.c b/odr/ber_bit.c index 666d329..1733226 100644 --- a/odr/ber_bit.c +++ b/odr/ber_bit.c @@ -1,56 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_bit.c,v $ - * Revision 1.12 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.11 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.10 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.9 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.8 1999/01/08 11:23:21 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.7 1995/09/29 17:12:16 quinn - * Smallish - * - * Revision 1.6 1995/09/27 15:02:54 quinn - * Modified function heads & prototypes. - * - * Revision 1.5 1995/05/16 08:50:43 quinn - * License, documentation, and memory fixes - * - * Revision 1.4 1995/04/18 08:15:13 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.3 1995/03/08 12:12:04 quinn - * Added better error checking. - * - * Revision 1.2 1995/02/03 17:04:31 quinn - * *** empty log message *** - * - * Revision 1.1 1995/02/02 20:38:49 quinn - * Updates. - * + * $Id: ber_bit.c,v 1.13 2002-07-25 12:51:08 adam Exp $ * */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int ber_bitstring(ODR o, Odr_bitmask *p, int cons) { diff --git a/odr/ber_bool.c b/odr/ber_bool.c index d82ab47..289d681 100644 --- a/odr/ber_bool.c +++ b/odr/ber_bool.c @@ -1,45 +1,9 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_bool.c,v $ - * Revision 1.11 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.10 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.9 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.8 1995/09/29 17:12:16 quinn - * Smallish - * - * Revision 1.7 1995/09/27 15:02:55 quinn - * Modified function heads & prototypes. - * - * Revision 1.6 1995/05/16 08:50:43 quinn - * License, documentation, and memory fixes - * - * Revision 1.5 1995/04/18 08:15:14 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.4 1995/03/21 10:17:27 quinn - * Fixed little bug in decoder. - * - * Revision 1.3 1995/03/08 12:12:06 quinn - * Added better error checking. - * - * Revision 1.2 1995/02/09 15:51:45 quinn - * Works better now. - * - * Revision 1.1 1995/02/02 16:21:51 quinn - * First kick. - * + * $Id: ber_bool.c,v 1.12 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H @@ -47,7 +11,7 @@ #endif #include -#include +#include "odr-priv.h" int ber_boolean(ODR o, int *val) { @@ -55,35 +19,35 @@ int ber_boolean(ODR o, int *val) switch (o->direction) { - case ODR_ENCODE: - if (ber_enclen(o, 1, 1, 1) != 1) - return 0; - if (odr_putc(o, *val) < 0) - return 0; + case ODR_ENCODE: + if (ber_enclen(o, 1, 1, 1) != 1) + return 0; + if (odr_putc(o, *val) < 0) + return 0; #ifdef ODR_DEBUG - fprintf(stderr, "[val=%d]\n", *val); + fprintf(stderr, "[val=%d]\n", *val); #endif - return 1; - case ODR_DECODE: - if ((res = ber_declen(o->bp, &len)) < 0) - { - o->error = OPROTO; - return 0; - } - if (len != 1) - { - o->error = OPROTO; - return 0; - } - o->bp+= res; - *val = *o->bp; - o->bp++; + return 1; + case ODR_DECODE: + if ((res = ber_declen(o->bp, &len)) < 0) + { + o->error = OPROTO; + return 0; + } + if (len != 1) + { + o->error = OPROTO; + return 0; + } + o->bp+= res; + *val = *o->bp; + o->bp++; #ifdef ODR_DEBUG - fprintf(stderr, "[val=%d]\n", *val); + fprintf(stderr, "[val=%d]\n", *val); #endif - return 1; - case ODR_PRINT: - return 1; - default: o->error = OOTHER; return 0; + return 1; + case ODR_PRINT: + return 1; + default: o->error = OOTHER; return 0; } } diff --git a/odr/ber_int.c b/odr/ber_int.c index 6774a69..6fa7a41 100644 --- a/odr/ber_int.c +++ b/odr/ber_int.c @@ -1,69 +1,9 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_int.c,v $ - * Revision 1.19 2000-10-06 12:46:27 adam - * Including sys/types.h and netinet/in.h instead on arpa/inet.h on Unix. - * - * Revision 1.18 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.17 2000/02/28 11:20:06 adam - * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL. - * - * Revision 1.16 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.15 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.14 1999/05/26 07:49:35 adam - * C++ compilation. - * - * Revision 1.13 1999/01/08 11:23:22 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.12 1996/07/06 19:58:33 quinn - * System headerfiles gathered in yconfig - * - * Revision 1.11 1995/09/29 17:12:16 quinn - * Smallish - * - * Revision 1.10 1995/09/29 17:01:50 quinn - * More Windows work - * - * Revision 1.9 1995/09/28 10:12:39 quinn - * Windows-support changes - * - * Revision 1.8 1995/09/27 15:02:55 quinn - * Modified function heads & prototypes. - * - * Revision 1.7 1995/05/16 08:50:44 quinn - * License, documentation, and memory fixes - * - * Revision 1.6 1995/04/18 08:15:14 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.5 1995/03/27 15:01:44 quinn - * Added include of sys/types to further portability - * - * Revision 1.4 1995/03/08 12:12:07 quinn - * Added better error checking. - * - * Revision 1.3 1995/02/09 15:51:46 quinn - * Works better now. - * - * Revision 1.2 1995/02/07 17:52:58 quinn - * A damn mess, but now things work, I think. - * - * Revision 1.1 1995/02/02 16:21:52 quinn - * First kick. - * + * $Id: ber_int.c,v 1.20 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -78,7 +18,7 @@ #include #endif -#include +#include "odr-priv.h" static int ber_encinteger(ODR o, int val); static int ber_decinteger(const unsigned char *buf, int *val); diff --git a/odr/ber_len.c b/odr/ber_len.c index e57997a..6fd3f9b 100644 --- a/odr/ber_len.c +++ b/odr/ber_len.c @@ -1,35 +1,16 @@ /* - * Copyright (C) 1995-2000, Index Data. + * Copyright (C) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_len.c,v $ - * Revision 1.9 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.8 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.7 1999/01/08 11:23:23 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.6 1995/09/29 17:12:17 quinn - * Smallish - * - * Revision 1.5 1995/09/27 15:02:55 quinn - * Modified function heads & prototypes. - * - * Revision 1.4 1995/05/16 08:50:45 quinn - * License, documentation, and memory fixes - * - * + * $Id: ber_len.c,v 1.10 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif #include -#include +#include "odr-priv.h" /* * Encode BER length octets. If exact, lenlen is the exact desired diff --git a/odr/ber_null.c b/odr/ber_null.c index 0e9beeb..bd334c9 100644 --- a/odr/ber_null.c +++ b/odr/ber_null.c @@ -1,51 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_null.c,v $ - * Revision 1.11 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.10 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.9 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.8 1995/09/29 17:12:18 quinn - * Smallish - * - * Revision 1.7 1995/09/27 15:02:55 quinn - * Modified function heads & prototypes. - * - * Revision 1.6 1995/05/22 11:32:01 quinn - * Fixing Interface to odr_null. - * - * Revision 1.5 1995/05/16 08:50:46 quinn - * License, documentation, and memory fixes - * - * Revision 1.4 1995/04/18 08:15:16 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.3 1995/03/08 12:12:09 quinn - * Added better error checking. - * - * Revision 1.2 1995/02/09 15:51:46 quinn - * Works better now. - * - * Revision 1.1 1995/02/02 16:21:52 quinn - * First kick. - * + * $Id: ber_null.c,v 1.12 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" /* * BER-en/decoder for NULL type. @@ -54,24 +18,24 @@ int ber_null(ODR o) { switch (o->direction) { - case ODR_ENCODE: - if (odr_putc(o, 0X00) < 0) - return 0; + case ODR_ENCODE: + if (odr_putc(o, 0X00) < 0) + return 0; #ifdef ODR_DEBUG - fprintf(stderr, "[NULL]\n"); + fprintf(stderr, "[NULL]\n"); #endif - return 1; - case ODR_DECODE: - if (*(o->bp++) != 0X00) - { - o->error = OPROTO; - return 0; - } + return 1; + case ODR_DECODE: + if (*(o->bp++) != 0X00) + { + o->error = OPROTO; + return 0; + } #ifdef ODR_DEBUG - fprintf(stderr, "[NULL]\n"); + fprintf(stderr, "[NULL]\n"); #endif - return 1; - case ODR_PRINT: return 1; - default: o->error = OOTHER; return 0; + return 1; + case ODR_PRINT: return 1; + default: o->error = OOTHER; return 0; } } diff --git a/odr/ber_oct.c b/odr/ber_oct.c index e12fedb..4f04960 100644 --- a/odr/ber_oct.c +++ b/odr/ber_oct.c @@ -1,73 +1,15 @@ /* - * Copyright (c) 1995-2001, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_oct.c,v $ - * Revision 1.18 2001-06-26 13:03:48 adam - * Bug fix: introduced by previous commit. - * - * Revision 1.17 2001/06/26 12:14:15 adam - * When BER decoding a null byte is appended to the OCTET buffer. - * - * Revision 1.16 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.15 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.14 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.13 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.12 1999/01/08 11:23:24 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.11 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.10 1995/09/29 17:12:18 quinn - * Smallish - * - * Revision 1.9 1995/09/27 15:02:55 quinn - * Modified function heads & prototypes. - * - * Revision 1.8 1995/05/16 08:50:47 quinn - * License, documentation, and memory fixes - * - * Revision 1.7 1995/04/18 08:15:17 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.6 1995/03/17 10:17:41 quinn - * Added memory management. - * - * Revision 1.5 1995/03/08 12:12:10 quinn - * Added better error checking. - * - * Revision 1.4 1995/02/10 15:55:28 quinn - * Bug fixes, mostly. - * - * Revision 1.3 1995/02/03 17:04:34 quinn - * *** empty log message *** - * - * Revision 1.2 1995/02/02 20:38:50 quinn - * Updates. - * - * Revision 1.1 1995/02/02 16:21:52 quinn - * First kick. - * + * $Id: ber_oct.c,v 1.19 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int ber_octetstring(ODR o, Odr_oct *p, int cons) { diff --git a/odr/ber_oid.c b/odr/ber_oid.c index cf75c66..0f48b31 100644 --- a/odr/ber_oid.c +++ b/odr/ber_oid.c @@ -1,54 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_oid.c,v $ - * Revision 1.12 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.11 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.10 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.9 1995/09/29 17:12:19 quinn - * Smallish - * - * Revision 1.8 1995/09/27 15:02:56 quinn - * Modified function heads & prototypes. - * - * Revision 1.7 1995/05/16 08:50:47 quinn - * License, documentation, and memory fixes - * - * Revision 1.6 1995/04/18 08:15:18 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.5 1995/03/20 12:18:22 quinn - * Fixed bug in ber_oid - * - * Revision 1.4 1995/03/08 12:12:11 quinn - * Added better error checking. - * - * Revision 1.3 1995/03/01 08:40:56 quinn - * Smallish changes. - * - * Revision 1.2 1995/02/14 20:39:55 quinn - * Fixed bugs in completeBER and (serious one in) ber_oid. - * - * Revision 1.1 1995/02/03 17:04:36 quinn - * Initial revision - * + * $Id: ber_oid.c,v 1.13 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int ber_oidc(ODR o, Odr_oid *p) { @@ -58,88 +19,89 @@ int ber_oidc(ODR o, Odr_oid *p) switch (o->direction) { - case ODR_DECODE: - if ((res = ber_declen(o->bp, &len)) < 1) - { - o->error = OPROTO; - return 0; - } - if (len < 0) - { - o->error = OPROTO; - return 0; - } - o->bp += res; - if (len == 0) - { - *p = -1; - return 1; - } - p[0] = *o->bp / 40; - if (p[0] > 2) - p[0] = 2; - p[1] = *o->bp - p[0] * 40; - o->bp++; - pos = 2; - len--; - while (len) - { - p[pos] = 0; - do - { - if (!len) - { - o->error = OPROTO; - return 0; - } - p[pos] <<= 7; - p[pos] |= *o->bp & 0X7F; - len--; - } - while (*(o->bp++) & 0X80); - pos++; - } - p[pos] = -1; - return 1; - case ODR_ENCODE: - /* we'll allow ourselves the quiet luxury of only doing encodings - shorter than 127 */ - lenp = odr_tell(o); - if (odr_putc(o, 0) < 0) /* dummy */ - return 0; - if (p[0] < 0 && p[1] <= 0) - { - o->error = ODATA; - return 0; - } - for (pos = 1; p[pos] >= 0; pos++) - { - id = pos > 1 ? p[pos] : p[0] * 40 + p[1]; - n = 0; - do - { - octs[n++] = id & 0X7F; - id >>= 7; - } - while (id); - while (n--) - { - unsigned char p; + case ODR_DECODE: + if ((res = ber_declen(o->bp, &len)) < 1) + { + o->error = OPROTO; + return 0; + } + if (len < 0) + { + o->error = OPROTO; + return 0; + } + o->bp += res; + if (len == 0) + { + *p = -1; + return 1; + } + p[0] = *o->bp / 40; + if (p[0] > 2) + p[0] = 2; + p[1] = *o->bp - p[0] * 40; + o->bp++; + pos = 2; + len--; + while (len) + { + p[pos] = 0; + do + { + if (!len) + { + o->error = OPROTO; + return 0; + } + p[pos] <<= 7; + p[pos] |= *o->bp & 0X7F; + len--; + } + while (*(o->bp++) & 0X80); + pos++; + } + p[pos] = -1; + return 1; + case ODR_ENCODE: + /* we'll allow ourselves the quiet luxury of only doing encodings + shorter than 127 */ + lenp = odr_tell(o); + if (odr_putc(o, 0) < 0) /* dummy */ + return 0; + if (p[0] < 0 && p[1] <= 0) + { + o->error = ODATA; + return 0; + } + for (pos = 1; p[pos] >= 0; pos++) + { + id = pos > 1 ? p[pos] : p[0] * 40 + p[1]; + n = 0; + do + { + octs[n++] = id & 0X7F; + id >>= 7; + } + while (id); + while (n--) + { + unsigned char p; - p = octs[n] | ((n > 0) << 7); - if (odr_putc(o, p) < 0) - return 0; - } - } - end = odr_tell(o); - odr_seek(o, ODR_S_SET, lenp); - if (ber_enclen(o, (end - lenp) - 1, 1, 1) != 1) - { - o->error = OOTHER; - return 0; - } - odr_seek(o, ODR_S_END, 0); - return 1; - default: o->error = OOTHER; return 0; + p = octs[n] | ((n > 0) << 7); + if (odr_putc(o, p) < 0) + return 0; + } + } + end = odr_tell(o); + odr_seek(o, ODR_S_SET, lenp); + if (ber_enclen(o, (end - lenp) - 1, 1, 1) != 1) + { + o->error = OOTHER; + return 0; + } + odr_seek(o, ODR_S_END, 0); + return 1; + default: + o->error = OOTHER; return 0; } } diff --git a/odr/ber_tag.c b/odr/ber_tag.c index 03b9c79..61a6872 100644 --- a/odr/ber_tag.c +++ b/odr/ber_tag.c @@ -1,87 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: ber_tag.c,v $ - * Revision 1.22 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.21 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.20 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.19 1999/01/08 11:23:25 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.18 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.17 1997/09/30 09:33:10 adam - * Minor changes - removed indentation of ifdef. - * - * Revision 1.16 1997/09/17 12:10:33 adam - * YAZ version 1.4. - * - * Revision 1.15 1997/09/01 08:51:06 adam - * New windows NT/95 port using MSV5.0. Had to avoid a few static - * variables used in function ber_tag. These are now part of the - * ODR structure. - * - * Revision 1.14 1997/05/14 06:53:56 adam - * C++ support. - * - * Revision 1.13 1995/09/29 17:12:21 quinn - * Smallish - * - * Revision 1.12 1995/09/27 15:02:57 quinn - * Modified function heads & prototypes. - * - * Revision 1.11 1995/05/16 08:50:48 quinn - * License, documentation, and memory fixes - * - * Revision 1.10 1995/04/18 08:15:18 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.9 1995/03/15 08:37:18 quinn - * Fixed protocol bugs. - * - * Revision 1.8 1995/03/10 11:44:40 quinn - * Fixed serious stack-bug in odr_cons_begin - * - * Revision 1.7 1995/03/08 12:12:13 quinn - * Added better error checking. - * - * Revision 1.6 1995/02/14 11:54:33 quinn - * Adjustments. - * - * Revision 1.5 1995/02/10 18:57:24 quinn - * More in the way of error-checking. - * - * Revision 1.4 1995/02/10 15:55:28 quinn - * Bug fixes, mostly. - * - * Revision 1.3 1995/02/09 15:51:46 quinn - * Works better now. - * - * Revision 1.2 1995/02/07 17:52:59 quinn - * A damn mess, but now things work, I think. - * - * Revision 1.1 1995/02/02 16:21:53 quinn - * First kick. - * + * $Id: ber_tag.c,v 1.23 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif #include -#include +#include "odr-priv.h" /* ber_tag * On encoding: @@ -95,14 +24,14 @@ */ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) { - Odr_ber_tag *odr_ber_tag = &o->odr_ber_tag; + struct Odr_ber_tag *odr_ber_tag = &o->op->odr_ber_tag; int rd; char **pp = (char **)p; if (o->direction == ODR_DECODE) *pp = 0; o->t_class = -1; - if (o->stackp < 0) + if (o->op->stackp < 0) { odr_seek(o, ODR_S_SET, 0); o->top = 0; @@ -111,63 +40,63 @@ int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt) } switch (o->direction) { - case ODR_ENCODE: - if (!*pp) - { - if (!opt) - o->error = OREQUIRED; - return 0; - } - if ((rd = ber_enctag(o, zclass, tag, *constructed)) < 0) - return -1; + case ODR_ENCODE: + if (!*pp) + { + if (!opt) + o->error = OREQUIRED; + return 0; + } + if ((rd = ber_enctag(o, zclass, tag, *constructed)) < 0) + return -1; #ifdef ODR_DEBUG - fprintf(stderr, "\n[class=%d,tag=%d,cons=%d,stackp=%d]", zclass, tag, - *constructed, o->stackp); + fprintf(stderr, "\n[class=%d,tag=%d,cons=%d,stackp=%d]", zclass, tag, + *constructed, o->stackp); #endif - return 1; - - case ODR_DECODE: - if (o->stackp > -1 && !odr_constructed_more(o)) + return 1; + + case ODR_DECODE: + if (o->op->stackp > -1 && !odr_constructed_more(o)) + { + if (!opt) + o->error = OREQUIRED; + return 0; + } + if (odr_ber_tag->lclass < 0) + { + if ((odr_ber_tag->br = ber_dectag(o->bp, &odr_ber_tag->lclass, + &odr_ber_tag->ltag, &odr_ber_tag->lcons)) <= 0) { - if (!opt) - o->error = OREQUIRED; - return 0; - } - if (odr_ber_tag->lclass < 0) - { - if ((odr_ber_tag->br = ber_dectag(o->bp, &odr_ber_tag->lclass, - &odr_ber_tag->ltag, &odr_ber_tag->lcons)) <= 0) - { - o->error = OPROTO; - return 0; - } + o->error = OPROTO; + return 0; + } #ifdef ODR_DEBUG - fprintf(stderr, - "\n[class=%d,tag=%d,cons=%d,stackp=%d]", - odr_ber_tag->lclass, odr_ber_tag->ltag, - odr_ber_tag->lcons, o->stackp); + fprintf(stderr, + "\n[class=%d,tag=%d,cons=%d,stackp=%d]", + odr_ber_tag->lclass, odr_ber_tag->ltag, + odr_ber_tag->lcons, o->stackp); #endif - } - if (zclass == odr_ber_tag->lclass && tag == odr_ber_tag->ltag) - { - o->bp += odr_ber_tag->br; - *constructed = odr_ber_tag->lcons; - odr_ber_tag->lclass = -1; - return 1; - } - else - { - if (!opt) - o->error = OREQUIRED; - return 0; - } - case ODR_PRINT: - if (!*pp && !opt) - o->error = OREQUIRED; - return *pp != 0; - default: - o->error = OOTHER; + } + if (zclass == odr_ber_tag->lclass && tag == odr_ber_tag->ltag) + { + o->bp += odr_ber_tag->br; + *constructed = odr_ber_tag->lcons; + odr_ber_tag->lclass = -1; + return 1; + } + else + { + if (!opt) + o->error = OREQUIRED; return 0; + } + case ODR_PRINT: + if (!*pp && !opt) + o->error = OREQUIRED; + return *pp != 0; + default: + o->error = OOTHER; + return 0; } } diff --git a/odr/dumpber.c b/odr/dumpber.c index 2ba5a70..1fbdecf 100644 --- a/odr/dumpber.c +++ b/odr/dumpber.c @@ -1,53 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data. + * Copyright (c) 1995-2002, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: dumpber.c,v $ - * Revision 1.12 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.11 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.10 1999/01/08 11:23:26 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.9 1998/01/14 09:53:26 quinn - * Added a bit more info to dump. - * - * Revision 1.8 1997/05/14 06:53:57 adam - * C++ support. - * - * Revision 1.7 1996/03/08 14:38:41 quinn - * Fixed output. - * - * Revision 1.6 1996/01/19 15:41:34 quinn - * dumpber was ignoring the file argument. - * - * Revision 1.5 1995/10/18 16:12:55 quinn - * Better diagnostics. Added special case in NULL to handle WAIS server. - * - * Revision 1.4 1995/09/29 17:12:21 quinn - * Smallish - * - * Revision 1.3 1995/09/27 15:02:57 quinn - * Modified function heads & prototypes. - * - * Revision 1.2 1995/06/27 13:20:51 quinn - * Fixed sign-clash. Non-fatal warning - * - * Revision 1.1 1995/06/19 12:38:45 quinn - * Added BER dumper. - * - * + * $Id: dumpber.c,v 1.13 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif #include -#include +#include "odr-priv.h" static int do_dumpBER(FILE *f, const char *buf, int len, int level, int offset) { diff --git a/odr/odr.c b/odr/odr.c index e172eda..15c6e67 100644 --- a/odr/odr.c +++ b/odr/odr.c @@ -1,119 +1,8 @@ /* - * Copyright (c) 1995-2001, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Log: odr.c,v $ - * Revision 1.34 2001-02-21 13:46:53 adam - * C++ fixes. - * - * Revision 1.33 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.32 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.31 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.30 1999/08/27 09:40:32 adam - * Renamed logf function to yaz_log. Removed VC++ project files. - * - * Revision 1.29 1999/04/27 08:34:10 adam - * Modified odr_destroy so that file is not closed when file is 0. - * - * Revision 1.28 1998/07/20 12:38:13 adam - * More LOG_DEBUG-diagnostics. - * - * Revision 1.27 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.26 1997/11/24 11:33:56 adam - * Using function odr_nullval() instead of global ODR_NULLVAL when - * appropriate. - * - * Revision 1.25 1997/10/31 12:20:08 adam - * Improved memory debugging for xmalloc/nmem.c. References to NMEM - * instead of ODR in n ESPEC-1 handling in source d1_espec.c. - * Bug fix: missing fclose in data1_read_espec1. - * - * Revision 1.24 1997/09/01 08:51:07 adam - * New windows NT/95 port using MSV5.0. Had to avoid a few static - * variables used in function ber_tag. These are now part of the - * ODR structure. - * - * Revision 1.23 1997/04/30 08:52:10 quinn - * Null - * - * Revision 1.22 1996/10/08 12:58:17 adam - * New ODR function, odr_choice_enable_bias, to control behaviour of - * odr_choice_bias. - * - * Revision 1.21 1996/07/26 13:38:19 quinn - * Various smaller things. Gathered header-files. - * - * Revision 1.20 1995/11/08 17:41:32 quinn - * Smallish. - * - * Revision 1.19 1995/11/01 13:54:41 quinn - * Minor adjustments - * - * Revision 1.18 1995/09/29 17:12:22 quinn - * Smallish - * - * Revision 1.17 1995/09/29 17:01:50 quinn - * More Windows work - * - * Revision 1.16 1995/09/27 15:02:57 quinn - * Modified function heads & prototypes. - * - * Revision 1.15 1995/08/15 12:00:22 quinn - * Updated External - * - * Revision 1.14 1995/06/19 12:38:46 quinn - * Added BER dumper. - * - * Revision 1.13 1995/05/22 11:32:02 quinn - * Fixing Interface to odr_null. - * - * Revision 1.12 1995/05/16 08:50:49 quinn - * License, documentation, and memory fixes - * - * Revision 1.11 1995/05/15 11:56:08 quinn - * More work on memory management. - * - * Revision 1.10 1995/04/18 08:15:20 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.9 1995/04/10 10:23:11 quinn - * Smallish changes. - * - * Revision 1.8 1995/03/17 10:17:43 quinn - * Added memory management. - * - * Revision 1.7 1995/03/10 11:44:41 quinn - * Fixed serious stack-bug in odr_cons_begin - * - * Revision 1.6 1995/03/08 12:12:15 quinn - * Added better error checking. - * - * Revision 1.5 1995/03/07 13:28:57 quinn - * *** empty log message *** - * - * Revision 1.4 1995/03/07 13:16:13 quinn - * Fixed bug in odr_reset - * - * Revision 1.3 1995/03/07 10:21:31 quinn - * odr_errno-->odr_error - * - * Revision 1.2 1995/03/07 10:19:05 quinn - * Addded some method functions to the ODR type. - * - * Revision 1.1 1995/03/07 09:23:15 quinn - * Installing top-level API and documentation. - * + * $Id: odr.c,v 1.35 2002-07-25 12:51:08 adam Exp $ * */ #if HAVE_CONFIG_H @@ -124,7 +13,7 @@ #include #include -#include +#include "odr-priv.h" Odr_null *ODR_NULLVAL = (Odr_null *) "NULL"; /* the presence of a null value */ @@ -169,6 +58,21 @@ void odr_setprint(ODR o, FILE *file) o->print = file; } +int odr_set_charset(ODR o, const char *to, const char *from) +{ +#if HAVE_ICONV_H + if (o->op->iconv_handle != (iconv_t)(-1)) + iconv_close (o->op->iconv_handle); + + o->op->iconv_handle = iconv_open (to, from); + if (o->op->iconv_handle == (iconv_t)(-1)) + return -1; + return 0; +#else + return -1; +#endif +} + #include ODR odr_createmem(int direction) @@ -184,7 +88,11 @@ ODR odr_createmem(int direction) r->can_grow = 1; r->mem = nmem_create(); r->enable_bias = 1; - r->odr_ber_tag.lclass = -1; + r->op = xmalloc (sizeof(*r->op)); + r->op->odr_ber_tag.lclass = -1; +#if HAVE_ICONV_H + r->op->iconv_handle = (iconv_t)(-1); +#endif odr_reset(r); yaz_log (LOG_DEBUG, "odr_createmem dir=%d o=%p", direction, r); return r; @@ -199,10 +107,14 @@ void odr_reset(ODR o) o->t_class = -1; o->t_tag = -1; o->indent = 0; - o->stackp = -1; + o->op->stackp = -1; nmem_reset(o->mem); o->choice_bias = -1; o->lenlen = 1; +#if HAVE_ICONV_H + if (o->op->iconv_handle != (iconv_t)(-1)) + iconv(o->op->iconv_handle, 0, 0, 0, 0); +#endif yaz_log (LOG_DEBUG, "odr_reset o=%p", o); } @@ -213,6 +125,11 @@ void odr_destroy(ODR o) xfree(o->buf); if (o->print && o->print != stderr) fclose(o->print); +#if HAVE_ICONV_H + if (o->op->iconv_handle != (iconv_t)(-1)) + iconv_close (o->op->iconv_handle); +#endif + xfree(o->op); xfree(o); yaz_log (LOG_DEBUG, "odr_destroy o=%p", o); } diff --git a/odr/odr_any.c b/odr/odr_any.c index 9331bf8..3c5c067 100644 --- a/odr/odr_any.c +++ b/odr/odr_any.c @@ -1,46 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_any.c,v $ - * Revision 1.10 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.9 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.8 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.7 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.6 1995/09/29 17:12:22 quinn - * Smallish - * - * Revision 1.5 1995/09/27 15:02:58 quinn - * Modified function heads & prototypes. - * - * Revision 1.4 1995/05/16 08:50:50 quinn - * License, documentation, and memory fixes - * - * Revision 1.3 1995/03/17 10:17:46 quinn - * Added memory management. - * - * Revision 1.2 1995/03/08 12:12:18 quinn - * Added better error checking. - * - * Revision 1.1 1995/02/09 15:51:47 quinn - * Works better now. - * + * $Id: odr_any.c,v 1.11 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" /* * This is a catch-all type. It stuffs a random ostring (assumed to be properly diff --git a/odr/odr_bit.c b/odr/odr_bit.c index 9492b6e..aa10414 100644 --- a/odr/odr_bit.c +++ b/odr/odr_bit.c @@ -1,60 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_bit.c,v $ - * Revision 1.14 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.13 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.12 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.11 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.10 1995/09/29 17:12:22 quinn - * Smallish - * - * Revision 1.9 1995/09/27 15:02:58 quinn - * Modified function heads & prototypes. - * - * Revision 1.8 1995/05/16 08:50:51 quinn - * License, documentation, and memory fixes - * - * Revision 1.7 1995/03/17 10:17:48 quinn - * Added memory management. - * - * Revision 1.6 1995/03/08 12:12:19 quinn - * Added better error checking. - * - * Revision 1.5 1995/02/10 18:57:25 quinn - * More in the way of error-checking. - * - * Revision 1.4 1995/02/09 15:51:47 quinn - * Works better now. - * - * Revision 1.3 1995/02/07 14:13:45 quinn - * Bug fixes. - * - * Revision 1.2 1995/02/03 17:04:37 quinn - * *** empty log message *** - * - * Revision 1.1 1995/02/02 20:38:50 quinn - * Updates. - * - * + * $Id: odr_bit.c,v 1.15 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif #include -#include +#include "odr-priv.h" /* * Top level bitstring string en/decoder. diff --git a/odr/odr_bool.c b/odr/odr_bool.c index 0ea96b4..597293c 100644 --- a/odr/odr_bool.c +++ b/odr/odr_bool.c @@ -1,53 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_bool.c,v $ - * Revision 1.12 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.11 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.10 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.9 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.8 1995/09/29 17:12:23 quinn - * Smallish - * - * Revision 1.7 1995/09/27 15:02:58 quinn - * Modified function heads & prototypes. - * - * Revision 1.6 1995/05/16 08:50:52 quinn - * License, documentation, and memory fixes - * - * Revision 1.5 1995/03/17 10:17:49 quinn - * Added memory management. - * - * Revision 1.4 1995/03/08 12:12:20 quinn - * Added better error checking. - * - * Revision 1.3 1995/02/10 18:57:25 quinn - * More in the way of error-checking. - * - * Revision 1.2 1995/02/09 15:51:47 quinn - * Works better now. - * - * Revision 1.1 1995/02/02 16:21:53 quinn - * First kick. - * + * $Id: odr_bool.c,v 1.13 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif #include -#include +#include "odr-priv.h" /* * Top level boolean en/decoder. diff --git a/odr/odr_choice.c b/odr/odr_choice.c index eb00387..d752714 100644 --- a/odr/odr_choice.c +++ b/odr/odr_choice.c @@ -3,72 +3,13 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_choice.c,v $ - * Revision 1.19 2002-02-20 14:42:30 adam - * Fixed BER decoding of OPTIONAL CHOICE - * - * Revision 1.18 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.17 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.16 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.15 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.14 1997/05/14 06:53:57 adam - * C++ support. - * - * Revision 1.13 1997/04/30 08:52:10 quinn - * Null - * - * Revision 1.12 1996/10/08 12:58:17 adam - * New ODR function, odr_choice_enable_bias, to control behaviour of - * odr_choice_bias. - * - * Revision 1.11 1995/09/29 17:12:23 quinn - * Smallish - * - * Revision 1.10 1995/09/27 15:02:58 quinn - * Modified function heads & prototypes. - * - * Revision 1.9 1995/08/15 12:00:23 quinn - * Updated External - * - * Revision 1.8 1995/06/19 17:01:51 quinn - * This should bring us in sync with the version distributed as 1.0b - * - * Revision 1.7 1995/06/19 13:06:50 quinn - * Fixed simple bug in the code to handle untagged choice elements. - * - * Revision 1.6 1995/05/16 08:50:53 quinn - * License, documentation, and memory fixes - * - * Revision 1.5 1995/03/18 12:16:31 quinn - * Minor changes. - * - * Revision 1.4 1995/03/14 16:59:38 quinn - * Added odr_constructed_more check - * - * Revision 1.3 1995/03/08 12:12:22 quinn - * Added better error checking. - * - * Revision 1.2 1995/02/09 15:51:48 quinn - * Works better now. - * - * Revision 1.1 1995/02/07 17:52:59 quinn - * A damn mess, but now things work, I think. - * + * $Id: odr_choice.c,v 1.20 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp, const char *name) @@ -110,7 +51,7 @@ int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp, { if (o->direction == ODR_DECODE && cl < 0) { - if (o->stackp > -1 && !odr_constructed_more(o)) + if (o->op->stackp > -1 && !odr_constructed_more(o)) return 0; if (ber_dectag(o->bp, &cl, &tg, &cn) <= 0) return 0; diff --git a/odr/odr_cons.c b/odr/odr_cons.c index c74229c..0bda85a 100644 --- a/odr/odr_cons.c +++ b/odr/odr_cons.c @@ -1,84 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Log: odr_cons.c,v $ - * Revision 1.22 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.21 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.20 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.19 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.18 1997/05/14 06:53:58 adam - * C++ support. - * - * Revision 1.17 1996/10/23 12:31:24 adam - * Added 'static' modifier to dummy variable in odr_constructed_begin. - * - * Revision 1.16 1996/07/26 13:38:20 quinn - * Various smaller things. Gathered header-files. - * - * Revision 1.15 1995/09/29 17:12:23 quinn - * Smallish - * - * Revision 1.14 1995/09/27 15:02:58 quinn - * Modified function heads & prototypes. - * - * Revision 1.13 1995/08/15 11:16:39 quinn - * Fixed pretty-printers. - * - * Revision 1.12 1995/06/19 12:38:47 quinn - * Added BER dumper. - * - * Revision 1.11 1995/05/16 08:50:53 quinn - * License, documentation, and memory fixes - * - * Revision 1.10 1995/04/18 08:15:21 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.9 1995/03/28 09:15:49 quinn - * Fixed bug in the printing mode - * - * Revision 1.8 1995/03/15 11:18:04 quinn - * Fixed serious bug in odr_cons - * - * Revision 1.7 1995/03/10 11:44:41 quinn - * Fixed serious stack-bug in odr_cons_begin - * - * Revision 1.6 1995/03/08 12:12:23 quinn - * Added better error checking. - * - * Revision 1.5 1995/02/10 18:57:25 quinn - * More in the way of error-checking. - * - * Revision 1.4 1995/02/10 15:55:29 quinn - * Bug fixes, mostly. - * - * Revision 1.3 1995/02/09 15:51:48 quinn - * Works better now. - * - * Revision 1.2 1995/02/07 17:52:59 quinn - * A damn mess, but now things work, I think. - * - * Revision 1.1 1995/02/02 16:21:53 quinn - * First kick. + * $Id: odr_cons.c,v 1.23 2002-07-25 12:51:08 adam Exp $ * */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" void odr_setlenlen(ODR o, int len) { @@ -105,30 +36,30 @@ int odr_constructed_begin(ODR o, void *p, int zclass, int tag, if (!res || !cons) return 0; - if (o->stackp == ODR_MAX_STACK - 1) + if (o->op->stackp == ODR_MAX_STACK - 1) { o->error = OSTACK; return 0; } - o->stack[++(o->stackp)].lenb = o->bp; - o->stack[o->stackp].len_offset = odr_tell(o); + o->op->stack[++(o->op->stackp)].lenb = o->bp; + o->op->stack[o->op->stackp].len_offset = odr_tell(o); #ifdef ODR_DEBUG - fprintf(stderr, "[cons_begin(%d)]", o->stackp); + fprintf(stderr, "[cons_begin(%d)]", o->op->stackp); #endif if (o->direction == ODR_ENCODE) { static unsigned char dummy[sizeof(int)+1]; - o->stack[o->stackp].lenlen = lenlen; + o->op->stack[o->op->stackp].lenlen = lenlen; if (odr_write(o, dummy, lenlen) < 0) /* dummy */ return 0; } else if (o->direction == ODR_DECODE) { - if ((res = ber_declen(o->bp, &o->stack[o->stackp].len)) < 0) + if ((res = ber_declen(o->bp, &o->op->stack[o->op->stackp].len)) < 0) return 0; - o->stack[o->stackp].lenlen = res; + o->op->stack[o->op->stackp].lenlen = res; o->bp += res; } else if (o->direction == ODR_PRINT) @@ -142,8 +73,8 @@ int odr_constructed_begin(ODR o, void *p, int zclass, int tag, o->error = OOTHER; return 0; } - o->stack[o->stackp].base = o->bp; - o->stack[o->stackp].base_offset = odr_tell(o); + o->op->stack[o->op->stackp].base = o->bp; + o->op->stack[o->op->stackp].base_offset = odr_tell(o); return 1; } @@ -151,10 +82,10 @@ int odr_constructed_more(ODR o) { if (o->error) return 0; - if (o->stackp < 0) + if (o->op->stackp < 0) return 0; - if (o->stack[o->stackp].len >= 0) - return o->bp - o->stack[o->stackp].base < o->stack[o->stackp].len; + if (o->op->stack[o->op->stackp].len >= 0) + return o->bp - o->op->stack[o->op->stackp].base < o->op->stack[o->op->stackp].len; else return (!(*o->bp == 0 && *(o->bp + 1) == 0)); } @@ -166,69 +97,69 @@ int odr_constructed_end(ODR o) if (o->error) return 0; - if (o->stackp < 0) + if (o->op->stackp < 0) { o->error = OOTHER; return 0; } switch (o->direction) { - case ODR_DECODE: - if (o->stack[o->stackp].len < 0) - { - if (*o->bp++ == 0 && *(o->bp++) == 0) - { - o->stackp--; + case ODR_DECODE: + if (o->op->stack[o->op->stackp].len < 0) + { + if (*o->bp++ == 0 && *(o->bp++) == 0) + { + o->op->stackp--; return 1; - } - else - { - o->error = OOTHER; - return 0; - } - } - else if (o->bp - o->stack[o->stackp].base != - o->stack[o->stackp].len) - { - o->error = OCONLEN; - return 0; - } - o->stackp--; - return 1; - case ODR_ENCODE: - pos = odr_tell(o); - odr_seek(o, ODR_S_SET, o->stack[o->stackp].len_offset); - if ((res = ber_enclen(o, pos - o->stack[o->stackp].base_offset, - o->stack[o->stackp].lenlen, 1)) < 0) - { - o->error = OLENOV; - return 0; - } - odr_seek(o, ODR_S_END, 0); - if (res == 0) /* indefinite encoding */ - { + } + else + { + o->error = OOTHER; + return 0; + } + } + else if (o->bp - o->op->stack[o->op->stackp].base != + o->op->stack[o->op->stackp].len) + { + o->error = OCONLEN; + return 0; + } + o->op->stackp--; + return 1; + case ODR_ENCODE: + pos = odr_tell(o); + odr_seek(o, ODR_S_SET, o->op->stack[o->op->stackp].len_offset); + if ((res = ber_enclen(o, pos - o->op->stack[o->op->stackp].base_offset, + o->op->stack[o->op->stackp].lenlen, 1)) < 0) + { + o->error = OLENOV; + return 0; + } + odr_seek(o, ODR_S_END, 0); + if (res == 0) /* indefinite encoding */ + { #ifdef ODR_DEBUG - fprintf(stderr, "[cons_end(%d): indefinite]", o->stackp); + fprintf(stderr, "[cons_end(%d): indefinite]", o->op->stackp); #endif - if (odr_putc(o, 0) < 0 || odr_putc(o, 0) < 0) - return 0; - } + if (odr_putc(o, 0) < 0 || odr_putc(o, 0) < 0) + return 0; + } #ifdef ODR_DEBUG - else - { - fprintf(stderr, "[cons_end(%d): definite]", o->stackp); - } + else + { + fprintf(stderr, "[cons_end(%d): definite]", o->op->stackp); + } #endif - o->stackp--; - return 1; - case ODR_PRINT: - o->stackp--; - o->indent--; - odr_prname(o, 0); - fprintf(o->print, "}\n"); - return 1; - default: - o->error = OOTHER; - return 0; + o->op->stackp--; + return 1; + case ODR_PRINT: + o->op->stackp--; + o->indent--; + odr_prname(o, 0); + fprintf(o->print, "}\n"); + return 1; + default: + o->error = OOTHER; + return 0; } } diff --git a/odr/odr_enum.c b/odr/odr_enum.c index 5fcc29b..b60014b 100644 --- a/odr/odr_enum.c +++ b/odr/odr_enum.c @@ -1,31 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_enum.c,v $ - * Revision 1.5 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.4 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.3 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.2 1999/01/08 11:23:27 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.1 1998/03/20 14:45:01 adam - * Implemented odr_enum and odr_set_of. - * + * $Id: odr_enum.c,v 1.6 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" /* * Top level enum en/decoder. diff --git a/odr/odr_int.c b/odr/odr_int.c index 7d8f66c..3637174 100644 --- a/odr/odr_int.c +++ b/odr/odr_int.c @@ -1,61 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_int.c,v $ - * Revision 1.15 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.14 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.13 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.12 1999/01/08 11:23:28 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.11 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.10 1995/09/29 17:12:24 quinn - * Smallish - * - * Revision 1.9 1995/09/29 17:01:50 quinn - * More Windows work - * - * Revision 1.8 1995/09/27 15:02:59 quinn - * Modified function heads & prototypes. - * - * Revision 1.7 1995/05/16 08:50:54 quinn - * License, documentation, and memory fixes - * - * Revision 1.6 1995/03/17 10:17:51 quinn - * Added memory management. - * - * Revision 1.5 1995/03/08 12:12:25 quinn - * Added better error checking. - * - * Revision 1.4 1995/02/10 18:57:25 quinn - * More in the way of error-checking. - * - * Revision 1.3 1995/02/09 15:51:48 quinn - * Works better now. - * - * Revision 1.2 1995/02/07 14:13:45 quinn - * Bug fixes. - * - * Revision 1.1 1995/02/02 16:21:53 quinn - * First kick. - * + * $Id: odr_int.c,v 1.16 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" /* * Top level integer en/decoder. diff --git a/odr/odr_mem.c b/odr/odr_mem.c index f938a68..9b2c7cc 100644 --- a/odr/odr_mem.c +++ b/odr/odr_mem.c @@ -1,76 +1,15 @@ /* - * Copyright (c) 1995-2001, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Log: odr_mem.c,v $ - * Revision 1.19 2001-03-25 21:55:12 adam - * Added odr_intdup. Ztest server returns TaskPackage for ItemUpdate. - * - * Revision 1.18 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.17 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.16 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.15 1999/03/31 11:18:25 adam - * Implemented odr_strdup. Added Reference ID to backend server API. - * - * Revision 1.14 1998/07/20 12:38:15 adam - * More LOG_DEBUG-diagnostics. - * - * Revision 1.13 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.12 1995/11/08 17:41:33 quinn - * Smallish. - * - * Revision 1.11 1995/11/01 13:54:43 quinn - * Minor adjustments - * - * Revision 1.10 1995/10/25 16:58:19 quinn - * Stupid bug in odr_malloc - * - * Revision 1.9 1995/10/13 16:08:08 quinn - * Added OID utility - * - * Revision 1.8 1995/09/29 17:12:24 quinn - * Smallish - * - * Revision 1.7 1995/09/27 15:02:59 quinn - * Modified function heads & prototypes. - * - * Revision 1.6 1995/08/21 09:10:41 quinn - * Smallish fixes to suppport new formats. - * - * Revision 1.5 1995/05/16 08:50:55 quinn - * License, documentation, and memory fixes - * - * Revision 1.4 1995/05/15 11:56:09 quinn - * More work on memory management. - * - * Revision 1.3 1995/04/18 08:15:21 quinn - * Added dynamic memory allocation on encoding (whew). Code is now somewhat - * neater. We'll make the same change for decoding one day. - * - * Revision 1.2 1995/03/17 10:17:52 quinn - * Added memory management. - * - * Revision 1.1 1995/03/14 10:27:40 quinn - * Modified makefile to use common lib - * Beginning to add memory management to odr - * + * $Id: odr_mem.c,v 1.20 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif #include -#include +#include "odr-priv.h" #include /* ------------------------ NIBBLE MEMORY ---------------------- */ diff --git a/odr/odr_null.c b/odr/odr_null.c index eb43bfe..8158421 100644 --- a/odr/odr_null.c +++ b/odr/odr_null.c @@ -1,56 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_null.c,v $ - * Revision 1.13 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.12 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.11 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.10 1997/11/24 11:33:56 adam - * Using function odr_nullval() instead of global ODR_NULLVAL when - * appropriate. - * - * Revision 1.9 1995/10/18 16:12:56 quinn - * Better diagnostics. Added special case in NULL to handle WAIS server. - * - * Revision 1.8 1995/09/29 17:12:24 quinn - * Smallish - * - * Revision 1.7 1995/09/27 15:02:59 quinn - * Modified function heads & prototypes. - * - * Revision 1.6 1995/05/22 11:32:03 quinn - * Fixing Interface to odr_null. - * - * Revision 1.5 1995/05/16 08:50:56 quinn - * License, documentation, and memory fixes - * - * Revision 1.4 1995/03/08 12:12:26 quinn - * Added better error checking. - * - * Revision 1.3 1995/02/10 18:57:25 quinn - * More in the way of error-checking. - * - * Revision 1.2 1995/02/09 15:51:49 quinn - * Works better now. - * - * Revision 1.1 1995/02/02 16:21:54 quinn - * First kick. - * + * $Id: odr_null.c,v 1.14 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" /* * Top level null en/decoder. diff --git a/odr/odr_oct.c b/odr/odr_oct.c index 7fd03f8..008aaa1 100644 --- a/odr/odr_oct.c +++ b/odr/odr_oct.c @@ -1,64 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_oct.c,v $ - * Revision 1.16 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.15 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.14 1999/10/19 12:35:55 adam - * Better dump of OCTET STRING. - * - * Revision 1.13 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.12 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.11 1995/09/29 17:12:25 quinn - * Smallish - * - * Revision 1.10 1995/09/27 15:02:59 quinn - * Modified function heads & prototypes. - * - * Revision 1.9 1995/05/16 08:50:56 quinn - * License, documentation, and memory fixes - * - * Revision 1.8 1995/03/17 10:17:54 quinn - * Added memory management. - * - * Revision 1.7 1995/03/08 12:12:27 quinn - * Added better error checking. - * - * Revision 1.6 1995/02/10 18:57:26 quinn - * More in the way of error-checking. - * - * Revision 1.5 1995/02/09 15:51:49 quinn - * Works better now. - * - * Revision 1.4 1995/02/07 14:13:46 quinn - * Bug fixes. - * - * Revision 1.3 1995/02/03 17:04:38 quinn - * *** empty log message *** - * - * Revision 1.2 1995/02/02 20:38:51 quinn - * Updates. - * - * Revision 1.1 1995/02/02 16:21:54 quinn - * First kick. - * + * $Id: odr_oct.c,v 1.17 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include +#include "odr-priv.h" /* * Top level octet string en/decoder. @@ -134,7 +86,7 @@ int odr_cstring(ODR o, char **p, int opt, const char *name) fprintf(o->print, "'%s'\n", *p); return 1; } - t = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); /* wrapper for octstring */ + t = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); /* wrapper for octstring */ if (o->direction == ODR_ENCODE) { t->buf = (unsigned char *) *p; @@ -155,3 +107,102 @@ int odr_cstring(ODR o, char **p, int opt, const char *name) } return 1; } + +/* + * iconv interface to octetstring. + */ +int odr_iconv_string(ODR o, char **p, int opt, const char *name) +{ + int cons = 0, res; + Odr_oct *t; + + if (o->error) + return 0; + if (o->t_class < 0) + { + o->t_class = ODR_UNIVERSAL; + o->t_tag = ODR_OCTETSTRING; + } + if ((res = ber_tag(o, p, o->t_class, o->t_tag, &cons, opt)) < 0) + return 0; + if (!res) + return opt; + if (o->direction == ODR_PRINT) + { + odr_prname(o, name); + fprintf(o->print, "'%s'\n", *p); + return 1; + } + t = (Odr_oct *)odr_malloc(o, sizeof(Odr_oct)); /* wrapper for octstring */ + if (o->direction == ODR_ENCODE) + { + t->buf = 0; +#if HAVE_ICONV_H + if (o->op->iconv_handle != (iconv_t)(-1)) + { + size_t inleft = strlen(*p); + char *inbuf = *p; + size_t outleft = 4 * inleft + 2; + char *outbuf = odr_malloc (o, outleft); + size_t ret; + + t->buf = outbuf; + + ret = iconv (o->op->iconv_handle, &inbuf, &inleft, + &outbuf, &outleft); + if (ret == (size_t)(-1)) + { + o->error = ODATA; + return 0; + } + t->size = t->len = outbuf - (char*) t->buf; + } +#endif + if (!t->buf) + { + t->buf = (unsigned char *) *p; + t->size = t->len = strlen(*p); + } + } + else + { + t->size= 0; + t->len = 0; + t->buf = 0; + } + if (!ber_octetstring(o, t, cons)) + return 0; + if (o->direction == ODR_DECODE) + { + *p = 0; +#if HAVE_ICONV_H + if (o->op->iconv_handle != (iconv_t)(-1)) + { + size_t inleft = t->len; + char *inbuf = t->buf; + size_t outleft = 4 * inleft + 2; + char *outbuf = odr_malloc (o, outleft); + size_t ret; + + *p = outbuf; + + ret = iconv (o->op->iconv_handle, &inbuf, &inleft, + &outbuf, &outleft); + if (ret == (size_t)(-1)) + { + o->error = ODATA; + return 0; + } + inleft = outbuf - (char*) *p; + + (*p)[inleft] = '\0'; /* null terminate it */ + } +#endif + if (!*p) + { + *p = (char *) t->buf; + *(*p + t->len) = '\0'; /* ber_octs reserves space for this */ + } + } + return 1; +} diff --git a/odr/odr_oid.c b/odr/odr_oid.c index 7e7e1b8..cbb968e 100644 --- a/odr/odr_oid.c +++ b/odr/odr_oid.c @@ -1,65 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_oid.c,v $ - * Revision 1.16 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.15 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.14 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.13 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.12 1995/09/29 17:12:25 quinn - * Smallish - * - * Revision 1.11 1995/09/27 15:03:00 quinn - * Modified function heads & prototypes. - * - * Revision 1.10 1995/05/29 08:11:44 quinn - * Moved oid from odr/asn to util. - * - * Revision 1.9 1995/05/16 08:50:57 quinn - * License, documentation, and memory fixes - * - * Revision 1.8 1995/03/17 10:17:55 quinn - * Added memory management. - * - * Revision 1.7 1995/03/08 12:12:29 quinn - * Added better error checking. - * - * Revision 1.6 1995/03/01 08:40:56 quinn - * Smallish changes. - * - * Revision 1.5 1995/02/10 18:57:26 quinn - * More in the way of error-checking. - * - * Revision 1.4 1995/02/10 15:55:29 quinn - * Bug fixes, mostly. - * - * Revision 1.3 1995/02/09 15:51:49 quinn - * Works better now. - * - * Revision 1.2 1995/02/07 14:13:46 quinn - * Bug fixes. - * - * Revision 1.1 1995/02/03 17:04:38 quinn - * Initial revision - * - * + * $Id: odr_oid.c,v 1.17 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" #include /* diff --git a/odr/odr_seq.c b/odr/odr_seq.c index 4f3fa3b..191b97e 100644 --- a/odr/odr_seq.c +++ b/odr/odr_seq.c @@ -1,102 +1,16 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_seq.c,v $ - * Revision 1.27 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.26 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.25 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.24 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.23 1998/03/20 14:45:01 adam - * Implemented odr_enum and odr_set_of. - * - * Revision 1.22 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.21 1997/11/24 11:33:56 adam - * Using function odr_nullval() instead of global ODR_NULLVAL when - * appropriate. - * - * Revision 1.20 1997/09/29 07:17:31 adam - * Added typecast to avoid warnings on MSVC. - * - * Revision 1.19 1997/06/23 10:31:11 adam - * Added RVDM's SEQUENCE OF patch again! - * - * Revision 1.18 1997/05/14 06:53:58 adam - * C++ support. - * - * Revision 1.17 1997/05/05 11:21:09 adam - * In handling of SEQUENCE OF: Counter set to zero when SEQUENCE - * OF isn't there at all. - * - * Revision 1.16 1995/09/29 17:12:26 quinn - * Smallish - * - * Revision 1.15 1995/09/27 15:03:00 quinn - * Modified function heads & prototypes. - * - * Revision 1.14 1995/08/15 11:16:39 quinn - * Fixed pretty-printers. - * - * Revision 1.13 1995/05/22 14:56:57 quinn - * Fixed problem in decoding empty sequence. - * - * Revision 1.12 1995/05/18 13:06:32 quinn - * Smallish. - * - * Revision 1.11 1995/05/17 08:41:54 quinn - * Small, hopefully insignificant change. - * - * Revision 1.10 1995/05/16 08:50:59 quinn - * License, documentation, and memory fixes - * - * Revision 1.9 1995/03/17 10:17:57 quinn - * Added memory management. - * - * Revision 1.8 1995/03/15 11:18:05 quinn - * Fixed serious bug in odr_cons - * - * Revision 1.7 1995/03/08 12:12:30 quinn - * Added better error checking. - * - * Revision 1.6 1995/02/10 15:55:29 quinn - * Bug fixes, mostly. - * - * Revision 1.5 1995/02/09 15:51:49 quinn - * Works better now. - * - * Revision 1.4 1995/02/07 17:53:00 quinn - * A damn mess, but now things work, I think. - * - * Revision 1.3 1995/02/07 14:13:46 quinn - * Bug fixes. - * - * Revision 1.2 1995/02/06 16:45:03 quinn - * Small mods. - * - * Revision 1.1 1995/02/02 16:21:54 quinn - * First kick. - * + * $Id: odr_seq.c,v 1.28 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int odr_sequence_begin(ODR o, void *p, int size, const char *name) { diff --git a/odr/odr_tag.c b/odr/odr_tag.c index 19459c7..288403b 100644 --- a/odr/odr_tag.c +++ b/odr/odr_tag.c @@ -1,48 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_tag.c,v $ - * Revision 1.11 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.10 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.9 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.8 1997/05/14 06:53:59 adam - * C++ support. - * - * Revision 1.7 1996/02/20 12:52:54 quinn - * Added odr_peektag - * - * Revision 1.6 1995/12/14 16:28:26 quinn - * More explain stuff. - * - * Revision 1.5 1995/09/29 17:12:27 quinn - * Smallish - * - * Revision 1.4 1995/09/27 15:03:00 quinn - * Modified function heads & prototypes. - * - * Revision 1.3 1995/05/16 08:51:00 quinn - * License, documentation, and memory fixes - * - * Revision 1.2 1995/03/08 12:12:31 quinn - * Added better error checking. - * - * Revision 1.1 1995/02/02 16:21:54 quinn - * First kick. - * + * $Id: odr_tag.c,v 1.12 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int odr_peektag(ODR o, int *zclass, int *tag, int *cons) { @@ -51,7 +18,7 @@ int odr_peektag(ODR o, int *zclass, int *tag, int *cons) o->error = OOTHER; return 0; } - if (o->stackp > -1 && !odr_constructed_more(o)) + if (o->op->stackp > -1 && !odr_constructed_more(o)) return 0; if (ber_dectag(o->bp, zclass, tag, cons) <= 0) { diff --git a/odr/odr_use.c b/odr/odr_use.c index 99141d6..972d5f7 100644 --- a/odr/odr_use.c +++ b/odr/odr_use.c @@ -1,49 +1,15 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Log: odr_use.c,v $ - * Revision 1.11 2000-02-29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.10 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.9 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.8 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.7 1995/09/29 17:12:27 quinn - * Smallish - * - * Revision 1.6 1995/09/27 15:03:00 quinn - * Modified function heads & prototypes. - * - * Revision 1.5 1995/08/10 08:54:47 quinn - * Added Explain. - * - * Revision 1.4 1995/06/16 13:16:12 quinn - * Fixed Defaultdiagformat. - * - * Revision 1.3 1995/05/16 08:51:00 quinn - * License, documentation, and memory fixes - * - * Revision 1.2 1995/02/09 15:51:50 quinn - * Works better now. - * - * Revision 1.1 1995/02/03 17:04:39 quinn - * Initial revision - * + * $Id: odr_use.c,v 1.12 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include +#include "odr-priv.h" int odr_external(ODR o, Odr_external **p, int opt, const char *name) { @@ -83,7 +49,7 @@ int odr_visiblestring(ODR o, char **p, int opt, const char *name) */ int odr_generalstring(ODR o, char **p, int opt, const char *name) { - return odr_implicit_tag(o, odr_cstring, p, ODR_UNIVERSAL, + return odr_implicit_tag(o, odr_iconv_string, p, ODR_UNIVERSAL, ODR_GENERALSTRING,opt, name); } diff --git a/odr/odr_util.c b/odr/odr_util.c index 71273f5..5f7d7e5 100644 --- a/odr/odr_util.c +++ b/odr/odr_util.c @@ -1,41 +1,8 @@ /* - * Copyright (c) 1995-2000, Index Data + * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Log: odr_util.c,v $ - * Revision 1.20 2001-09-24 21:51:55 adam - * New Z39.50 OID utilities: yaz_oidval_to_z3950oid, yaz_str_to_z3950oid - * and yaz_z3950oid_to_str. - * - * Revision 1.19 2000/02/29 13:44:55 adam - * Check for config.h (currently not generated). - * - * Revision 1.18 2000/01/31 13:15:21 adam - * Removed uses of assert(3). Cleanup of ODR. CCL parser update so - * that some characters are not surrounded by spaces in resulting term. - * ILL-code updates. - * - * Revision 1.17 1999/11/30 13:47:12 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.16 1999/04/20 09:56:48 adam - * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun). - * Modified all encoders/decoders to reflect this change. - * - * Revision 1.15 1999/01/08 11:23:29 adam - * Added const modifier to some of the BER/ODR encoding routines. - * - * Revision 1.14 1998/10/13 15:58:36 adam - * Minor fix in odr_getoidbystr_nmem. - * - * Revision 1.13 1998/02/11 11:53:34 adam - * Changed code so that it compiles as C++. - * - * Revision 1.12 1997/10/31 12:20:08 adam - * Improved memory debugging for xmalloc/nmem.c. References to NMEM - * instead of ODR in n ESPEC-1 handling in source d1_espec.c. - * Bug fix: missing fclose in data1_read_espec1. - * + * $Id: odr_util.c,v 1.21 2002-07-25 12:51:08 adam Exp $ */ #if HAVE_CONFIG_H #include @@ -44,7 +11,7 @@ #include #include #include -#include +#include "odr-priv.h" #include void odr_prname(ODR o, const char *name)