Version 4.2.68
[yaz-moved-to-github.git] / src / zoom-sru.c
index b997eeb..0776057 100644 (file)
@@ -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
@@ -247,7 +268,7 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
     NMEM nmem;
     ZOOM_Event event;
     int *start, *count;
-    const char *syntax, *elementSetName;
+    const char *syntax, *elementSetName, *schema;
 
     if (!c->tasks)
         return zoom_complete;
@@ -260,7 +281,7 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
         count = &c->tasks->u.search.count;
         syntax = c->tasks->u.search.syntax;
         elementSetName = c->tasks->u.search.elementSetName;
-
+        schema = c->tasks->u.search.schema;
         /* Required not for reporting client hit count multiple times into session */
         if (!c->tasks->u.search.recv_search_fired) {
             yaz_log(YLOG_DEBUG, "posting ZOOM_EVENT_RECV_SEARCH");
@@ -277,6 +298,7 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
         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;
@@ -346,7 +368,7 @@ static zoom_ret handle_srw_response(ZOOM_connection c,
                                                  resultset->odr);
             }
             ZOOM_record_cache_add(resultset, npr, pos, syntax, elementSetName,
-                                  sru_rec->recordSchema, diag);
+                                  schema, diag);
         }
         *count -= i;
         *start += i;