From ac286ae76051058c8e340bf84eb98391340b7d22 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 14 Feb 2003 18:49:22 +0000 Subject: [PATCH] More type casts. Modify CQL tree - bool is C++ reserved name. Using YAZ SOAP instead of gSOAP for ZOOM client (still incomplete). --- TODO | 10 ++- ccl/cclfind.c | 4 +- ccl/cclptree.c | 3 +- ccl/ccltoken.c | 3 +- client/client.c | 4 +- comstack/comstack.c | 41 +---------- configure.in | 10 +-- cql/cql.y | 10 +-- cql/cqlstring.c | 6 +- cql/cqltransform.c | 20 +++--- cql/cqlutil.c | 40 +++++------ cql/xcqlutil.c | 18 ++--- doc/tools.xml | 4 +- include/yaz/cql.h | 4 +- include/yaz/oid.h | 5 +- include/yaz/proto.h | 3 +- include/yaz/soap.h | 12 ++-- include/yaz/srw.h | 8 ++- odr/ber_any.c | 4 +- server/Makefile.am | 4 +- server/seshigh.c | 106 ++++++++++++++++++++++------- server/statserv.c | 5 +- zoom/zoomsh.c | 3 +- zutil/soap.c | 14 ++-- zutil/srw.c | 11 ++- zutil/srwtst.c | 91 +++++++++++++++++++++++++ zutil/zgdu.c | 114 ++++++++++++++++++++----------- zutil/zoom-c.c | 189 +++++++++++++++++++++++++++++++++++++++------------ zutil/zoom-p.h | 13 ++-- 29 files changed, 517 insertions(+), 242 deletions(-) create mode 100644 zutil/srwtst.c diff --git a/TODO b/TODO index 6301931..be48670 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,12 @@ -YAZ TODO $Id: TODO,v 1.7 2002-08-20 12:03:34 adam Exp $ +YAZ TODO $Id: TODO,v 1.8 2003-02-14 18:49:22 adam Exp $ -Complete EXPLAIN support in retrieval module. +Improve timeouts in GFS. + +Database in URL for GFS. + +SRW support for ZOOM. + +Complete ODR print. Versions to be put automatically in configure.in diff --git a/ccl/cclfind.c b/ccl/cclfind.c index c83d90e..8153a0e 100644 --- a/ccl/cclfind.c +++ b/ccl/cclfind.c @@ -44,7 +44,7 @@ /* CCL find (to rpn conversion) * Europagate, 1995 * - * $Id: cclfind.c,v 1.32 2002-12-28 12:13:03 adam Exp $ + * $Id: cclfind.c,v 1.33 2003-02-14 18:49:22 adam Exp $ * * Old Europagate log: * @@ -801,7 +801,7 @@ static struct ccl_rpn_node *search_terms (CCL_parser cclp, /* ! word order specified */ /* % word order not specified */ p_prox = mk_node(CCL_RPN_TERM); - p_prox->u.t.term = xmalloc(cclp->look_token->len); + p_prox->u.t.term = (char *) xmalloc(cclp->look_token->len); memcpy(p_prox->u.t.term, cclp->look_token->name, cclp->look_token->len); p_prox->u.t.term[cclp->look_token->len] = 0; diff --git a/ccl/cclptree.c b/ccl/cclptree.c index 0710fdd..924971f 100644 --- a/ccl/cclptree.c +++ b/ccl/cclptree.c @@ -44,7 +44,7 @@ /* CCL print rpn tree - infix notation * Europagate, 1995 * - * $Id: cclptree.c,v 1.11 2002-12-28 12:13:03 adam Exp $ + * $Id: cclptree.c,v 1.12 2003-02-14 18:49:23 adam Exp $ * * Old Europagate Log: * @@ -70,6 +70,7 @@ #include #include +#include #include diff --git a/ccl/ccltoken.c b/ccl/ccltoken.c index e530e11..31a18d8 100644 --- a/ccl/ccltoken.c +++ b/ccl/ccltoken.c @@ -44,7 +44,7 @@ /* CCL - lexical analysis * Europagate, 1995 * - * $Id: ccltoken.c,v 1.21 2002-12-28 12:13:03 adam Exp $ + * $Id: ccltoken.c,v 1.22 2003-02-14 18:49:23 adam Exp $ * * Old Europagate Log: * @@ -85,6 +85,7 @@ #include #include +#include #include diff --git a/client/client.c b/client/client.c index ddeacaf..85e54b6 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.180 2003-02-12 15:06:43 adam Exp $ + * $Id: client.c,v 1.181 2003-02-14 18:49:23 adam Exp $ */ #include @@ -966,7 +966,7 @@ static int send_searchRequest(char *arg) break; case QueryType_CQL: query.which = Z_Query_type_104; - ext = odr_malloc(out, sizeof(*ext)); + ext = (Z_External *) odr_malloc(out, sizeof(*ext)); ext->direct_reference = odr_getoidbystr(out, "1.2.840.10003.16.2"); ext->indirect_reference = 0; ext->descriptor = 0; diff --git a/comstack/comstack.c b/comstack/comstack.c index 121d143..07903eb 100644 --- a/comstack/comstack.c +++ b/comstack/comstack.c @@ -1,45 +1,8 @@ /* - * Copyright (c) 1995-2001, Index Data + * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Log: comstack.c,v $ - * Revision 1.10 2002-06-04 11:36:10 adam - * New COMSTACK: UNIX socket - * - * Revision 1.9 2001/10/22 13:57:24 adam - * Implemented cs_rcvconnect and cs_look as described in the documentation. - * - * Revision 1.8 2001/07/19 19:49:02 adam - * Added include of string.h. - * - * Revision 1.7 2001/03/21 12:43:36 adam - * Implemented cs_create_host. Better error reporting for SSL comstack. - * - * Revision 1.6 1999/11/30 13:47:11 adam - * Improved installation. Moved header files to include/yaz. - * - * Revision 1.5 1998/06/22 11:32:35 adam - * Added 'conditional cs_listen' feature. - * - * Revision 1.4 1997/09/29 07:16:14 adam - * Array cs_errlist no longer global. - * - * Revision 1.3 1997/09/01 08:49:14 adam - * New windows NT/95 port using MSV5.0. Minor changes only. - * - * Revision 1.2 1995/09/29 17:01:48 quinn - * More Windows work - * - * Revision 1.1 1995/06/14 09:58:20 quinn - * Renamed yazlib to comstack. - * - * Revision 1.2 1995/05/16 08:51:15 quinn - * License, documentation, and memory fixes - * - * Revision 1.1 1995/03/14 10:28:34 quinn - * Adding server-side support to tcpip.c and fixing bugs in nonblocking I/O - * - * + * $Id: comstack.c,v 1.11 2003-02-14 18:49:23 adam Exp $ */ #include diff --git a/configure.in b/configure.in index 4763db1..620cf6e 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl YAZ Toolkit, Index Data 1994-2003 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.103 2003-02-12 15:06:42 adam Exp $ +dnl $Id: configure.in,v 1.104 2003-02-14 18:49:22 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.9.3) dnl @@ -308,19 +308,19 @@ if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then fi AM_CONDITIONAL(ISTHR, test $HAVETHREADS = "1") dnl -dnl ----- XML/XSLT +dnl ----- libXML2/XSLT AC_SUBST(XSLT_LIB) AC_SUBST(XSLT_CFLAGS) -xsltdir=NONE +xsltdir=no AC_ARG_WITH(xslt, [ --with-xslt[=PREFIX] Use libxslt in PREFIX/{lib,include}],[xsltdir=$withval]) -if test "x$xsltdir" = "xNONE"; then +if test "$xsltdir" = "yes"; then for d in /usr /usr/local; do if test -x $d/bin/xslt-config; then xsltdir=$d fi done fi -if true; then +if test "$xsltdir" != "no"; then AC_MSG_CHECKING(for XSLT) if test -x $xsltdir/bin/xslt-config; then XSLT_LIB=`$xsltdir/bin/xslt-config --libs` diff --git a/cql/cql.y b/cql/cql.y index 0bcc9cb..582be81 100644 --- a/cql/cql.y +++ b/cql/cql.y @@ -1,4 +1,4 @@ -/* $Id: cql.y,v 1.2 2003-01-11 03:18:53 adam Exp $ +/* $Id: cql.y,v 1.3 2003-02-14 18:49:23 adam Exp $ Copyright (C) 2002-2003 Index Data Aps @@ -71,9 +71,9 @@ cqlQuery: } searchClause { struct cql_node *cn = cql_node_mk_boolean($2.buf); - cn->u.bool.modifiers = $2.rel; - cn->u.bool.left = $1.cql; - cn->u.bool.right = $4.cql; + cn->u.boolean.modifiers = $2.rel; + cn->u.boolean.left = $1.cql; + cn->u.boolean.right = $4.cql; $$.cql = cn; } @@ -250,7 +250,7 @@ int cql_parser_stream(CQL_parser cp, CQL_parser cql_parser_create(void) { - CQL_parser cp = malloc (sizeof(*cp)); + CQL_parser cp = (CQL_parser) malloc (sizeof(*cp)); return cp; } diff --git a/cql/cqlstring.c b/cql/cqlstring.c index b04dd5b..49a7882 100644 --- a/cql/cqlstring.c +++ b/cql/cqlstring.c @@ -1,4 +1,4 @@ -/* $Id: cqlstring.c,v 1.1 2003-01-06 08:20:27 adam Exp $ +/* $Id: cqlstring.c,v 1.2 2003-02-14 18:49:23 adam Exp $ Copyright (C) 2002-2003 Index Data Aps @@ -15,7 +15,7 @@ struct cql_buf_info { int getbuf(void *vp) { - struct cql_buf_info *bi = vp; + struct cql_buf_info *bi = (struct cql_buf_info *) vp; if (bi->str[bi->off] == 0) return 0; return bi->str[bi->off++]; @@ -23,7 +23,7 @@ int getbuf(void *vp) void ungetbuf(int b, void *vp) { - struct cql_buf_info *bi = vp; + struct cql_buf_info *bi = (struct cql_buf_info *) vp; if (b) (bi->off--); } diff --git a/cql/cqltransform.c b/cql/cqltransform.c index 7bbfc9f..1f2a0d6 100644 --- a/cql/cqltransform.c +++ b/cql/cqltransform.c @@ -1,4 +1,4 @@ -/* $Id: cqltransform.c,v 1.2 2003-01-11 03:18:53 adam Exp $ +/* $Id: cqltransform.c,v 1.3 2003-02-14 18:49:23 adam Exp $ Copyright (C) 2002-2003 Index Data Aps @@ -26,7 +26,7 @@ struct cql_transform_t_ { cql_transform_t cql_transform_open_FILE(FILE *f) { char line[1024]; - cql_transform_t ct = malloc (sizeof(*ct)); + cql_transform_t ct = (cql_transform_t) malloc (sizeof(*ct)); struct cql_prop_entry **pp = &ct->entry; ct->error = 0; @@ -56,12 +56,12 @@ cql_transform_t cql_transform_open_FILE(FILE *f) if (cp_value_end != cp_value_start && strchr(" \t\r\n", cp_value_end[-1])) cp_value_end--; - *pp = malloc (sizeof(**pp)); - (*pp)->pattern = malloc (cp_pattern_end - line + 1); + *pp = (struct cql_prop_entry *) malloc (sizeof(**pp)); + (*pp)->pattern = (char *) malloc (cp_pattern_end - line + 1); memcpy ((*pp)->pattern, line, cp_pattern_end - line); (*pp)->pattern[cp_pattern_end-line] = 0; - (*pp)->value = malloc (cp_value_end - cp_value_start + 1); + (*pp)->value = (char *) malloc (cp_value_end - cp_value_start + 1); if (cp_value_start != cp_value_end) memcpy ((*pp)->value, cp_value_start, cp_value_end-cp_value_start); (*pp)->value[cp_value_end - cp_value_start] = 0; @@ -389,15 +389,15 @@ void cql_transform_r(cql_transform_t ct, } break; case CQL_NODE_BOOL: - if (cn->u.bool.prefixes && prefix_level < 20) - prefix_ar[prefix_level++] = cn->u.bool.prefixes; + if (cn->u.boolean.prefixes && prefix_level < 20) + prefix_ar[prefix_level++] = cn->u.boolean.prefixes; (*pr)("@", client_data); - (*pr)(cn->u.bool.value, client_data); + (*pr)(cn->u.boolean.value, client_data); (*pr)(" ", client_data); - cql_transform_r(ct, cn->u.bool.left, pr, client_data, + cql_transform_r(ct, cn->u.boolean.left, pr, client_data, prefix_ar, prefix_level); - cql_transform_r(ct, cn->u.bool.right, pr, client_data, + cql_transform_r(ct, cn->u.boolean.right, pr, client_data, prefix_ar, prefix_level); } } diff --git a/cql/cqlutil.c b/cql/cqlutil.c index 6207d19..d1caa2d 100644 --- a/cql/cqlutil.c +++ b/cql/cqlutil.c @@ -1,4 +1,4 @@ -/* $Id: cqlutil.c,v 1.1 2003-01-06 08:20:27 adam Exp $ +/* $Id: cqlutil.c,v 1.2 2003-02-14 18:49:23 adam Exp $ Copyright (C) 2002-2003 Index Data Aps @@ -14,7 +14,7 @@ See the file LICENSE. void cql_fputs(const char *buf, void *client_data) { - FILE *f = client_data; + FILE *f = (FILE *) client_data; fputs(buf, f); } @@ -39,10 +39,10 @@ struct cql_node *cql_node_dup (struct cql_node *cp) cn->u.mod.next = cql_node_dup(cp->u.mod.next); break; case CQL_NODE_BOOL: - cn = cql_node_mk_boolean(cp->u.bool.value); - cn->u.bool.left = cql_node_dup(cp->u.bool.left); - cn->u.bool.right = cql_node_dup(cp->u.bool.right); - cn->u.bool.prefixes = cql_node_dup(cp->u.bool.prefixes); + cn = cql_node_mk_boolean(cp->u.boolean.value); + cn->u.boolean.left = cql_node_dup(cp->u.boolean.left); + cn->u.boolean.right = cql_node_dup(cp->u.boolean.right); + cn->u.boolean.prefixes = cql_node_dup(cp->u.boolean.prefixes); } return cn; } @@ -51,7 +51,7 @@ struct cql_node *cql_node_mk_sc(const char *index, const char *relation, const char *term) { - struct cql_node *p = malloc(sizeof(*p)); + struct cql_node *p = (struct cql_node *) malloc(sizeof(*p)); p->which = CQL_NODE_ST; p->u.st.index = 0; if (index) @@ -70,7 +70,7 @@ struct cql_node *cql_node_mk_sc(const char *index, struct cql_node *cql_node_mk_mod(const char *name, const char *value) { - struct cql_node *p = malloc(sizeof(*p)); + struct cql_node *p = (struct cql_node *) malloc(sizeof(*p)); p->which = CQL_NODE_MOD; p->u.mod.name = 0; @@ -85,15 +85,15 @@ struct cql_node *cql_node_mk_mod(const char *name, struct cql_node *cql_node_mk_boolean(const char *op) { - struct cql_node *p = malloc(sizeof(*p)); + struct cql_node *p = (struct cql_node *) malloc(sizeof(*p)); p->which = CQL_NODE_BOOL; - p->u.bool.value = 0; + p->u.boolean.value = 0; if (op) - p->u.bool.value = strdup(op); - p->u.bool.left = 0; - p->u.bool.right = 0; - p->u.bool.modifiers = 0; - p->u.bool.prefixes = 0; + p->u.boolean.value = strdup(op); + p->u.boolean.left = 0; + p->u.boolean.right = 0; + p->u.boolean.modifiers = 0; + p->u.boolean.prefixes = 0; return p; } @@ -107,7 +107,7 @@ struct cql_node *cql_node_prefix(struct cql_node *n, const char *prefix, } else if (n->which == CQL_NODE_BOOL) { - cpp = &n->u.bool.prefixes; + cpp = &n->u.boolean.prefixes; } if (cpp) { @@ -167,10 +167,10 @@ void cql_node_destroy(struct cql_node *cn) cql_node_destroy(cn->u.mod.next); break; case CQL_NODE_BOOL: - free (cn->u.bool.value); - cql_node_destroy(cn->u.bool.left); - cql_node_destroy(cn->u.bool.right); - cql_node_destroy(cn->u.bool.prefixes); + free (cn->u.boolean.value); + cql_node_destroy(cn->u.boolean.left); + cql_node_destroy(cn->u.boolean.right); + cql_node_destroy(cn->u.boolean.prefixes); } free (cn); } diff --git a/cql/xcqlutil.c b/cql/xcqlutil.c index 9294a02..60c486b 100644 --- a/cql/xcqlutil.c +++ b/cql/xcqlutil.c @@ -1,4 +1,4 @@ -/* $Id: xcqlutil.c,v 1.1 2003-01-06 08:20:27 adam Exp $ +/* $Id: xcqlutil.c,v 1.2 2003-02-14 18:49:23 adam Exp $ Copyright (C) 2002-2003 Index Data Aps @@ -126,13 +126,13 @@ static void cql_to_xml_r(struct cql_node *cn, case CQL_NODE_BOOL: pr_n("\n", pr, client_data, level); prefixes(cn->u.st.prefixes, pr, client_data, level+2); - if (cn->u.bool.value) + if (cn->u.boolean.value) { - struct cql_node *m = cn->u.bool.modifiers; + struct cql_node *m = cn->u.boolean.modifiers; pr_n("\n", pr, client_data, level+2); pr_n("", pr, client_data, level+4); - pr_cdata(cn->u.bool.value, pr, client_data); + pr_cdata(cn->u.boolean.value, pr, client_data); pr_n("\n", pr, client_data, 0); if (m) @@ -155,16 +155,16 @@ static void cql_to_xml_r(struct cql_node *cn, } pr_n("\n", pr, client_data, level+2); } - if (cn->u.bool.left) + if (cn->u.boolean.left) { printf ("%*s\n", level+2, ""); - cql_to_xml_r(cn->u.bool.left, pr, client_data, level+4); + cql_to_xml_r(cn->u.boolean.left, pr, client_data, level+4); printf ("%*s\n", level+2, ""); } - if (cn->u.bool.right) + if (cn->u.boolean.right) { printf ("%*s\n", level+2, ""); - cql_to_xml_r(cn->u.bool.right, pr, client_data, level+4); + cql_to_xml_r(cn->u.boolean.right, pr, client_data, level+4); printf ("%*s\n", level+2, ""); } pr_n("\n", pr, client_data, level); @@ -185,7 +185,7 @@ void cql_to_xml_stdio(struct cql_node *cn, FILE *f) void cql_buf_write_handler (const char *b, void *client_data) { - struct cql_buf_write_info *info = client_data; + struct cql_buf_write_info *info = (struct cql_buf_write_info *)client_data; int l = strlen(b); if (info->off < 0 || (info->off + l >= info->max)) { diff --git a/doc/tools.xml b/doc/tools.xml index 51de233..b158495 100644 --- a/doc/tools.xml +++ b/doc/tools.xml @@ -1,4 +1,4 @@ - + Supporting Tools @@ -600,7 +600,7 @@ struct cql_node { struct cql_node *right; struct cql_node *modifiers; struct cql_node *prefixes; - } bool; + } boolean; struct { char *name; char *value; diff --git a/include/yaz/cql.h b/include/yaz/cql.h index 9ae7b6b..87bcb5d 100644 --- a/include/yaz/cql.h +++ b/include/yaz/cql.h @@ -1,4 +1,4 @@ -/* $Id: cql.h,v 1.1 2003-01-06 08:20:27 adam Exp $ +/* $Id: cql.h,v 1.2 2003-02-14 18:49:23 adam Exp $ Copyright (C) 2002-2003 Index Data Aps @@ -91,7 +91,7 @@ struct cql_node { struct cql_node *right; struct cql_node *modifiers; struct cql_node *prefixes; - } bool; + } boolean; struct { char *name; char *value; diff --git a/include/yaz/oid.h b/include/yaz/oid.h index d9f18df..cfb4bce 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.13 2003-01-06 08:20:27 adam Exp $ + * $Id: oid.h,v 1.14 2003-02-14 18:49:23 adam Exp $ */ #ifndef OID_H @@ -41,7 +41,8 @@ typedef enum oid_proto PROTO_Z3950, PROTO_SR, PROTO_GENERAL, - PROTO_WAIS + PROTO_WAIS, + PROTO_SRW, } oid_proto; typedef enum oid_class diff --git a/include/yaz/proto.h b/include/yaz/proto.h index f1bf623..8051bca 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.7 2003-02-12 15:06:43 adam Exp $ + * $Id: proto.h,v 1.8 2003-02-14 18:49:23 adam Exp $ */ #ifndef Z_PROTO_H #define Z_PROTO_H @@ -154,6 +154,7 @@ 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/soap.h b/include/yaz/soap.h index 9c60462..0123828 100644 --- a/include/yaz/soap.h +++ b/include/yaz/soap.h @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: soap.h,v 1.1 2003-02-12 15:06:43 adam Exp $ + * $Id: soap.h,v 1.2 2003-02-14 18:49:23 adam Exp $ */ #ifndef YAZ_SOAP_H @@ -10,11 +10,6 @@ #include -#if HAVE_XSLT -#include -#include -#endif - typedef struct { char *fault_code; char *fault_string; @@ -40,11 +35,12 @@ typedef struct { const char *ns; } Z_SOAP; +typedef int (*Z_SOAP_fun)(ODR o, void * ptr, void **handler_data, + void *client_data, const char *ns); typedef struct { char *ns; void *client_data; - int (*f)(ODR o, xmlNodePtr ptr, void **handler_data, - void *client_data, const char *ns); + Z_SOAP_fun f; } Z_SOAP_Handler; YAZ_EXPORT int z_soap_codec(ODR o, Z_SOAP **pp, diff --git a/include/yaz/srw.h b/include/yaz/srw.h index 5f29e40..f2cc9ae 100644 --- a/include/yaz/srw.h +++ b/include/yaz/srw.h @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: srw.h,v 1.1 2003-02-12 15:06:43 adam Exp $ + * $Id: srw.h,v 1.2 2003-02-14 18:49:23 adam Exp $ */ #ifndef YAZ_SRW_H @@ -58,8 +58,14 @@ typedef struct { } u; } Z_SRW_searchRetrieve; +#if 1 +YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr, + Z_SRW_searchRetrieve **handler_data, + void *client_data, const char *ns); +#else YAZ_EXPORT int yaz_srw_codec(ODR o, xmlNodePtr pptr, Z_SRW_searchRetrieve **handler_data, void *client_data, const char *ns); +#endif YAZ_EXPORT Z_SRW_searchRetrieve *yaz_srw_get(ODR o, int which); #endif diff --git a/odr/ber_any.c b/odr/ber_any.c index 5328dee..c3e0947 100644 --- a/odr/ber_any.c +++ b/odr/ber_any.c @@ -2,11 +2,13 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: ber_any.c,v 1.21 2003-02-12 15:06:43 adam Exp $ + * $Id: ber_any.c,v 1.22 2003-02-14 18:49:23 adam Exp $ */ #if HAVE_CONFIG_H #include #endif +#include + #include "odr-priv.h" int ber_any(ODR o, Odr_any **p) diff --git a/server/Makefile.am b/server/Makefile.am index 9bc6a8a..0cae60c 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.8 2003-02-12 15:06:43 adam Exp $ + noinst_LTLIBRARIES=libserver.la @@ -7,4 +7,4 @@ libserver_la_SOURCES = eventl.c seshigh.c statserv.c requestq.c tcpdchk.c \ EXTRA_DIST=service.c -AM_CPPFLAGS=-I$(top_srcdir)/include $(XSLT_CFLAGS) +AM_CPPFLAGS=-I$(top_srcdir)/include $(XSLT_CFLAGS) -DDOCDIR=\"$(datadir)/doc/$(PACKAGE)\" diff --git a/server/seshigh.c b/server/seshigh.c index 9ba52f6..a6a9a13 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.134 2003-02-12 15:06:43 adam Exp $ + * $Id: seshigh.c,v 1.135 2003-02-14 18:49:24 adam Exp $ */ /* @@ -28,9 +28,13 @@ #include #include +#include #ifdef WIN32 +#include +#define S_ISREG(x) (x & _S_IFREG) #include #else +#include #include #endif #include @@ -459,9 +463,11 @@ static void srw_bend_fetch(association *assoc, int pos, rr.request_format_raw = yaz_oidval_to_z3950oid(assoc->decode, CLASS_TRANSYN, VAL_TEXT_XML); - rr.comp = odr_malloc(assoc->decode, sizeof(*rr.comp)); + rr.comp = (Z_RecordComposition *) + odr_malloc(assoc->decode, sizeof(*rr.comp)); rr.comp->which = Z_RecordComp_complex; - rr.comp->u.complex = odr_malloc(assoc->decode, sizeof(Z_CompSpec)); + rr.comp->u.complex = (Z_CompSpec *) + odr_malloc(assoc->decode, sizeof(Z_CompSpec)); rr.comp->u.complex->selectAlternativeSyntax = (bool_t *) odr_malloc(assoc->encode, sizeof(bool_t)); *rr.comp->u.complex->selectAlternativeSyntax = 0; @@ -470,8 +476,8 @@ static void srw_bend_fetch(association *assoc, int pos, rr.comp->u.complex->num_recordSyntax = 0; rr.comp->u.complex->recordSyntax = 0; - rr.comp->u.complex->generic = odr_malloc(assoc->decode, - sizeof(Z_Specification)); + rr.comp->u.complex->generic = (Z_Specification *) + odr_malloc(assoc->decode, sizeof(Z_Specification)); rr.comp->u.complex->generic->which = Z_Specification_uri; rr.comp->u.complex->generic->u.uri = srw_req->recordSchema; rr.comp->u.complex->generic->elementSpec = 0; @@ -547,8 +553,8 @@ static void srw_bend_search(association *assoc, request *req, if (rr.errcode) { srw_res->num_diagnostics = 1; - srw_res->diagnostics = - odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics)); + srw_res->diagnostics = (Z_SRW_diagnostic *) + odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics)); srw_res->diagnostics[0].code = odr_intdup(assoc->encode, rr.errcode); } @@ -567,7 +573,7 @@ static void srw_bend_search(association *assoc, request *req, int j = 0; if (start + number > rr.hits) number = rr.hits - start + 1; - srw_res->records = + srw_res->records = (Z_SRW_record *) odr_malloc(assoc->encode, number * sizeof(*srw_res->records)); for (i = 0; igdu_request->u.HTTP_Request; - Z_HTTP_Header *hp; ODR o = assoc->encode; - Z_GDU *p; + Z_GDU *p = 0; Z_HTTP_Response *hres = 0; int keepalive = 1; -#if 0 - yaz_log(LOG_LOG, "HTTP Request. method=%s Version=%s Path=%s", - hreq->method, hreq->version, hreq->path); - - for (hp = hreq->headers; hp; hp = hp->next) - yaz_log(LOG_LOG, "%s: %s", hp->name, hp->value); -#endif - if (!strcmp(hreq->method, "GET")) { - if (!strcmp(hreq->path, "/")) +#ifdef DOCDIR + if (strlen(hreq->path) >= 5 && strlen(hreq->path) < 80 && + !memcmp(hreq->path, "/doc/", 5)) + { + FILE *f; + char fpath[120]; + + strcpy(fpath, DOCDIR); + strcat(fpath, hreq->path+4); + f = fopen(fpath, "rb"); + if (f) { + struct stat sbuf; + if (fstat(fileno(f), &sbuf) || !S_ISREG(sbuf.st_mode)) + { + fclose(f); + f = 0; + } + } + if (f) + { + long sz; + fseek(f, 0L, SEEK_END); + sz = ftell(f); + if (sz >= 0 && sz < 500000) + { + const char *ctype = "application/octet-stream"; + const char *cp; + + p = z_get_HTTP_Response(o, 200); + hres = p->u.HTTP_Response; + hres->content_buf = (char *) odr_malloc(o, sz + 1); + hres->content_len = sz; + fseek(f, 0L, SEEK_SET); + fread(hres->content_buf, 1, sz, f); + if ((cp = strrchr(fpath, '.'))) { + cp++; + if (!strcmp(cp, "png")) + ctype = "image/png"; + else if (!strcmp(cp, "gif")) + ctype = "image/gif"; + else if (!strcmp(cp, "xml")) + ctype = "text/xml"; + else if (!strcmp(cp, "html")) + ctype = "text/html"; + } + z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype); + yaz_log(LOG_LOG, "OK send page %s size=%ld", fpath, sz); + } + fclose(f); + } + } +#endif + if (!strcmp(hreq->path, "/")) { + struct stat sbuf; + const char *doclink = ""; p = z_get_HTTP_Response(o, 200); hres = p->u.HTTP_Response; - hres->content_buf = odr_malloc(o, 400); + hres->content_buf = (char *) odr_malloc(o, 400); +#ifdef DOCDIR + if (stat(DOCDIR "/yaz.html", &sbuf) == 0 && S_ISREG(sbuf.st_mode)) + doclink = "

Documentation

"; +#endif sprintf (hres->content_buf, "\n" "\n" @@ -620,23 +675,24 @@ static void process_http_request(association *assoc, request *req) " \n" "

YAZ " YAZ_VERSION "

\n" + "%s" " \n" - "\n"); + "\n", doclink); hres->content_len = strlen(hres->content_buf); z_HTTP_header_add(o, &hres->headers, "Content-Type", "text/html"); } - else + if (!p) { p = z_get_HTTP_Response(o, 404); } } else if (!strcmp(hreq->method, "POST")) { +#if HAVE_XSLT const char *content_type = z_HTTP_header_lookup(hreq->headers, "Content-Type"); const char *soap_action = z_HTTP_header_lookup(hreq->headers, "SOAPAction"); - p = 0; /* no response yet */ if (content_type && soap_action && !yaz_strcmp_del("text/xml", content_type, "; ")) { @@ -645,7 +701,8 @@ static void process_http_request(association *assoc, request *req) int http_code = 500; static Z_SOAP_Handler soap_handlers[2] = { - {"http://www.loc.gov/zing/srw/v1.0/", 0, yaz_srw_codec}, + {"http://www.loc.gov/zing/srw/v1.0/", 0, + (Z_SOAP_fun) yaz_srw_codec}, {0, 0, 0} }; @@ -679,6 +736,7 @@ static void process_http_request(association *assoc, request *req) soap_handlers); hres->code = http_code; } +#endif if (!p) /* still no response ? */ p = z_get_HTTP_Response(o, 500); } diff --git a/server/statserv.c b/server/statserv.c index dd3dc75..3480c5d 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -6,7 +6,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.91 2003-02-12 15:06:43 adam Exp $ + * $Id: statserv.c,v 1.92 2003-02-14 18:49:24 adam Exp $ */ #include @@ -695,7 +695,8 @@ void statserv_setcontrol(statserv_options_block *block) void statserv_add_soap_handler(int (*h)(struct bend_soap_rr *rr), const char *ns) { - struct bend_soap_handler *sh = xmalloc(sizeof(*sh)); + struct bend_soap_handler *sh = (struct bend_soap_handler *) + xmalloc(sizeof(*sh)); sh->handler = h; sh->ns = xstrdup(ns); diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index bf35f6a..cd0ab0e 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,5 +1,5 @@ /* - * $Id: zoomsh.c,v 1.12 2003-01-06 08:20:28 adam Exp $ + * $Id: zoomsh.c,v 1.13 2003-02-14 18:49:24 adam Exp $ * * ZOOM-C Shell */ @@ -440,6 +440,7 @@ int main (int argc, char **argv) int i, res; ZOOM_connection z39_con[MAX_CON]; ZOOM_resultset z39_res[MAX_CON]; + for (i = 0; i +#if HAVE_XSLT +#include +#include + static const char *soap_v1_1 = "http://schemas.xmlsoap.org/soap/envelope/"; static const char *soap_v1_2 = "http://www.w3.org/2001/06/soap-envelope"; @@ -15,7 +19,8 @@ int z_soap_error(ODR o, Z_SOAP *p, const char *details) { p->which = Z_SOAP_error; - p->u.soap_error = odr_malloc(o, sizeof(*p->u.soap_error)); + p->u.soap_error = (Z_SOAP_Fault *) + odr_malloc(o, sizeof(*p->u.soap_error)); p->u.soap_error->fault_code = odr_strdup(o, fault_code); p->u.soap_error->fault_string = odr_strdup(o, fault_string); if (details) @@ -39,7 +44,7 @@ int z_soap_codec(ODR o, Z_SOAP **pp, if (!content_buf || !*content_buf || !content_len) return -1; - *pp = p = odr_malloc(o, sizeof(*p)); + *pp = p = (Z_SOAP *) odr_malloc(o, sizeof(*p)); p->ns = soap_v1_1; doc = xmlParseMemory(*content_buf, *content_len); @@ -201,7 +206,7 @@ int z_soap_codec(ODR o, Z_SOAP **pp, return ret; } xmlDocDumpMemory(doc, &buf_out, &len_out); - *content_buf = odr_malloc(o, len_out); + *content_buf = (char *) odr_malloc(o, len_out); *content_len = len_out; memcpy(*content_buf, buf_out, len_out); xmlFree(buf_out); @@ -210,3 +215,4 @@ int z_soap_codec(ODR o, Z_SOAP **pp, } return 0; } +#endif diff --git a/zutil/srw.c b/zutil/srw.c index 1fa9fca..9da8df6 100644 --- a/zutil/srw.c +++ b/zutil/srw.c @@ -2,11 +2,15 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: srw.c,v 1.1 2003-02-12 15:06:44 adam Exp $ + * $Id: srw.c,v 1.2 2003-02-14 18:49:24 adam Exp $ */ #include +#if HAVE_XSLT +#include +#include + static void add_xsd_string_n(xmlNodePtr ptr, const char *elem, char *val, int len) { @@ -213,9 +217,10 @@ static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs, } -int yaz_srw_codec(ODR o, xmlNodePtr pptr, Z_SRW_searchRetrieve **handler_data, +int yaz_srw_codec(ODR o, void * vptr, Z_SRW_searchRetrieve **handler_data, void *client_data, const char *ns) { + xmlNodePtr pptr = vptr; if (o->direction == ODR_DECODE) { xmlNodePtr method = pptr->children; @@ -376,6 +381,7 @@ Z_SRW_searchRetrieve *yaz_srw_get(ODR o, int which) sr->u.request = odr_malloc(o, sizeof(*sr->u.request)); sr->u.request->query = 0; sr->u.request->xQuery = 0; + sr->u.request->pQuery = 0; sr->u.request->sortKeys = 0; sr->u.request->xSortKeys = 0; sr->u.request->startRecord = 0; @@ -396,3 +402,4 @@ Z_SRW_searchRetrieve *yaz_srw_get(ODR o, int which) } return sr; } +#endif diff --git a/zutil/srwtst.c b/zutil/srwtst.c new file mode 100644 index 0000000..562f2fe --- /dev/null +++ b/zutil/srwtst.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2002-2003, Index Data. + * See the file LICENSE for details. + * + * $Id: srwtst.c,v 1.1 2003-02-14 18:49:24 adam Exp $ + */ + +#include + +#if HAVE_XSLT +Z_SOAP_Handler h[2] = { + {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec}, + {0, 0, 0} +}; + +int main(int argc, char **argv) +{ + char buf[163840]; + char *content_buf = buf; + int content_len; + int ret; + size_t no; + Z_SOAP *soap_package = 0; + ODR decode, encode; + int debug = 0; + + if (argc == 2 && !strcmp(argv[1], "debug")) + debug = 1; + no = fread(buf, 1, sizeof(buf), stdin); + if (no < 1 || no == sizeof(buf)) + { + fprintf(stderr, "Bad file or too big\n"); + exit (1); + } + decode = odr_createmem(ODR_DECODE); + encode = odr_createmem(ODR_ENCODE); + content_len = no; + ret = z_soap_codec(decode, &soap_package, + &content_buf, &content_len, h); + if (!soap_package) + { + fprintf(stderr, "Decoding seriously failed\n"); + exit(1); + } + if (debug) + { + fprintf(stderr, "got NS = %s\n", soap_package->ns); + if (soap_package->which == Z_SOAP_generic && + soap_package->u.generic->no == 0) + { + Z_SRW_searchRetrieve *sr = soap_package->u.generic->p; + if (sr->which == Z_SRW_searchRetrieve_request) + { + Z_SRW_searchRetrieveRequest *req = sr->u.request; + } + else if (sr->which == Z_SRW_searchRetrieve_response) + { + Z_SRW_searchRetrieveResponse *res = sr->u.response; + if (res->records && res->num_records) + { + int i; + for (i = 0; inum_records; i++) + { + fprintf (stderr, "%d\n", i); + if (res->records[i].recordData_buf) + fwrite(res->records[i].recordData_buf, 1, + res->records[i].recordData_len, stderr); + } + } + } + + } + } + ret = z_soap_codec(encode, &soap_package, + &content_buf, &content_len, h); + if (content_buf && content_len) + fwrite (content_buf, content_len, 1, stdout); + else + { + fprintf(stderr, "No output!\n"); + exit(1); + } + exit(0); +} +#else +int main(int argc, char **argv) +{ + fprintf(stderr, "SOAP disabled\n"); + exit(1); +} +#endif diff --git a/zutil/zgdu.c b/zutil/zgdu.c index c06777e..5524118 100644 --- a/zutil/zgdu.c +++ b/zutil/zgdu.c @@ -2,7 +2,7 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: zgdu.c,v 1.1 2003-02-12 15:06:44 adam Exp $ + * $Id: zgdu.c,v 1.2 2003-02-14 18:49:24 adam Exp $ */ #include @@ -37,8 +37,8 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, else if (o->buf[i] == ':') break; } - *headers = odr_malloc(o, sizeof(**headers)); - (*headers)->name = odr_malloc(o, i - po + 1); + *headers = (Z_HTTP_Header *) odr_malloc(o, sizeof(**headers)); + (*headers)->name = (char*) odr_malloc(o, i - po + 1); memcpy ((*headers)->name, o->buf + po, i - po); (*headers)->name[i - po] = '\0'; i++; @@ -47,7 +47,7 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, for (po = i; i < o->size-1 && o->buf[i] != '\r' ; i++) ; - (*headers)->value = odr_malloc(o, i - po + 1); + (*headers)->value = (char*) odr_malloc(o, i - po + 1); memcpy ((*headers)->value, o->buf + po, i - po); (*headers)->value[i - po] = '\0'; @@ -75,7 +75,7 @@ static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, else { *content_len = o->size - i; - *content_buf = odr_malloc(o, *content_len + 1); + *content_buf = (char*) odr_malloc(o, *content_len + 1); memcpy(*content_buf, o->buf + i, *content_len); (*content_buf)[*content_len] = '\0'; } @@ -87,7 +87,7 @@ void z_HTTP_header_add(ODR o, Z_HTTP_Header **hp, const char *n, { while (*hp) hp = &(*hp)->next; - *hp = odr_malloc(o, sizeof(**hp)); + *hp = (Z_HTTP_Header *) odr_malloc(o, sizeof(**hp)); (*hp)->name = odr_strdup(o, n); (*hp)->value = odr_strdup(o, v); (*hp)->next = 0; @@ -102,13 +102,33 @@ const char *z_HTTP_header_lookup(Z_HTTP_Header *hp, const char *n) } +Z_GDU *z_get_HTTP_Request(ODR o) +{ + Z_GDU *p = (Z_GDU *) odr_malloc(o, sizeof(*p)); + Z_HTTP_Request *hreq; + + p->which = Z_GDU_HTTP_Request; + p->u.HTTP_Request = (Z_HTTP_Request *) odr_malloc(o, sizeof(*hreq)); + hreq = p->u.HTTP_Request; + hreq->headers = 0; + hreq->content_len = 0; + hreq->content_buf = 0; + hreq->version = "1.1"; + hreq->method = "POST"; + hreq->path = "/"; + z_HTTP_header_add(o, &hreq->headers, "User-Agent", + "YAZ/" YAZ_VERSION); + return p; +} + Z_GDU *z_get_HTTP_Response(ODR o, int code) { - Z_GDU *p = odr_malloc(o, sizeof(*p)); + Z_GDU *p = (Z_GDU *) odr_malloc(o, sizeof(*p)); Z_HTTP_Response *hres; p->which = Z_GDU_HTTP_Response; - hres = p->u.HTTP_Response = odr_malloc(o, sizeof(*hres)); + p->u.HTTP_Response = (Z_HTTP_Response *) odr_malloc(o, sizeof(*hres)); + hres = p->u.HTTP_Response; hres->headers = 0; hres->content_len = 0; hres->content_buf = 0; @@ -118,7 +138,7 @@ Z_GDU *z_get_HTTP_Response(ODR o, int code) "YAZ/" YAZ_VERSION); if (code != 200) { - hres->content_buf = odr_malloc(o, 400); + hres->content_buf = (char*) odr_malloc(o, 400); sprintf (hres->content_buf, "\n" "\n" @@ -158,19 +178,22 @@ const char *z_HTTP_errmsg(int code) int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) { if (o->direction == ODR_DECODE) { - *p = odr_malloc(o, sizeof(**p)); + *p = (Z_GDU *) odr_malloc(o, sizeof(**p)); if (o->size > 10 && !memcmp(o->buf, "HTTP/", 5)) { int i, po; Z_HTTP_Response *hr; (*p)->which = Z_GDU_HTTP_Response; - hr = (*p)->u.HTTP_Response = odr_malloc(o, sizeof(*hr)); - +#if HTTP_DEBUG + fprintf(stderr, "-- HTTP decode:\n%.*s\n", o->size, o->buf); +#endif + hr = (*p)->u.HTTP_Response = (Z_HTTP_Response *) + odr_malloc(o, sizeof(*hr)); po = i = 5; while (i < o->size-2 && o->buf[i] != ' ' && o->buf[i] != '\r') i++; - hr->version = odr_malloc(o, i - po + 1); + hr->version = (char *) odr_malloc(o, i - po + 1); if (i - po) memcpy(hr->version, o->buf + po, i - po); hr->version[i-po] = 0; @@ -201,10 +224,11 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) Z_HTTP_Request *hr; #if HTTP_DEBUG - fprintf(stderr, "HTTP decode:\n%.*s\n", o->size, o->buf); + fprintf(stderr, "-- HTTP decode:\n%.*s\n", o->size, o->buf); #endif (*p)->which = Z_GDU_HTTP_Request; - hr = (*p)->u.HTTP_Request = odr_malloc(o, sizeof(*hr)); + hr = (*p)->u.HTTP_Request = + (Z_HTTP_Request *) odr_malloc(o, sizeof(*hr)); /* method .. */ for (i = 0; o->buf[i] != ' '; i++) @@ -213,7 +237,7 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) o->error = OHTTP; return 0; } - hr->method = odr_malloc(o, i+1); + hr->method = (char *) odr_malloc(o, i+1); memcpy (hr->method, o->buf, i); hr->method[i] = '\0'; /* path */ @@ -224,7 +248,7 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) o->error = OHTTP; return 0; } - hr->path = odr_malloc(o, i - po + 1); + hr->path = (char *) odr_malloc(o, i - po + 1); memcpy (hr->path, o->buf+po, i - po); hr->path[i - po] = '\0'; /* HTTP version */ @@ -245,7 +269,7 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) } i++; } - hr->version = odr_malloc(o, i - po + 1); + hr->version = (char *) odr_malloc(o, i - po + 1); memcpy(hr->version, o->buf + po, i - po); hr->version[i - po] = '\0'; /* headers */ @@ -269,7 +293,7 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) sprintf(sbuf, "HTTP/%s %d %s\r\n", (*p)->u.HTTP_Response->version, (*p)->u.HTTP_Response->code, z_HTTP_errmsg((*p)->u.HTTP_Response->code)); - odr_write(o, sbuf, strlen(sbuf)); + odr_write(o, (unsigned char *) sbuf, strlen(sbuf)); /* apply Content-Length if not already applied */ if (!z_HTTP_header_lookup((*p)->u.HTTP_Response->headers, "Content-Length")) @@ -282,42 +306,54 @@ int z_GDU (ODR o, Z_GDU **p, int opt, const char *name) } for (h = (*p)->u.HTTP_Response->headers; h; h = h->next) { - odr_write(o, h->name, strlen(h->name)); - odr_write(o, ": ", 2); - odr_write(o, h->value, strlen(h->value)); - odr_write(o, "\r\n", 2); + odr_write(o, (unsigned char *) h->name, strlen(h->name)); + odr_write(o, (unsigned char *) ": ", 2); + odr_write(o, (unsigned char *) h->value, strlen(h->value)); + odr_write(o, (unsigned char *) "\r\n", 2); } - odr_write(o, "\r\n", 2); + odr_write(o, (unsigned char *) "\r\n", 2); if ((*p)->u.HTTP_Response->content_buf) - odr_write(o, (*p)->u.HTTP_Response->content_buf, + odr_write(o, (unsigned char *) + (*p)->u.HTTP_Response->content_buf, (*p)->u.HTTP_Response->content_len); #if HTTP_DEBUG - fprintf(stderr, "HTTP response:\n%.*s\n", o->top, o->buf); + fprintf(stderr, "-- HTTP response:\n%.*s\n", o->top, o->buf); #endif break; case Z_GDU_HTTP_Request: - odr_write(o, (*p)->u.HTTP_Request->method, + odr_write(o, (unsigned char *) (*p)->u.HTTP_Request->method, strlen((*p)->u.HTTP_Request->method)); - odr_write(o, " ", 1); - odr_write(o, (*p)->u.HTTP_Request->path, + odr_write(o, (unsigned char *) " ", 1); + odr_write(o, (unsigned char *) (*p)->u.HTTP_Request->path, strlen((*p)->u.HTTP_Request->path)); - odr_write(o, " HTTP/", 6); - odr_write(o, (*p)->u.HTTP_Request->version, + odr_write(o, (unsigned char *) " HTTP/", 6); + odr_write(o, (unsigned char *) (*p)->u.HTTP_Request->version, strlen((*p)->u.HTTP_Request->version)); - odr_write(o, "\r\n", 2); + odr_write(o, (unsigned char *) "\r\n", 2); + if ((*p)->u.HTTP_Request->content_len && + !z_HTTP_header_lookup((*p)->u.HTTP_Request->headers, + "Content-Length")) + { + char lstr[20]; + sprintf(lstr, "%d", (*p)->u.HTTP_Request->content_len); + z_HTTP_header_add(o, + &(*p)->u.HTTP_Request->headers, + "Content-Length", lstr); + } for (h = (*p)->u.HTTP_Request->headers; h; h = h->next) { - odr_write(o, h->name, strlen(h->name)); - odr_write(o, ": ", 2); - odr_write(o, h->value, strlen(h->value)); - odr_write(o, "\r\n", 2); + odr_write(o, (unsigned char *) h->name, strlen(h->name)); + odr_write(o, (unsigned char *) ": ", 2); + odr_write(o, (unsigned char *) h->value, strlen(h->value)); + odr_write(o, (unsigned char *) "\r\n", 2); } - odr_write(o, "\r\n", 2); + odr_write(o, (unsigned char *) "\r\n", 2); if ((*p)->u.HTTP_Request->content_buf) - odr_write(o, (*p)->u.HTTP_Request->content_buf, + odr_write(o, (unsigned char *) + (*p)->u.HTTP_Request->content_buf, (*p)->u.HTTP_Request->content_len); #if HTTP_DEBUG - fprintf(stderr, "HTTP request:\n%.*s\n", o->top, o->buf); + fprintf(stderr, "-- HTTP request:\n%.*s\n", o->top, o->buf); #endif break; case Z_GDU_Z3950: diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index a414e45..7bad637 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.17 2003-02-12 15:06:44 adam Exp $ + * $Id: zoom-c.c,v 1.18 2003-02-14 18:49:24 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -18,7 +18,7 @@ #include #include #include - +#include #if HAVE_SYS_POLL_H #include @@ -174,6 +174,8 @@ void ZOOM_connection_remove_task (ZOOM_connection c) } } +static int ZOOM_connection_exec_task (ZOOM_connection c); + void ZOOM_connection_remove_tasks (ZOOM_connection c) { while (c->tasks) @@ -187,7 +189,7 @@ ZOOM_connection_create (ZOOM_options options) { ZOOM_connection c = (ZOOM_connection) xmalloc (sizeof(*c)); - c->soap = 0; + c->proto = PROTO_Z3950; c->cs = 0; c->mask = 0; c->reconnect_ok = 0; @@ -203,6 +205,7 @@ ZOOM_connection_create (ZOOM_options options) c->options = ZOOM_options_create_with_parent(options); c->host_port = 0; + c->path = 0; c->proxy = 0; c->charset = c->lang = 0; @@ -326,6 +329,7 @@ ZOOM_connection_connect(ZOOM_connection c, c->lang = 0; xfree (c->host_port); + xfree (c->path); if (portnum) { char hostn[128]; @@ -432,10 +436,6 @@ ZOOM_connection_destroy(ZOOM_connection c) ZOOM_resultset r; if (!c) return; -#if HAVE_GSOAP - if (c->soap) - soap_end(c->soap); -#endif if (c->cs) cs_close (c->cs); for (r = c->resultsets; r; r = r->next) @@ -650,43 +650,59 @@ static zoom_ret do_connect (ZOOM_connection c) if (memcmp(c->host_port, "http:", 5) == 0) { -#if HAVE_GSOAP - c->soap = soap_new(); - c->soap->namespaces = srw_namespaces; +#if HAVE_XSLT + const char *path; + c->proto = PROTO_SRW; + effective_host = c->host_port + 5; + if (*effective_host == '/') + effective_host++; + if (*effective_host == '/') + effective_host++; + if (!(path = strchr(effective_host, '/'))) + path = "/"; + xfree(c->path); + c->path = xstrdup(path); #else c->state = STATE_IDLE; set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW"); + return zoom_complete; #endif } - else + c->cs = cs_create_host (effective_host, 0, &add); + + if (c->cs) { - c->cs = cs_create_host (effective_host, 0, &add); - - if (c->cs) + int ret = cs_connect (c->cs, add); + if (ret == 0) { - int ret = cs_connect (c->cs, add); - if (ret == 0) - { - ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_CONNECT); - ZOOM_connection_put_event(c, event); + ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_CONNECT); + ZOOM_connection_put_event(c, event); + if (c->proto == PROTO_Z3950) ZOOM_connection_send_init(c); - c->state = STATE_ESTABLISHED; - return zoom_pending; - } - else if (ret > 0) + else { - c->state = STATE_CONNECTING; - c->mask = ZOOM_SELECT_EXCEPT; - if (c->cs->io_pending & CS_WANT_WRITE) - c->mask += ZOOM_SELECT_WRITE; - if (c->cs->io_pending & CS_WANT_READ) - c->mask += ZOOM_SELECT_READ; - return zoom_pending; + /* no init request for SRW .. */ + assert (c->tasks->which == ZOOM_TASK_CONNECT); + ZOOM_connection_remove_task (c); + c->mask = 0; + ZOOM_connection_exec_task (c); } + c->state = STATE_ESTABLISHED; + return zoom_pending; + } + else if (ret > 0) + { + c->state = STATE_CONNECTING; + c->mask = ZOOM_SELECT_EXCEPT; + if (c->cs->io_pending & CS_WANT_WRITE) + c->mask += ZOOM_SELECT_WRITE; + if (c->cs->io_pending & CS_WANT_READ) + c->mask += ZOOM_SELECT_READ; + return zoom_pending; } - c->state = STATE_IDLE; - set_ZOOM_error(c, ZOOM_ERROR_CONNECT, effective_host); } + c->state = STATE_IDLE; + set_ZOOM_error(c, ZOOM_ERROR_CONNECT, effective_host); return zoom_complete; } @@ -897,6 +913,72 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) return send_APDU (c, apdu); } +static zoom_ret send_srw (ZOOM_connection c, Z_SRW_searchRetrieve *sr) +{ + Z_SOAP_Handler h[2] = { + {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec}, + {0, 0, 0} + }; + ODR o = odr_createmem(ODR_ENCODE); + int ret; + Z_SOAP *p = odr_malloc(o, sizeof(*p)); + Z_GDU *gdu; + ZOOM_Event event; + + gdu = z_get_HTTP_Request(c->odr_out); + gdu->u.HTTP_Request->path = c->path; + z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, + "Content-Type", "text/xml"); + z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, + "SOAPAction", "\"\""); + p->which = Z_SOAP_generic; + p->u.generic = odr_malloc(o, sizeof(*p->u.generic)); + p->u.generic->no = 0; + p->u.generic->ns = 0; + p->u.generic->p = sr; + p->ns = "http://schemas.xmlsoap.org/soap/envelope/"; + + ret = z_soap_codec(o, &p, + &gdu->u.HTTP_Request->content_buf, + &gdu->u.HTTP_Request->content_len, h); + + if (!z_GDU(c->odr_out, &gdu, 0, 0)) + return zoom_complete; + c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0); + + odr_destroy(o); + + event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU); + ZOOM_connection_put_event (c, event); + odr_reset(c->odr_out); + return do_write (c); +} + +static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) +{ + ZOOM_resultset resultset; + Z_SRW_searchRetrieve *sr = yaz_srw_get(c->odr_out, + Z_SRW_searchRetrieve_request); + + assert (c->tasks); + assert (c->tasks->which == ZOOM_TASK_SEARCH); + + resultset = c->tasks->u.search.resultset; + assert(resultset); + assert (resultset->z_query); + + if (resultset->z_query->which == Z_Query_type_104 + && resultset->z_query->u.type_104->which == Z_External_CQL) + sr->u.request->query = resultset->z_query->u.type_104->u.cql; + else + sr->u.request->query = "dc.title = computer"; + + sr->u.request->startRecord = odr_intdup (c->odr_out, resultset->start + 1); + sr->u.request->maximumRecords = odr_intdup (c->odr_out, resultset->count); + + return send_srw(c, sr); +} + static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) { ZOOM_resultset r; @@ -2096,9 +2178,9 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) } task->running = 1; ret = zoom_complete; - if (c->soap) +#if 0 + if (c->proto == PROTO_SRW) { -#if HAVE_GSOAP ZOOM_resultset resultset; switch (task->which) { @@ -2127,16 +2209,16 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) resultset->z_query->u.type_104->u.cql); break; } -#else - ; #endif - } - else if (c->cs || task->which == ZOOM_TASK_CONNECT) + if (c->cs || task->which == ZOOM_TASK_CONNECT) { switch (task->which) { case ZOOM_TASK_SEARCH: - ret = ZOOM_connection_send_search(c); + if (c->proto == PROTO_SRW) + ret = ZOOM_connection_srw_send_search(c); + else + ret = ZOOM_connection_send_search(c); break; case ZOOM_TASK_RETRIEVE: ret = send_present (c); @@ -2305,10 +2387,16 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) } } +static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) +{ + c->mask = 0; + yaz_log (LOG_DEBUG, "handle_http"); + ZOOM_connection_remove_task(c); +} + static int do_read (ZOOM_connection c) { int r; - Z_APDU *apdu; ZOOM_Event event; event = ZOOM_Event_create (ZOOM_EVENT_RECV_DATA); @@ -2337,18 +2425,22 @@ static int do_read (ZOOM_connection c) } else { + Z_GDU *gdu; ZOOM_Event event; odr_reset (c->odr_in); odr_setbuf (c->odr_in, c->buf_in, r, 0); event = ZOOM_Event_create (ZOOM_EVENT_RECV_APDU); ZOOM_connection_put_event (c, event); - if (!z_APDU (c->odr_in, &apdu, 0, 0)) + + if (!z_GDU (c->odr_in, &gdu, 0, 0)) { set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); do_close (c); } - else - handle_apdu (c, apdu); + else if (gdu->which == Z_GDU_Z3950) + handle_apdu (c, gdu->u.z3950); + else if (gdu->which == Z_GDU_HTTP_Response) + handle_http (c, gdu->u.HTTP_Response); c->reconnect_ok = 0; } return 1; @@ -2554,7 +2646,16 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) else if (ret == 0) { ZOOM_connection_put_event (c, event); - ZOOM_connection_send_init (c); + if (c->proto == PROTO_Z3950) + ZOOM_connection_send_init(c); + else + { + /* no init request for SRW .. */ + assert (c->tasks->which == ZOOM_TASK_CONNECT); + ZOOM_connection_remove_task (c); + c->mask = 0; + ZOOM_connection_exec_task (c); + } c->state = STATE_ESTABLISHED; } else diff --git a/zutil/zoom-p.h b/zutil/zoom-p.h index 0f7a81e..f62d940 100644 --- a/zutil/zoom-p.h +++ b/zutil/zoom-p.h @@ -1,14 +1,10 @@ /* * Private C header for ZOOM C. - * $Id: zoom-p.h,v 1.3 2003-01-06 08:20:29 adam Exp $ + * $Id: zoom-p.h,v 1.4 2003-02-14 18:49:24 adam Exp $ */ -#if HAVE_GSOAP -#include -#else -struct soap { - int dummy; -}; +#if HAVE_XSLT +#include #endif #include @@ -34,9 +30,10 @@ struct ZOOM_query_p { #define ZOOM_SELECT_EXCEPT 4 struct ZOOM_connection_p { - struct soap *soap; + enum oid_proto proto; COMSTACK cs; char *host_port; + char *path; int error; char *addinfo; const char *diagset; -- 1.7.10.4