diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-03-06 13:42:15 +0800 |
---|---|---|
committer | Geoff Levand <geoff@infradead.org> | 2013-03-06 06:06:09 -0800 |
commit | e01ca9726e5ce96605cb57595999885fde18884b (patch) | |
tree | fbd9300a9cf87c8947e57c922f88003be47ab58c /ui/common | |
parent | 861efae137793ac3b6c946aacd16cbe44c9e9032 (diff) | |
download | talos-petitboot-e01ca9726e5ce96605cb57595999885fde18884b.tar.gz talos-petitboot-e01ca9726e5ce96605cb57595999885fde18884b.zip |
ui/common/url: remove scheme separator from URL scheme definitions
To make the scheme definitions more useful for other functions.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Geoff Levand <geoff@infradead.org>
Diffstat (limited to 'ui/common')
-rw-r--r-- | ui/common/url.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/ui/common/url.c b/ui/common/url.c index 64aa254..3e7b384 100644 --- a/ui/common/url.c +++ b/ui/common/url.c @@ -41,38 +41,38 @@ struct pb_scheme_info { static const struct pb_scheme_info schemes[] = { { .scheme = pb_url_file, - .str = "file://", - .str_len = sizeof("file://") - 1, + .str = "file", + .str_len = sizeof("file") - 1, }, { .scheme = pb_url_ftp, - .str = "ftp://", - .str_len = sizeof("ftp://") - 1, + .str = "ftp", + .str_len = sizeof("ftp") - 1, }, { .scheme = pb_url_http, - .str = "http://", - .str_len = sizeof("http://") - 1, + .str = "http", + .str_len = sizeof("http") - 1, }, { .scheme = pb_url_https, - .str = "https://", - .str_len = sizeof("https://") - 1, + .str = "https", + .str_len = sizeof("https") - 1, }, { .scheme = pb_url_nfs, - .str = "nfs://", - .str_len = sizeof("nfs://") - 1, + .str = "nfs", + .str_len = sizeof("nfs") - 1, }, { .scheme = pb_url_sftp, - .str = "sftp://", - .str_len = sizeof("sftp://") - 1, + .str = "sftp", + .str_len = sizeof("sftp") - 1, }, { .scheme = pb_url_tftp, - .str = "tftp://", - .str_len = sizeof("tftp://") - 1, + .str = "tftp", + .str_len = sizeof("tftp") - 1, }, }; @@ -82,13 +82,28 @@ static const struct pb_scheme_info *file_scheme = &schemes[0]; * pb_url_find_scheme - Find the pb_scheme_info for a URL string. */ -static const struct pb_scheme_info *pb_url_find_scheme(const char *url_str) +static const struct pb_scheme_info *pb_url_find_scheme(const char *url) { - unsigned int i; + static const int sep_len = sizeof("://") - 1; + static const char *sep = "://"; + unsigned int i, url_len; - for (i = 0; i < sizeof(schemes) / sizeof(schemes[0]); i++) - if (!strncasecmp(url_str, schemes[i].str, schemes[i].str_len)) - return &schemes[i]; + url_len = strlen(url); + + for (i = 0; i < sizeof(schemes) / sizeof(schemes[0]); i++) { + const struct pb_scheme_info *scheme = &schemes[i]; + + if (url_len < scheme->str_len + sep_len) + continue; + + if (strncmp(url + scheme->str_len, sep, sep_len)) + continue; + + if (strncasecmp(url, scheme->str, scheme->str_len)) + continue; + + return scheme; + } /* Assume this is a non-url local file. */ @@ -123,7 +138,7 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str) si = pb_url_find_scheme(url_str); url->scheme = si->scheme; - p = url_str + si->str_len; + p = url_str + si->str_len + strlen("://"); url->full = talloc_strdup(url, url_str); |