Bump copyright year
[yaz-moved-to-github.git] / src / zoom-c.c
index d0f5042..0dd7110 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2009 Index Data
+ * Copyright (C) 1995-2010 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -1071,7 +1071,7 @@ static void resultset_destroy(ZOOM_resultset r)
 ZOOM_API(size_t)
     ZOOM_resultset_size(ZOOM_resultset r)
 {
-    yaz_log(log_details, "ZOOM_resultset_size r=%p count=%d",
+    yaz_log(log_details, "ZOOM_resultset_size r=%p count=" ODR_INT_PRINTF,
             r, r->size);
     return r->size;
 }
@@ -1213,14 +1213,14 @@ static zoom_ret do_connect(ZOOM_connection c)
     if (c->cs && c->cs->protocol == PROTO_HTTP)
     {
 #if YAZ_HAVE_XML2
-        const char *path = 0;
+        const char *db = 0;
 
         c->proto = PROTO_HTTP;
-        cs_get_host_args(c->host_port, &path);
+        cs_get_host_args(c->host_port, &db);
         xfree(c->path);
-        c->path = (char*) xmalloc(strlen(path)+2);
-        c->path[0] = '/';
-        strcpy(c->path+1, path);
+
+        c->path = xmalloc(strlen(db) * 3 + 2);
+        yaz_encode_sru_dbpath_buf(c->path, db);
 #else
         set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW");
         do_close(c);
@@ -1445,11 +1445,7 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
     char *fdatabase = 0;
     
     if (database)
-    {
-        fdatabase = (char *) odr_malloc(c->odr_out, strlen(database)+2);
-        strcpy(fdatabase, "/");
-        strcat(fdatabase, database);
-    }
+        fdatabase = yaz_encode_sru_dbpath_odr(c->odr_out, database);
     gdu = z_get_HTTP_Request_host_path(c->odr_out, c->host_port,
                                        fdatabase ? fdatabase : c->path);
 
@@ -1635,12 +1631,19 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c)
             yaz_iconv_t cd = yaz_iconv_open(cp, "UTF-8");
             if (cd)
             {
+                int r;
                 search_req->query = yaz_copy_Z_Query(search_req->query,
                                                      c->odr_out);
                 
-                yaz_query_charset_convert_rpnquery(search_req->query->u.type_1,
-                                                   c->odr_out, cd);
+                r = yaz_query_charset_convert_rpnquery_check(
+                    search_req->query->u.type_1,
+                    c->odr_out, cd);
                 yaz_iconv_close(cd);
+                if (r)
+                {  /* query could not be char converted */
+                    set_ZOOM_error(c, ZOOM_ERROR_INVALID_QUERY, 0);
+                    return zoom_complete;
+                }
             }
         }
     }
@@ -1971,6 +1974,9 @@ static const char *return_record(ZOOM_record rec, int *len,
                 charset);
             if (ret_buf)
                 return ret_buf;
+            /* bad ISO2709. Return fail unless raw (ISO2709) is wanted */
+            if (marctype != YAZ_MARC_ISO2709)
+                return 0;
         }
         return return_string_record(rec, len,
                                     (const char *) r->u.octet_aligned->buf,
@@ -2905,7 +2911,7 @@ ZOOM_API(size_t)
 }
 
 static void ZOOM_scanset_term_x(ZOOM_scanset scan, size_t pos,
-                                int *occ,
+                                size_t *occ,
                                 const char **value_term, size_t *value_len,
                                 const char **disp_term, size_t *disp_len)
 {
@@ -2963,7 +2969,7 @@ static void ZOOM_scanset_term_x(ZOOM_scanset scan, size_t pos,
 
 ZOOM_API(const char *)
     ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
-                      int *occ, int *len)
+                      size_t *occ, size_t *len)
 {
     const char *value_term = 0;
     size_t value_len = 0;
@@ -2979,7 +2985,7 @@ ZOOM_API(const char *)
 
 ZOOM_API(const char *)
     ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
-                              int *occ, int *len)
+                              size_t *occ, size_t *len)
 {
     const char *value_term = 0;
     size_t value_len = 0;
@@ -4077,6 +4083,8 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
             Z_SRW_PDU *sr = (Z_SRW_PDU*) soap_package->u.generic->p;
 
             ZOOM_options_set(c->options, "sru_version", sr->srw_version);
+            ZOOM_options_setl(c->options, "sru_extra_response_data",
+                sr->extraResponseData_buf, sr->extraResponseData_len);
             if (sr->which == Z_SRW_searchRetrieve_response)
                 cret = handle_srw_response(c, sr->u.response);
             else if (sr->which == Z_SRW_scan_response)