X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Furi.c;h=efa11bf4df23af6123388ba8057023643a22149a;hp=c05a0548833a13aa0d2c0c28dda78e9009731dfe;hb=2f570511e1ca2d63705dc425e9e7bc3f3d744f64;hpb=86c4a75e2ed9282be2202d9202be7f6a07dd3410 diff --git a/src/uri.c b/src/uri.c index c05a054..efa11bf 100644 --- a/src/uri.c +++ b/src/uri.c @@ -1,11 +1,14 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2009 Index Data + * Copyright (C) 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 +#endif #include #include @@ -98,7 +101,7 @@ void yaz_array_to_uri(char **path, ODR o, char **name, char **value) 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; @@ -129,64 +132,37 @@ int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val) { 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'; - - if (*path) - path++; - } - (*name)[no] = 0; - (*val)[no] = 0; - return no; -} - -char *yaz_uri_val(const char *path, const char *name, ODR o) -{ - size_t nlen = strlen(name); - if (*path != '?') - return 0; - path++; - while (path && *path) - { - const char *p1 = strchr(path, '='); - if (!p1) - break; - if ((size_t)(p1 - path) == nlen && !memcmp(path, name, nlen)) + (*name)[no] = odr_strdupn(o, path, cp - path); + path = cp; + if (*path == '=') { size_t i = 0; char *ret; - - path = p1 + 1; - p1 = strchr(path, '&'); - if (!p1) - p1 = strlen(path) + path; - ret = (char *) odr_malloc(o, p1 - path + 1); + path++; + for (cp = path; *cp && *cp != '&'; cp++) + ; + (*val)[no] = ret = (char *) odr_malloc(o, cp - path + 1); while (*path && *path != '&') { size_t l = 3; @@ -194,15 +170,16 @@ char *yaz_uri_val(const char *path, const char *name, ODR o) path += l; } ret[i] = '\0'; - return ret; } - path = strchr(p1, '&'); - if (path) - path++; + else + (*val)[no] = odr_strdup(o, ""); } - return 0; + (*name)[no] = 0; + (*val)[no] = 0; + return no; } + /* * Local variables: * c-basic-offset: 4