zoom: one common search task
[yaz-moved-to-github.git] / src / zoom-sru.c
index bdfe175..8f5feb0 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -62,8 +62,29 @@ static zoom_ret send_srw(ZOOM_connection c, Z_SRW_PDU *sr)
 static Z_SRW_PDU *ZOOM_srw_get_pdu(ZOOM_connection c, int type)
 {
     Z_SRW_PDU *sr = yaz_srw_get_pdu(c->odr_out, type, c->sru_version);
-    sr->username = c->user;
-    sr->password = c->password;
+    if (c->url_authentication && c->user)
+    {
+        Z_SRW_extra_arg **ea = &sr->extra_args;
+        while (*ea)
+            ea = &(*ea)->next;
+        *ea = (Z_SRW_extra_arg *) odr_malloc(c->odr_out, sizeof(**ea));
+        (*ea)->name = "x-username";
+        (*ea)->value = c->user;
+        ea = &(*ea)->next;
+        if (c->password)
+        {
+            *ea = (Z_SRW_extra_arg *) odr_malloc(c->odr_out, sizeof(**ea));
+            (*ea)->name = "x-password";
+            (*ea)->value = c->password;
+            ea = &(*ea)->next;
+        }
+        *ea = 0;
+    }
+    else
+    {
+        sr->username = c->user;
+        sr->password = c->password;
+    }
     return sr;
 }
 #endif
@@ -150,12 +171,6 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
             facet_list = yaz_pqf_parse_facet_list(c->odr_out, facets);
         schema = c->tasks->u.search.schema;
         break;
-    case ZOOM_TASK_RETRIEVE:
-        resultset = c->tasks->u.retrieve.resultset;
-        schema = c->tasks->u.retrieve.schema;
-
-        start = &c->tasks->u.retrieve.start;
-        count = &c->tasks->u.retrieve.count;
 
         if (*start >= resultset->size)
             return zoom_complete;
@@ -166,8 +181,8 @@ zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c)
         {
             ZOOM_record rec =
                 ZOOM_record_cache_lookup(resultset, i + *start,
-                                         c->tasks->u.retrieve.syntax,
-                                         c->tasks->u.retrieve.elementSetName,
+                                         c->tasks->u.search.syntax,
+                                         c->tasks->u.search.elementSetName,
                                          schema);
             if (!rec)
                 break;
@@ -271,14 +286,6 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
         if (res->facetList)
             ZOOM_handle_facet_list(resultset, res->facetList);
         break;
-    case ZOOM_TASK_RETRIEVE:
-        resultset = c->tasks->u.retrieve.resultset;
-        start = &c->tasks->u.retrieve.start;
-        count = &c->tasks->u.retrieve.count;
-        syntax = c->tasks->u.retrieve.syntax;
-        elementSetName = c->tasks->u.retrieve.elementSetName;
-        schema = c->tasks->u.retrieve.schema;
-        break;
     default:
         return zoom_complete;
     }
@@ -329,16 +336,10 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
             npr->u.databaseRecord->indirect_reference = 0;
             npr->u.databaseRecord->which = Z_External_octet;
 
-            npr->u.databaseRecord->u.octet_aligned = (Odr_oct *)
-                odr_malloc(c->odr_in, sizeof(Odr_oct));
-            npr->u.databaseRecord->u.octet_aligned->buf =
-                sru_rec->recordData_buf;
-            npr->u.databaseRecord->u.octet_aligned->len =
-                sru_rec->recordData_len;
-#if OCT_SIZE
-            npr->u.databaseRecord->u.octet_aligned->size =
-                sru_rec->recordData_len;
-#endif
+            npr->u.databaseRecord->u.octet_aligned =
+                odr_create_Odr_oct(c->odr_in,
+                                   sru_rec->recordData_buf,
+                                   sru_rec->recordData_len);
             if (sru_rec->recordSchema
                 && !strcmp(sru_rec->recordSchema,
                            "info:srw/schema/1/diagnostics-v1.1"))
@@ -420,9 +421,10 @@ int ZOOM_handle_sru(ZOOM_connection c, Z_HTTP_Response *hres,
     {
         Z_SOAP *soap_package = 0;
         ODR o = c->odr_in;
-        Z_SOAP_Handler soap_handlers[3] = {
+        Z_SOAP_Handler soap_handlers[4] = {
             {YAZ_XMLNS_SRU_v1_response, 0, (Z_SOAP_fun) yaz_srw_codec},
             {YAZ_XMLNS_SRU_v2_mask, 0, (Z_SOAP_fun) yaz_srw_codec},
+            {"searchRetrieveResponse", 0, (Z_SOAP_fun) yaz_srw_codec},
             {0, 0, 0}
         };
         ret = z_soap_codec(o, &soap_package,