http_client_host_shared_dns_callback(const struct dns_lookup_result *result,
struct http_client_host_shared *hshared)
{
- const struct http_client_settings *set = &hshared->cctx->set;
+ struct http_client_context *cctx = hshared->cctx;
struct http_client_host *host;
hshared->dns_lookup = NULL;
memcpy(hshared->ips, result->ips, sizeof(*hshared->ips) * hshared->ips_count);
hshared->ips_timeout = ioloop_timeval;
- timeval_add_msecs(&hshared->ips_timeout, set->dns_ttl_msecs);
+ i_assert(cctx->dns_ttl_msecs > 0);
+ timeval_add_msecs(&hshared->ips_timeout, cctx->dns_ttl_msecs);
/* notify all sessions */
host = hshared->hosts_list;
static void http_client_host_shared_lookup
(struct http_client_host_shared *hshared)
{
- const struct http_client_settings *set = &hshared->cctx->set;
+ struct http_client_context *cctx = hshared->cctx;
struct dns_lookup_settings dns_set;
struct ip_addr *ips;
int ret;
i_assert(!hshared->explicit_ip);
i_assert(hshared->dns_lookup == NULL);
- if (set->dns_client != NULL) {
+ if (cctx->dns_client != NULL) {
e_debug(hshared->event, "Performing asynchronous DNS lookup");
- (void)dns_client_lookup(set->dns_client, hshared->name,
+ (void)dns_client_lookup(cctx->dns_client, hshared->name,
http_client_host_shared_dns_callback, hshared, &hshared->dns_lookup);
- } else if (set->dns_client_socket_path != NULL) {
+ } else if (cctx->dns_client_socket_path != NULL) {
+ i_assert(cctx->dns_lookup_timeout_msecs > 0);
e_debug(hshared->event, "Performing asynchronous DNS lookup");
i_zero(&dns_set);
- dns_set.dns_client_socket_path = set->dns_client_socket_path;
- if (set->connect_timeout_msecs > 0)
- dns_set.timeout_msecs = set->connect_timeout_msecs;
- else if (set->request_timeout_msecs > 0)
- dns_set.timeout_msecs = set->request_timeout_msecs;
- else {
- dns_set.timeout_msecs =
- HTTP_CLIENT_DEFAULT_DNS_LOOKUP_TIMEOUT_MSECS;
- }
+ dns_set.dns_client_socket_path = cctx->dns_client_socket_path;
+ dns_set.timeout_msecs = cctx->dns_lookup_timeout_msecs;
(void)dns_lookup(hshared->name, &dns_set,
http_client_host_shared_dns_callback, hshared, &hshared->dns_lookup);
} else {
if (hshared->ips_count > 0) {
hshared->ips_timeout = ioloop_timeval;
- timeval_add_msecs(&hshared->ips_timeout, set->dns_ttl_msecs);
+ i_assert(cctx->dns_ttl_msecs > 0);
+ timeval_add_msecs(&hshared->ips_timeout, cctx->dns_ttl_msecs);
}
}
void http_client_host_shared_switch_ioloop(
struct http_client_host_shared *hshared)
{
- const struct http_client_settings *set = &hshared->cctx->set;
+ struct http_client_context *cctx = hshared->cctx;
- if (hshared->dns_lookup != NULL && set->dns_client == NULL)
+ if (hshared->dns_lookup != NULL && cctx->dns_client == NULL)
dns_lookup_switch_ioloop(hshared->dns_lookup);
if (hshared->to_idle != NULL)
hshared->to_idle = io_loop_move_timeout(&hshared->to_idle);
/* merge provided settings with context defaults */
client->set = cctx->set;
if (set != NULL) {
+ client->set.dns_client = set->dns_client;
+ client->set.dns_client_socket_path =
+ p_strdup_empty(pool, set->dns_client_socket_path);
+ client->set.dns_ttl_msecs = set->dns_ttl_msecs;
+
if (set->user_agent != NULL && *set->user_agent != '\0')
client->set.user_agent = p_strdup_empty(pool, set->user_agent);
if (set->rawlog_dir != NULL && *set->rawlog_dir != '\0')
pool_unref(&cctx->pool);
}
+static unsigned int
+http_client_get_dns_lookup_timeout_msecs(const struct http_client_settings *set)
+{
+ if (set->connect_timeout_msecs > 0)
+ return set->connect_timeout_msecs;
+ if (set->request_timeout_msecs > 0)
+ return set->request_timeout_msecs;
+ return HTTP_CLIENT_DEFAULT_DNS_LOOKUP_TIMEOUT_MSECS;
+}
+
static void
http_client_context_update_settings(struct http_client_context *cctx)
{
bool debug;
/* revert back to context settings */
+ cctx->dns_client = cctx->set.dns_client;
+ cctx->dns_client_socket_path = cctx->set.dns_client_socket_path;
+ cctx->dns_ttl_msecs = cctx->set.dns_ttl_msecs;
+ cctx->dns_lookup_timeout_msecs =
+ http_client_get_dns_lookup_timeout_msecs(&cctx->set);
debug = cctx->set.debug;
- /* merge with available client settings */
+ i_assert(cctx->dns_ttl_msecs > 0);
+ i_assert(cctx->dns_lookup_timeout_msecs > 0);
+
+ /* override with available client settings */
for (client = cctx->clients_list; client != NULL;
client = client->next) {
+ unsigned dns_lookup_timeout_msecs =
+ http_client_get_dns_lookup_timeout_msecs(&client->set);
+
+ if (cctx->dns_client == NULL)
+ cctx->dns_client = client->set.dns_client;
+ if (cctx->dns_client_socket_path == NULL) {
+ cctx->dns_client_socket_path =
+ client->set.dns_client_socket_path;
+ }
+ if (client->set.dns_ttl_msecs != 0 &&
+ cctx->dns_ttl_msecs > client->set.dns_ttl_msecs)
+ cctx->dns_ttl_msecs = client->set.dns_ttl_msecs;
+ if (dns_lookup_timeout_msecs != 0 &&
+ cctx->dns_lookup_timeout_msecs > dns_lookup_timeout_msecs) {
+ cctx->dns_lookup_timeout_msecs =
+ dns_lookup_timeout_msecs;
+ }
debug = debug || client->set.debug;
}