1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
4 typedef struct DnsQuestion DnsQuestion
;
5 typedef struct DnsQuestionItem DnsQuestionItem
;
8 #include "resolved-dns-rr.h"
10 /* A simple array of resource keys */
12 typedef enum DnsQuestionFlags
{
13 DNS_QUESTION_WANTS_UNICAST_REPLY
= 1 << 0, /* For mDNS: sender is willing to accept unicast replies */
16 struct DnsQuestionItem
{
18 DnsQuestionFlags flags
;
23 size_t n_keys
, n_allocated
;
24 DnsQuestionItem items
[];
27 DnsQuestion
*dns_question_new(size_t n
);
28 DnsQuestion
*dns_question_ref(DnsQuestion
*q
);
29 DnsQuestion
*dns_question_unref(DnsQuestion
*q
);
31 int dns_question_new_address(DnsQuestion
**ret
, int family
, const char *name
, bool convert_idna
);
32 int dns_question_new_reverse(DnsQuestion
**ret
, int family
, const union in_addr_union
*a
);
33 int dns_question_new_service(DnsQuestion
**ret
, const char *service
, const char *type
, const char *domain
, bool with_txt
, bool convert_idna
);
35 int dns_question_add_raw(DnsQuestion
*q
, DnsResourceKey
*key
, DnsQuestionFlags flags
);
36 int dns_question_add(DnsQuestion
*q
, DnsResourceKey
*key
, DnsQuestionFlags flags
);
38 int dns_question_matches_rr(DnsQuestion
*q
, DnsResourceRecord
*rr
, const char *search_domain
);
39 int dns_question_matches_cname_or_dname(DnsQuestion
*q
, DnsResourceRecord
*rr
, const char* search_domain
);
40 int dns_question_is_valid_for_query(DnsQuestion
*q
);
41 int dns_question_contains_key(DnsQuestion
*q
, const DnsResourceKey
*k
);
42 int dns_question_is_equal(DnsQuestion
*a
, DnsQuestion
*b
);
44 int dns_question_cname_redirect(DnsQuestion
*q
, const DnsResourceRecord
*cname
, DnsQuestion
**ret
);
46 void dns_question_dump(DnsQuestion
*q
, FILE *f
);
48 const char *dns_question_first_name(DnsQuestion
*q
);
50 static inline DnsResourceKey
*dns_question_first_key(DnsQuestion
*q
) {
51 return (q
&& q
->n_keys
> 0) ? q
->items
[0].key
: NULL
;
54 static inline size_t dns_question_size(DnsQuestion
*q
) {
55 return q
? q
->n_keys
: 0;
58 static inline bool dns_question_isempty(DnsQuestion
*q
) {
59 return dns_question_size(q
) <= 0;
62 int dns_question_merge(DnsQuestion
*a
, DnsQuestion
*b
, DnsQuestion
**ret
);
64 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuestion
*, dns_question_unref
);
66 #define _DNS_QUESTION_FOREACH(u, k, q) \
67 for (size_t UNIQ_T(i, u) = ({ \
68 (k) = ((q) && (q)->n_keys > 0) ? (q)->items[0].key : NULL; \
71 (q) && (UNIQ_T(i, u) < (q)->n_keys); \
72 UNIQ_T(i, u)++, (k) = (UNIQ_T(i, u) < (q)->n_keys ? (q)->items[UNIQ_T(i, u)].key : NULL))
74 #define DNS_QUESTION_FOREACH(key, q) _DNS_QUESTION_FOREACH(UNIQ, key, q)
76 #define _DNS_QUESTION_FOREACH_ITEM(u, item, q) \
77 for (size_t UNIQ_T(i, u) = ({ \
78 (item) = dns_question_isempty(q) ? NULL : (q)->items; \
81 UNIQ_T(i, u) < dns_question_size(q); \
82 UNIQ_T(i, u)++, (item) = (UNIQ_T(i, u) < dns_question_size(q) ? (q)->items + UNIQ_T(i, u) : NULL))
84 #define DNS_QUESTION_FOREACH_ITEM(item, q) _DNS_QUESTION_FOREACH_ITEM(UNIQ, item, q)