]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: uri - Allow host after scheme with 'iax' scheme
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 5 Nov 2024 11:36:40 +0000 (13:36 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
src/lib/test-uri.c
src/lib/uri-util.c
src/lib/uri-util.h

index 9b0edf8ee8f4421a9f3a632de12b14c8ca1c0b50..6dede362aa58fd87bd59ecf35128a809e4f45564 100644 (file)
@@ -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();
 }
index 12e3c5ec2689b13b36351d9498a5a4399a158654..ef16028e6875180ce3371826eae9ccb21130a7e8 100644 (file)
@@ -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) {
index 29283bd09e25b965b4e75e4eee7fba96ecca5879..35ed67704a6055d12ba5736ded88ba884af5a9d7 100644 (file)
@@ -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 {