From 21ea17f766bb492a93154ec7b242653fa37dec91 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 8 Jan 1999 11:23:10 +0000 Subject: [PATCH] Added const modifier to some of the BER/ODR encoding routines. --- CHANGELOG | 4 ++++ LICENSE | 2 +- README | 4 ++-- comstack/tcpip.c | 20 +++++++------------- comstack/waislen.c | 11 ++++++++--- header.c | 9 ++++++--- include/odr.h | 15 +++++++++------ include/prt.h | 17 ++++++++++------- include/tcpip.h | 8 ++++++-- odr/ber_any.c | 11 +++++++---- odr/ber_bit.c | 7 +++++-- odr/ber_int.c | 15 +++++++++------ odr/ber_len.c | 11 +++++++---- odr/ber_oct.c | 10 +++++++--- odr/ber_tag.c | 11 +++++++---- odr/dumpber.c | 13 ++++++++----- odr/odr_enum.c | 8 +++++--- odr/odr_int.c | 8 +++++--- odr/odr_util.c | 9 ++++++--- 19 files changed, 119 insertions(+), 74 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7f27f4e..39246fa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ Possible compatibility problems with earlier versions marked with '*'. +* Added const modifier to buffer parameter for some ODR/BER encoding +routines: ber_dectag, ber_declen, odp_more_chunks, completeBER, +completeWAIS, odr_dumpBER. + Fixed bug in client.c which caused a crash when a scanResponse didn't contain positionOfTerm. diff --git a/LICENSE b/LICENSE index a530fc2..42fb75c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-1998 Index Data. + * Copyright (c) 1995-1999 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, diff --git a/README b/README index 2521a65..5409620 100644 --- a/README +++ b/README @@ -1,10 +1,10 @@ - * Copyright (C) 1995-1998, Index Data. + * Copyright (C) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss Compilation and installation for YAZ - $Id: README,v 1.23 1998-09-22 09:41:21 adam Exp $ + $Id: README,v 1.24 1999-01-08 11:23:12 adam Exp $ The primary output of the source here is the lib/libyaz.a library, which contains support functions for implementing the server or client diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 667accf..29960cd 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1998, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: tcpip.c,v $ - * Revision 1.25 1998-07-07 15:49:23 adam + * Revision 1.26 1999-01-08 11:23:14 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.25 1998/07/07 15:49:23 adam * Added braces to avoid warning. * * Revision 1.24 1998/06/29 07:59:17 adam @@ -159,9 +162,8 @@ #include #include -/* Chas added the following 2, so we get the definition of completeBER */ +/* Chas added the following, so we get the definition of completeBER */ #include -#include int tcpip_close(COMSTACK h); int tcpip_put(COMSTACK h, char *buf, int size); @@ -178,14 +180,6 @@ COMSTACK tcpip_accept(COMSTACK h); char *tcpip_addrstr(COMSTACK h); void *tcpip_straddr(COMSTACK h, const char *str); -/* - * Determine length/completeness of incoming packages - */ -/* Chas: Removed the definition of completeBERfrom here, use the one in the */ -/* include directory as that as the extern "C" around it */ -/*int completeBER(unsigned char *buf, int len); */ /* from the ODR module */ -int completeWAIS(unsigned char *buf, int len); /* from waislen.c */ - #undef TRACE_TCPIP #ifdef TRACE_TCPIP #define TRC(x) x @@ -201,7 +195,7 @@ typedef struct tcpip_state int written; /* -1 if we aren't writing */ int towrite; /* to verify against user input */ - int (*complete)(unsigned char *buf, int len); /* length/completeness */ + int (*complete)(const unsigned char *buf, int len); /* length/comple. */ struct sockaddr_in addr; /* returned by cs_straddr */ char buf[128]; /* returned by cs_addrstr */ } tcpip_state; diff --git a/comstack/waislen.c b/comstack/waislen.c index aabe69c..8a91cf3 100644 --- a/comstack/waislen.c +++ b/comstack/waislen.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: waislen.c,v $ - * Revision 1.3 1996-02-29 14:23:13 adam + * Revision 1.4 1999-01-08 11:23:15 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.3 1996/02/29 14:23:13 adam * Bug fix. * * Revision 1.2 1996/02/26 18:34:44 adam @@ -17,10 +20,12 @@ */ #include +#include +#include /* * Return length of WAIS package or 0 */ -int completeWAIS(unsigned char *buf, int len) +int completeWAIS(const unsigned char *buf, int len) { int i, lval = 0; diff --git a/header.c b/header.c index 206e856..82fbbcb 100644 --- a/header.c +++ b/header.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1998, Index Data. + * Copyright (c) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss - * + 9 * $Log: header.c,v $ - * Revision 1.6 1998-01-05 09:03:37 adam + * Revision 1.7 1999-01-08 11:23:13 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.6 1998/01/05 09:03:37 adam * 1998. * * Revision 1.5 1997/07/02 14:12:52 adam diff --git a/include/odr.h b/include/odr.h index bd0356f..2e15659 100644 --- a/include/odr.h +++ b/include/odr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-1998, Index Data. + * Copyright (c) 1995-1999, 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, @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: odr.h,v $ - * Revision 1.26 1998-03-20 17:29:20 adam + * Revision 1.27 1999-01-08 11:23:17 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.26 1998/03/20 17:29:20 adam * Include of odr_use.h in odr.h. Added prototype for odr_enum. * * Revision 1.25 1998/02/11 11:53:33 adam @@ -237,11 +240,11 @@ typedef int Odr_oid; /* terminate by -1 */ typedef struct odr_constack { - unsigned char *base; /* starting point of data */ + const unsigned char *base; /* starting point of data */ int base_offset; int len; /* length of data, if known, else -1 (decoding only) */ - unsigned char *lenb; /* where to encode length */ + const unsigned char *lenb; /* where to encode length */ int len_offset; int lenlen; /* length of length-field */ } odr_constack; @@ -271,9 +274,9 @@ typedef struct odr int direction; /* the direction of this stream */ int error; /* current error state (0==OK) */ - unsigned char *buf; /* for encoding or decoding */ + const unsigned char *buf; /* for encoding or decoding */ int buflen; /* size of buffer for encoding, len for decoding */ - unsigned char *bp; /* position in buffer */ + const unsigned char *bp; /* position in buffer */ int left; /* bytes remaining in buffer */ odr_ecblock ecb; /* memory control block */ diff --git a/include/prt.h b/include/prt.h index ed79b41..ac021d1 100644 --- a/include/prt.h +++ b/include/prt.h @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1998, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: prt.h,v $ - * Revision 1.24 1998-03-20 17:29:20 adam + * Revision 1.25 1999-01-08 11:23:18 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.24 1998/03/20 17:29:20 adam * Include of odr_use.h in odr.h. Added prototype for odr_enum. * * Revision 1.23 1998/03/20 14:45:27 adam @@ -32,13 +35,13 @@ extern "C" { YAZ_EXPORT int ber_boolean(ODR o, int *val); YAZ_EXPORT int ber_tag(ODR o, void *p, int zclass, int tag, int *constructed, int opt); YAZ_EXPORT int ber_enctag(ODR o, int zclass, int tag, int constructed); -YAZ_EXPORT int ber_dectag(unsigned char *buf, int *zclass, int *tag, int *constructed); +YAZ_EXPORT int ber_dectag(const unsigned char *buf, int *zclass, int *tag, int *constructed); YAZ_EXPORT int odr_bool(ODR o, int **p, int opt); YAZ_EXPORT int odr_integer(ODR o, int **p, int opt); YAZ_EXPORT int odr_enum(ODR o, int **p, int opt); YAZ_EXPORT int odr_implicit_settag(ODR o, int zclass, int tag); YAZ_EXPORT int ber_enclen(ODR o, int len, int lenlen, int exact); -YAZ_EXPORT int ber_declen(unsigned char *buf, int *len); +YAZ_EXPORT int ber_declen(const unsigned char *buf, int *len); YAZ_EXPORT char *odr_indent(ODR o); YAZ_EXPORT int ber_null(ODR o); YAZ_EXPORT int odr_null(ODR o, Odr_null **p, int opt); @@ -51,7 +54,7 @@ YAZ_EXPORT int odr_sequence_end(ODR o); YAZ_EXPORT int odr_set_end(ODR o); YAZ_EXPORT int ber_octetstring(ODR o, Odr_oct *p, int cons); YAZ_EXPORT int odr_octetstring(ODR o, Odr_oct **p, int opt); -YAZ_EXPORT int odp_more_chunks(ODR o, unsigned char *base, int len); +YAZ_EXPORT int odp_more_chunks(ODR o, const unsigned char *base, int len); YAZ_EXPORT int odr_constructed_more(ODR o); YAZ_EXPORT int odr_bitstring(ODR o, Odr_bitmask **p, int opt); YAZ_EXPORT int ber_bitstring(ODR o, Odr_bitmask *p, int cons); @@ -64,7 +67,7 @@ YAZ_EXPORT int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num); YAZ_EXPORT int odr_set_of(ODR o, Odr_fun type, void *p, int *num); YAZ_EXPORT int odr_any(ODR o, Odr_any **p, int opt); YAZ_EXPORT int ber_any(ODR o, Odr_any **p); -YAZ_EXPORT int completeBER(unsigned char *buf, int len); +YAZ_EXPORT int completeBER(const unsigned char *buf, int len); YAZ_EXPORT void odr_begin(ODR o); YAZ_EXPORT void odr_end(ODR o); YAZ_EXPORT Odr_oid *odr_oiddup(ODR odr, Odr_oid *o); @@ -72,7 +75,7 @@ YAZ_EXPORT Odr_oid *odr_oiddup_nmem(NMEM nmem, Odr_oid *o); YAZ_EXPORT int odr_grow_block(odr_ecblock *b, int min_bytes); YAZ_EXPORT int odr_write(ODR o, unsigned char *buf, int bytes); YAZ_EXPORT int odr_seek(ODR o, int whence, int offset); -YAZ_EXPORT int odr_dumpBER(FILE *f, char *buf, int len); +YAZ_EXPORT int odr_dumpBER(FILE *f, const char *buf, int len); YAZ_EXPORT void odr_choice_bias(ODR o, int what); YAZ_EXPORT void odr_choice_enable_bias(ODR o, int mode); YAZ_EXPORT int odr_total(ODR o); diff --git a/include/tcpip.h b/include/tcpip.h index 1c30c3f..c1bd7ef 100644 --- a/include/tcpip.h +++ b/include/tcpip.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1999, 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, @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: tcpip.h,v $ - * Revision 1.11 1998-06-22 11:32:38 adam + * Revision 1.12 1999-01-08 11:23:19 adam + * Added const modifier to some of the BER/ODR encoding routines. + * + * Revision 1.11 1998/06/22 11:32:38 adam * Added 'conditional cs_listen' feature. * * Revision 1.10 1998/05/18 13:07:01 adam @@ -83,6 +86,7 @@ extern "C" { #endif +YAZ_EXPORT int completeWAIS(const unsigned char *buf, int len); YAZ_EXPORT struct sockaddr_in *tcpip_strtoaddr(const char *str); YAZ_EXPORT COMSTACK tcpip_type(int s, int blocking, int protocol); diff --git a/odr/ber_any.c b/odr/ber_any.c index 3c00d47..bebfbb3 100644 --- a/odr/ber_any.c +++ b/odr/ber_any.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_any.c,v $ - * Revision 1.14 1998-02-11 11:53:34 adam + * 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 @@ -80,10 +83,10 @@ int ber_any(ODR o, Odr_any **p) /* * Return length of BER-package or 0. */ -int completeBER(unsigned char *buf, int len) +int completeBER(const unsigned char *buf, int len) { int res, ll, zclass, tag, cons; - unsigned char *b = buf; + const unsigned char *b = buf; if (!len) return 0; diff --git a/odr/ber_bit.c b/odr/ber_bit.c index 6f9dcdc..d95336b 100644 --- a/odr/ber_bit.c +++ b/odr/ber_bit.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_bit.c,v $ - * Revision 1.7 1995-09-29 17:12:16 quinn + * 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 @@ -34,7 +37,7 @@ int ber_bitstring(ODR o, Odr_bitmask *p, int cons) { int res, len; - unsigned char *base; + const unsigned char *base; switch (o->direction) { diff --git a/odr/ber_int.c b/odr/ber_int.c index 8b5ea7d..6d0da35 100644 --- a/odr/ber_int.c +++ b/odr/ber_int.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_int.c,v $ - * Revision 1.12 1996-07-06 19:58:33 quinn + * 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 @@ -50,10 +53,9 @@ #include #include -#include static int ber_encinteger(ODR o, int val); -static int ber_decinteger(unsigned char *buf, int *val); +static int ber_decinteger(const unsigned char *buf, int *val); int ber_integer(ODR o, int *val) { @@ -112,9 +114,10 @@ int ber_encinteger(ODR o, int val) /* * Returns: Number of bytes read or 0 if no match, -1 if error. */ -int ber_decinteger(unsigned char *buf, int *val) +int ber_decinteger(const unsigned char *buf, int *val) { - unsigned char *b = buf, fill; + const unsigned char *b = buf; + unsigned char fill; int res, len, remains; union { int i; unsigned char c[sizeof(int)]; } tmp; diff --git a/odr/ber_len.c b/odr/ber_len.c index d9b43ab..e772e73 100644 --- a/odr/ber_len.c +++ b/odr/ber_len.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1995, Index Data. + * Copyright (C) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_len.c,v $ - * Revision 1.6 1995-09-29 17:12:17 quinn + * 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 @@ -91,9 +94,9 @@ int ber_enclen(ODR o, int len, int lenlen, int exact) * len = -1 indefinite. * len >= 0 Length. */ -int ber_declen(unsigned char *buf, int *len) +int ber_declen(const unsigned char *buf, int *len) { - unsigned char *b = buf; + const unsigned char *b = buf; int n; if (*b == 0X80) /* Indefinite */ diff --git a/odr/ber_oct.c b/odr/ber_oct.c index e7c91a8..86c4e5a 100644 --- a/odr/ber_oct.c +++ b/odr/ber_oct.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_oct.c,v $ - * Revision 1.11 1998-02-11 11:53:34 adam + * 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 @@ -45,7 +48,8 @@ int ber_octetstring(ODR o, Odr_oct *p, int cons) { int res, len; - unsigned char *base, *c; + const unsigned char *base; + unsigned char *c; switch (o->direction) { diff --git a/odr/ber_tag.c b/odr/ber_tag.c index 8dc5e17..dcfd8ae 100644 --- a/odr/ber_tag.c +++ b/odr/ber_tag.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1997, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_tag.c,v $ - * Revision 1.18 1998-02-11 11:53:34 adam + * 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 @@ -199,9 +202,9 @@ int ber_enctag(ODR o, int zclass, int tag, int constructed) /* ber_dectag * Decode BER identifier octets. Return number of bytes read or -1 for error. */ -int ber_dectag(unsigned char *buf, int *zclass, int *tag, int *constructed) +int ber_dectag(const unsigned char *buf, int *zclass, int *tag, int *constructed) { - unsigned char *b = buf; + const unsigned char *b = buf; *zclass = *b >> 6; *constructed = (*b >> 5) & 0X01; diff --git a/odr/dumpber.c b/odr/dumpber.c index 1af624a..62a1735 100644 --- a/odr/dumpber.c +++ b/odr/dumpber.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: dumpber.c,v $ - * Revision 1.9 1998-01-14 09:53:26 quinn + * 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 @@ -37,10 +40,10 @@ #include #include -static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) +static int do_dumpBER(FILE *f, const char *buf, int len, int level, int offset) { int res, ll, zclass, tag, cons, lenlen, taglen; - char *b = buf, *bp = buf; + const char *b = buf, *bp = buf; if (!len) return 0; @@ -133,7 +136,7 @@ static int do_dumpBER(FILE *f, char *buf, int len, int level, int offset) return b - buf; } -int odr_dumpBER(FILE *f, char *buf, int len) +int odr_dumpBER(FILE *f, const char *buf, int len) { return do_dumpBER(f, buf, len, 0, 0); } diff --git a/odr/odr_enum.c b/odr/odr_enum.c index 078593d..7c4f900 100644 --- a/odr/odr_enum.c +++ b/odr/odr_enum.c @@ -1,16 +1,18 @@ /* - * Copyright (c) 1995-1998, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: odr_enum.c,v $ - * Revision 1.1 1998-03-20 14:45:01 adam + * 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. * */ #include -#include /* * Top level enum en/decoder. diff --git a/odr/odr_int.c b/odr/odr_int.c index 8cfab5f..a7d1eef 100644 --- a/odr/odr_int.c +++ b/odr/odr_int.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: odr_int.c,v $ - * Revision 1.11 1998-02-11 11:53:34 adam + * 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 @@ -40,7 +43,6 @@ */ #include -#include /* * Top level integer en/decoder. diff --git a/odr/odr_util.c b/odr/odr_util.c index e8856e6..bb0194b 100644 --- a/odr/odr_util.c +++ b/odr/odr_util.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1995-1998, Index Data + * Copyright (c) 1995-1999, Index Data * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: odr_util.c,v $ - * Revision 1.14 1998-10-13 15:58:36 adam + * 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 @@ -35,7 +38,7 @@ char *odr_indent(ODR o) return buf; } -int odp_more_chunks(ODR o, unsigned char *base, int len) +int odp_more_chunks(ODR o, const unsigned char *base, int len) { if (!len) return 0; -- 1.7.10.4