Presence of port can be tested with port != 0.
Presence of IP can be tested with ip->family != 0.
url.userid = reply->destuser;
url.auth_type = client->auth_mech_name;
url.host_name = reply->host;
- if (reply->port != 143) {
- url.have_port = TRUE;
+ if (reply->port != 143)
url.port = reply->port;
- }
str_append(referral, "REFERRAL ");
str_append(referral, imap_url_create(&url));
hostname = host->name;
hash_table_insert(client->hosts, hostname, host);
- if (host_url->have_host_ip) {
+ 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;
req = http_client_request_new(client, "CONNECT", callback, context);
req->origin_url.host_name = p_strdup(req->pool, host);
req->origin_url.port = port;
- req->origin_url.have_port = TRUE;
req->connect_tunnel = TRUE;
req->target = req->origin_url.host_name;
return req;
void *context)
{
struct http_client_request *req;
- const char *hostname = net_ip2addr(ip);
+ const char *hostname;
+
+ i_assert(ip->family != 0);
+ hostname = net_ip2addr(ip);
req = http_client_request_connect
(client, hostname, port, callback, context);
req->origin_url.host_ip = *ip;
- req->origin_url.have_host_ip = TRUE;
return req;
}
{
i_assert(req->state == HTTP_REQUEST_STATE_NEW);
req->origin_url.port = port;
- req->origin_url.have_port = TRUE;
}
void http_client_request_set_ssl(struct http_client_request *req,
addr->a.un.path = host_socket;
} else if (req->connect_direct) {
addr->type = HTTP_CLIENT_PEER_ADDR_RAW;
- if (host_url->have_host_ip)
- addr->a.tcp.ip = host_url->host_ip;
+ addr->a.tcp.ip = host_url->host_ip;
addr->a.tcp.port =
- (host_url->have_port ? host_url->port : HTTPS_DEFAULT_PORT);
+ (host_url->port != 0 ? host_url->port : HTTPS_DEFAULT_PORT);
} else if (host_url->have_ssl) {
if (req->ssl_tunnel)
addr->type = HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL;
else
addr->type = HTTP_CLIENT_PEER_ADDR_HTTPS;
- if (host_url->have_host_ip)
- addr->a.tcp.ip = host_url->host_ip;
+ addr->a.tcp.ip = host_url->host_ip;
addr->a.tcp.https_name = host_url->host_name;
addr->a.tcp.port =
- (host_url->have_port ? host_url->port : HTTPS_DEFAULT_PORT);
+ (host_url->port != 0 ? host_url->port : HTTPS_DEFAULT_PORT);
} else {
addr->type = HTTP_CLIENT_PEER_ADDR_HTTP;
- if (host_url->have_host_ip)
- addr->a.tcp.ip = host_url->host_ip;
+ addr->a.tcp.ip = host_url->host_ip;
addr->a.tcp.port =
- (host_url->have_port ? host_url->port : HTTP_DEFAULT_PORT);
+ (host_url->port != 0 ? host_url->port : HTTPS_DEFAULT_PORT);
}
}
if (url != NULL) {
url->host_name = p_strdup(parser->pool, auth.host_literal);
url->host_ip = auth.host_ip;
- url->have_host_ip = auth.have_host_ip;
url->port = auth.port;
- url->have_port = auth.have_port;
url->user = p_strdup(parser->pool, user);
url->password = p_strdup(parser->pool, password);
}
} else if (!have_authority && url != NULL) {
url->host_name = p_strdup_empty(parser->pool, base->host_name);
url->host_ip = base->host_ip;
- url->have_host_ip = base->have_host_ip;
url->port = base->port;
- url->have_port = base->have_port;
url->have_ssl = base->have_ssl;
url->user = p_strdup_empty(parser->pool, base->user);
url->password = p_strdup_empty(parser->pool, base->password);
url->host_name = p_strdup(pool, host.host_literal);
url->host_ip = host.host_ip;
url->port = host.port;
- url->have_host_ip = host.have_host_ip;
- url->have_port = host.have_port;
target->url = url;
target->format = HTTP_REQUEST_TARGET_FORMAT_ASTERISK;
return 0;
base.host_name = host.host_literal;
base.host_ip = host.host_ip;
base.port = host.port;
- base.have_host_ip = host.have_host_ip;
- base.have_port = host.have_port;
memset(parser, '\0', sizeof(*parser));
uri_parser_init(parser, pool, request_target);
{
memset(dest, 0, sizeof(*dest));
dest->host_name = p_strdup(pool, src->host_name);
- if (src->have_host_ip) {
- dest->host_ip = src->host_ip;
- dest->have_host_ip = TRUE;
- }
- if (src->have_port) {
- dest->port = src->port;
- dest->have_port = TRUE;
- }
+ dest->host_ip = src->host_ip;
+ dest->port = src->port;
dest->have_ssl = src->have_ssl;
}
str_append(urlstr, url->host_name);
else
uri_append_host_name(urlstr, url->host_name);
- } else if (url->have_host_ip) {
- uri_append_host_ip(urlstr, &url->host_ip);
} else
- i_unreached();
- if (url->have_port)
- uri_append_port(urlstr, url->port);
+ uri_append_host_ip(urlstr, &url->host_ip);
+ uri_append_port(urlstr, url->port);
}
static void
/* #fragment (still encoded) */
const char *enc_fragment;
- unsigned int have_host_ip:1; /* URL uses IP address */
- unsigned int have_port:1;
unsigned int have_ssl:1;
};
method, url->host_name,
t_strconcat("/", url->path, url->enc_query, NULL),
got_request_response, test_req);
- if (url->have_port)
+ if (url->port != 0)
http_client_request_set_port(http_req, url->port);
if (url->have_ssl)
http_client_request_set_ssl(http_req, TRUE);
.target_raw = "example.com:443",
.target = {
.format = HTTP_REQUEST_TARGET_FORMAT_AUTHORITY,
- .url = { .host_name = "example.com", .have_port = TRUE, .port = 443 }
+ .url = { .host_name = "example.com", .port = 443 }
},
.version_major = 1, .version_minor = 2,
},{ .request =
.format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
.url = {
.host_name = "www.example.com",
- .have_port = TRUE, .port = 443,
+ .port = 443,
.have_ssl = TRUE
}
},
.target_raw = "http://api.example.com:8080/commit?user=dirk",
.target = {
.format = HTTP_REQUEST_TARGET_FORMAT_ABSOLUTE,
- .url = { .host_name = "api.example.com", .have_port = TRUE, .port = 8080 }
+ .url = { .host_name = "api.example.com", .port = 8080 }
},
.version_major = 1, .version_minor = 1,
.payload = "Content!\r\n"
}
if (request.target.url == NULL) {
test_out("request->target.url = (null)",
- test->target.url.host_name == NULL && !test->target.url.have_port);
+ 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) {
strcmp(request.target.url->host_name,
test->target.url.host_name) == 0);
}
- if (!request.target.url->have_port) {
+ if (request.target.url->port == 0) {
test_out("request->target.url->port = (unspecified)",
- request.target.url->have_port == test->target.url.have_port);
+ request.target.url->port == test->target.url.port);
} else {
test_out(t_strdup_printf
("request->target.url->port = %u", request.target.url->port),
- request.target.url->have_port == test->target.url.have_port &&
request.target.url->port == test->target.url.port);
}
test_out(t_strdup_printf("request->target.url->have_ssl = %s",
.url = "http://www.dovecot.org:8080",
.url_parsed = {
.host_name = "www.dovecot.org",
- .port = 8080, .have_port = TRUE }
+ .port = 8080 }
},{
.url = "http://127.0.0.1",
.url_parsed = {
.host_name = "127.0.0.1",
- .have_host_ip = TRUE }
+ .host_ip = { .family = AF_INET } }
},{
.url = "http://[::1]",
.url_parsed = {
.host_name = "[::1]",
- .have_host_ip = TRUE }
+ .host_ip = { .family = AF_INET6 } }
},{
.url = "http://[::1]:8080",
.url_parsed = {
.host_name = "[::1]",
- .have_host_ip = TRUE,
- .port = 8080, .have_port = TRUE }
+ .host_ip = { .family = AF_INET6 },
+ .port = 8080 }
},{
.url = "http://user@api.dovecot.org",
.flags = HTTP_URL_ALLOW_USERINFO_PART,
} else {
test_assert(strcmp(urlp->host_name, urlt->host_name) == 0);
}
- if (!urlp->have_port) {
- test_assert(urlp->have_port == urlt->have_port);
- } else {
- test_assert(urlp->have_port == urlt->have_port && urlp->port == urlt->port);
- }
- if (!urlp->have_host_ip) {
- test_assert(urlp->have_host_ip == urlt->have_host_ip);
- } else {
- test_assert(urlp->have_host_ip == urlt->have_host_ip);
- }
+ test_assert(urlp->port == urlt->port);
+ test_assert(urlp->host_ip.family == urlt->host_ip.family);
if (urlp->user == NULL || urlt->user == NULL) {
test_assert(urlp->user == urlt->user);
} else {
}
/* validate port */
- if ((!url->have_port && uctx->url_port != 143) ||
- (url->have_port && uctx->url_port != url->port)) {
+ if ((url->port == 0 && uctx->url_port != 143) ||
+ (url->port != 0 && uctx->url_port != url->port)) {
*error_r = "Invalid URL: Inappropriate server port";
return FALSE;
}
if (url != NULL) {
url->host_name = auth.host_literal;
url->host_ip = auth.host_ip;
- url->have_host_ip = auth.have_host_ip;
url->port = auth.port;
- url->have_port = auth.have_port;
}
return 1;
}
url->host_name = p_strdup_empty(parser->pool, base->host_name);
url->host_ip = base->host_ip;
- url->have_host_ip = base->have_host_ip;
- url->have_port = base->have_port;
url->port = base->port;
url->userid = p_strdup_empty(parser->pool, base->userid);
url->auth_type = p_strdup_empty(parser->pool, base->auth_type);
str_append(urlstr, url->host_name);
else
uri_append_host_name(urlstr, url->host_name);
- } else if (url->have_host_ip) {
+ } else {
uri_append_host_ip(urlstr, &url->host_ip);
- } else
- i_unreached();
- if (url->have_port)
- uri_append_port(urlstr, url->port);
+ }
+ uri_append_port(urlstr, url->port);
/* Older syntax (RFC 2192) requires this slash at all times */
str_append_c(urlstr, '/');
size_t uauth_token_size;
time_t uauth_expire; /* (time_t)-1 if not set */
- unsigned int have_host_ip:1; /* url uses IP address */
- unsigned int have_port:1;
unsigned int have_partial:1;
};
.url_parsed = {
.host_name = "localhost",
.userid = "user",
- .port = 993, .have_port = TRUE }
+ .port = 993 }
},{
.url = "imap://user@127.0.0.1",
.url_parsed = {
.host_name = "127.0.0.1",
- .userid = "user",
- .have_host_ip = TRUE }
+ .host_ip = { .family = AF_INET },
+ .userid = "user" }
},{
.url = "imap://user@[::1]",
.url_parsed = {
.host_name = "[::1]",
- .userid = "user",
- .have_host_ip = TRUE }
+ .host_ip = { .family = AF_INET6 },
+ .userid = "user" }
},{
.url = "imap://user@4example.com:423",
.url_parsed = {
.host_name = "4example.com",
.userid = "user",
- .port = 423, .have_port = TRUE }
+ .port = 423 }
},{
.url = "imap://beelzebub@666.4example.com:999",
.url_parsed = {
.host_name = "666.4example.com",
.userid = "beelzebub",
- .port = 999, .have_port = TRUE }
+ .port = 999 }
},{
.url = "imap://user@example.com/",
.url_parsed = {
test_out_quiet(t_strdup_printf("url->auth_type = %s", urlp->auth_type),
strcmp(urlp->auth_type, urlt->auth_type) == 0);
}
- if (!urlp->have_port) {
+ if (urlp->port == 0) {
test_out_quiet("url->port = (unspecified)",
- urlp->have_port == urlt->have_port);
+ urlp->port == urlt->port);
} else {
test_out_quiet(t_strdup_printf("url->port = %u", urlp->port),
- urlp->have_port == urlt->have_port && urlp->port == urlt->port);
+ urlp->port == urlt->port);
}
- if (!urlp->have_host_ip) {
+ if (urlp->host_ip.family == 0) {
test_out_quiet("url->host_ip = (unspecified)",
- urlp->have_host_ip == urlt->have_host_ip);
+ urlp->host_ip.family == urlt->host_ip.family);
} else {
test_out_quiet("url->host_ip = (valid)",
- urlp->have_host_ip == urlt->have_host_ip);
+ urlp->host_ip.family == urlt->host_ip.family);
}
if (urlp->mailbox == NULL || urlt->mailbox == NULL) {
test_out_quiet(t_strdup_printf("url->mailbox = %s", urlp->mailbox),
auth->host_literal = p_strdup(parser->pool, str_c(literal));
auth->host_ip.family = AF_INET6;
auth->host_ip.u.ip6 = ip6;
- auth->have_host_ip = TRUE;
}
return 1;
}
auth->host_literal = p_strdup(parser->pool, str_c(literal));
auth->host_ip.family = AF_INET;
auth->host_ip.u.ip4 = ip4;
- auth->have_host_ip = TRUE;
}
return ret;
}
/* reg-name */
if (uri_parse_reg_name(parser, literal) < 0)
return -1;
- if (auth != NULL) {
+ if (auth != NULL)
auth->host_literal = p_strdup(parser->pool, str_c(literal));
- auth->have_host_ip = FALSE;
- }
return 0;
}
return -1;
}
- if (auth != NULL) {
+ if (auth != NULL)
auth->port = port;
- auth->have_port = TRUE;
- }
return 1;
}
{
const char *addr = net_ip2addr(host_ip);
+ i_assert(host_ip->family != 0);
+
if (host_ip->family == AF_INET) {
str_append(out, addr);
return;
void uri_append_port(string_t *out, in_port_t port)
{
- str_printfa(out, ":%u", port);
+ if (port != 0)
+ str_printfa(out, ":%u", port);
}
void uri_append_path_segment_data(string_t *out, const char *esc,
struct ip_addr host_ip;
in_port_t port;
-
- unsigned int have_host_ip:1;
- unsigned int have_port:1;
};
struct uri_parser {