Extra brace around it stmt to avoid warning
[yaz-moved-to-github.git] / src / zoom-sru.c
index 9936bdd..c3328fe 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -34,7 +34,6 @@ static void set_SRU_error(ZOOM_connection c, Z_SRW_diagnostic *d)
 static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
 {
     Z_GDU *gdu;
-    ZOOM_Event event;
     const char *database =  ZOOM_options_get(c->options, "databaseName");
 
     gdu = z_get_HTTP_Request_uri(c->odr_out, c->host_port,
@@ -57,18 +56,7 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
     {
         yaz_solr_encode_request(gdu->u.HTTP_Request, sr, c->odr_out, c->charset);
     }
-    if (!z_GDU(c->odr_out, &gdu, 0, 0))
-        return zoom_complete;
-    if (c->odr_print)
-        z_GDU(c->odr_print, &gdu, 0, 0);
-    if (c->odr_save)
-        z_GDU(c->odr_save, &gdu, 0, 0);
-    c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
-
-    event = ZOOM_Event_create(ZOOM_EVENT_SEND_APDU);
-    ZOOM_connection_put_event(c, event);
-    odr_reset(c->odr_out);
-    return ZOOM_send_buf(c);
+    return ZOOM_send_GDU(c, gdu);
 }
 #endif
 
@@ -313,7 +301,7 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
         }
         for (i = 0; i<res->num_records; i++)
         {
-            int pos;
+            int pos = *start + i;
             Z_SRW_record *sru_rec;
             Z_SRW_diagnostic *diag = 0;
             int num_diag;
@@ -321,12 +309,10 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
             Z_NamePlusRecord *npr = (Z_NamePlusRecord *)
                 odr_malloc(c->odr_in, sizeof(Z_NamePlusRecord));
 
-            /* recordPosition is 1 based */
+            /* only trust recordPosition if >= calculated position */
             if (res->records[i].recordPosition &&
-                *res->records[i].recordPosition > 0)
+                *res->records[i].recordPosition >= pos + 1)
                 pos = *res->records[i].recordPosition - 1;
-            else
-                pos = *start + i;
 
             sru_rec = &res->records[i];
 
@@ -418,15 +404,19 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
         Z_SRW_PDU *sr;
         ret = yaz_solr_decode_response(c->odr_in, hres, &sr);
         if (ret == 0)
+        {
             if (sr->which == Z_SRW_searchRetrieve_response)
                 *cret = handle_srw_response(c, sr->u.response);
+            else if (sr->which == Z_SRW_scan_response)
+                handle_srw_scan_response(c, sr->u.scan_response);
+        }
     }
     else
     {
         Z_SOAP *soap_package = 0;
         ODR o = c->odr_in;
         Z_SOAP_Handler soap_handlers[3] = {
-            {YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec},
+            {YAZ_XMLNS_SRU_v1_response, 0, (Z_SOAP_fun) yaz_srw_codec},
             {YAZ_XMLNS_SRU_v2_response, 0, (Z_SOAP_fun) yaz_srw_codec},
             {0, 0, 0}
         };