From: Aki Tuomi Date: Tue, 5 Nov 2024 11:36:40 +0000 (+0200) Subject: lib: uri - Allow host after scheme with 'iax' scheme X-Git-Tag: 2.4.0~283 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=663db075b99cbe9352344a6ac4e00ed0d56beba5;p=thirdparty%2Fdovecot%2Fcore.git lib: uri - Allow host after scheme with 'iax' scheme --- diff --git a/src/lib/test-uri.c b/src/lib/test-uri.c index 9b0edf8ee8..6dede362aa 100644 --- a/src/lib/test-uri.c +++ b/src/lib/test-uri.c @@ -427,7 +427,6 @@ const char *rfc_uri_tests[] = { "%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~resource", "xmpp:ji%C5%99i@%C4%8Dechy.example/v%20Praze", /* from RFC 5456 */ -#if 0 // these don't comply with RFC 3986 "iax:example.com/alice", "iax:example.com:4569/alice", "iax:example.com:4570/alice?friends", @@ -442,7 +441,6 @@ const char *rfc_uri_tests[] = { "iax:alice@AtLaNtA.com:4569/ALicE", "iax:ALICE@atlanta.com/alice", "iax:alice@atlanta.com/alice", -#endif /* from RFC 5724 */ "sms:+15105550101", "sms:+15105550101,+15105550102", @@ -824,6 +822,38 @@ static void test_uri_aaa(void) test_end(); } +static void test_uri_iax(void) +{ + test_begin("uri iax"); + const char *uri = "iax:[2001:db8::1]:4569/alice?friend"; + struct uri_parser parser; + uri_parser_init(&parser, pool_datastack_create(), uri); + + const char *scheme; + struct uri_authority auth; + int relative; + const char *const *path; + const char *query; + int ret; + ret = uri_parse_scheme(&parser, &scheme); + test_assert(ret > 0); + test_assert_strcmp(scheme, "iax"); + ret = uri_parse_host_authority(&parser, &auth); + test_assert(ret > 0); + test_assert_strcmp(auth.host.name, "[2001:db8::1]"); + test_assert_ucmp(auth.port, ==, 4569); + ret = uri_parse_path(&parser, &relative, &path); + test_assert(ret > 0); + test_assert(relative == 0); + test_assert_strcmp(path[0], "alice"); + test_assert(path[1] == NULL); + ret = uri_parse_query(&parser, &query); + test_assert(ret > 0); + test_assert_strcmp(query, "friend"); + test_end(); +} + + void test_uri(void) { test_uri_valid(); @@ -831,4 +861,5 @@ void test_uri(void) test_uri_rfc(); test_uri_escape(); test_uri_aaa(); + test_uri_iax(); } diff --git a/src/lib/uri-util.c b/src/lib/uri-util.c index 12e3c5ec26..ef16028e68 100644 --- a/src/lib/uri-util.c +++ b/src/lib/uri-util.c @@ -1128,6 +1128,7 @@ int uri_parse_absolute_generic(struct uri_parser *parser, enum uri_parse_flags flags) { int relative, aret, ret = 0; + bool allow_missing_slashslash = FALSE; /* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] @@ -1155,12 +1156,19 @@ int uri_parse_absolute_generic(struct uri_parser *parser, if (strcmp(scheme, "aaa") == 0 || (flags & URI_PARSE_SEMICOLON_PARAMS) != 0) parser->semicolon_params = TRUE; + if (strcmp(scheme, "iax") == 0 || + (flags & URI_PARSE_ALLOW_MISSING_SLASHSLASH) != 0) + allow_missing_slashslash = TRUE; } /* "//" authority */ aret = uri_parse_slashslash_authority(parser, NULL); if (aret < 0) return -1; + else if (aret == 0 && allow_missing_slashslash) { + if ((aret = uri_parse_authority(parser, NULL)) < 0) + return -1; + } /* path-absolute / path-rootless / path-empty */ if (aret == 0) { diff --git a/src/lib/uri-util.h b/src/lib/uri-util.h index 29283bd09e..35ed67704a 100644 --- a/src/lib/uri-util.h +++ b/src/lib/uri-util.h @@ -14,6 +14,8 @@ enum uri_parse_flags { URI_PARSE_ALLOW_FRAGMENT_PART = BIT(1), /* Allow ';param' after host - violates RFC3986 */ URI_PARSE_SEMICOLON_PARAMS = BIT(2), + /* Allow scheme:host - violates RFC3986 */ + URI_PARSE_ALLOW_MISSING_SLASHSLASH = BIT(3), }; struct uri_host {