+static int http_parse_arguments(struct http_request *r, NMEM nmem,
+ const char *args)
+{
+ const char *p2 = args;
+
+ while (*p2)
+ {
+ struct http_argument *a;
+ const char *equal = strchr(p2, '=');
+ const char *eoa = strchr(p2, '&');
+ if (!equal)
+ {
+ yaz_log(YLOG_WARN, "Expected '=' in argument");
+ return -1;
+ }
+ if (!eoa)
+ eoa = equal + strlen(equal); // last argument
+ else if (equal > eoa)
+ {
+ yaz_log(YLOG_WARN, "Missing '&' in argument");
+ return -1;
+ }
+ a = nmem_malloc(nmem, sizeof(struct http_argument));
+ a->name = nmem_strdupn(nmem, p2, equal - p2);
+ a->value = nmem_strdupn(nmem, equal+1, eoa - equal - 1);
+ urldecode(a->name, a->name);
+ urldecode(a->value, a->value);
+ a->next = r->arguments;
+ r->arguments = a;
+ p2 = eoa;
+ while (*p2 == '&')
+ p2++;
+ }
+ return 0;
+}
+