From 377e50914cd78d52e77032a3eaf8972f23b4e7b9 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 9 Oct 2007 06:00:55 +0000 Subject: [PATCH] Revised types for functions cs_complete_auto, etc. The functions cs_complete_auto, cs_complete_auto_head takes 'const char *' as buffer rather than 'const unsigned char *'. This makes some casts unnecessary. This also fixes tst_comstack which used to test cs_complete_http. This function, howver is no longer public, so cs_complete_auto is used instead. --- include/yaz/comstack.h | 7 ++-- include/yaz/tcpip.h | 3 +- include/yaz/unix.h | 3 +- src/comstack.c | 12 +++---- src/tcpip.c | 11 +++--- src/unix.c | 9 +++-- src/waislen.c | 5 ++- test/tst_comstack.c | 92 ++++++++++++++++++++++++------------------------ 8 files changed, 69 insertions(+), 73 deletions(-) diff --git a/include/yaz/comstack.h b/include/yaz/comstack.h index bbfbe52..c78d6dc 100644 --- a/include/yaz/comstack.h +++ b/include/yaz/comstack.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: comstack.h,v 1.29 2007-10-07 08:53:26 adam Exp $ */ +/* $Id: comstack.h,v 1.30 2007-10-09 06:00:55 adam Exp $ */ /** * \file comstack.h @@ -126,13 +126,14 @@ YAZ_EXPORT const char *cs_errmsg(int n); YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp); YAZ_EXPORT void cs_get_host_args(const char *type_and_host, const char **args); -YAZ_EXPORT int cs_complete_auto_head(const unsigned char *buf, int len); -YAZ_EXPORT int cs_complete_auto(const unsigned char *buf, int len); +YAZ_EXPORT int cs_complete_auto_head(const char *buf, int len); +YAZ_EXPORT int cs_complete_auto(const char *buf, int len); YAZ_EXPORT void *cs_get_ssl(COMSTACK cs); YAZ_EXPORT int cs_set_ssl_ctx(COMSTACK cs, void *ctx); YAZ_EXPORT int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname); YAZ_EXPORT int cs_get_peer_certificate_x509(COMSTACK cs, char **buf, int *len); YAZ_EXPORT void cs_set_max_recv_bytes(COMSTACK cs, int max_recv_bytes); +YAZ_EXPORT int completeWAIS(const char *buf, int len); /* * error management. diff --git a/include/yaz/tcpip.h b/include/yaz/tcpip.h index 8269d8c..0b5d3a2 100644 --- a/include/yaz/tcpip.h +++ b/include/yaz/tcpip.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: tcpip.h,v 1.13 2007-10-07 08:53:26 adam Exp $ */ +/* $Id: tcpip.h,v 1.14 2007-10-09 06:00:55 adam Exp $ */ /** * \file tcpip.h @@ -38,7 +38,6 @@ YAZ_BEGIN_CDECL -YAZ_EXPORT int completeWAIS(const unsigned char *buf, int len); YAZ_EXPORT COMSTACK tcpip_type(int s, int flags, int protocol, void *vp); YAZ_EXPORT COMSTACK ssl_type(int s, int flags, int protocol, void *vp); YAZ_EXPORT COMSTACK yaz_tcpip_create(int s, int flags, int protocol, diff --git a/include/yaz/unix.h b/include/yaz/unix.h index 8c60ac8..53ea488 100644 --- a/include/yaz/unix.h +++ b/include/yaz/unix.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: unix.h,v 1.9 2007-04-12 13:52:57 adam Exp $ */ +/* $Id: unix.h,v 1.10 2007-10-09 06:00:55 adam Exp $ */ /** * \file unix.h @@ -40,7 +40,6 @@ YAZ_BEGIN_CDECL -YAZ_EXPORT int completeWAIS(const unsigned char *buf, int len); YAZ_EXPORT struct sockaddr_un *unix_strtoaddr(const char *str); YAZ_EXPORT COMSTACK unix_type(int s, int flags, int protocol, void *vp); diff --git a/src/comstack.c b/src/comstack.c index 62978da..896127b 100644 --- a/src/comstack.c +++ b/src/comstack.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: comstack.c,v 1.20 2007-10-07 08:53:26 adam Exp $ + * $Id: comstack.c,v 1.21 2007-10-09 06:00:56 adam Exp $ */ /** @@ -348,25 +348,25 @@ static int cs_complete_http(const char *buf, int len, int head_only) return 0; } -static int cs_complete_auto_x(const unsigned char *buf, int len, int head_only) +static int cs_complete_auto_x(const char *buf, int len, int head_only) { if (len > 5 && buf[0] >= 0x20 && buf[0] < 0x7f && buf[1] >= 0x20 && buf[1] < 0x7f && buf[2] >= 0x20 && buf[2] < 0x7f) { - int r = cs_complete_http((const char *) buf, len, head_only); + int r = cs_complete_http(buf, len, head_only); return r; } - return completeBER(buf, len); + return completeBER((const unsigned char *) buf, len); } -int cs_complete_auto(const unsigned char *buf, int len) +int cs_complete_auto(const char *buf, int len) { return cs_complete_auto_x(buf, len, 0); } -int cs_complete_auto_head(const unsigned char *buf, int len) +int cs_complete_auto_head(const char *buf, int len) { return cs_complete_auto_x(buf, len, 1); } diff --git a/src/tcpip.c b/src/tcpip.c index b1f9fa9..2ef9dc2 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.35 2007-10-07 08:53:26 adam Exp $ + * $Id: tcpip.c,v 1.36 2007-10-09 06:00:56 adam Exp $ */ /** * \file tcpip.c @@ -104,7 +104,7 @@ typedef struct tcpip_state int written; /* -1 if we aren't writing */ int towrite; /* to verify against user input */ - int (*complete)(const unsigned char *buf, int len); /* length/comple. */ + int (*complete)(const char *buf, int len); /* length/complete. */ #if HAVE_GETADDRINFO struct addrinfo *ai; #else @@ -409,8 +409,7 @@ int tcpip_more(COMSTACK h) { tcpip_state *sp = (tcpip_state *)h->cprivate; - return sp->altlen && (*sp->complete)((unsigned char *) sp->altbuf, - sp->altlen); + return sp->altlen && (*sp->complete)(sp->altbuf, sp->altlen); } /* @@ -895,7 +894,7 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) sp->altsize = tmpi; } h->io_pending = 0; - while (!(berlen = (*sp->complete)((unsigned char *)*buf, hasread))) + while (!(berlen = (*sp->complete)(*buf, hasread))) { if (!*bufsize) { @@ -1026,7 +1025,7 @@ int ssl_get(COMSTACK h, char **buf, int *bufsize) sp->altsize = tmpi; } h->io_pending = 0; - while (!(berlen = (*sp->complete)((unsigned char *)*buf, hasread))) + while (!(berlen = (*sp->complete)(*buf, hasread))) { if (!*bufsize) { diff --git a/src/unix.c b/src/unix.c index 6aebb25..73bd7c5 100644 --- a/src/unix.c +++ b/src/unix.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: unix.c,v 1.19 2007-06-05 05:42:07 adam Exp $ + * $Id: unix.c,v 1.20 2007-10-09 06:00:56 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ /** @@ -90,7 +90,7 @@ typedef struct unix_state int written; /* -1 if we aren't writing */ int towrite; /* to verify against user input */ - int (*complete)(const unsigned char *buf, int len); /* length/comple. */ + int (*complete)(const char *buf, int len); /* length/complete. */ struct sockaddr_un addr; /* returned by cs_straddr */ int uid; int gid; @@ -309,8 +309,7 @@ static int unix_more(COMSTACK h) { unix_state *sp = (unix_state *)h->cprivate; - return sp->altlen && (*sp->complete)((unsigned char *) sp->altbuf, - sp->altlen); + return sp->altlen && (*sp->complete)(sp->altbuf, sp->altlen); } /* @@ -575,7 +574,7 @@ static int unix_get(COMSTACK h, char **buf, int *bufsize) sp->altsize = tmpi; } h->io_pending = 0; - while (!(berlen = (*sp->complete)((unsigned char *)*buf, hasread))) + while (!(berlen = (*sp->complete)(*buf, hasread))) { if (!*bufsize) { diff --git a/src/waislen.c b/src/waislen.c index e065c65..fc9a9c7 100644 --- a/src/waislen.c +++ b/src/waislen.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: waislen.c,v 1.5 2007-01-03 08:42:15 adam Exp $ + * $Id: waislen.c,v 1.6 2007-10-09 06:00:56 adam Exp $ */ /** * \file waislen.c @@ -11,11 +11,10 @@ #include #include -#include /* * Return length of WAIS package or 0 */ -int completeWAIS(const unsigned char *buf, int len) +int completeWAIS(const char *buf, int len) { int i, lval = 0; diff --git a/test/tst_comstack.c b/test/tst_comstack.c index c2e2597..4c2ed58 100644 --- a/test/tst_comstack.c +++ b/test/tst_comstack.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: tst_comstack.c,v 1.1 2007-01-11 10:30:41 adam Exp $ + * $Id: tst_comstack.c,v 1.2 2007-10-09 06:00:56 adam Exp $ */ #include @@ -21,12 +21,12 @@ static void tst_http_request(void) "\r\n" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 16), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 17), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 18), 18); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 19), 18); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 16), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 17), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 18), 18); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 19), 18); } { /* one header, no content */ @@ -37,11 +37,11 @@ static void tst_http_request(void) "\r\n" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 34), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 35), 35); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 36), 35); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 34), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 35), 35); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 36), 35); } { /* one content-length header, length 0 */ @@ -52,11 +52,11 @@ static void tst_http_request(void) "\r\n" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 35), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 37), 37); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 38), 37); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 35), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 37), 37); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 38), 37); } { /* one content-length header, length 5 */ @@ -68,11 +68,11 @@ static void tst_http_request(void) "ABCDE" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 41), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 42), 42); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 43), 42); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 42), 42); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 43), 42); } { /* LF only in GET, one content-length header, length 5 */ @@ -84,11 +84,11 @@ static void tst_http_request(void) "ABCDE" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 40), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 41), 41); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 42), 41); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 41); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 42), 41); } { /* LF only in all places, one content-length header, length 5 */ @@ -100,11 +100,11 @@ static void tst_http_request(void) "ABCDE" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 38), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 39), 39); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 40), 39); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 38), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 39), 39); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 39); } { @@ -116,8 +116,8 @@ static void tst_http_request(void) "\r\n" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 45), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 46), 46); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 45), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 46), 46); } { @@ -132,8 +132,8 @@ static void tst_http_request(void) "0\r\n\r\n" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 58), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 59), 59); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 58), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 59), 59); } { @@ -150,8 +150,8 @@ static void tst_http_request(void) "0\r\n\r\n" "GET / HTTP/1.0\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 64), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 65), 65); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 64), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 65), 65); } } @@ -165,9 +165,9 @@ static void tst_http_response(void) "\r\n" "HTTP/1.1 200 OK\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 24), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 24), 0); } { /* response, content */ @@ -179,11 +179,11 @@ static void tst_http_response(void) "12" "HTTP/1.1 200 OK\r\n"; - YAZ_CHECK_EQ(cs_complete_http(http_buf, 1), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 2), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 39), 0); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 40), 40); - YAZ_CHECK_EQ(cs_complete_http(http_buf, 41), 40); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 39), 0); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 40); + YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 40); } } -- 1.7.10.4