/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
#include <math.h>
if (ret != 0)
return ret;
- if (x->type < y->type)
- return -1;
- if (x->type > y->type)
- return 1;
+ ret = CMP(x->type, y->type);
+ if (ret != 0)
+ return ret;
- if (x->class < y->class)
- return -1;
- if (x->class > y->class)
- return 1;
+ ret = CMP(x->class, y->class);
+ if (ret != 0)
+ return ret;
return 0;
}
snprintf(buf, buf_size, "%s %s%s%.0u %s%s%.0u",
dns_resource_key_name(key),
strempty(c), c ? "" : "CLASS", c ? 0 : key->class,
- strempty(t), t ? "" : "TYPE", t ? 0 : key->class);
+ strempty(t), t ? "" : "TYPE", t ? 0 : key->type);
return ans;
}
return dns_resource_record_new(key);
}
-DnsResourceRecord* dns_resource_record_ref(DnsResourceRecord *rr) {
- if (!rr)
- return NULL;
-
- assert(rr->n_ref > 0);
- rr->n_ref++;
-
- return rr;
-}
-
-DnsResourceRecord* dns_resource_record_unref(DnsResourceRecord *rr) {
- if (!rr)
- return NULL;
-
- assert(rr->n_ref > 0);
-
- if (rr->n_ref > 1) {
- rr->n_ref--;
- return NULL;
- }
+static DnsResourceRecord* dns_resource_record_free(DnsResourceRecord *rr) {
+ assert(rr);
if (rr->key) {
switch(rr->key->type) {
case DNS_TYPE_OPENPGPKEY:
default:
- free(rr->generic.data);
+ if (!rr->unparseable)
+ free(rr->generic.data);
}
+ if (rr->unparseable)
+ free(rr->generic.data);
+
free(rr->wire_format);
dns_resource_key_unref(rr->key);
}
return mfree(rr);
}
+DEFINE_TRIVIAL_REF_UNREF_FUNC(DnsResourceRecord, dns_resource_record, dns_resource_record_free);
+
int dns_resource_record_new_reverse(DnsResourceRecord **ret, int family, const union in_addr_union *address, const char *hostname) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL;
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL;
if (!rr->ptr.name)
return -ENOMEM;
- *ret = rr;
- rr = NULL;
+ *ret = TAKE_PTR(rr);
return 0;
}
struct tm tm;
assert(buf);
- assert(l > strlen("YYYYMMDDHHmmSS"));
+ assert(l > STRLEN("YYYYMMDDHHmmSS"));
if (!gmtime_r(&sec, &tm))
return -EINVAL;
case DNS_TYPE_RRSIG: {
_cleanup_free_ char *alg = NULL;
- char expiration[strlen("YYYYMMDDHHmmSS") + 1], inception[strlen("YYYYMMDDHHmmSS") + 1];
+ char expiration[STRLEN("YYYYMMDDHHmmSS") + 1], inception[STRLEN("YYYYMMDDHHmmSS") + 1];
const char *type;
int n;
*out = rr->tlsa.data;
return rr->tlsa.data_size;
-
case DNS_TYPE_OPENPGPKEY:
default:
*out = rr->generic.data;
if (dns_resource_record_equal(x, y))
return 0;
- /* This is a bit dirty, we don't implement proper ordering, but
- * the hashtable doesn't need ordering anyway, hence we don't
- * care. */
- return x < y ? -1 : 1;
+ /* We still use CMP() here, even though don't implement proper
+ * ordering, since the hashtable doesn't need ordering anyway. */
+ return CMP(x, y);
}
const struct hash_ops dns_resource_record_hash_ops = {
break;
}
- t = copy;
- copy = NULL;
+ t = TAKE_PTR(copy);
return t;
}