From 019eca69c2a438db0aea7b8760685c618cb5f552 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 5 Oct 2007 16:46:55 +0000 Subject: [PATCH] Implemented function cs_create_host. Implemented function cs_create_host parses a YAZ host component. This is to be used for HTTP Connect tunneling (bug #1752). --- include/yaz/comstack.h | 4 ++- src/comstack.c | 74 ++++++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/include/yaz/comstack.h b/include/yaz/comstack.h index f19d54d..3307a91 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.27 2007-04-12 13:52:57 adam Exp $ */ +/* $Id: comstack.h,v 1.28 2007-10-05 16:46:55 adam Exp $ */ /** * \file comstack.h @@ -133,6 +133,8 @@ 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 cs_complete_http(const char *buf, int len); +YAZ_EXPORT int cs_parse_host(const char *uri, const char **host, + CS_TYPE *t, enum oid_proto *proto); /* * error management. diff --git a/src/comstack.c b/src/comstack.c index db3b002..6934ea6 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.18 2007-01-11 10:30:41 adam Exp $ + * $Id: comstack.c,v 1.19 2007-10-05 16:46:55 adam Exp $ */ /** @@ -74,62 +74,74 @@ void cs_get_host_args(const char *type_and_host, const char **args) } } -COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp) +int cs_parse_host(const char *uri, const char **host, + CS_TYPE *t, enum oid_proto *proto) { - enum oid_proto proto = PROTO_Z3950; - const char *host = 0; - COMSTACK cs; - CS_TYPE t; - - if (strncmp (type_and_host, "tcp:", 4) == 0) + if (strncmp (uri, "tcp:", 4) == 0) { - t = tcpip_type; - host = type_and_host + 4; + *t = tcpip_type; + *host = uri + 4; + *proto = PROTO_Z3950; } - else if (strncmp (type_and_host, "ssl:", 4) == 0) + else if (strncmp (uri, "ssl:", 4) == 0) { #if HAVE_OPENSSL_SSL_H - t = ssl_type; - host = type_and_host + 4; + *t = ssl_type; + *host = uri + 4; + *proto = PROTO_Z3950; #else return 0; #endif } - else if (strncmp (type_and_host, "unix:", 5) == 0) + else if (strncmp (uri, "unix:", 5) == 0) { #ifndef WIN32 - t = unix_type; - host = type_and_host + 5; + *t = unix_type; + *host = uri + 5; + *proto = PROTO_Z3950; #else return 0; #endif } - else if (strncmp(type_and_host, "http:", 5) == 0) + else if (strncmp(uri, "http:", 5) == 0) { - t = tcpip_type; - host = type_and_host + 5; - while (host[0] == '/') - host++; - proto = PROTO_HTTP; + *t = tcpip_type; + *host = uri + 5; + while (**host == '/') + (*host)++; + *proto = PROTO_HTTP; } - else if (strncmp(type_and_host, "https:", 6) == 0) + else if (strncmp(uri, "https:", 6) == 0) { #if HAVE_OPENSSL_SSL_H - t = ssl_type; - host = type_and_host + 6; - while (host[0] == '/') - host++; - proto = PROTO_HTTP; + *t = ssl_type; + *host = uri + 6; + while (**host == '/') + (*host)++; + *proto = PROTO_HTTP; #else return 0; #endif } else { - t = tcpip_type; - host = type_and_host; + *proto = PROTO_Z3950; + *t = tcpip_type; + *host = uri; } - cs = cs_create (t, blocking, proto); + return 1; +} + +COMSTACK cs_create_host(const char *vhost, int blocking, void **vp) +{ + enum oid_proto proto = PROTO_Z3950; + const char *host = 0; + COMSTACK cs; + CS_TYPE t; + + cs_parse_host(vhost, &host, &t, &proto); + + cs = cs_create(t, blocking, proto); if (!cs) return 0; -- 1.7.10.4