From: Stephan Bosch Date: Sun, 15 Sep 2013 00:34:06 +0000 (+0300) Subject: uri-util: Added support for parsing bare authority URI component (for use in HTTP). X-Git-Tag: 2.2.6~86 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df70bf8c997cd91452cdb3a5c2e20605d30446d2;p=thirdparty%2Fdovecot%2Fcore.git uri-util: Added support for parsing bare authority URI component (for use in HTTP). --- diff --git a/src/lib-http/http-url.c b/src/lib-http/http-url.c index 1574feedd4..80a9ae39d4 100644 --- a/src/lib-http/http-url.c +++ b/src/lib-http/http-url.c @@ -69,7 +69,7 @@ static bool http_url_do_parse(struct http_url_parser *url_parser) } /* "//" host [ ":" port ] */ - if ((ret = uri_parse_authority(parser, &auth)) < 0) + if ((ret = uri_parse_slashslash_authority(parser, &auth)) < 0) return FALSE; if (ret > 0) { if (auth.enc_userinfo != NULL) { diff --git a/src/lib-imap/imap-url.c b/src/lib-imap/imap-url.c index a97208a941..911d1d26be 100644 --- a/src/lib-imap/imap-url.c +++ b/src/lib-imap/imap-url.c @@ -221,7 +221,7 @@ static int imap_url_parse_iserver(struct imap_url_parser *url_parser) */ /* "//" iserver */ - if ((ret = uri_parse_authority(parser, &auth)) <= 0) + if ((ret = uri_parse_slashslash_authority(parser, &auth)) <= 0) return ret; /* iuserinfo = enc-user [iauth] / [enc-user] iauth */ diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index 7b224c2ac4..2bc0dbbd08 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -509,22 +509,16 @@ static int uri_parse_port(struct uri_parser *parser, struct uri_authority *auth) return 0; } -int uri_parse_authority(struct uri_parser *parser, struct uri_authority *auth) +int uri_parse_authority(struct uri_parser *parser, + struct uri_authority *auth) { const unsigned char *p; int ret; - /* hier-part = "//" authority {...} - * relative-part = "//" authority {...} + /* * authority = [ userinfo "@" ] host [ ":" port ] */ - /* Parse "//" as part of authority */ - if ((parser->end - parser->cur) <= 2 || parser->cur[0] != '/' || - parser->cur[1] != '/') - return 0; - parser->cur += 2; - if (auth != NULL) memset(auth, 0, sizeof(*auth)); @@ -566,6 +560,18 @@ int uri_parse_authority(struct uri_parser *parser, struct uri_authority *auth) return 1; } +int uri_parse_slashslash_authority(struct uri_parser *parser, + struct uri_authority *auth) +{ + /* "//" authority */ + + if ((parser->end - parser->cur) <= 2 || parser->cur[0] != '/' || + parser->cur[1] != '/') + return 0; + + return uri_parse_authority(parser, auth); +} + int uri_parse_path_segment(struct uri_parser *parser, const char **segment_r) { const unsigned char *p = parser->cur; diff --git a/src/lib/uri-util.h b/src/lib/uri-util.h index c850365ea6..e64c8ebabe 100644 --- a/src/lib/uri-util.h +++ b/src/lib/uri-util.h @@ -35,7 +35,10 @@ bool uri_data_decode(struct uri_parser *parser, const char *data, int uri_cut_scheme(const char **uri_p, const char **scheme_r); int uri_parse_scheme(struct uri_parser *parser, const char **scheme_r); -int uri_parse_authority(struct uri_parser *parser, struct uri_authority *auth); +int uri_parse_authority(struct uri_parser *parser, + struct uri_authority *auth); +int uri_parse_slashslash_authority(struct uri_parser *parser, + struct uri_authority *auth); int uri_parse_path_segment(struct uri_parser *parser, const char **segment_r); int uri_parse_path(struct uri_parser *parser, int *relative_r,