Branch data Line data Source code
1 : : /* SPDX-License-Identifier: LGPL-2.1+ */ 2 : : #pragma once 3 : : 4 : : typedef struct DnsQuestion DnsQuestion; 5 : : 6 : : #include "macro.h" 7 : : #include "resolved-dns-rr.h" 8 : : 9 : : /* A simple array of resource keys */ 10 : : 11 : : struct DnsQuestion { 12 : : unsigned n_ref; 13 : : size_t n_keys, n_allocated; 14 : : DnsResourceKey* keys[0]; 15 : : }; 16 : : 17 : : DnsQuestion *dns_question_new(size_t n); 18 : : DnsQuestion *dns_question_ref(DnsQuestion *q); 19 : : DnsQuestion *dns_question_unref(DnsQuestion *q); 20 : : 21 : : int dns_question_new_address(DnsQuestion **ret, int family, const char *name, bool convert_idna); 22 : : int dns_question_new_reverse(DnsQuestion **ret, int family, const union in_addr_union *a); 23 : : int dns_question_new_service(DnsQuestion **ret, const char *service, const char *type, const char *domain, bool with_txt, bool convert_idna); 24 : : 25 : : int dns_question_add_raw(DnsQuestion *q, DnsResourceKey *key); 26 : : int dns_question_add(DnsQuestion *q, DnsResourceKey *key); 27 : : 28 : : int dns_question_matches_rr(DnsQuestion *q, DnsResourceRecord *rr, const char *search_domain); 29 : : int dns_question_matches_cname_or_dname(DnsQuestion *q, DnsResourceRecord *rr, const char* search_domain); 30 : : int dns_question_is_valid_for_query(DnsQuestion *q); 31 : : int dns_question_contains(DnsQuestion *a, const DnsResourceKey *k); 32 : : int dns_question_is_equal(DnsQuestion *a, DnsQuestion *b); 33 : : 34 : : int dns_question_cname_redirect(DnsQuestion *q, const DnsResourceRecord *cname, DnsQuestion **ret); 35 : : 36 : : const char *dns_question_first_name(DnsQuestion *q); 37 : : 38 : 0 : static inline size_t dns_question_size(DnsQuestion *q) { 39 [ # # ]: 0 : return q ? q->n_keys : 0; 40 : : } 41 : : 42 : 0 : static inline bool dns_question_isempty(DnsQuestion *q) { 43 : 0 : return dns_question_size(q) <= 0; 44 : : } 45 : : 46 [ # # ]: 0 : DEFINE_TRIVIAL_CLEANUP_FUNC(DnsQuestion*, dns_question_unref); 47 : : 48 : : #define _DNS_QUESTION_FOREACH(u, key, q) \ 49 : : for (size_t UNIQ_T(i, u) = ({ \ 50 : : (key) = ((q) && (q)->n_keys > 0) ? (q)->keys[0] : NULL; \ 51 : : 0; \ 52 : : }); \ 53 : : (q) && (UNIQ_T(i, u) < (q)->n_keys); \ 54 : : UNIQ_T(i, u)++, (key) = (UNIQ_T(i, u) < (q)->n_keys ? (q)->keys[UNIQ_T(i, u)] : NULL)) 55 : : 56 : : #define DNS_QUESTION_FOREACH(key, q) _DNS_QUESTION_FOREACH(UNIQ, key, q)