As a preparation to make dns_client_settings configurable.
struct auth_passdb *passdb;
struct auth_userdb *userdb;
struct dns_client_settings dns_set;
+ struct dns_client_parameters dns_params;
for (passdb = auth->masterdbs; passdb != NULL; passdb = passdb->next)
auth_passdb_init(passdb);
i_zero(&dns_set);
dns_set.dns_client_socket_path = AUTH_DNS_SOCKET_PATH;
dns_set.timeout_msecs = AUTH_DNS_DEFAULT_TIMEOUT_MSECS;
- dns_set.idle_timeout_msecs = AUTH_DNS_IDLE_TIMEOUT_MSECS;
- dns_set.cache_ttl_secs = AUTH_DNS_CACHE_TTL_SECS;
+ dns_params.idle_timeout_msecs = AUTH_DNS_IDLE_TIMEOUT_MSECS;
+ dns_params.cache_ttl_secs = AUTH_DNS_CACHE_TTL_SECS;
- auth->dns_client = dns_client_init(&dns_set, NULL);
+ auth->dns_client = dns_client_init(&dns_set, &dns_params, NULL);
}
static void auth_deinit(struct auth *auth)
}
int dns_lookup(const char *host, const struct dns_client_settings *set,
+ const struct dns_client_parameters *params,
struct event *event_parent, dns_lookup_callback_t *callback,
void *context, struct dns_lookup **lookup_r)
{
struct dns_client *client;
- i_assert(set->cache_ttl_secs == 0);
- client = dns_client_init(set, event_parent);
+ i_assert(params == NULL || params->cache_ttl_secs == 0);
+ client = dns_client_init(set, params, event_parent);
client->deinit_client_at_free = TRUE;
return dns_client_lookup(client, host, client->conn.event, callback,
context, lookup_r);
int dns_lookup_ptr(const struct ip_addr *ip,
const struct dns_client_settings *set,
+ const struct dns_client_parameters *params,
struct event *event_parent,
dns_lookup_callback_t *callback, void *context,
struct dns_lookup **lookup_r)
{
struct dns_client *client;
- i_assert(set->cache_ttl_secs == 0);
- client = dns_client_init(set, event_parent);
+ i_assert(params == NULL || params->cache_ttl_secs == 0);
+ client = dns_client_init(set, params, event_parent);
client->deinit_client_at_free = TRUE;
return dns_client_lookup_ptr(client, ip, client->conn.event,
callback, context, lookup_r);
};
struct dns_client *dns_client_init(const struct dns_client_settings *set,
+ const struct dns_client_parameters *params,
struct event *event_parent)
{
struct dns_client *client;
client = i_new(struct dns_client, 1);
client->timeout_msecs = set->timeout_msecs;
- client->idle_timeout_msecs = set->idle_timeout_msecs;
+ client->idle_timeout_msecs = params == NULL ? 0 : params->idle_timeout_msecs;
client->clist = connection_list_init(&dns_client_set, &dns_client_vfuncs);
client->ioloop = current_ioloop;
client->path = i_strdup(set->dns_client_socket_path);
client->conn.event_parent = event_parent;
connection_init_client_unix(client->clist, &client->conn, client->path);
event_add_category(client->conn.event, &event_category_dns);
- if (set->cache_ttl_secs > 0) {
- client->cache = dns_client_cache_init(set->cache_ttl_secs,
+ if (params != NULL && params->cache_ttl_secs > 0) {
+ client->cache = dns_client_cache_init(params->cache_ttl_secs,
dns_client_cache_refresh, client);
}
return client;
struct dns_client_settings {
const char *dns_client_socket_path;
unsigned int timeout_msecs;
+};
+
+struct dns_client_parameters {
/* the idle_timeout_msecs works only with the dns_client_* API.
0 = disconnect immediately */
unsigned int idle_timeout_msecs;
When failing with -1, the callback is called before returning from the
function. */
int dns_lookup(const char *host, const struct dns_client_settings *set,
+ const struct dns_client_parameters *params,
struct event *event_parent,
dns_lookup_callback_t *callback, void *context,
struct dns_lookup **lookup_r) ATTR_NULL(4);
-#define dns_lookup(host, set, event_parent, callback, context, lookup_r) \
+#define dns_lookup(host, set, params, event_parent, callback, context, lookup_r) \
dns_lookup(host - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct dns_lookup_result *, typeof(context))), \
- set, event_parent, (dns_lookup_callback_t *)callback, context, lookup_r)
+ set, params, event_parent, (dns_lookup_callback_t *)callback, context, lookup_r)
int dns_lookup_ptr(const struct ip_addr *ip,
const struct dns_client_settings *set,
+ const struct dns_client_parameters *params,
struct event *event_parent,
dns_lookup_callback_t *callback, void *context,
struct dns_lookup **lookup_r) ATTR_NULL(4);
-#define dns_lookup_ptr(host, set, event_parent, callback, context, lookup_r) \
+#define dns_lookup_ptr(host, set, params, event_parent, callback, context, lookup_r) \
dns_lookup_ptr(host - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct dns_lookup_result *, typeof(context))), \
- set, event_parent, \
+ set, params, event_parent, \
(dns_lookup_callback_t *)callback, context, lookup_r)
/* Abort the DNS lookup without calling the callback. */
void dns_lookup_abort(struct dns_lookup **lookup);
/* Alternative API for clients that need to do multiple DNS lookups. */
struct dns_client *dns_client_init(const struct dns_client_settings *set,
+ const struct dns_client_parameters *params,
struct event *event_parent);
void dns_client_deinit(struct dns_client **client);
.ret = result == NULL ? -1 : 0,
.result = result
};
- test_assert(dns_lookup(name, &set, NULL, test_callback_ips, &ctx, &lookup) == 0);
+ test_assert(dns_lookup(name, &set, NULL, NULL, test_callback_ips,
+ &ctx, &lookup) == 0);
io_loop_run(test_server.loop);
}
};
struct ip_addr addr;
i_assert(net_addr2ip(name, &addr) == 0);
- test_assert(dns_lookup_ptr(&addr, &set, NULL, test_callback_name, &ctx, &lookup) == 0);
+ test_assert(dns_lookup_ptr(&addr, &set, NULL, NULL, test_callback_name,
+ &ctx, &lookup) == 0);
io_loop_run(test_server.loop);
}
.result = NULL,
};
- test_assert(dns_lookup("waitfor1500", &set, NULL, test_callback_ips, &ctx, &lookup) == 0);
+ test_assert(dns_lookup("waitfor1500", &set, NULL, NULL, test_callback_ips,
+ &ctx, &lookup) == 0);
io_loop_run(current_ioloop);
destroy_dns_server(&test_server);
.result = NULL,
};
- test_assert(dns_lookup("waitfor1500", &set, NULL, test_callback_ips, &ctx, &lookup) == 0);
+ test_assert(dns_lookup("waitfor1500", &set, NULL, NULL, test_callback_ips,
+ &ctx, &lookup) == 0);
struct timeout *to = timeout_add_short(100, io_loop_stop, current_ioloop);
io_loop_run(current_ioloop);
timeout_remove(&to);
const struct dns_client_settings set = {
.dns_client_socket_path = TEST_SOCKET_NAME,
.timeout_msecs = 1000,
+ };
+
+ const struct dns_client_parameters params = {
.cache_ttl_secs = 4,
};
- struct dns_client *client = dns_client_init(&set, event);
+ struct dns_client *client = dns_client_init(&set, ¶ms, event);
/* lookup localhost */
ctx.result = "127.0.0.1\t::1";
ctx->conn = conn;
- if (dns_lookup(conn->set.hostname, &dns_set, conn->conn.event,
+ if (dns_lookup(conn->set.hostname, &dns_set, NULL, conn->conn.event,
doveadm_client_dns_lookup_callback, ctx,
&conn->dns_lookup) != 0) {
*error_r = t_strdup(ctx->error);
dns_set.dns_client_socket_path = cctx->dns_client_socket_path;
dns_set.timeout_msecs = cctx->dns_lookup_timeout_msecs;
io_loop_set_current(cctx->ioloop);
- (void)dns_lookup(hshared->name, &dns_set, hshared->event,
+ (void)dns_lookup(hshared->name, &dns_set, NULL, hshared->event,
http_client_host_shared_dns_callback,
hshared, &hshared->dns_lookup);
io_loop_set_current(prev_ioloop);
{
struct dns_client *dns_client;
struct dns_client_settings dns_set;
+ struct dns_client_parameters dns_params;
struct http_client_settings http_set;
struct http_client_context *http_cctx;
struct http_client *http_client1, *http_client2, *http_client3, *http_client4;
i_zero_safe(&dns_set);
dns_set.dns_client_socket_path = PKG_RUNDIR"/dns-client";
dns_set.timeout_msecs = 30*1000;
- dns_set.idle_timeout_msecs = UINT_MAX;
+ dns_params.idle_timeout_msecs = UINT_MAX;
/* check if there is a DNS client */
if (access(dns_set.dns_client_socket_path, R_OK|W_OK) == 0) {
- dns_client = dns_client_init(&dns_set, NULL);
+ dns_client = dns_client_init(&dns_set, &dns_params, NULL);
if (dns_client_connect(dns_client, &error) < 0)
i_fatal("Couldn't initialize DNS client: %s", error);
conn->ips = i_new(struct ip_addr, ips_count);
memcpy(conn->ips, ips, ips_count * sizeof(*ips));
} else {
- (void)dns_lookup(conn->client->set->imapc_host, &dns_set,
+ (void)dns_lookup(conn->client->set->imapc_host, &dns_set, NULL,
conn->event, imapc_connection_dns_callback,
conn, &conn->dns_lookup);
return;
struct settings_simple test_set;
settings_simple_init(&test_set, NULL);
- struct dns_client *client = dns_client_init(&set, NULL);
+ struct dns_client *client = dns_client_init(&set, NULL, NULL);
struct dlua_script *script;
const char *error;
prclient->dns_set.timeout_msecs =
pclient->params.client_connect_timeout_msecs;
(void)dns_lookup(prclient->address, &prclient->dns_set,
- pclient->event,
+ NULL, pclient->event,
program_client_net_connect_resolved,
prclient, &prclient->lookup);
return 0;
conn->set.dns_client_socket_path;
dns_set.timeout_msecs = conn->set.connect_timeout_msecs;
e_debug(conn->event, "Performing asynchronous DNS lookup");
- (void)dns_lookup(conn->host, &dns_set, conn->event,
+ (void)dns_lookup(conn->host, &dns_set, NULL, conn->event,
smtp_client_connection_dns_callback, conn,
&conn->dns_lookup);
} else {
dns_set.dns_client_socket_path =
client->set.dns_client_socket_path;
dns_set.timeout_msecs = POP3C_DNS_LOOKUP_TIMEOUT_MSECS;
- if (dns_lookup(client->set.host, &dns_set, client->event,
+ if (dns_lookup(client->set.host, &dns_set, NULL, client->event,
pop3c_dns_callback, client,
&client->dns_lookup) < 0)
return -1;