Include proto.h for prototype of yaz_use_attribute_create
[yaz-moved-to-github.git] / src / solr.c
index 9897bb1..4ae57bb 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.
  */
 /**
@@ -18,6 +18,7 @@
 #include <yaz/log.h>
 #include <yaz/facet.h>
 #include <yaz/wrbuf.h>
+#include <yaz/proto.h>
 
 #include "sru-p.h"
 
@@ -87,9 +88,8 @@ static void yaz_solr_decode_result_docs(ODR o, xmlNodePtr ptr,
             record->recordSchema = 0;
             record->recordPacking = Z_SRW_recordPacking_XML;
             record->recordData_len = buf->use;
-            record->recordData_buf = odr_malloc(o, buf->use + 1);
-            memcpy(record->recordData_buf, buf->content, buf->use);
-            record->recordData_buf[buf->use] = '\0';
+            record->recordData_buf =
+                odr_strdupn(o, (const char *) buf->content, buf->use);
             record->recordPosition = odr_intdup(o, start + offset + 1);
 
             xmlBufferFree(buf);
@@ -483,6 +483,7 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
     char *q;
     char *pos;
     char *cp;
+    const char *path_args = 0;
     int i = 0;
 
     z_HTTP_header_add_basic_auth(encode, &hreq->headers,
@@ -581,8 +582,17 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
 
     path = (char *)
         odr_malloc(encode, strlen(hreq->path) +
-                   strlen(uri_args) + strlen(solr_op) + 4);
+                   strlen(uri_args) + strlen(solr_op) + 5);
 
+    cp = strchr(hreq->path, '#');
+    if (cp)
+        *cp = '\0';
+    cp = strchr(hreq->path, '?');
+    if (cp)
+    {
+        *cp = '\0'; /* args in path */
+        path_args = cp + 1;
+    }
     strcpy(path, hreq->path);
     cp = strrchr(path, '/');
     if (cp)
@@ -593,6 +603,11 @@ int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
     strcat(path, "/");
     strcat(path, solr_op);
     strcat(path, "?");
+    if (path_args)
+    {
+        strcat(path, path_args);
+        strcat(path, "&");
+    }
     strcat(path, uri_args);
     hreq->path = path;