]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Started using struct uri_host in struct http_url.
authorStephan Bosch <stephan@rename-it.nl>
Sun, 8 May 2016 21:08:00 +0000 (23:08 +0200)
committerGitLab <gitlab@git.dovecot.net>
Mon, 16 May 2016 07:36:48 +0000 (10:36 +0300)
src/lib-http/http-client-host.c
src/lib-http/http-client-request.c
src/lib-http/http-url.c
src/lib-http/http-url.h
src/lib-http/test-http-client.c
src/lib-http/test-http-request-parser.c
src/lib-http/test-http-url.c
src/plugins/fts-solr/solr-connection.c
src/plugins/fts/fts-parser-tika.c

index 12544b1e0499c82e1e93c73222b30ee4868d2d42..e5f02545bbe807567a5362d75443200ca43e73f9 100644 (file)
@@ -176,7 +176,7 @@ struct http_client_host *http_client_host_get
                }
 
        } else {
-               const char *hostname = host_url->host_name;
+               const char *hostname = host_url->host.name;
 
                host = hash_table_lookup(client->hosts, hostname);
                if (host == NULL) {
@@ -185,10 +185,10 @@ struct http_client_host *http_client_host_get
                        hostname = host->name;
                        hash_table_insert(client->hosts, hostname, host);
 
-                       if (host_url->host_ip.family != 0) {
+                       if (host_url->host.ip.family != 0) {
                                host->ips_count = 1;
                                host->ips = i_new(struct ip_addr, host->ips_count);
-                               host->ips[0] = host_url->host_ip;
+                               host->ips[0] = host_url->host.ip;
                        }
 
                        http_client_host_debug(host, "Host created");
index 930b92e2a14e1c6957b2069748c3f562498280e7..6bfdc54b583c929aa215ed1a998c665201b722bb 100644 (file)
@@ -91,7 +91,7 @@ http_client_request(struct http_client *client,
        struct http_client_request *req;
 
        req = http_client_request_new(client, method, callback, context);
-       req->origin_url.host_name = p_strdup(req->pool, host);
+       req->origin_url.host.name = p_strdup(req->pool, host);
        req->target = (target == NULL ? "/" : p_strdup(req->pool, target));
        return req;
 }
@@ -125,10 +125,10 @@ http_client_request_connect(struct http_client *client,
        struct http_client_request *req;
 
        req = http_client_request_new(client, "CONNECT", callback, context);
-       req->origin_url.host_name = p_strdup(req->pool, host);
+       req->origin_url.host.name = p_strdup(req->pool, host);
        req->origin_url.port = port;
        req->connect_tunnel = TRUE;
-       req->target = req->origin_url.host_name;
+       req->target = req->origin_url.host.name;
        return req;
 }
 
@@ -147,7 +147,7 @@ http_client_request_connect_ip(struct http_client *client,
 
        req = http_client_request_connect
                (client, hostname, port, callback, context);
-       req->origin_url.host_ip = *ip;
+       req->origin_url.host.ip = *ip;
        return req;
 }
 
@@ -617,7 +617,7 @@ http_client_request_get_peer_addr(const struct http_client_request *req,
                addr->a.un.path = host_socket;          
        } else if (req->connect_direct) {
                addr->type = HTTP_CLIENT_PEER_ADDR_RAW;
-               addr->a.tcp.ip = host_url->host_ip;
+               addr->a.tcp.ip = host_url->host.ip;
                addr->a.tcp.port =
                        (host_url->port != 0 ? host_url->port : HTTPS_DEFAULT_PORT);
        } else if (host_url->have_ssl) {
@@ -625,13 +625,13 @@ http_client_request_get_peer_addr(const struct http_client_request *req,
                        addr->type = HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL;
                else
                        addr->type = HTTP_CLIENT_PEER_ADDR_HTTPS;
-               addr->a.tcp.ip = host_url->host_ip;
-               addr->a.tcp.https_name = host_url->host_name;
+               addr->a.tcp.ip = host_url->host.ip;
+               addr->a.tcp.https_name = host_url->host.name;
                addr->a.tcp.port =
                        (host_url->port != 0 ? host_url->port : HTTPS_DEFAULT_PORT);
        } else {
                addr->type = HTTP_CLIENT_PEER_ADDR_HTTP;
-               addr->a.tcp.ip = host_url->host_ip;
+               addr->a.tcp.ip = host_url->host.ip;
                addr->a.tcp.port =
                        (host_url->port != 0 ? host_url->port : HTTPS_DEFAULT_PORT);
        }
index fab368addd8f7c50e2724e98a744a82e25546b09..e3f645cbe5cf5a06cf665da64f043a463ec28065 100644 (file)
@@ -79,8 +79,7 @@ static bool http_url_parse_authority(struct http_url_parser *url_parser)
                }
        }
        if (url != NULL) {
-               url->host_name = p_strdup(parser->pool, auth.host.name);
-               url->host_ip = auth.host.ip;
+               uri_host_copy(parser->pool, &url->host, &auth.host);
                url->port = auth.port;
                url->user = p_strdup(parser->pool, user);
                url->password = p_strdup(parser->pool, password);
@@ -232,8 +231,7 @@ static bool http_url_do_parse(struct http_url_parser *url_parser)
                        parser->error = "Relative HTTP URL not allowed";
                        return FALSE;
                } else if (!have_authority && url != NULL) {
-                       url->host_name = p_strdup_empty(parser->pool, base->host_name); 
-                       url->host_ip = base->host_ip;
+                       uri_host_copy(parser->pool, &url->host, &base->host);
                        url->port = base->port;
                        url->have_ssl = base->have_ssl;
                        url->user = p_strdup_empty(parser->pool, base->user);
@@ -381,8 +379,7 @@ int http_url_request_target_parse(const char *request_target,
 
        if (request_target[0] == '*' && request_target[1] == '\0') {
                struct http_url *url = p_new(pool, struct http_url, 1);
-               url->host_name = p_strdup(pool, auth.host.name);
-               url->host_ip = auth.host.ip;
+               uri_host_copy(pool, &url->host, &auth.host);
                url->port = auth.port;
                target->url = url;
                target->format = HTTP_REQUEST_TARGET_FORMAT_ASTERISK;
@@ -390,8 +387,7 @@ int http_url_request_target_parse(const char *request_target,
        }
 
        memset(&base, 0, sizeof(base));
-       base.host_name = auth.host.name;
-       base.host_ip = auth.host.ip;
+       base.host = auth.host;
        base.port = auth.port;
 
        memset(parser, '\0', sizeof(*parser));
@@ -421,8 +417,7 @@ void http_url_copy_authority(pool_t pool, struct http_url *dest,
        const struct http_url *src)
 {
        memset(dest, 0, sizeof(*dest));
-       dest->host_name = p_strdup(pool, src->host_name);
-       dest->host_ip = src->host_ip;
+       uri_host_copy(pool, &dest->host, &src->host);
        dest->port = src->port;
        dest->have_ssl = src->have_ssl;
 }
@@ -495,15 +490,9 @@ http_url_add_scheme(string_t *urlstr, const struct http_url *url)
 static void
 http_url_add_authority(string_t *urlstr, const struct http_url *url)
 {
-       /* host:port */
-       if (url->host_name != NULL) {
-               /* assume IPv6 literal if starts with '['; avoid encoding */
-               if (*url->host_name == '[')
-                       str_append(urlstr, url->host_name);
-               else
-                       uri_append_host_name(urlstr, url->host_name);
-       } else
-               uri_append_host_ip(urlstr, &url->host_ip);
+       /* host */
+       uri_append_host(urlstr, &url->host);
+       /* port */
        uri_append_port(urlstr, url->port);
 }
 
index 3831000f078cb9592ce7e0e7c3d64639073dd9a3..6d3863ac150a5032b4114a43845a1151e17b0731 100644 (file)
@@ -2,13 +2,13 @@
 #define HTTP_URL_H
 
 #include "net.h"
+#include "uri-util.h"
 
 struct http_request_target;
 
 struct http_url {
        /* server */
-       const char *host_name;
-       struct ip_addr host_ip;
+       struct uri_host host;
        in_port_t port;
 
        /* userinfo (not parsed by default) */
index d7ea66b5a4a9e96d10ef2df21e114c8224aa660d..4899f1cbbb69df5d94fae18739e7dcd92bcbd4fb 100644 (file)
@@ -295,7 +295,7 @@ test_http_request_init(struct http_client *http_client,
        test_req = i_new(struct http_test_request, 1);
        test_req->write_output = TRUE;
        http_req = http_client_request(http_client,
-               method, url->host_name,
+               method, url->host.name,
                t_strconcat("/", url->path, url->enc_query, NULL),
                got_request_response, test_req);
        if (url->port != 0)
index 1cab0d92684449bebe0750ac619858d3f3c4c6f8..3011db55220cedaa7a0fb690aa69b00ac7f0bba2 100644 (file)
@@ -42,7 +42,7 @@ valid_request_parse_tests[] = {
                .target_raw = "/",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ORIGIN,
-                       .url = { .host_name = "example.com" }
+                       .url = { .host = { .name = "example.com" } }
                },
                .version_major = 1, .version_minor = 1,
        },{ .request =
@@ -54,7 +54,7 @@ valid_request_parse_tests[] = {
                .target_raw = "*",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ASTERISK,
-                       .url = { .host_name = "example.com" }
+                       .url = { .host = { .name = "example.com" } }
                },
                .version_major = 1, .version_minor = 0,
        },{ .request =
@@ -65,7 +65,9 @@ valid_request_parse_tests[] = {
                .target_raw = "example.com:443",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_AUTHORITY,
-                       .url = { .host_name = "example.com", .port = 443 }
+                       .url = {
+                               .host = { .name = "example.com" },
+                               .port = 443 }
                },
                .version_major = 1, .version_minor = 2,
        },{ .request =
@@ -77,7 +79,7 @@ valid_request_parse_tests[] = {
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
                        .url = {
-                               .host_name = "www.example.com",
+                               .host = { .name = "www.example.com" },
                                .port = 443,
                                .have_ssl = TRUE
                        }
@@ -93,7 +95,9 @@ valid_request_parse_tests[] = {
                .target_raw = "http://api.example.com:8080/commit?user=dirk",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
-                       .url = { .host_name = "api.example.com", .port = 8080 }
+                       .url = {
+                               .host = { .name = "api.example.com" },
+                               .port = 8080 }
                },
                .version_major = 1, .version_minor = 1,
                .payload = "Content!\r\n"
@@ -106,7 +110,8 @@ valid_request_parse_tests[] = {
                .target_raw = "http://www.example.com/index.php?seq=1",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
-                       .url = { .host_name = "www.example.com" }
+                       .url = {
+                               .host = { .name = "www.example.com" }}
                },
                .version_major = 1, .version_minor = 1,
                .connection_close = TRUE
@@ -118,7 +123,7 @@ valid_request_parse_tests[] = {
                .target_raw = "http://www.example.com/index.html",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
-                       .url = { .host_name = "www.example.com" }
+                       .url = { .host = { .name = "www.example.com" } }
                },
                .version_major = 1, .version_minor = 0,
                .connection_close = TRUE
@@ -131,7 +136,7 @@ valid_request_parse_tests[] = {
                .target_raw = "http://www.example.com/index.html",
                .target = {
                        .format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
-                       .url = { .host_name = "www.example.com" }
+                       .url = { .host = { .name = "www.example.com" } }
                },
                .version_major = 1, .version_minor = 1,
                .expect_100_continue = TRUE
@@ -229,18 +234,18 @@ static void test_http_request_parse_valid(void)
                        }
                        if (request.target.url == NULL) {
                                test_out("request->target.url = (null)",
-                                       test->target.url.host_name == NULL && test->target.url.port == 0);
+                                       test->target.url.host.name == NULL && test->target.url.port == 0);
                        } else {
-                               if (request.target.url->host_name == NULL ||
-                                       test->target.url.host_name == NULL) {
-                                       test_out(t_strdup_printf("request->target.url->host_name = %s",
-                                                       request.target.url->host_name),
-                                               request.target.url->host_name == test->target.url.host_name);
+                               if (request.target.url->host.name == NULL ||
+                                       test->target.url.host.name == NULL) {
+                                       test_out(t_strdup_printf("request->target.url->host.name = %s",
+                                                       request.target.url->host.name),
+                                               request.target.url->host.name == test->target.url.host.name);
                                } else {
-                                       test_out(t_strdup_printf("request->target.url->host_name = %s",
-                                                       request.target.url->host_name),
-                                               strcmp(request.target.url->host_name,
-                                                       test->target.url.host_name) == 0);
+                                       test_out(t_strdup_printf("request->target.url->host.name = %s",
+                                                       request.target.url->host.name),
+                                               strcmp(request.target.url->host.name,
+                                                       test->target.url.host.name) == 0);
                                }
                                if (request.target.url->port == 0) {
                                        test_out("request->target.url->port = (unspecified)",
index fc1aa5c03b3956d253b2fd170e59f64b3dc2ae02..a278220cae8baf240c6deef2be828c74d319728c 100644 (file)
@@ -19,55 +19,59 @@ static struct valid_http_url_test valid_url_tests[] = {
        {
                .url = "http://localhost",
                .url_parsed = {
-                       .host_name = "localhost" }
+                       .host = { .name = "localhost" } }
        },{
                .url = "http://www.%65%78%61%6d%70%6c%65.com",
                .url_parsed = {
-                       .host_name = "www.example.com" }
+                       .host = { .name = "www.example.com" } }
        },{
                .url = "http://www.dovecot.org:8080",
                .url_parsed = {
-                       .host_name = "www.dovecot.org",
+                       .host = { .name = "www.dovecot.org" },
                        .port = 8080 }
        },{
                .url = "http://127.0.0.1",
                .url_parsed = {
-                       .host_name = "127.0.0.1",
-                       .host_ip = { .family = AF_INET } }
+                       .host = {
+                               .name = "127.0.0.1",
+                               .ip = { .family = AF_INET } } }
        },{
                .url = "http://[::1]",
                .url_parsed = {
-                       .host_name = "[::1]",
-                       .host_ip = { .family = AF_INET6 } }
+                       .host = {
+                               .name = "[::1]",
+                               .ip = { .family = AF_INET6 } } }
        },{
                .url = "http://[::1]:8080",
                .url_parsed = {
-                       .host_name = "[::1]",
-                       .host_ip = { .family = AF_INET6 },
+                       .host = {
+                               .name = "[::1]",
+                               .ip = { .family = AF_INET6 } },
                        .port = 8080 }
        },{
                .url = "http://user@api.dovecot.org",
                .flags = HTTP_URL_ALLOW_USERINFO_PART,
                .url_parsed = {
-                       .host_name = "api.dovecot.org", .user = "user" }
+                       .host = { .name = "api.dovecot.org" },
+                       .user = "user" }
        },{
                .url = "http://userid:secret@api.dovecot.org",
                .flags = HTTP_URL_ALLOW_USERINFO_PART,
                .url_parsed = {
-                       .host_name = "api.dovecot.org",
+                       .host = { .name = "api.dovecot.org" },
                        .user = "userid", .password = "secret" }
        },{
                .url = "http://su%3auserid:secret@api.dovecot.org",
                .flags = HTTP_URL_ALLOW_USERINFO_PART,
                .url_parsed = {
-                       .host_name = "api.dovecot.org",
+                       .host = { .name = "api.dovecot.org" },
                        .user = "su:userid", .password = "secret" }
        },{
                .url = "http://www.example.com/"
                        "?question=What%20are%20you%20doing%3f&answer=Nothing.",
                .url_parsed = {
                        .path = "/",
-                       .host_name = "www.example.com",
+                       .host = { .name = "www.example.com" },
                        .enc_query = "question=What%20are%20you%20doing%3f&answer=Nothing." }
        },{
                /* These next 2 URLs don't follow the recommendations in
@@ -81,20 +85,20 @@ static struct valid_http_url_test valid_url_tests[] = {
                .url = "http://256.0.0.1/that/reverts/to/DNS",
                .url_parsed = {
                        .path = "/that/reverts/to/DNS",
-                       .host_name = "256.0.0.1"
+                       .host = { .name = "256.0.0.1" }
                }
        },{
                .url = "http://127.0.0.284/this/also/reverts/to/DNS",
                .url_parsed = {
                        .path = "/this/also/reverts/to/DNS",
-                       .host_name = "127.0.0.284"
+                       .host = { .name = "127.0.0.284" }
                }
        },{
                .url = "http://www.example.com/#Status%20of%20development",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
                .url_parsed = {
                        .path = "/",
-                       .host_name = "www.example.com",
+                       .host = { .name = "www.example.com" },
                        .enc_fragment = "Status%20of%20development" }
 
        
@@ -110,180 +114,180 @@ static struct valid_http_url_test valid_url_tests[] = {
         */
        },{ // "g"             =  "http://a/b/c/g"
                .url = "g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g" }
        },{ // "./g"           =  "http://a/b/c/g"
                .url = "./g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g" }
        },{ // "g/"            =  "http://a/b/c/g/"
                .url = "g/",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g/" }
        },{ // "/g"            =  "http://a/g"
                .url = "/g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/g" }
        },{ // "//g"           =  "http://g"
                .url = "//g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "g"} }
        },{ // "?y"            =  "http://a/b/c/d;p?y"
                .url = "?y",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "y" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "y" }
        },{ // "g?y"           =  "http://a/b/c/g?y"
                .url = "g?y",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g", .enc_query = "y" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y" }
        },{ // "#s"            =  "http://a/b/c/d;p?q#s"
                .url = "#s",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q",
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q",
                        .enc_fragment = "s" }
        },{ // "g#s"           =  "http://a/b/c/g#s"
                .url = "g#s",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g", .enc_fragment = "s" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_fragment = "s" }
 
        },{ // "g?y#s"         =  "http://a/b/c/g?y#s"
                .url = "g?y#s",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g", .enc_query = "y",
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y",
                        .enc_fragment = "s" }
        },{ // ";x"            =  "http://a/b/c/;x"
                .url = ";x",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/;x" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/;x" }
        },{ // "g;x"           =  "http://a/b/c/g;x"
                .url = "g;x",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g;x" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g;x" }
 
        },{ // "g;x?y#s"       =  "http://a/b/c/g;x?y#s"
                .url = "g;x?y#s",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g;x", .enc_query = "y",
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g;x", .enc_query = "y",
                        .enc_fragment = "s" }
        },{ // ""              =  "http://a/b/c/d;p?q"
                .url = "",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" }
        },{ // "."             =  "http://a/b/c/"
                .url = ".",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/" }
        },{ // "./"            =  "http://a/b/c/"
                .url = "./",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/" }
        },{ // ".."            =  "http://a/b/"
                .url = "..",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/" }
        },{ // "../"           =  "http://a/b/"
                .url = "../",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/" }
        },{ // "../g"          =  "http://a/b/g"
                .url = "../g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/g" }
        },{ // "../.."         =  "http://a/"
                .url = "../..",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/" }
        },{ // "../../"        =  "http://a/"
                .url = "../../",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/" }
        },{ // "../../g"       =  "http://a/g"
                .url = "../../g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/g" }
 
        /* 5.4.2. Abnormal Examples
         */
        },{ // "../../../g"    =  "http://a/g"
                .url = "../../../g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/g" }
        },{ // "../../../../g" =  "http://a/g"
                .url = "../../../../g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/g" }
        },{ // "/./g"          =  "http://a/g"
                .url = "/./g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/g" }
        },{ // "/../g"         =  "http://a/g"
                .url = "/../g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/g" }
        },{ // "g."            =  "http://a/b/c/g."
                .url = "g.",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g." }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g." }
        },{ // ".g"            =  "http://a/b/c/.g"
                .url = ".g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/.g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/.g" }
        },{ // "g.."           =  "http://a/b/c/g.."
                .url = "g..",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g.." }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g.." }
        },{ // "..g"           =  "http://a/b/c/..g"
                .url = "..g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/..g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/..g" }
        },{ // "./../g"        =  "http://a/b/g"
                .url = "./../g",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/g" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/g" }
        },{ // "./g/."         =  "http://a/b/c/g/"
                .url = "./g/.",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g/" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g/" }
        },{ // "g/./h"         =  "http://a/b/c/g/h"
                .url = "g/./h",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g/h" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g/h" }
        },{ // "g/../h"        =  "http://a/b/c/h"
                .url = "g/../h",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/h" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/h" }
        },{ // "g;x=1/./y"     =  "http://a/b/c/g;x=1/y"
                .url = "g;x=1/./y",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g;x=1/y" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g;x=1/y" }
        },{ // "g;x=1/../y"    =  "http://a/b/c/y"
                .url = "g;x=1/../y",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/y" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/y" }
        },{ // "g?y/./x"       =  "http://a/b/c/g?y/./x"
                .url = "g?y/./x",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g", .enc_query = "y/./x" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y/./x" }
        },{ // "g?y/../x"      =  "http://a/b/c/g?y/../x"
                .url = "g?y/../x",
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
-               .url_parsed = { .host_name = "a", .path = "/b/c/g", .enc_query = "y/../x" }
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
+               .url_parsed = { .host = {.name = "a"}, .path = "/b/c/g", .enc_query = "y/../x" }
        },{ // "g#s/./x"       =  "http://a/b/c/g#s/./x"
                .url = "g#s/./x",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
                .url_parsed =
-                       { .host_name = "a", .path = "/b/c/g", .enc_fragment = "s/./x" }
+                       { .host = {.name = "a"}, .path = "/b/c/g", .enc_fragment = "s/./x" }
        },{ // "g#s/../x"      =  "http://a/b/c/g#s/../x"       
                .url = "g#s/../x",
                .flags = HTTP_URL_ALLOW_FRAGMENT_PART,
-               .url_base = { .host_name = "a", .path = "/b/c/d;p", .enc_query = "q" },
+               .url_base = { .host = {.name = "a"}, .path = "/b/c/d;p", .enc_query = "q" },
                .url_parsed =
-                       { .host_name = "a", .path = "/b/c/g", .enc_fragment = "s/../x" }
+                       { .host = {.name = "a"}, .path = "/b/c/g", .enc_fragment = "s/../x" }
        }
 };
 
@@ -303,20 +307,20 @@ static void test_http_url_valid(void)
 
                test_begin(t_strdup_printf("http url valid [%d]", i));
 
-               if (urlb->host_name == NULL) urlb = NULL;
+               if (urlb->host.name == NULL) urlb = NULL;
                if (http_url_parse(url, urlb, flags, pool_datastack_create(), &urlp, &error) < 0)
                        urlp = NULL;
 
                test_out_reason(t_strdup_printf("http_url_parse(%s)",
                        valid_url_tests[i].url), urlp != NULL, error);
                if (urlp != NULL) {
-                       if (urlp->host_name == NULL || urlt->host_name == NULL) {
-                               test_assert(urlp->host_name == urlt->host_name);
+                       if (urlp->host.name == NULL || urlt->host.name == NULL) {
+                               test_assert(urlp->host.name == urlt->host.name);
                        } else {
-                               test_assert(strcmp(urlp->host_name, urlt->host_name) == 0);
+                               test_assert(strcmp(urlp->host.name, urlt->host.name) == 0);
                        }
                        test_assert(urlp->port == urlt->port);
-                       test_assert(urlp->host_ip.family == urlt->host_ip.family);
+                       test_assert(urlp->host.ip.family == urlt->host.ip.family);
                        if (urlp->user == NULL || urlt->user == NULL) {
                                test_assert(urlp->user == urlt->user);
                        } else {
@@ -412,7 +416,7 @@ static void test_http_url_invalid(void)
                struct http_url *urlp;
                const char *error = NULL;
 
-               if (urlb->host_name == NULL)
+               if (urlb->host.name == NULL)
                        urlb = NULL;
 
                test_begin(t_strdup_printf("http url invalid [%d]", i));
index 1eca106876932582d2ca8b69981c3bad23373f95..1ae5b168582594e5a4d9b0f5afcfb76e08330ba6 100644 (file)
@@ -115,7 +115,7 @@ int solr_connection_init(const char *url, bool debug,
        }
 
        conn = i_new(struct solr_connection, 1);
-       conn->http_host = i_strdup(http_url->host_name);
+       conn->http_host = i_strdup(http_url->host.name);
        conn->http_port = http_url->port;
        conn->http_base_url = i_strconcat(http_url->path, http_url->enc_query, NULL);
        conn->http_ssl = http_url->have_ssl;
index 474f11be297c612ff344fb327db081c9e6f8ae17..4a86fe20bf180dfd30f936da7fbf4d2cf79d8552 100644 (file)
@@ -147,7 +147,7 @@ fts_parser_tika_try_init(struct mail_user *user, const char *content_type,
        parser->user = user;
 
        http_req = http_client_request(tika_http_client, "PUT",
-                       http_url->host_name,
+                       http_url->host.name,
                        t_strconcat(http_url->path, http_url->enc_query, NULL),
                        fts_tika_parser_response, parser);
        http_client_request_set_port(http_req, http_url->port);