clang-format

pull/604/head
Brad House 1 year ago
parent c433477753
commit a76c95a6d7
  1. 4
      src/lib/ares__buf.c
  2. 2
      src/lib/ares__buf.h
  3. 9
      src/lib/ares_dns_mapping.c
  4. 13
      src/lib/ares_dns_parse.c
  5. 63
      src/lib/ares_dns_record.c
  6. 86
      src/lib/ares_dns_record.h
  7. 14
      src/lib/ares_dns_write.c
  8. 3
      src/lib/ares_fds.c
  9. 7
      src/lib/ares_process.c

@ -558,7 +558,7 @@ ares_status_t ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
}
ares_status_t ares__buf_fetch_bytes_dup(ares__buf_t *buf, size_t len,
ares_bool_t null_term,
ares_bool_t null_term,
unsigned char **bytes)
{
size_t remaining_len;
@ -568,7 +568,7 @@ ares_status_t ares__buf_fetch_bytes_dup(ares__buf_t *buf, size_t len,
return ARES_EBADRESP;
}
*bytes = ares_malloc(null_term?len+1:len);
*bytes = ares_malloc(null_term ? len + 1 : len);
if (*bytes == NULL) {
return ARES_ENOMEM;
}

@ -299,7 +299,7 @@ ares_status_t ares__buf_fetch_bytes(ares__buf_t *buf, unsigned char *bytes,
* \return ARES_SUCCESS or one of the c-ares error codes
*/
ares_status_t ares__buf_fetch_bytes_dup(ares__buf_t *buf, size_t len,
ares_bool_t null_term,
ares_bool_t null_term,
unsigned char **bytes);
/*! Fetch the requested number of bytes and place them into the provided

@ -497,11 +497,10 @@ static const ares_dns_rr_key_t rr_naptr_keys[] = {
ARES_RR_NAPTR_ORDER, ARES_RR_NAPTR_PREFERENCE, ARES_RR_NAPTR_FLAGS,
ARES_RR_NAPTR_SERVICES, ARES_RR_NAPTR_REGEXP, ARES_RR_NAPTR_REPLACEMENT
};
static const ares_dns_rr_key_t rr_opt_keys[] = { ARES_RR_OPT_UDP_SIZE,
ARES_RR_OPT_EXT_RCODE,
ARES_RR_OPT_VERSION,
ARES_RR_OPT_FLAGS,
ARES_RR_OPT_OPTIONS };
static const ares_dns_rr_key_t rr_opt_keys[] = {
ARES_RR_OPT_UDP_SIZE, ARES_RR_OPT_EXT_RCODE, ARES_RR_OPT_VERSION,
ARES_RR_OPT_FLAGS, ARES_RR_OPT_OPTIONS
};
static const ares_dns_rr_key_t rr_tlsa_keys[] = { ARES_RR_TLSA_CERT_USAGE,
ARES_RR_TLSA_SELECTOR,
ARES_RR_TLSA_MATCH,

@ -493,7 +493,7 @@ static ares_status_t ares_dns_parse_rr_tlsa(ares__buf_t *buf, ares_dns_rr_t *rr,
}
static ares_status_t ares_dns_parse_rr_svcb(ares__buf_t *buf, ares_dns_rr_t *rr,
size_t rdlength)
size_t rdlength)
{
ares_status_t status;
size_t orig_len = ares__buf_len(buf);
@ -503,8 +503,8 @@ static ares_status_t ares_dns_parse_rr_svcb(ares__buf_t *buf, ares_dns_rr_t *rr,
return status;
}
status = ares_dns_parse_and_set_dns_name(buf, ARES_FALSE, rr,
ARES_RR_SVCB_TARGET);
status =
ares_dns_parse_and_set_dns_name(buf, ARES_FALSE, rr, ARES_RR_SVCB_TARGET);
if (status != ARES_SUCCESS) {
return status;
}
@ -544,8 +544,7 @@ static ares_status_t ares_dns_parse_rr_svcb(ares__buf_t *buf, ares_dns_rr_t *rr,
}
static ares_status_t ares_dns_parse_rr_https(ares__buf_t *buf,
ares_dns_rr_t *rr,
size_t rdlength)
ares_dns_rr_t *rr, size_t rdlength)
{
ares_status_t status;
size_t orig_len = ares__buf_len(buf);
@ -555,8 +554,8 @@ static ares_status_t ares_dns_parse_rr_https(ares__buf_t *buf,
return status;
}
status = ares_dns_parse_and_set_dns_name(buf, ARES_FALSE, rr,
ARES_RR_HTTPS_TARGET);
status =
ares_dns_parse_and_set_dns_name(buf, ARES_FALSE, rr, ARES_RR_HTTPS_TARGET);
if (status != ARES_SUCCESS) {
return status;
}

@ -97,10 +97,11 @@ static void ares__dns_options_free(ares__dns_options_t *options)
{
size_t i;
if (options == NULL)
if (options == NULL) {
return;
}
for (i=0; i<options->cnt; i++) {
for (i = 0; i < options->cnt; i++) {
ares_free(options->optval[i].val);
}
ares_free(options->optval);
@ -809,7 +810,8 @@ const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr,
size_t const *bin_len = NULL;
if ((ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BIN &&
ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BINP) || len == NULL) {
ares_dns_rr_key_datatype(key) != ARES_DATATYPE_BINP) ||
len == NULL) {
return NULL;
}
@ -846,7 +848,7 @@ const char *ares_dns_rr_get_str(const ares_dns_rr_t *dns_rr,
}
size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key)
ares_dns_rr_key_t key)
{
const ares__dns_options_t *opts;
@ -863,17 +865,17 @@ size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
}
unsigned short ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
size_t idx,
const unsigned char **val,
size_t *val_len)
ares_dns_rr_key_t key, size_t idx,
const unsigned char **val, size_t *val_len)
{
const ares__dns_options_t *opts;
if (val)
if (val) {
*val = NULL;
if (val_len)
}
if (val_len) {
*val_len = 0;
}
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_OPT) {
return 65535;
@ -899,18 +901,18 @@ unsigned short ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr,
}
ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
const unsigned char **val,
size_t *val_len)
ares_dns_rr_key_t key, unsigned short opt,
const unsigned char **val, size_t *val_len)
{
const ares__dns_options_t *opts;
size_t i;
if (val)
if (val) {
*val = NULL;
if (val_len)
}
if (val_len) {
*val_len = 0;
}
if (ares_dns_rr_key_datatype(key) != ARES_DATATYPE_OPT) {
return ARES_FALSE;
@ -921,14 +923,15 @@ ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
return ARES_FALSE;
}
for (i=0; i<opts->cnt; i++) {
for (i = 0; i < opts->cnt; i++) {
if (opts->optval[i].opt == opt) {
break;
}
}
if (i >= opts->cnt)
if (i >= opts->cnt) {
return ARES_FALSE;
}
if (val) {
*val = opts->optval[i].val;
@ -1061,8 +1064,8 @@ ares_status_t ares_dns_rr_set_bin(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
{
ares_status_t status;
ares_dns_datatype_t datatype = ares_dns_rr_key_datatype(key);
size_t alloclen = (datatype == ARES_DATATYPE_BINP)?len+1:len;
unsigned char *temp = ares_malloc(alloclen);
size_t alloclen = (datatype == ARES_DATATYPE_BINP) ? len + 1 : len;
unsigned char *temp = ares_malloc(alloclen);
if (temp == NULL) {
return ARES_ENOMEM;
@ -1126,12 +1129,9 @@ ares_status_t ares_dns_rr_set_str(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
return status;
}
ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
unsigned char *val,
size_t val_len)
ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, unsigned short opt,
unsigned char *val, size_t val_len)
{
ares__dns_options_t **options;
size_t idx;
@ -1152,9 +1152,10 @@ ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
return ARES_ENOMEM;
}
for (idx=0; idx<(*options)->cnt; idx++) {
if ((*options)->optval[idx].opt == opt)
for (idx = 0; idx < (*options)->cnt; idx++) {
if ((*options)->optval[idx].opt == opt) {
break;
}
}
/* Duplicate entry, replace */
@ -1196,10 +1197,8 @@ done:
return ARES_SUCCESS;
}
ares_status_t ares_dns_rr_set_opt(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
const unsigned char *val,
ares_status_t ares_dns_rr_set_opt(ares_dns_rr_t *dns_rr, ares_dns_rr_key_t key,
unsigned short opt, const unsigned char *val,
size_t val_len)
{
unsigned char *temp = NULL;

@ -39,22 +39,22 @@
* on requests (e.g. ARES_REC_TYPE_ANY), and some may only be valid on
* responses */
typedef enum {
ARES_REC_TYPE_A = 1, /*!< Host address. */
ARES_REC_TYPE_NS = 2, /*!< Authoritative server. */
ARES_REC_TYPE_CNAME = 5, /*!< Canonical name. */
ARES_REC_TYPE_SOA = 6, /*!< Start of authority zone. */
ARES_REC_TYPE_PTR = 12, /*!< Domain name pointer. */
ARES_REC_TYPE_HINFO = 13, /*!< Host information. */
ARES_REC_TYPE_MX = 15, /*!< Mail routing information. */
ARES_REC_TYPE_TXT = 16, /*!< Text strings. */
ARES_REC_TYPE_AAAA = 28, /*!< RFC 3596. Ip6 Address. */
ARES_REC_TYPE_SRV = 33, /*!< RFC 2782. Server Selection. */
ARES_REC_TYPE_NAPTR = 35, /*!< RFC 3403. Naming Authority Pointer */
ARES_REC_TYPE_OPT = 41, /*!< RFC 6891. EDNS0 option (meta-RR) */
ARES_REC_TYPE_TLSA = 52, /*!< RFC 6698. DNS-Based Authentication of Named
* Entities (DANE) Transport Layer Security
* (TLS) Protocol: TLSA */
ARES_REC_TYPE_A = 1, /*!< Host address. */
ARES_REC_TYPE_NS = 2, /*!< Authoritative server. */
ARES_REC_TYPE_CNAME = 5, /*!< Canonical name. */
ARES_REC_TYPE_SOA = 6, /*!< Start of authority zone. */
ARES_REC_TYPE_PTR = 12, /*!< Domain name pointer. */
ARES_REC_TYPE_HINFO = 13, /*!< Host information. */
ARES_REC_TYPE_MX = 15, /*!< Mail routing information. */
ARES_REC_TYPE_TXT = 16, /*!< Text strings. */
ARES_REC_TYPE_AAAA = 28, /*!< RFC 3596. Ip6 Address. */
ARES_REC_TYPE_SRV = 33, /*!< RFC 2782. Server Selection. */
ARES_REC_TYPE_NAPTR = 35, /*!< RFC 3403. Naming Authority Pointer */
ARES_REC_TYPE_OPT = 41, /*!< RFC 6891. EDNS0 option (meta-RR) */
ARES_REC_TYPE_TLSA = 52, /*!< RFC 6698. DNS-Based Authentication of Named
* Entities (DANE) Transport Layer Security
* (TLS) Protocol: TLSA */
ARES_REC_TYPE_SVCB = 64, /*!< RFC 9460. General Purpose Service Binding */
ARES_REC_TYPE_HTTPS = 65, /*!< RFC 9460. Service Binding type for use with
* HTTPS */
@ -154,7 +154,7 @@ typedef enum {
* printable. Guaranteed to have a NULL
* terminator for convenience (not included in
* length) */
ARES_DATATYPE_OPT = 9, /*!< Array of options. 16bit identifier, BINP
ARES_DATATYPE_OPT = 9, /*!< Array of options. 16bit identifier, BINP
* data. */
} ares_dns_datatype_t;
@ -297,19 +297,19 @@ typedef enum {
/*! SVCB (and HTTPS) known parameters */
typedef enum {
/*! Mandatory keys in this RR (RFC 9460 Section 8) */
ARES_SVCB_PARAM_MANDATORY = 0,
ARES_SVCB_PARAM_MANDATORY = 0,
/*! Additional supported protocols (RFC 9460 Section 7.1) */
ARES_SVCB_PARAM_ALPN = 1,
ARES_SVCB_PARAM_ALPN = 1,
/*! No support for default protocol (RFC 9460 Section 7.1) */
ARES_SVCB_PARAM_NO_DEFAULT_ALPN = 2,
/*! Port for alternative endpoint (RFC 9460 Section 7.2) */
ARES_SVCB_PARAM_PORT = 3,
ARES_SVCB_PARAM_PORT = 3,
/*! IPv4 address hints (RFC 9460 Section 7.3) */
ARES_SVCB_PARAM_IPV4HINT = 4,
ARES_SVCB_PARAM_IPV4HINT = 4,
/*! RESERVED (held for Encrypted ClientHello) */
ARES_SVCB_PARAM_ECH = 5,
ARES_SVCB_PARAM_ECH = 5,
/*! IPv6 address hints (RFC 9460 Section 7.3) */
ARES_SVCB_PARAM_IPV6HINT = 6
ARES_SVCB_PARAM_IPV6HINT = 6
} ares_svcb_param_t;
/*! String representation of DNS Record Type
@ -709,8 +709,7 @@ unsigned int ares_dns_rr_get_u32(const ares_dns_rr_t *dns_rr,
* \return pointer binary data or NULL on error
*/
const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
size_t *len);
ares_dns_rr_key_t key, size_t *len);
/*! Retrieve the number of options stored for the RR.
*
@ -718,8 +717,8 @@ const unsigned char *ares_dns_rr_get_bin(const ares_dns_rr_t *dns_rr,
* \param[in] key DNS Resource Record Key
* \return count, or 0 if none.
*/
size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key);
/*! Retrieve the option for the RR by index.
*
@ -733,11 +732,9 @@ size_t ares_dns_rr_get_opt_cnt(const ares_dns_rr_t *dns_rr,
* length.
* \return option key/id on success, 65535 on misuse.
*/
unsigned short ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
size_t idx,
const unsigned char **val,
size_t *val_len);
unsigned short ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, size_t idx,
const unsigned char **val, size_t *val_len);
/*! Retrieve the option for the RR by the option key/id.
*
@ -751,11 +748,10 @@ unsigned short ares_dns_rr_get_opt(const ares_dns_rr_t *dns_rr,
* length.
* \return ARES_TRUE on success, ARES_FALSE on misuse.
*/
ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
const unsigned char **val,
size_t *val_len);
ares_bool_t ares_dns_rr_get_opt_byid(const ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, unsigned short opt,
const unsigned char **val,
size_t *val_len);
/*! Parse a complete DNS message.
*
@ -796,11 +792,9 @@ ares_status_t ares_dns_rr_set_str_own(ares_dns_rr_t *dns_rr,
ares_status_t ares_dns_rr_set_bin_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, unsigned char *val,
size_t len);
ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key,
unsigned short opt,
unsigned char *val,
size_t val_len);
ares_status_t ares_dns_rr_set_opt_own(ares_dns_rr_t *dns_rr,
ares_dns_rr_key_t key, unsigned short opt,
unsigned char *val, size_t val_len);
ares_status_t ares_dns_record_rr_prealloc(ares_dns_record_t *dnsrec,
ares_dns_section_t sect, size_t cnt);
@ -878,10 +872,10 @@ typedef struct {
} ares__dns_optval_t;
typedef struct {
ares__dns_optval_t *optval; /*!< Attribute/value pairs */
size_t cnt; /*!< Count of Attribute/Value pairs */
size_t alloc; /*!< Allocated count of attribute/value
* pairs */
ares__dns_optval_t *optval; /*!< Attribute/value pairs */
size_t cnt; /*!< Count of Attribute/Value pairs */
size_t alloc; /*!< Allocated count of attribute/value
* pairs */
} ares__dns_options_t;
typedef struct {

@ -543,7 +543,7 @@ static ares_status_t ares_dns_write_rr_opt(ares__buf_t *buf,
}
/* Append Options */
for (i=0; i<ares_dns_rr_get_opt_cnt(rr, ARES_RR_OPT_OPTIONS); i++) {
for (i = 0; i < ares_dns_rr_get_opt_cnt(rr, ARES_RR_OPT_OPTIONS); i++) {
unsigned short opt;
size_t val_len;
const unsigned char *val;
@ -625,14 +625,14 @@ static ares_status_t ares_dns_write_rr_svcb(ares__buf_t *buf,
}
/* TARGET */
status = ares_dns_write_rr_name(buf, rr, namelist, ARES_FALSE,
ARES_RR_SVCB_TARGET);
status =
ares_dns_write_rr_name(buf, rr, namelist, ARES_FALSE, ARES_RR_SVCB_TARGET);
if (status != ARES_SUCCESS) {
return status;
}
/* Append Params */
for (i=0; i<ares_dns_rr_get_opt_cnt(rr, ARES_RR_SVCB_PARAMS); i++) {
for (i = 0; i < ares_dns_rr_get_opt_cnt(rr, ARES_RR_SVCB_PARAMS); i++) {
unsigned short opt;
size_t val_len;
const unsigned char *val;
@ -676,14 +676,14 @@ static ares_status_t ares_dns_write_rr_https(ares__buf_t *buf,
}
/* TARGET */
status = ares_dns_write_rr_name(buf, rr, namelist, ARES_FALSE,
ARES_RR_HTTPS_TARGET);
status =
ares_dns_write_rr_name(buf, rr, namelist, ARES_FALSE, ARES_RR_HTTPS_TARGET);
if (status != ARES_SUCCESS) {
return status;
}
/* Append Params */
for (i=0; i<ares_dns_rr_get_opt_cnt(rr, ARES_RR_HTTPS_PARAMS); i++) {
for (i = 0; i < ares_dns_rr_get_opt_cnt(rr, ARES_RR_HTTPS_PARAMS); i++) {
unsigned short opt;
size_t val_len;
const unsigned char *val;

@ -48,8 +48,9 @@ int ares_fds(ares_channel_t *channel, fd_set *read_fds, fd_set *write_fds)
node = ares__llist_node_next(node)) {
const struct server_connection *conn = ares__llist_node_val(node);
if (!active_queries && !conn->is_tcp)
if (!active_queries && !conn->is_tcp) {
continue;
}
/* Always wait on read */
FD_SET(conn->fd, read_fds);

@ -737,9 +737,8 @@ static void handle_conn_error(struct server_connection *conn,
ares_status_t ares__requeue_query(struct query *query, struct timeval *now)
{
const ares_channel_t *channel = query->channel;
size_t max_tries = ares__slist_len(channel->servers) *
channel->tries;
const ares_channel_t *channel = query->channel;
size_t max_tries = ares__slist_len(channel->servers) * channel->tries;
query->try_count++;
@ -796,7 +795,6 @@ static ares_status_t ares__append_tcpbuf(struct server_state *server,
return ares__buf_append(server->tcp_send, query->qbuf, query->qlen);
}
static size_t ares__retry_penalty(struct query *query)
{
const ares_channel_t *channel = query->channel;
@ -828,7 +826,6 @@ static size_t ares__retry_penalty(struct query *query)
return timeplus;
}
ares_status_t ares__send_query(struct query *query, struct timeval *now)
{
ares_channel_t *channel = query->channel;

Loading…
Cancel
Save