Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/yaz
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Aug 2011 16:42:49 +0000 (18:42 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Aug 2011 16:42:49 +0000 (18:42 +0200)
30 files changed:
NEWS
client/client.c
configure.ac
debian/changelog
debian/rules
include/yaz/Makefile.am
include/yaz/base64.h [new file with mode: 0644]
include/yaz/json.h
include/yaz/nmem.h
include/yaz/wrbuf.h
src/Makefile.am
src/base64.c [new file with mode: 0644]
src/http.c
src/nmemsdup.c
src/seshigh.c
src/session.h
src/srwutil.c
src/statserv.c
src/tcpdchk.c
src/wrbuf.c
src/zoom-c.c
src/zoom-p.h
src/zoom-sru.c
test/test_libstemmer.c
test/test_nmem.c
test/test_wrbuf.c
util/srwtst.c
win/makefile
yaz.spec
zoom/zoomsh.c

diff --git a/NEWS b/NEWS
index 4448f3b..7e204b3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+--- 4.2.7 2011/08/03
+
+ZOOM C includes HTTP response buffer as additional info if it fails
+to decode the SRU response.
+
+Make wrbuf_json_puts available.
+
 --- 4.2.6 2011/07/28
 
 zoom: throw diagnostic for invalid value for option "sru". Before a
index 4cf2207..3665ade 100644 (file)
@@ -2377,9 +2377,9 @@ static int cmd_update_common(const char *arg, int version)
 
 #if YAZ_HAVE_XML2
     if (protocol == PROTO_HTTP)
-        return send_SRW_update(action_no, recid_buf, rec_buf, rec_len);
+        return send_SRW_update(action_no, recid, rec_buf, rec_len);
 #endif
-    return send_Z3950_update(version, action_no, recid_buf, rec_buf, rec_len);
+    return send_Z3950_update(version, action_no, recid, rec_buf, rec_len);
 }
 
 #if YAZ_HAVE_XML2
index 2961291..bf6ac35 100644 (file)
@@ -1,7 +1,7 @@
 dnl This file is part of the YAZ toolkit.
 dnl Copyright (C) 1995-2011 Index Data
 AC_PREREQ([2.60])
-AC_INIT([yaz],[4.2.6],[yaz-help@indexdata.dk])
+AC_INIT([yaz],[4.2.7],[yaz-help@indexdata.dk])
 AC_CONFIG_HEADERS(include/config.h)
 AC_CONFIG_SRCDIR([configure.ac])
 AC_CONFIG_AUX_DIR([config])
index 4c07b71..70397fd 100644 (file)
@@ -1,3 +1,9 @@
+yaz (4.2.7-1indexdata) unstable; urgency=low
+
+  * Upstream.
+
+ -- Adam Dickmeiss <adam@indexdata.dk>  Wed, 03 Aug 2011 13:35:38 +0200
+
 yaz (4.2.6-1indexdata) unstable; urgency=low
 
   * Upstream.
index 49239e7..f1fb121 100755 (executable)
@@ -98,7 +98,7 @@ binary-arch: build install
        dh_fixperms
 #      dh_perl
 #      dh_python
-       dh_makeshlibs -V 'libyaz4 (>= 4.2.6)'
+       dh_makeshlibs -V 'libyaz4 (>= 4.2.7)'
        dh_installdeb
        dh_shlibdeps  -l debian/libyaz4/usr/lib
        dh_gencontrol
index d43ed8f..823a8dd 100644 (file)
@@ -3,7 +3,8 @@
 
 noinst_HEADERS = icu_I18N.h
 
-pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h rpn2cql.h rpn2solr.h \
+pkginclude_HEADERS= backend.h base64.h \
+ ccl.h ccl_xml.h cql.h rpn2cql.h rpn2solr.h \
  solr.h comstack.h \
  diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \
  nmem.h nmem_xml.h odr.h errno.h facet.h \
diff --git a/include/yaz/base64.h b/include/yaz/base64.h
new file mode 100644 (file)
index 0000000..8db22dd
--- /dev/null
@@ -0,0 +1,75 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2011 Index Data.
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Index Data nor the names of its contributors
+ *       may be used to endorse or promote products derived from this
+ *       software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file base64.h
+ * \brief Header for Base64 utilities
+ */
+
+#ifndef YAZ_BASE64_H
+#define YAZ_BASE64_H
+
+#include <yaz/yconfig.h>
+YAZ_BEGIN_CDECL
+
+/** \brief encodes Base64 string
+    \param in input string
+    \param out resulting Base64 string
+
+    The out buffer should at least be of size:
+
+    (strlen(in)*8) / 6 + 12
+*/
+YAZ_EXPORT
+void yaz_base64encode(const char *in, char *out);
+
+/** \brief decodes Base64 string
+    \param in input Base64 encoded string
+    \param out result string
+    \retval 0 OK
+    \retval -1 invalid character
+
+    The out buffer should at least be of size:
+
+    strlen(in)
+*/
+YAZ_EXPORT
+int yaz_base64decode(const char *in, char *out);
+
+YAZ_END_CDECL
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index de7803a..5c53d70 100644 (file)
@@ -187,6 +187,13 @@ void json_parser_subst(json_parser_t p, int idx, struct json_node *n);
 YAZ_EXPORT
 void json_write_wrbuf(struct json_node *node, WRBUF result);
 
+/** \brief writes JSON text to WRBUF with escaping
+    \param b result
+    \param str input string to be encoded
+*/
+YAZ_EXPORT
+void wrbuf_json_puts(WRBUF b, const char *str);
+
 YAZ_END_CDECL
 
 #endif
index c12ddc0..192f362 100644 (file)
@@ -134,6 +134,21 @@ YAZ_EXPORT void nmem_strsplitx(NMEM nmem, const char *delim,
 YAZ_EXPORT void nmem_strsplit_blank(NMEM nmem, const char *dstr,
                                     char ***darray, int *num);
 
+
+/** \brief allocates sub strings out of string using certain delimitors
+    \param nmem NMEM handle
+    \param delim delimitor chars (splits on each char in there) 
+    \param dstr string to be split
+    \param darray result string array for each sub string
+    \param num number of result strings
+    \param collapse 1=collapse multiple delims to one; 0=no collapse
+    \param escape_char != 0, an escape char (could be \)
+*/
+YAZ_EXPORT void nmem_strsplit_escape(NMEM nmem, const char *delim,
+                                     const char *dstr,
+                                     char ***darray, int *num, int collapse,
+                                     int escape_char);
+
 /** \brief allocates and sets integer for NMEM
     \param nmem NMEM handle
     \param v integer value
index 1296538..1b11e2f 100644 (file)
@@ -63,13 +63,21 @@ YAZ_EXPORT void wrbuf_destroy(WRBUF b);
  */
 YAZ_EXPORT void wrbuf_rewind(WRBUF b);
 
-/** \brief append constant size buffer to WRBU
+/** \brief append constant size buffer to WRBUF
     \param b WRBUF
     \param buf buffer
     \param size size of buffer
  */
 YAZ_EXPORT void wrbuf_write(WRBUF b, const char *buf, size_t size);
 
+/** \brief inserts buffer into WRBUF at some position
+    \param b WRBUF
+    \param pos position (0=beginning)
+    \param buf buffer
+    \param size size of buffer
+ */
+YAZ_EXPORT void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size);
+
 /** \brief appends C-string to WRBUF
     \param b WRBUF
     \param buf C-string (0-terminated)
index fc22046..8f66427 100644 (file)
@@ -71,7 +71,7 @@ GEN_FILES = oid_std.c \
   z-charneg.c \
   ill-core.c item-req.c oclc-ill-req-ext.c
 
-libyaz_la_SOURCES=version.c options.c log.c \
+libyaz_la_SOURCES=base64.c version.c options.c log.c \
  $(GEN_FILES) \
   marcdisp.c marc_read_xml.c marc_read_iso2709.c marc_read_line.c \
   wrbuf.c oid_db.c errno.c \
diff --git a/src/base64.c b/src/base64.c
new file mode 100644 (file)
index 0000000..d007a34
--- /dev/null
@@ -0,0 +1,111 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2011 Index Data
+ * See the file LICENSE for details.
+ */
+/**
+ * \file base64.c
+ * \brief Base64 encode/decode utilities
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <yaz/base64.h>
+
+void yaz_base64encode(const char *in, char *out)
+{
+    static char encoding[] =
+        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+    unsigned char buf[3];
+    long n;
+
+    while (*in != 0)
+    {
+       const char *pad = 0;
+        buf[0] = in[0];
+       buf[1] = in[1];
+       if (in[1] == 0)
+        {
+           buf[2] = 0;
+           pad = "==";
+       }
+        else
+        {
+           buf[2] = in[2];
+           if (in[2] == 0)
+               pad = "=";
+       }
+
+       /* Treat three eight-bit numbers as on 24-bit number */
+       n = (buf[0] << 16) + (buf[1] << 8) + buf[2];
+
+       /* Write the six-bit chunks out as four encoded characters */
+       *out++ = encoding[(n >> 18) & 63];
+       *out++ = encoding[(n >> 12) & 63];
+       if (in[1] != 0)
+           *out++ = encoding[(n >> 6) & 63];
+       if (in[1] != 0 && in[2] != 0)
+           *out++ = encoding[n & 63];
+
+       if (pad != 0) {
+           while (*pad != 0)
+               *out++ = *pad++;
+           break;
+       }
+       in += 3;
+    }
+    *out++ = 0;
+}
+
+int yaz_base64decode(const char *in, char *out)
+{
+    const char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+       "abcdefghijklmnopqrstuvwxyz0123456789+/";
+    int len = strlen(in);
+
+    while (len >= 4)
+    {
+       char i0, i1, i2, i3;
+       char *p;
+
+       if (!(p = strchr(map, in[0])))
+           return -1;
+       i0 = p - map;
+       len--;
+       if (!(p = strchr(map, in[1])))
+           return -1;
+       i1 = p - map;
+       len--;
+       *(out++) = i0 << 2 | i1 >> 4;
+       if (in[2] == '=')
+           break;
+       if (!(p = strchr(map, in[2])))
+           return -1;
+       i2 = p - map;
+       len--;
+       *(out++) = i1 << 4 | i2 >> 2;
+       if (in[3] == '=')
+           break;
+       if (!(p = strchr(map, in[3])))
+           return -1;
+       i3 = p - map;
+       len--;
+       *(out++) = i2 << 6 | i3;
+
+       in += 4;
+    }
+
+    *out = '\0';
+    return 0;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index c05dc02..e6a04a5 100644 (file)
 #include <yaz/yaz-iconv.h>
 #include <yaz/matchstr.h>
 #include <yaz/zgdu.h>
+#include <yaz/base64.h>
 
 #ifdef WIN32
 #define strncasecmp _strnicmp
 #define strcasecmp _stricmp
 #endif
  
-
-/*
- * This function's counterpart, yaz_base64decode(), is in srwutil.c.
- * I feel bad that they're not together, but each function is only
- * needed in one place, and those places are not together.  Maybe one
- * day we'll move them into a new httputil.c, and declare them in a
- * corresponding httputil.h
- */
-static void yaz_base64encode(const char *in, char *out)
-{
-    static char encoding[] =
-        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-    unsigned char buf[3];
-    long n;
-
-    while (*in != 0) {
-       char *pad = 0;
-        buf[0] = in[0];
-       buf[1] = in[1];
-       if (in[1] == 0) {
-           buf[2] = 0;
-           pad = "==";
-       } else {
-           buf[2] = in[2];
-           if (in[2] == 0)
-               pad = "=";
-       }
-
-       /* Treat three eight-bit numbers as on 24-bit number */
-       n = (buf[0] << 16) + (buf[1] << 8) + buf[2];
-
-       /* Write the six-bit chunks out as four encoded characters */
-       *out++ = encoding[(n >> 18) & 63];
-       *out++ = encoding[(n >> 12) & 63];
-       if (in[1] != 0)
-           *out++ = encoding[(n >> 6) & 63];
-       if (in[1] != 0 && in[2] != 0)
-           *out++ = encoding[n & 63];
-
-       if (pad != 0) {
-           while (*pad != 0)
-               *out++ = *pad++;
-           break;
-       }
-       in += 3;
-    }
-
-    *out++ = 0;
-}
-
-
 static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers,
                                   char **content_buf, int *content_len)
 {
index f697e73..fcfb074 100644 (file)
@@ -67,40 +67,19 @@ void nmem_strsplit(NMEM nmem, const char *delim, const char *dstr,
 void nmem_strsplitx(NMEM nmem, const char *delim, const char *dstr,
                     char ***darray, int *num, int collapse)
 {
-    const char *cp = dstr;
-    *num = 0;
+    nmem_strsplit_escape(nmem, delim, dstr, darray, num, collapse, 0);
+}
 
+void nmem_strsplit_escape(NMEM nmem, const char *delim, const char *dstr,
+                          char ***darray, int *num, int collapse,
+                          int escape_char)
+{
+    *darray = 0;
+    /* two passes over the input string.. */
     while (1)
     {
-        if (collapse)
-        {
-            if (!*cp)
-                break;
-            while (*cp && strchr(delim, *cp))
-                cp++;
-            if (!*cp)
-                break;
-            while (*cp && !strchr(delim, *cp))
-                cp++;
-            (*num)++;
-        }
-        else
-        {
-            (*num)++;
-            while (*cp && !strchr(delim, *cp))
-                cp++;
-            if (!*cp)
-                break;
-            cp++;
-        }
-    }
-    if (!*num)
-        *darray = 0;
-    else
-    {
         size_t i = 0;
-        *darray = (char **) nmem_malloc(nmem, *num * sizeof(**darray));
-        cp = dstr;
+        const char *cp = dstr;
         while (1)
         {
             const char *cp0;
@@ -108,26 +87,44 @@ void nmem_strsplitx(NMEM nmem, const char *delim, const char *dstr,
             {
                 if (!*cp)
                     break;
-                while (*cp && strchr(delim, *cp))
+                while (*cp && strchr(delim, *cp) && *cp != escape_char)
                     cp++;
                 if (!*cp)
                     break;
                 cp0 = cp;
                 while (*cp && !strchr(delim, *cp))
+                {
+                    if (*cp == escape_char)
+                        cp++;
                     cp++;
-                (*darray)[i++] = nmem_strdupn(nmem, cp0, cp - cp0);
+                }
+                if (*darray)
+                    (*darray)[i] = nmem_strdupn(nmem, cp0, cp - cp0);
+                i++;
             }
             else
             {
                 cp0 = cp;
                 while (*cp && !strchr(delim, *cp))
+                {
+                    if (*cp == escape_char)
+                        cp++;
                     cp++;
-                (*darray)[i++] = nmem_strdupn(nmem, cp0, cp - cp0);
+                }
+                if (*darray)
+                    (*darray)[i] = nmem_strdupn(nmem, cp0, cp - cp0);
+                i++;
                 if (!*cp)
                     break;
                 cp++;
             }
         }
+        *num = i;
+        if (!*num)
+            break; /* no items, so stop, *darray=0 already */
+        else if (*darray)
+            break; /* second pass, stop */
+        *darray = (char **) nmem_malloc(nmem, *num * sizeof(**darray));
     }
 }
 
index 739c998..c2311bb 100644 (file)
@@ -1879,7 +1879,6 @@ static void process_http_request(association *assoc, request *req)
                 {0, 0, 0}
             };
             char ctype[80];
-            int ret;
             p = z_get_HTTP_Response(o, 200);
             hres = p->u.HTTP_Response;
 
@@ -1890,9 +1889,9 @@ static void process_http_request(association *assoc, request *req)
             if (stylesheet && *stylesheet == '\0')
                 stylesheet = 0;
 
-            ret = z_soap_codec_enc_xsl(assoc->encode, &soap_package,
-                                       &hres->content_buf, &hres->content_len,
-                                       soap_handlers, charset, stylesheet);
+            z_soap_codec_enc_xsl(assoc->encode, &soap_package,
+                                 &hres->content_buf, &hres->content_len,
+                                 soap_handlers, charset, stylesheet);
             hres->code = http_code;
 
             strcpy(ctype, "text/xml");
@@ -2860,7 +2859,6 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb)
     Odr_int *next;
     Odr_int *num;
     int errcode = 0;
-    const char *errstring = 0;
 
     yaz_log(log_requestdetail, "Got PresentRequest.");
 
@@ -2889,7 +2887,6 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb)
             resp->records = diagrec(assoc, bprr->errcode, bprr->errstring);
             *resp->presentStatus = Z_PresentStatus_failure;
             errcode = bprr->errcode;
-            errstring = bprr->errstring;
         }
     }
     apdu = (Z_APDU *)odr_malloc(assoc->encode, sizeof(*apdu));
index 34f1ddb..af2d2ee 100644 (file)
@@ -43,6 +43,7 @@
 struct gfs_server {
     statserv_options_block cb;
     char *host;
+    char *id;
     int listen_ref;
     cql_transform_t cql_transform;
     CCL_bibset ccl_transform;
index 9eff9aa..a04516a 100644 (file)
@@ -14,6 +14,7 @@
 #include <assert.h>
 #include <yaz/srw.h>
 #include <yaz/matchstr.h>
+#include <yaz/base64.h>
 #include <yaz/yaz-iconv.h>
 #include "sru-p.h"
 
@@ -85,52 +86,6 @@ const char *yaz_element_attribute_value_get(xmlNodePtr ptr,
 }
 #endif
 
-static int yaz_base64decode(const char *in, char *out)
-{
-    const char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-       "abcdefghijklmnopqrstuvwxyz0123456789+/";
-    int olen = 0;
-    int len = strlen(in);
-
-    while (len >= 4)
-    {
-       char i0, i1, i2, i3;
-       char *p;
-
-       if (!(p = strchr(map, in[0])))
-           return 0;
-       i0 = p - map;
-       len--;
-       if (!(p = strchr(map, in[1])))
-           return 0;
-       i1 = p - map;
-       len--;
-       *(out++) = i0 << 2 | i1 >> 4;
-       olen++;
-       if (in[2] == '=')
-           break;
-       if (!(p = strchr(map, in[2])))
-           return 0;
-       i2 = p - map;
-       len--;
-       *(out++) = i1 << 4 | i2 >> 2;
-       olen++;
-       if (in[3] == '=')
-           break;
-       if (!(p = strchr(map, in[3])))
-           return 0;
-       i3 = p - map;
-       len--;
-       *(out++) = i2 << 6 | i3;
-       olen++;
-
-       in += 4;
-    }
-
-    *out = '\0';
-    return olen;
-}
-
 int yaz_srw_check_content_type(Z_HTTP_Response *hres)
 {
     const char *content_type = z_HTTP_header_lookup(hres->headers,
@@ -161,7 +116,7 @@ static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq,
 
     if (basic)
     {
-        int len, olen;
+        int len;
         char out[256];
         char ubuf[256] = "", pbuf[256] = "", *p;
         if (strncmp(basic, "Basic ", 6))
@@ -170,7 +125,7 @@ static void yaz_srw_decodeauth(Z_SRW_PDU *sr, Z_HTTP_Request *hreq,
         len = strlen(basic);
         if (!len || len > 256)
             return;
-        olen = yaz_base64decode(basic, out);
+        yaz_base64decode(basic, out);
         /* Format of out should be username:password at this point */
         strcpy(ubuf, out);
         if ((p = strchr(ubuf, ':')))
@@ -437,7 +392,6 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
         char *startRecord = 0;
         char *maximumTerms = 0;
         char *responsePosition = 0;
-        char *extraRequestData = 0;
         Z_SRW_extra_arg *extra_args = 0;
 #endif
         char **uri_name;
@@ -500,7 +454,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                 else if (!strcmp(n, "responsePosition"))
                     responsePosition = v;
                 else if (!strcmp(n, "extraRequestData"))
-                    extraRequestData = v;
+                    ; /* ignoring extraRequestData */
                 else if (n[0] == 'x' && n[1] == '-')
                 {
                     Z_SRW_extra_arg **l = &extra_args;
index a039251..4a469de 100644 (file)
@@ -214,7 +214,7 @@ static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr)
 #endif
 
 #if YAZ_HAVE_XML2
-static struct gfs_server * gfs_server_new(void)
+static struct gfs_server * gfs_server_new(const char *id)
 {
     struct gfs_server *n = (struct gfs_server *)
         nmem_malloc(gfs_nmem, sizeof(*n));
@@ -228,6 +228,7 @@ static struct gfs_server * gfs_server_new(void)
     n->directory = 0;
     n->docpath = 0;
     n->stylesheet = 0;
+    n->id = nmem_strdup_null(gfs_nmem, id);
     n->retrieval = yaz_retrieval_create();
     return n;
 }
@@ -386,7 +387,7 @@ static void xml_config_read(void)
                 else
                     yaz_log(YLOG_WARN, "Unknown attribute '%s' for server",
                             attr->name);
-            gfs = *gfsp = gfs_server_new();
+            gfs = *gfsp = gfs_server_new(id);
             gfs->server_node_ptr = ptr_server;
             if (listenref)
             {
index 26acb8e..8cff301 100644 (file)
 int allow_severity = LOG_INFO;  /* not YLOG !! */
 int deny_severity = LOG_WARNING;
 
-#ifdef LOG_DEBUG
-#undef LOG_DEBUG
-#endif
-#ifdef LOG_WARN
-#undef LOG_WARN
-#endif
-
 #endif
 
 int check_ip_tcpd(void *cd, const char *addr, int len, int type)
@@ -71,7 +64,6 @@ int check_ip_tcpd(void *cd, const char *addr, int len, int type)
 #if HAVE_TCPD_H
             struct request_info request_info;
             int i;
-#endif
             char *host_name = 0, *host_addr = 0;
             struct hostent *host;
 
@@ -82,7 +74,6 @@ int check_ip_tcpd(void *cd, const char *addr, int len, int type)
                                       AF_INET)))
                 host_name = (char*) host->h_name;
             host_addr = inet_ntoa(addr_in->sin_addr);
-#if HAVE_TCPD_H
             if (host_addr)
                 request_init(&request_info, RQ_DAEMON, daemon_name,
                              RQ_CLIENT_NAME, host_name,
@@ -99,8 +90,8 @@ int check_ip_tcpd(void *cd, const char *addr, int len, int type)
                          host_name ? host_name : host_addr);
                 return 1;
             }
-            yaz_log (YLOG_DEBUG, "access granted from %s",
-                     host_name ? host_name : host_addr);
+            yaz_log(YLOG_DEBUG, "access granted from %s",
+                    host_name ? host_name : host_addr);
 #endif
         }
     }
index 67de45e..13793ed 100644 (file)
@@ -74,6 +74,17 @@ void wrbuf_write(WRBUF b, const char *buf, size_t size)
     b->pos += size;
 }
 
+void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size)
+{
+    if (size <= 0 || pos > b->pos)
+        return;
+    if (b->pos + size >= b->size)
+        wrbuf_grow(b, size);
+    memmove(b->buf + pos + size, b->buf + pos, b->pos - pos);
+    memcpy(b->buf + pos, buf, size);
+    b->pos += size;
+}
+
 void wrbuf_puts(WRBUF b, const char *buf)
 {
     wrbuf_write(b, buf, strlen(buf));
index d2f33da..00158ec 100644 (file)
@@ -1533,7 +1533,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
 {
     zoom_ret cret = zoom_complete;
     int ret = -1;
-    const char *addinfo = 0;
+    char *addinfo = 0;
     const char *connection_head = z_HTTP_header_lookup(hres->headers,
                                                        "Connection");
     const char *location;
@@ -1563,7 +1563,7 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
     }
     else 
     {  
-        ret = ZOOM_handle_sru(c, hres, &cret);
+        ret = ZOOM_handle_sru(c, hres, &cret, &addinfo);
         if (ret == 0)
         {
             if (c->no_redirects) /* end of redirect. change hosts again */
@@ -1576,7 +1576,11 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
         if (hres->code != 200)
             ZOOM_set_HTTP_error(c, hres->code, 0, 0);
         else
+        {
+            yaz_log(YLOG_LOG, "set error... addinfo=%s", addinfo ?
+                    addinfo : "NULL");
             ZOOM_set_error(c, ZOOM_ERROR_DECODE, addinfo);
+        }
         ZOOM_connection_close(c);
     }
     if (cret == zoom_complete)
index 3c7b7ea..fd2a04c 100644 (file)
@@ -271,7 +271,7 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c);
 zoom_ret ZOOM_connection_srw_send_scan(ZOOM_connection c);
 
 int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
-                    zoom_ret *cret);
+                    zoom_ret *cret, char **addinfo);
 
 void ZOOM_set_HTTP_error(ZOOM_connection c, int error,
                          const char *addinfo, const char *addinfo2);
index 105970f..f9baf44 100644 (file)
@@ -391,16 +391,15 @@ static void handle_srw_scan_response(ZOOM_connection c,
 #endif
 
 int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
-                    zoom_ret *cret)
+                    zoom_ret *cret, char **addinfo)
 {
 #if YAZ_HAVE_XML2
     int ret = 0;
-    const char *addinfo = 0;
 
     /* not redirect (normal response) */
     if (!yaz_srw_check_content_type(hres))
     {
-        addinfo = "content-type";
+        *addinfo = "content-type";
         ret = -1;
     }
     else if (c->sru_mode == zoom_sru_solr)
@@ -445,7 +444,19 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
                                 soap_package->u.fault->fault_string);
         }
         else
+        {
+            size_t max_chars = 1000;
+            size_t sz = hres->content_len;
+            if (sz > max_chars - 1)
+                sz = max_chars;
+            *addinfo = odr_malloc(c->odr_in, sz + 4);
+            memcpy(*addinfo, hres->content_buf, sz);
+            if (sz == max_chars)
+                strcpy(*addinfo + sz, "...");
+            else
+                strcpy(*addinfo + sz, "");
             ret = -1;
+        }
     }   
     return ret;
 #else
index 3c18e04..5deea5f 100644 (file)
@@ -20,13 +20,12 @@ int test_stemmer_stem(yaz_stemmer_p stemmer, const char* to_stem, const char *ex
     struct icu_buf_utf16 *src  = icu_buf_utf16_create(0);
     struct icu_buf_utf16 *dst  = icu_buf_utf16_create(0);
     struct icu_buf_utf8  *dst8 = icu_buf_utf8_create(0);
-
+    int rc = 0;
     UErrorCode status; 
     const char *result;
+
     icu_utf16_from_utf8_cstr(src, to_stem, &status);
     yaz_stemmer_stem(stemmer, dst, src, &status); 
-    /* Assume fail */
-    int rc = 0;
     if (status == U_ZERO_ERROR) {
         icu_utf16_to_utf8(dst8, dst, &status);
         result = icu_buf_utf8_to_cstr(dst8);
index 027b823..cc34f27 100644 (file)
@@ -72,8 +72,16 @@ void tst_nmem_strsplit(void)
     YAZ_CHECK(num > 0 && !strcmp(array[0], "a"));
     YAZ_CHECK(num > 1 && !strcmp(array[1], "b"));
     YAZ_CHECK(num > 2 && !strcmp(array[2], "cd"));
+
     nmem_strsplitx(nmem, ",", ",a,b,,cd", &array, &num, 0);
+    YAZ_CHECK(num == 5);
+    YAZ_CHECK(num > 0 && !strcmp(array[0], ""));
+    YAZ_CHECK(num > 1 && !strcmp(array[1], "a"));
+    YAZ_CHECK(num > 2 && !strcmp(array[2], "b"));
+    YAZ_CHECK(num > 3 && !strcmp(array[3], ""));
+    YAZ_CHECK(num > 4 && !strcmp(array[4], "cd"));
 
+    nmem_strsplit_escape(nmem, ",", ",a,b,,cd", &array, &num, 0, '\\');
     YAZ_CHECK(num == 5);
     YAZ_CHECK(num > 0 && !strcmp(array[0], ""));
     YAZ_CHECK(num > 1 && !strcmp(array[1], "a"));
@@ -81,6 +89,24 @@ void tst_nmem_strsplit(void)
     YAZ_CHECK(num > 3 && !strcmp(array[3], ""));
     YAZ_CHECK(num > 4 && !strcmp(array[4], "cd"));
 
+    nmem_strsplit_escape(nmem, ",", ",a,b\\,,cd", &array, &num, 0, '\\');
+    YAZ_CHECK(num == 4);
+    YAZ_CHECK(num > 0 && !strcmp(array[0], ""));
+    YAZ_CHECK(num > 1 && !strcmp(array[1], "a"));
+    YAZ_CHECK(num > 2 && !strcmp(array[2], "b\\,"));
+    YAZ_CHECK(num > 3 && !strcmp(array[3], "cd"));
+
+    nmem_strsplit_escape(nmem, ",", "\\,a,b\\,,cd", &array, &num, 0, '\\');
+    YAZ_CHECK(num == 3);
+    YAZ_CHECK(num > 0 && !strcmp(array[0], "\\,a"));
+    YAZ_CHECK(num > 1 && !strcmp(array[1], "b\\,"));
+    YAZ_CHECK(num > 2 && !strcmp(array[2], "cd"));
+
+    nmem_strsplit_escape(nmem, ",", "\\,a,b\\,\\,cd", &array, &num, 0, '\\');
+    YAZ_CHECK(num == 2);
+    YAZ_CHECK(num > 0 && !strcmp(array[0], "\\,a"));
+    YAZ_CHECK(num > 1 && !strcmp(array[1], "b\\,\\,cd"));
+
     nmem_destroy(nmem);
 }
 
index 007258a..f213561 100644 (file)
@@ -54,6 +54,27 @@ static void tstwrbuf(void)
             }
         wrbuf_rewind(wr);
     }
+
+    wrbuf_rewind(wr);
+    wrbuf_puts(wr, "1234");
+    wrbuf_insert(wr, 0, "abc", 3);
+    YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "abc1234"));
+
+    wrbuf_rewind(wr);
+    wrbuf_puts(wr, "1234");
+    wrbuf_insert(wr, 1, "abc", 3);
+    YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1abc234"));
+
+    wrbuf_rewind(wr);
+    wrbuf_puts(wr, "1234");
+    wrbuf_insert(wr, 4, "abc", 3);
+    YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234abc"));
+
+    wrbuf_rewind(wr);
+    wrbuf_puts(wr, "1234");
+    wrbuf_insert(wr, 5, "abc", 3);
+    YAZ_CHECK(!strcmp(wrbuf_cstr(wr), "1234"));
+
     wrbuf_destroy(wr);
 }
 
index 2a1802f..2c9a229 100644 (file)
@@ -20,7 +20,6 @@ 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;
@@ -37,8 +36,8 @@ int main(int argc, char **argv)
     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);
+    z_soap_codec(decode, &soap_package, 
+                 &content_buf, &content_len, h);
     if (!soap_package)
     {
         fprintf(stderr, "Decoding seriously failed\n");
@@ -88,8 +87,7 @@ int main(int argc, char **argv)
 
         }
     }
-    ret = z_soap_codec(encode, &soap_package,
-                       &content_buf, &content_len, h);
+    z_soap_codec(encode, &soap_package, &content_buf, &content_len, h);
     if (content_buf && content_len)
     {
         printf("%.*s", content_len, content_buf);
index 54e3881..3f8cc6f 100644 (file)
@@ -395,6 +395,7 @@ TEST_MUTEX_OBJS = \
    $(OBJDIR)\test_mutex.obj
 
 MISC_OBJS= \
+   $(OBJDIR)\base64.obj \
    $(OBJDIR)\version.obj \
    $(OBJDIR)\oid_std.obj \
    $(OBJDIR)\eventl.obj \
index 4a98bd7..ac59744 100644 (file)
--- a/yaz.spec
+++ b/yaz.spec
@@ -5,7 +5,7 @@
 
 Name: yaz
 Summary: Z39.50 Programs
-Version: 4.2.6
+Version: 4.2.7
 Release: 1indexdata
 
 # determine system
index 702b09d..9115bf3 100644 (file)
@@ -311,29 +311,6 @@ static void cmd_facets(ZOOM_connection *c, ZOOM_resultset *r,
                      const char **args)
 {
     int i;
-    size_t start = 0, count = 1;
-    const char *type = "render";
-    WRBUF render_str = 0;
-
-    if (0)
-    {
-        WRBUF tmp;
-
-        if ((tmp = next_token_new_wrbuf(args)))
-        {
-            start = atoi(wrbuf_cstr(tmp));
-            wrbuf_destroy(tmp);
-        }
-
-        if ((tmp = next_token_new_wrbuf(args)))
-        {
-            count = atoi(wrbuf_cstr(tmp));
-            wrbuf_destroy(tmp);
-        }
-        render_str = next_token_new_wrbuf(args);
-    }
-    if (render_str)
-        type = wrbuf_cstr(render_str);
 
     process_events(c);
 
@@ -357,9 +334,6 @@ static void cmd_facets(ZOOM_connection *c, ZOOM_resultset *r,
             }
         }
     }
-    if (render_str)
-        wrbuf_destroy(render_str);
-
 }
 
 static void cmd_ext(ZOOM_connection *c, ZOOM_resultset *r,