From: Stephan Bosch Date: Sun, 8 May 2016 21:08:00 +0000 (+0200) Subject: lib-http: Started using struct uri_host in struct http_url. X-Git-Tag: 2.3.0.rc1~3753 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f74dbd3ff682fea040f60383e001620d1f1b09d3;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Started using struct uri_host in struct http_url. --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 12544b1e04..e5f02545bb 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -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"); diff --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index 930b92e2a1..6bfdc54b58 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -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); } diff --git a/src/lib-http/http-url.c b/src/lib-http/http-url.c index fab368addd..e3f645cbe5 100644 --- a/src/lib-http/http-url.c +++ b/src/lib-http/http-url.c @@ -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); } diff --git a/src/lib-http/http-url.h b/src/lib-http/http-url.h index 3831000f07..6d3863ac15 100644 --- a/src/lib-http/http-url.h +++ b/src/lib-http/http-url.h @@ -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) */ diff --git a/src/lib-http/test-http-client.c b/src/lib-http/test-http-client.c index d7ea66b5a4..4899f1cbbb 100644 --- a/src/lib-http/test-http-client.c +++ b/src/lib-http/test-http-client.c @@ -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) diff --git a/src/lib-http/test-http-request-parser.c b/src/lib-http/test-http-request-parser.c index 1cab0d9268..3011db5522 100644 --- a/src/lib-http/test-http-request-parser.c +++ b/src/lib-http/test-http-request-parser.c @@ -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)", diff --git a/src/lib-http/test-http-url.c b/src/lib-http/test-http-url.c index fc1aa5c03b..a278220cae 100644 --- a/src/lib-http/test-http-url.c +++ b/src/lib-http/test-http-url.c @@ -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)); diff --git a/src/plugins/fts-solr/solr-connection.c b/src/plugins/fts-solr/solr-connection.c index 1eca106876..1ae5b16858 100644 --- a/src/plugins/fts-solr/solr-connection.c +++ b/src/plugins/fts-solr/solr-connection.c @@ -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; diff --git a/src/plugins/fts/fts-parser-tika.c b/src/plugins/fts/fts-parser-tika.c index 474f11be29..4a86fe20bf 100644 --- a/src/plugins/fts/fts-parser-tika.c +++ b/src/plugins/fts/fts-parser-tika.c @@ -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);