X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Furi.c;h=1d30cdaabef6b0b1af0d592c357c3ada0636d423;hb=03dccce903176e61f889b1558834aa5a09f9f8c0;hp=ed1350a41cc5b9697070cedd96beecc68976a98a;hpb=54dc5b4629da5b10c2f3d4e3bdb7cb70c46669a5;p=yaz-moved-to-github.git diff --git a/src/uri.c b/src/uri.c index ed1350a..1d30cda 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) 1995-2012 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 @@ -25,11 +28,9 @@ static int hex_digit (int ch) static void encode_uri_char(char *dst, char ch) { - if (ch == ' ') - strcpy(dst, "+"); /* mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" */ - else if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || - (ch >= '0' && ch <= '9') || strchr("-_.!~*'(|)", ch)) + if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || + (ch >= '0' && ch <= '9') || strchr("-_.!~*'(|)", ch)) { dst[0] = ch; dst[1] = '\0'; @@ -137,31 +138,37 @@ int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val) 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;