mirror of
https://github.com/systemd/systemd.git
synced 2024-10-30 23:21:22 +03:00
resolved: add dns_question_merge() helper
Very similar to dns_answer_merge(), but for DnsQuestion objects instead of DnsAnswer.
This commit is contained in:
parent
1482c86a50
commit
4d593fb151
@ -50,6 +50,19 @@ int dns_question_add_raw(DnsQuestion *q, DnsResourceKey *key, DnsQuestionFlags f
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dns_question_add_raw_all(DnsQuestion *a, DnsQuestion *b) {
|
||||
DnsQuestionItem *item;
|
||||
int r;
|
||||
|
||||
DNS_QUESTION_FOREACH_ITEM(item, b) {
|
||||
r = dns_question_add_raw(a, item->key, item->flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dns_question_add(DnsQuestion *q, DnsResourceKey *key, DnsQuestionFlags flags) {
|
||||
DnsQuestionItem *item;
|
||||
int r;
|
||||
@ -71,6 +84,19 @@ int dns_question_add(DnsQuestion *q, DnsResourceKey *key, DnsQuestionFlags flags
|
||||
return dns_question_add_raw(q, key, flags);
|
||||
}
|
||||
|
||||
static int dns_question_add_all(DnsQuestion *a, DnsQuestion *b) {
|
||||
DnsQuestionItem *item;
|
||||
int r;
|
||||
|
||||
DNS_QUESTION_FOREACH_ITEM(item, b) {
|
||||
r = dns_question_add(a, item->key, item->flags);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr, const char *search_domain) {
|
||||
DnsResourceKey *key;
|
||||
int r;
|
||||
@ -486,3 +512,35 @@ void dns_question_dump(DnsQuestion *question, FILE *f) {
|
||||
fputc('\n', f);
|
||||
}
|
||||
}
|
||||
|
||||
int dns_question_merge(DnsQuestion *a, DnsQuestion *b, DnsQuestion **ret) {
|
||||
_cleanup_(dns_question_unrefp) DnsQuestion *k = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
|
||||
if (a == b || dns_question_size(b) <= 0) {
|
||||
*ret = dns_question_ref(a);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dns_question_size(a) <= 0) {
|
||||
*ret = dns_question_ref(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
k = dns_question_new(dns_question_size(a) + dns_question_size(b));
|
||||
if (!k)
|
||||
return -ENOMEM;
|
||||
|
||||
r = dns_question_add_raw_all(k, a);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dns_question_add_all(k, b);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret = TAKE_PTR(k);
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ static inline bool dns_question_isempty(DnsQuestion *q) {
|
||||
return dns_question_size(q) <= 0;
|
||||
}
|
||||
|
||||
int dns_question_merge(DnsQuestion *a, DnsQuestion *b, DnsQuestion **ret);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuestion*, dns_question_unref);
|
||||
|
||||
#define _DNS_QUESTION_FOREACH(u, k, q) \
|
||||
|
Loading…
Reference in New Issue
Block a user