Simplify in a lot of places using odr_strdupn
[yaz-moved-to-github.git] / src / srwutil.c
index c18ca64..ae8ecae 100644 (file)
@@ -246,9 +246,7 @@ static void grab_charset(ODR o, const char *content_type, char **charset)
             while (i < 20 && charset_p[i] &&
                    !strchr("; \n\r", charset_p[i]))
                 i++;
-            *charset = (char*) odr_malloc(o, i+1);
-            memcpy(*charset, charset_p, i);
-            (*charset)[i] = '\0';
+            *charset = odr_strdupn(o, charset_p, i);
         }
     }
 }
@@ -397,6 +395,9 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
         char *startRecord = 0;
         char *maximumTerms = 0;
         char *responsePosition = 0;
+        const char *facetLimit = 0;
+        const char *facetStart = 0;
+        const char *facetSort = 0;
         Z_SRW_extra_arg *extra_args = 0;
 #endif
         char **uri_name;
@@ -468,6 +469,12 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                     maximumTerms = v;
                 else if (!strcmp(n, "responsePosition"))
                     responsePosition = v;
+                else if (!strcmp(n, "facetLimit"))
+                    facetLimit = v;
+                else if (!strcmp(n, "facetStart"))
+                    facetStart = v;
+                else if (!strcmp(n, "facetSort"))
+                    facetSort = v;
                 else if (!strcmp(n, "extraRequestData"))
                     ; /* ignoring extraRequestData */
                 else if (n[0] == 'x' && n[1] == '-')
@@ -552,6 +559,8 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
             sr->u.request->recordPacking = recordXMLEscaping;
             sr->u.request->packing = recordPacking;
             sr->u.request->stylesheet = stylesheet;
+            yaz_sru_facet_request(decode , &sr->u.request->facetList,
+                                  &facetLimit, &facetStart, &facetSort);
 
             yaz_sru_decode_integer(decode, "maximumRecords", maximumRecords,
                                    &sr->u.request->maximumRecords,
@@ -954,6 +963,19 @@ static int yaz_get_sru_parms(const Z_SRW_PDU *srw_pdu, ODR encode,
                                srw_pdu->u.request->stylesheet);
         yaz_add_name_value_int(encode, name, value, &i, "resultSetTTL",
                                srw_pdu->u.request->resultSetTTL);
+        {
+            const char *facetLimit = 0;
+            const char *facetStart = 0;
+            const char *facetSort = 0;
+            yaz_sru_facet_request(encode, &srw_pdu->u.request->facetList,
+                                  &facetLimit, &facetStart, &facetSort);
+            yaz_add_name_value_str(encode, name, value, &i, "facetLimit",
+                                   (char *) facetLimit);
+            yaz_add_name_value_str(encode, name, value, &i, "facetStart",
+                                   (char *) facetStart);
+            yaz_add_name_value_str(encode, name, value, &i, "facetSort",
+                                   (char *) facetSort);
+        }
         break;
     case Z_SRW_explain_request:
         value[i++] = "explain";
@@ -1042,7 +1064,6 @@ int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
         odr_malloc(encode, strlen(hreq->path) + strlen(uri_args) + 4);
 
     sprintf(path, "%s?%s", hreq->path, uri_args);
-    yaz_log(YLOG_DEBUG, "SRU HTTP Get Request %s", path);
     hreq->path = path;
 
     z_HTTP_header_add_content_type(encode, &hreq->headers,
@@ -1159,6 +1180,9 @@ void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args)
         Z_SRW_extra_arg **ea = &sr->extra_args;
         yaz_uri_to_array(extra_args, odr, &name, &val);
 
+        /** append rather than override */
+        while (*ea)
+            ea = &(*ea)->next;
         while (*name)
         {
             *ea = (Z_SRW_extra_arg *) odr_malloc(odr, sizeof(**ea));