- r = sd_event_add_time(t->query->manager->event, &t->timeout_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + TRANSACTION_TIMEOUT_USEC, 0, on_transaction_timeout, t);
- if (r < 0)
- return r;
-
- t->state = DNS_QUERY_PENDING;
- return 1;
-}
-
-DnsQuery *dns_query_free(DnsQuery *q) {
- unsigned n;
-
- if (!q)
- return NULL;
-
- sd_bus_message_unref(q->request);
- dns_packet_unref(q->received);
-
- dns_resource_record_freev(q->cached_rrs, q->n_cached_rrs);
-
- sd_event_source_unref(q->timeout_event_source);
-
- while (q->transactions)
- dns_query_transaction_free(q->transactions);
-
- if (q->manager) {
- LIST_REMOVE(queries, q->manager->dns_queries, q);
- q->manager->n_dns_queries--;
- }
-
- for (n = 0; n < q->n_keys; n++)
- free(q->keys[n].name);
- free(q->keys);
- free(q);
-
- return NULL;
-}
-
-int dns_query_new(Manager *m, DnsQuery **ret, DnsResourceKey *keys, unsigned n_keys) {
- _cleanup_(dns_query_freep) DnsQuery *q = NULL;
- const char *name = NULL;
-
- assert(m);
-
- if (n_keys <= 0 || n_keys >= 65535)
- return -EINVAL;
-
- if (m->n_dns_queries >= QUERIES_MAX)
- return -EBUSY;
-
- assert(keys);
-
- q = new0(DnsQuery, 1);
- if (!q)
- return -ENOMEM;
-
- q->keys = new(DnsResourceKey, n_keys);
- if (!q->keys)
- return -ENOMEM;
-
- for (q->n_keys = 0; q->n_keys < n_keys; q->n_keys++) {
- q->keys[q->n_keys].class = keys[q->n_keys].class;
- q->keys[q->n_keys].type = keys[q->n_keys].type;
- q->keys[q->n_keys].name = strdup(keys[q->n_keys].name);
- if (!q->keys[q->n_keys].name)
- return -ENOMEM;
-
- if (!name)
- name = q->keys[q->n_keys].name;
- else if (!dns_name_equal(name, q->keys[q->n_keys].name))
- return -EINVAL;
-
- log_debug("Looking up RR for %s %s %s",
- strna(dns_class_to_string(keys[q->n_keys].class)),
- strna(dns_type_to_string(keys[q->n_keys].type)),
- keys[q->n_keys].name);
- }
-
- LIST_PREPEND(queries, m->dns_queries, q);
- m->n_dns_queries++;
- q->manager = m;
-
- if (ret)
- *ret = q;
- q = NULL;
-