]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/resolve/resolved-dns-rr.c
resolved: add a DNS client stub resolver
[thirdparty/systemd.git] / src / resolve / resolved-dns-rr.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2014 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "resolved-dns-rr.h"
23
24 void dns_resource_key_free(DnsResourceKey *key) {
25 if (!key)
26 return;
27
28 free(key->name);
29 zero(*key);
30 }
31
32 DnsResourceRecord* dns_resource_record_new(void) {
33 DnsResourceRecord *rr;
34
35 rr = new0(DnsResourceRecord, 1);
36 if (!rr)
37 return NULL;
38
39 rr->n_ref = 1;
40 return rr;
41 }
42
43 DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
44 if (!rr)
45 return NULL;
46
47 assert(rr->n_ref > 0);
48 rr->n_ref++;
49
50 return rr;
51 }
52
53 DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
54 if (!rr)
55 return NULL;
56
57 assert(rr->n_ref > 0);
58
59 if (rr->n_ref > 1) {
60 rr->n_ref--;
61 return NULL;
62 }
63
64 if (IN_SET(rr->key.type, DNS_TYPE_PTR, DNS_TYPE_NS, DNS_TYPE_CNAME))
65 free(rr->ptr.name);
66 else if (rr->key.type == DNS_TYPE_HINFO) {
67 free(rr->hinfo.cpu);
68 free(rr->hinfo.os);
69 } else if (!IN_SET(rr->key.type, DNS_TYPE_A, DNS_TYPE_AAAA))
70 free(rr->generic.data);
71
72 dns_resource_key_free(&rr->key);
73 free(rr);
74
75 return NULL;
76 }