From 4ca818ec201c9dcf5461e419002c95fd2eac620e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 21 Feb 2003 12:08:57 +0000 Subject: [PATCH] Z_GDU definitions in zgdu.h. Renamed PROTO_SRW to PROTO_HTTP. --- comstack/comstack.c | 79 +++++++++++++++++++++++++++++++++++++++++++++-- comstack/tcpip.c | 10 +++--- comstack/unix.c | 7 ++--- include/yaz/Makefile.am | 4 +-- include/yaz/comstack.h | 7 +++-- include/yaz/oid.h | 4 +-- include/yaz/proto.h | 48 ++-------------------------- include/yaz/zgdu.h | 59 +++++++++++++++++++++++++++++++++++ odr/ber_any.c | 44 +------------------------- server/eventl.c | 4 +-- server/seshigh.c | 4 +-- zutil/zgdu.c | 6 ++-- zutil/zoom-c.c | 12 +++---- 13 files changed, 167 insertions(+), 121 deletions(-) create mode 100644 include/yaz/zgdu.h diff --git a/comstack/comstack.c b/comstack/comstack.c index 07903eb..a9d73bd 100644 --- a/comstack/comstack.c +++ b/comstack/comstack.c @@ -2,13 +2,16 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: comstack.c,v 1.11 2003-02-14 18:49:23 adam Exp $ + * $Id: comstack.c,v 1.12 2003-02-21 12:08:57 adam Exp $ */ #include +#include + #include #include #include +#include static const char *cs_errlist[] = { @@ -35,6 +38,7 @@ const char *cs_strerror(COMSTACK h) COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp) { + enum oid_proto proto = PROTO_Z3950; const char *host = 0; COMSTACK cs; CS_TYPE t; @@ -62,13 +66,33 @@ COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp) return 0; #endif } + else if (strncmp(type_and_host, "http:", 5) == 0) + { + t = tcpip_type; + host = type_and_host + 5; + if (host[0] == '/' && host[1] == '/') + host = host + 2; + proto = PROTO_HTTP; + } + else if (strncmp(type_and_host, "https:", 6) == 0) + { +#if HAVE_OPENSSL_SSL_H + t = ssl_type; + host = type_and_host + 6; + if (host[0] == '/' && host[1] == '/') + host = host + 2; +#else + return 0; +#endif + proto = PROTO_HTTP; + } else { t = tcpip_type; host = type_and_host; - + } - cs = cs_create (t, blocking, PROTO_Z3950); + cs = cs_create (t, blocking, proto); if (!cs) return 0; @@ -84,3 +108,52 @@ int cs_look (COMSTACK cs) { return cs->event; } + +int cs_complete_auto(const unsigned char *buf, int len) +{ + if (!len) + return 0; + if (!buf[0] && !buf[1]) + return 0; + if (len > 5 && buf[0] >= 0x20 && buf[0] < 0x7f + && buf[1] >= 0x20 && buf[1] < 0x7f + && buf[2] >= 0x20 && buf[2] < 0x7f) + { + /* deal with HTTP request/response */ + int i = 2, content_len = 0; + + while (i <= len-4) + { + if (buf[i] == '\r' && buf[i+1] == '\n') + { + i += 2; + if (buf[i] == '\r' && buf[i+1] == '\n') + { + /* i += 2 seems not to work with GCC -O2 .. + so i+2 is used instead .. */ + if (len >= (i+2)+ content_len) + return (i+2)+ content_len; + break; + } + if (i < len-18) + { + if (!memcmp(buf+i, "Content-Length:", 15)) + { + i+= 15; + if (buf[i] == ' ') + i++; + content_len = 0; + while (i <= len-4 && isdigit(buf[i])) + content_len = content_len*10 + (buf[i++] - '0'); + if (content_len < 0) /* prevent negative offsets */ + content_len = 0; + } + } + } + else + i++; + } + return 0; + } + return completeBER(buf, len); +} diff --git a/comstack/tcpip.c b/comstack/tcpip.c index dac1d67..b1f4f73 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.54 2003-02-20 15:10:24 adam Exp $ + * $Id: tcpip.c,v 1.55 2003-02-21 12:08:57 adam Exp $ */ #include @@ -10,8 +10,8 @@ #include #ifdef WIN32 -#include #else +#include #endif #include @@ -25,15 +25,13 @@ #include #include #include +#include #ifdef WIN32 #else #include #endif -/* Chas added the following, so we get the definition of completeBER */ -#include - static int tcpip_close(COMSTACK h); static int tcpip_put(COMSTACK h, char *buf, int size); static int tcpip_get(COMSTACK h, char **buf, int *bufsize); @@ -184,7 +182,7 @@ COMSTACK tcpip_type(int s, int blocking, int protocol, void *vp) if (protocol == PROTO_WAIS) state->complete = completeWAIS; else - state->complete = completeBER; + state->complete = cs_complete_auto; p->timeout = COMSTACK_DEFAULT_TIMEOUT; TRC(fprintf(stderr, "Created new TCPIP comstack\n")); diff --git a/comstack/unix.c b/comstack/unix.c index 908ab7e..bfd6de1 100644 --- a/comstack/unix.c +++ b/comstack/unix.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: unix.c,v 1.9 2003-01-06 08:20:27 adam Exp $ + * $Id: unix.c,v 1.10 2003-02-21 12:08:58 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ #ifndef WIN32 @@ -23,9 +23,6 @@ #include #include -/* Chas added the following, so we get the definition of completeBER */ -#include - #ifndef YAZ_SOCKLEN_T #define YAZ_SOCKLEN_T int #endif @@ -140,7 +137,7 @@ COMSTACK unix_type(int s, int blocking, int protocol, void *vp) if (protocol == PROTO_WAIS) state->complete = completeWAIS; else - state->complete = completeBER; + state->complete = cs_complete_auto; p->timeout = COMSTACK_DEFAULT_TIMEOUT; TRC(fprintf(stderr, "Created new UNIX comstack\n")); diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index db28269..7529eac 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.20 2003-02-12 15:06:43 adam Exp $ +## $Id: Makefile.am,v 1.21 2003-02-21 12:08:58 adam Exp $ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ diagbib1.h sortspec.h log.h logrpn.h marcdisp.h nmem.h odr.h oid.h \ @@ -11,5 +11,5 @@ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \ z-grs.h z-mterm2.h z-opac.h z-rrf1.h z-rrf2.h z-sum.h z-sutrs.h z-uifr1.h \ z-univ.h zes-expi.h zes-exps.h zes-order.h zes-pquery.h \ zes-psched.h zes-admin.h zes-pset.h zes-update.h zes-update0.h \ - zoom.h z-charneg.h charneg.h soap.h srw.h + zoom.h z-charneg.h charneg.h soap.h srw.h zgdu.h diff --git a/include/yaz/comstack.h b/include/yaz/comstack.h index 2c87e44..6993d5b 100644 --- a/include/yaz/comstack.h +++ b/include/yaz/comstack.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: comstack.h,v 1.7 2001-10-22 16:00:04 adam Exp $ + * $Id: comstack.h,v 1.8 2003-02-21 12:08:58 adam Exp $ */ #ifndef COMSTACK_H @@ -141,11 +141,14 @@ struct comstack #define CS_WANT_READ 1 #define CS_WANT_WRITE 2 + YAZ_EXPORT int cs_look (COMSTACK); YAZ_EXPORT const char *cs_strerror(COMSTACK h); YAZ_EXPORT const char *cs_errmsg(int n); YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host, - int blocking, void **vp); + int blocking, void **vp); +YAZ_EXPORT int cs_complete_auto(const unsigned char *buf, int len); + /* * error management. */ diff --git a/include/yaz/oid.h b/include/yaz/oid.h index cfb4bce..048918b 100644 --- a/include/yaz/oid.h +++ b/include/yaz/oid.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: oid.h,v 1.14 2003-02-14 18:49:23 adam Exp $ + * $Id: oid.h,v 1.15 2003-02-21 12:08:58 adam Exp $ */ #ifndef OID_H @@ -42,7 +42,7 @@ typedef enum oid_proto PROTO_SR, PROTO_GENERAL, PROTO_WAIS, - PROTO_SRW, + PROTO_HTTP, } oid_proto; typedef enum oid_class diff --git a/include/yaz/proto.h b/include/yaz/proto.h index 8051bca..0d0ea5a 100644 --- a/include/yaz/proto.h +++ b/include/yaz/proto.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: proto.h,v 1.8 2003-02-14 18:49:23 adam Exp $ + * $Id: proto.h,v 1.9 2003-02-21 12:08:58 adam Exp $ */ #ifndef Z_PROTO_H #define Z_PROTO_H @@ -42,6 +42,7 @@ #include #include #include +#include YAZ_BEGIN_CDECL @@ -110,51 +111,6 @@ YAZ_EXPORT const char* yaz_z3950_oid_value_to_str(oid_value ov, oid_class oc); YAZ_EXPORT void yaz_display_grs1(WRBUF wrbuf, Z_GenericRecord *r, int flags); -typedef struct Z_HTTP_Header Z_HTTP_Header; - -struct Z_HTTP_Header { - char *name; - char *value; - Z_HTTP_Header *next; -}; - -typedef struct { - char *method; - char *version; - char *path; - Z_HTTP_Header *headers; - char *content_buf; - int content_len; -} Z_HTTP_Request; - -typedef struct { - int code; - char *version; - Z_HTTP_Header *headers; - char *content_buf; - int content_len; -} Z_HTTP_Response; - -#define Z_GDU_Z3950 1 -#define Z_GDU_HTTP_Request 2 -#define Z_GDU_HTTP_Response 3 -typedef struct { - int which; - union { - Z_APDU *z3950; - Z_HTTP_Request *HTTP_Request; - Z_HTTP_Response *HTTP_Response; - } u; -} Z_GDU ; -YAZ_EXPORT int z_GDU (ODR o, Z_GDU **p, int opt, const char *name); -YAZ_EXPORT void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, - const char *v); -YAZ_EXPORT const char *z_HTTP_header_lookup(Z_HTTP_Header *hp, const char *n); - -YAZ_EXPORT const char *z_HTTP_errmsg(int code); - -YAZ_EXPORT Z_GDU *z_get_HTTP_Response(ODR o, int code); -YAZ_EXPORT Z_GDU *z_get_HTTP_Request(ODR o); YAZ_END_CDECL diff --git a/include/yaz/zgdu.h b/include/yaz/zgdu.h new file mode 100644 index 0000000..7f9a124 --- /dev/null +++ b/include/yaz/zgdu.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 1998-2003, Index Data + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Id: zgdu.h,v 1.1 2003-02-21 12:08:58 adam Exp $ + */ +#ifndef Z_GDU_H +#define Z_GDU_H + +#include + +typedef struct Z_HTTP_Header Z_HTTP_Header; + +struct Z_HTTP_Header { + char *name; + char *value; + Z_HTTP_Header *next; +}; + +typedef struct { + char *method; + char *version; + char *path; + Z_HTTP_Header *headers; + char *content_buf; + int content_len; +} Z_HTTP_Request; + +typedef struct { + int code; + char *version; + Z_HTTP_Header *headers; + char *content_buf; + int content_len; +} Z_HTTP_Response; + +#define Z_GDU_Z3950 1 +#define Z_GDU_HTTP_Request 2 +#define Z_GDU_HTTP_Response 3 +typedef struct { + int which; + union { + Z_APDU *z3950; + Z_HTTP_Request *HTTP_Request; + Z_HTTP_Response *HTTP_Response; + } u; +} Z_GDU ; +YAZ_EXPORT int z_GDU (ODR o, Z_GDU **p, int opt, const char *name); +YAZ_EXPORT void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, + const char *v); +YAZ_EXPORT const char *z_HTTP_header_lookup(Z_HTTP_Header *hp, const char *n); + +YAZ_EXPORT const char *z_HTTP_errmsg(int code); + +YAZ_EXPORT Z_GDU *z_get_HTTP_Response(ODR o, int code); +YAZ_EXPORT Z_GDU *z_get_HTTP_Request(ODR o); + +#endif diff --git a/odr/ber_any.c b/odr/ber_any.c index c3e0947..3b7f69a 100644 --- a/odr/ber_any.c +++ b/odr/ber_any.c @@ -2,12 +2,11 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: ber_any.c,v 1.22 2003-02-14 18:49:23 adam Exp $ + * $Id: ber_any.c,v 1.23 2003-02-21 12:08:58 adam Exp $ */ #if HAVE_CONFIG_H #include #endif -#include #include "odr-priv.h" @@ -49,47 +48,6 @@ int completeBER(const unsigned char *buf, int len) return 0; if (!buf[0] && !buf[1]) return 0; - if (len > 5 && buf[0] >= 0x20 && buf[0] < 0x7f - && buf[1] >= 0x20 && buf[1] < 0x7f - && buf[2] >= 0x20 && buf[2] < 0x7f) - { - /* deal with HTTP request/response */ - int i = 2, content_len = 0; - - while (i <= len-4) - { - if (buf[i] == '\r' && buf[i+1] == '\n') - { - i += 2; - if (buf[i] == '\r' && buf[i+1] == '\n') - { - /* i += 2 seems not to work with GCC -O2 .. - so i+2 is used instead .. */ - if (len >= (i+2)+ content_len) - return (i+2)+ content_len; - break; - } - if (i < len-18) - { - if (!memcmp(buf+i, "Content-Length:", 15)) - { - i+= 15; - if (buf[i] == ' ') - i++; - content_len = 0; - while (i <= len-4 && isdigit(buf[i])) - content_len = content_len*10 + (buf[i++] - '0'); - if (content_len < 0) /* prevent negative offsets */ - content_len = 0; - } - } - } - else - i++; - } - return 0; - } - /* BER from now on .. */ if ((res = ber_dectag(b, &zclass, &tag, &cons)) <= 0) return 0; if (res > len) diff --git a/server/eventl.c b/server/eventl.c index d430dc1..668eeb7 100644 --- a/server/eventl.c +++ b/server/eventl.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: eventl.c,v 1.38 2003-02-20 15:13:28 adam Exp $ + * $Id: eventl.c,v 1.39 2003-02-21 12:08:59 adam Exp $ */ #include @@ -97,7 +97,7 @@ int event_loop(IOCHAN *iochans) to.tv_sec = w; } } - yaz_log(LOG_DEBUG, "select start %d", to.tv_sec); + yaz_log(LOG_DEBUG, "select start %ld", (long) to.tv_sec); res = YAZ_EV_SELECT(max + 1, &in, &out, &except, &to); yaz_log(LOG_DEBUG, "select end"); if (res < 0) diff --git a/server/seshigh.c b/server/seshigh.c index b9f2e66..4427a88 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.144 2003-02-20 15:15:04 adam Exp $ + * $Id: seshigh.c,v 1.145 2003-02-21 12:08:59 adam Exp $ */ /* @@ -39,6 +39,7 @@ #include #endif #include +#include #include #include @@ -524,7 +525,6 @@ static void srw_bend_search(association *assoc, request *req, Z_SRW_searchRetrieveRequest *srw_req, Z_SRW_searchRetrieveResponse *srw_res) { - char *base = "Default"; int srw_error = 0; bend_search_rr rr; Z_External *ext; diff --git a/zutil/zgdu.c b/zutil/zgdu.c index b26b060..ab99984 100644 --- a/zutil/zgdu.c +++ b/zutil/zgdu.c @@ -2,10 +2,12 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: zgdu.c,v 1.7 2003-02-20 15:12:28 adam Exp $ + * $Id: zgdu.c,v 1.8 2003-02-21 12:08:59 adam Exp $ */ -#include +#include +#include +#include static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, char **content_buf, int *content_len) diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 0515eb5..48a2472 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.26 2003-02-20 15:11:38 adam Exp $ + * $Id: zoom-c.c,v 1.27 2003-02-21 12:08:59 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -550,7 +550,7 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) r->next = c->resultsets; c->resultsets = r; - if (c->host_port && c->proto == PROTO_SRW) + if (c->host_port && c->proto == PROTO_HTTP) { if (!c->cs) { @@ -645,7 +645,7 @@ static void ZOOM_resultset_retrieve (ZOOM_resultset r, if (!c) return; - if (c->host_port && c->proto == PROTO_SRW) + if (c->host_port && c->proto == PROTO_HTTP) { if (!c->cs) { @@ -717,7 +717,7 @@ static zoom_ret do_connect (ZOOM_connection c) { #if HAVE_XML2 const char *path; - c->proto = PROTO_SRW; + c->proto = PROTO_HTTP; effective_host = c->host_port + 5; if (*effective_host == '/') effective_host++; @@ -2221,13 +2221,13 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) switch (task->which) { case ZOOM_TASK_SEARCH: - if (c->proto == PROTO_SRW) + if (c->proto == PROTO_HTTP) ret = ZOOM_connection_srw_send_search(c); else ret = ZOOM_connection_send_search(c); break; case ZOOM_TASK_RETRIEVE: - if (c->proto == PROTO_SRW) + if (c->proto == PROTO_HTTP) ret = ZOOM_connection_srw_send_search(c); else ret = send_present (c); -- 1.7.10.4