/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2009 Index Data
+ * Copyright (C) 1995-2013 Index Data
* See the file LICENSE for details.
*/
/**
- * \file srwutil.c
- * \brief Implements SRW/SRU utilities.
+ * \file uri.c
+ * \brief Implements URI utilities.
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdlib.h>
#include <yaz/srw.h>
for(i = 0; name[i]; i++)
sz += strlen(name[i]) + 3 + strlen(value[i]) * 3;
*path = (char *) odr_malloc(o, sz);
-
+
for(i = 0; name[i]; i++)
{
size_t ilen;
{
cp++;
no++;
+ while (*cp && *cp != '=' && *cp != '&')
+ {
+ /* check that x-form names looks sane */
+ if (*cp <= ' ' || *cp >= 127)
+ return 0;
+ cp++;
+ }
}
*name = (char **) odr_malloc(o, no * sizeof(char*));
*val = (char **) odr_malloc(o, no * sizeof(char*));
for (no = 0; *path; no++)
{
- const char *p1 = strchr(path, '=');
- size_t i = 0;
- char *ret;
- if (!p1)
+ while (*path == '&')
+ path++;
+ if (!*path)
break;
- (*name)[no] = (char *) odr_malloc(o, (p1-path)+1);
- memcpy((*name)[no], path, p1-path);
- (*name)[no][p1-path] = '\0';
+ for (cp = path; *cp && *cp != '=' && *cp != '&'; cp++)
+ ;
- path = p1 + 1;
- p1 = strchr(path, '&');
- if (!p1)
- p1 = strlen(path) + path;
- (*val)[no] = ret = (char *) odr_malloc(o, p1 - path + 1);
- while (*path && *path != '&')
- {
- size_t l = 3;
- ret[i++] = decode_uri_char(path, &l);
- path += l;
- }
- ret[i] = '\0';
+ (*name)[no] = (char *) odr_malloc(o, (cp-path)+1);
+ memcpy((*name)[no], path, cp-path);
+ (*name)[no][cp-path] = '\0';
- if (*path)
+ path = cp;
+ if (*path == '=')
+ {
+ size_t i = 0;
+ char *ret;
path++;
+ for (cp = path; *cp && *cp != '&'; cp++)
+ ;
+ (*val)[no] = ret = (char *) odr_malloc(o, cp - path + 1);
+ while (*path && *path != '&')
+ {
+ size_t l = 3;
+ ret[i++] = decode_uri_char(path, &l);
+ path += l;
+ }
+ ret[i] = '\0';
+ }
+ else
+ (*val)[no] = odr_strdup(o, "");
}
(*name)[no] = 0;
(*val)[no] = 0;
{
size_t i = 0;
char *ret;
-
+
path = p1 + 1;
p1 = strchr(path, '&');
if (!p1)