clang-format

pull/641/head
Brad House 1 year ago
parent 45698509d8
commit 6e83c28ab4
  1. 4
      src/lib/ares__htable.c
  2. 31
      src/lib/ares__threads.c
  3. 3
      src/lib/ares_cancel.c
  4. 3
      src/lib/ares_fds.c
  5. 5
      src/lib/ares_getaddrinfo.c
  6. 3
      src/lib/ares_gethostbyaddr.c
  7. 3
      src/lib/ares_gethostbyname.c
  8. 11
      src/lib/ares_getnameinfo.c
  9. 9
      src/lib/ares_init.c
  10. 76
      src/lib/ares_private.h
  11. 3
      src/lib/ares_process.c
  12. 10
      src/lib/ares_qcache.c
  13. 3
      src/lib/ares_query.c
  14. 12
      src/lib/ares_search.c
  15. 3
      src/lib/ares_send.c
  16. 4
      src/lib/ares_timeout.c
  17. 44
      test/ares-test.h

@ -225,8 +225,8 @@ static ares_bool_t ares__htable_expand(ares__htable_t *htable)
/* Slow path, collisions */
while ((node = ares__llist_node_first(htable->buckets[i])) != NULL) {
const void *val = ares__llist_node_val(node);
size_t idx = HASH_IDX(htable, htable->bucket_key(val));
const void *val = ares__llist_node_val(node);
size_t idx = HASH_IDX(htable, htable->bucket_key(val));
/* Try fast path again as maybe we popped one collision off and the
* next we can reuse the llist parent */

@ -37,8 +37,9 @@ struct ares__thread_mutex {
static ares__thread_mutex_t *ares__thread_mutex_create(void)
{
ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut));
if (mut == NULL)
if (mut == NULL) {
return NULL;
}
InitializeCriticalSection(&mut->mutex);
return mut;
@ -46,28 +47,31 @@ static ares__thread_mutex_t *ares__thread_mutex_create(void)
static void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
{
if (mut == NULL)
if (mut == NULL) {
return;
}
DeleteCriticalSection(&mut->mutex);
ares_free(mut);
}
static void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
{
if (mut == NULL)
if (mut == NULL) {
return;
}
EnterCriticalSection(&mut->mutex);
}
static void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
{
if (mut == NULL)
if (mut == NULL) {
return;
}
LeaveCriticalSection(&mut->mutex);
}
# else
# include <pthread.h>
# include <pthread.h>
struct ares__thread_mutex {
pthread_mutex_t mutex;
@ -77,8 +81,9 @@ static ares__thread_mutex_t *ares__thread_mutex_create(void)
{
pthread_mutexattr_t attr;
ares__thread_mutex_t *mut = ares_malloc_zero(sizeof(*mut));
if (mut == NULL)
if (mut == NULL) {
return NULL;
}
if (pthread_mutexattr_init(&attr) != 0) {
ares_free(mut);
@ -104,32 +109,36 @@ fail:
static void ares__thread_mutex_destroy(ares__thread_mutex_t *mut)
{
if (mut == NULL)
if (mut == NULL) {
return;
}
pthread_mutex_destroy(&mut->mutex);
ares_free(mut);
}
static void ares__thread_mutex_lock(ares__thread_mutex_t *mut)
{
if (mut == NULL)
if (mut == NULL) {
return;
}
pthread_mutex_lock(&mut->mutex);
}
static void ares__thread_mutex_unlock(ares__thread_mutex_t *mut)
{
if (mut == NULL)
if (mut == NULL) {
return;
}
pthread_mutex_unlock(&mut->mutex);
}
#endif
# endif
ares_status_t ares__channel_threading_init(ares_channel_t *channel)
{
channel->lock = ares__thread_mutex_create();
if (channel->lock == NULL)
if (channel->lock == NULL) {
return ARES_ENOMEM;
}
return ARES_SUCCESS;
}

@ -37,8 +37,9 @@
*/
void ares_cancel(ares_channel_t *channel)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);

@ -37,8 +37,9 @@ int ares_fds(ares_channel_t *channel, fd_set *read_fds, fd_set *write_fds)
/* Are there any active queries? */
size_t active_queries;
if (channel == NULL || read_fds == NULL || write_fds == NULL)
if (channel == NULL || read_fds == NULL || write_fds == NULL) {
return 0;
}
ares__channel_lock(channel);

@ -673,8 +673,9 @@ void ares_getaddrinfo(ares_channel_t *channel, const char *name,
const struct ares_addrinfo_hints *hints,
ares_addrinfo_callback callback, void *arg)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
ares_getaddrinfo_int(channel, name, service, hints, callback, arg);
ares__channel_unlock(channel);
@ -764,7 +765,7 @@ static ares_bool_t as_is_first(const struct host_query *hquery)
static ares_bool_t as_is_only(const struct host_query *hquery)
{
size_t nname = ares_strlen(hquery->name);
if(hquery->channel->flags & ARES_FLAG_NOSEARCH) {
if (hquery->channel->flags & ARES_FLAG_NOSEARCH) {
return ARES_TRUE;
}
if (hquery->name != NULL && nname && hquery->name[nname - 1] == '.') {

@ -114,8 +114,9 @@ static void ares_gethostbyaddr_int(ares_channel_t *channel, const void *addr,
void ares_gethostbyaddr(ares_channel_t *channel, const void *addr, int addrlen,
int family, ares_host_callback callback, void *arg)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
ares_gethostbyaddr_int(channel, addr, addrlen, family, callback, arg);
ares__channel_unlock(channel);

@ -266,8 +266,7 @@ done:
/* I really have no idea why this is exposed as a public function, but since
* it is, we can't kill this legacy function. */
static ares_status_t ares_gethostbyname_file_int(ares_channel_t *channel,
const char *name,
int family,
const char *name, int family,
struct hostent **host)
{
const ares_hosts_entry_t *entry;

@ -86,10 +86,10 @@ static void append_scopeid(const struct sockaddr_in6 *addr6,
#endif
STATIC_TESTABLE char *ares_striendstr(const char *s1, const char *s2);
static void ares_getnameinfo_int(ares_channel_t *channel,
const struct sockaddr *sa,
ares_socklen_t salen, int flags_int,
ares_nameinfo_callback callback, void *arg)
static void ares_getnameinfo_int(ares_channel_t *channel,
const struct sockaddr *sa,
ares_socklen_t salen, int flags_int,
ares_nameinfo_callback callback, void *arg)
{
const struct sockaddr_in *addr = NULL;
const struct sockaddr_in6 *addr6 = NULL;
@ -190,8 +190,9 @@ void ares_getnameinfo(ares_channel_t *channel, const struct sockaddr *sa,
ares_socklen_t salen, int flags_int,
ares_nameinfo_callback callback, void *arg)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
ares_getnameinfo_int(channel, sa, salen, flags_int, callback, arg);

@ -507,8 +507,9 @@ done:
void ares_set_local_ip4(ares_channel_t *channel, unsigned int local_ip)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
channel->local_ip4 = local_ip;
ares__channel_unlock(channel);
@ -517,8 +518,9 @@ void ares_set_local_ip4(ares_channel_t *channel, unsigned int local_ip)
/* local_ip6 should be 16 bytes in length */
void ares_set_local_ip6(ares_channel_t *channel, const unsigned char *local_ip6)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
memcpy(&channel->local_ip6, local_ip6, sizeof(channel->local_ip6));
ares__channel_unlock(channel);
@ -527,8 +529,9 @@ void ares_set_local_ip6(ares_channel_t *channel, const unsigned char *local_ip6)
/* local_dev_name should be null terminated. */
void ares_set_local_dev(ares_channel_t *channel, const char *local_dev_name)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
ares_strcpy(channel->local_dev_name, local_dev_name,

@ -172,8 +172,8 @@ struct server_state {
* can be hard errors or timeouts
*/
struct ares_addr addr;
unsigned short udp_port; /* host byte order */
unsigned short tcp_port; /* host byte order */
unsigned short udp_port; /* host byte order */
unsigned short tcp_port; /* host byte order */
ares__llist_t *connections;
struct server_connection *tcp_conn;
@ -254,59 +254,59 @@ typedef struct ares__thread_mutex ares__thread_mutex_t;
struct ares_channeldata {
/* Configuration data */
unsigned int flags;
size_t timeout; /* in milliseconds */
size_t tries;
size_t ndots;
size_t maxtimeout; /* in milliseconds */
ares_bool_t rotate;
unsigned short udp_port; /* stored in network order */
unsigned short tcp_port; /* stored in network order */
int socket_send_buffer_size; /* setsockopt takes int */
int socket_receive_buffer_size; /* setsockopt takes int */
char **domains;
size_t ndomains;
struct apattern *sortlist;
size_t nsort;
char *lookups;
size_t ednspsz;
unsigned int qcache_max_ttl;
unsigned int optmask;
unsigned int flags;
size_t timeout; /* in milliseconds */
size_t tries;
size_t ndots;
size_t maxtimeout; /* in milliseconds */
ares_bool_t rotate;
unsigned short udp_port; /* stored in network order */
unsigned short tcp_port; /* stored in network order */
int socket_send_buffer_size; /* setsockopt takes int */
int socket_receive_buffer_size; /* setsockopt takes int */
char **domains;
size_t ndomains;
struct apattern *sortlist;
size_t nsort;
char *lookups;
size_t ednspsz;
unsigned int qcache_max_ttl;
unsigned int optmask;
/* For binding to local devices and/or IP addresses. Leave
* them null/zero for no binding.
*/
char local_dev_name[32];
unsigned int local_ip4;
unsigned char local_ip6[16];
char local_dev_name[32];
unsigned int local_ip4;
unsigned char local_ip6[16];
/* Thread safety lock */
ares__thread_mutex_t *lock;
/* Server addresses and communications state. Sorted by least consecutive
* failures, followed by the configuration order if failures are equal. */
ares__slist_t *servers;
ares__slist_t *servers;
/* random state to use when generating new ids and generating retry penalties
*/
ares_rand_state *rand_state;
ares_rand_state *rand_state;
/* All active queries in a single list */
ares__llist_t *all_queries;
ares__llist_t *all_queries;
/* Queries bucketed by qid, for quickly dispatching DNS responses: */
ares__htable_szvp_t *queries_by_qid;
ares__htable_szvp_t *queries_by_qid;
/* Queries bucketed by timeout, for quickly handling timeouts: */
ares__slist_t *queries_by_timeout;
ares__slist_t *queries_by_timeout;
/* Map linked list node member for connection to file descriptor. We use
* the node instead of the connection object itself so we can quickly look
* up a connection and remove it if necessary (as otherwise we'd have to
* scan all connections) */
ares__htable_asvp_t *connnode_by_socket;
ares__htable_asvp_t *connnode_by_socket;
ares_sock_state_cb sock_state_cb;
void *sock_state_cb_data;
ares_sock_state_cb sock_state_cb;
void *sock_state_cb_data;
ares_sock_create_callback sock_create_cb;
void *sock_create_cb_data;
@ -574,19 +574,19 @@ ares_status_t ares__qcache_create(ares_rand_state *rand_state,
unsigned int max_ttl,
ares__qcache_t **cache_out);
void ares__qcache_flush(ares__qcache_t *cache);
ares_status_t ares_qcache_insert(ares_channel_t *channel,
ares_status_t ares_qcache_insert(ares_channel_t *channel,
const struct timeval *now,
const struct query *query,
ares_dns_record_t *dnsrec);
ares_status_t ares_qcache_fetch(ares_channel_t *channel,
const struct query *query,
ares_dns_record_t *dnsrec);
ares_status_t ares_qcache_fetch(ares_channel_t *channel,
const struct timeval *now,
const unsigned char *qbuf, size_t qlen,
unsigned char **abuf, size_t *alen);
ares_status_t ares__channel_threading_init(ares_channel_t *channel);
void ares__channel_threading_destroy(ares_channel_t *channel);
void ares__channel_lock(ares_channel_t *channel);
void ares__channel_unlock(ares_channel_t *channel);
void ares__channel_threading_destroy(ares_channel_t *channel);
void ares__channel_lock(ares_channel_t *channel);
void ares__channel_unlock(ares_channel_t *channel);
#ifdef _MSC_VER
typedef __int64 ares_int64_t;

@ -142,8 +142,9 @@ static void processfds(ares_channel_t *channel, fd_set *read_fds,
{
struct timeval now;
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);

@ -127,7 +127,7 @@ fail:
return NULL;
}
static void ares__qcache_expire(ares__qcache_t *cache,
static void ares__qcache_expire(ares__qcache_t *cache,
const struct timeval *now)
{
ares__slist_node_t *node;
@ -421,16 +421,16 @@ done:
return status;
}
ares_status_t ares_qcache_insert(ares_channel_t *channel,
ares_status_t ares_qcache_insert(ares_channel_t *channel,
const struct timeval *now,
const struct query *query,
ares_dns_record_t *dnsrec)
const struct query *query,
ares_dns_record_t *dnsrec)
{
return ares__qcache_insert(channel->qcache, dnsrec, query->qbuf, query->qlen,
now);
}
ares_status_t ares_qcache_fetch(ares_channel_t *channel,
ares_status_t ares_qcache_fetch(ares_channel_t *channel,
const struct timeval *now,
const unsigned char *qbuf, size_t qlen,
unsigned char **abuf, size_t *alen)

@ -88,8 +88,9 @@ ares_status_t ares_query_qid(ares_channel_t *channel, const char *name,
void ares_query(ares_channel_t *channel, const char *name, int dnsclass,
int type, ares_callback callback, void *arg)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
ares_query_qid(channel, name, dnsclass, type, callback, arg, NULL);
ares__channel_unlock(channel);

@ -57,8 +57,9 @@ static void search_callback(void *arg, int status, int timeouts,
static void end_squery(struct search_query *squery, ares_status_t status,
unsigned char *abuf, size_t alen);
static void ares_search_int(ares_channel_t *channel, const char *name, int dnsclass,
int type, ares_callback callback, void *arg)
static void ares_search_int(ares_channel_t *channel, const char *name,
int dnsclass, int type, ares_callback callback,
void *arg)
{
struct search_query *squery;
char *s;
@ -157,11 +158,12 @@ static void ares_search_int(ares_channel_t *channel, const char *name, int dnscl
}
}
void ares_search(ares_channel_t *channel, const char *name, int dnsclass,
int type, ares_callback callback, void *arg)
void ares_search(ares_channel_t *channel, const char *name, int dnsclass,
int type, ares_callback callback, void *arg)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);
ares_search_int(channel, name, dnsclass, type, callback, arg);
ares__channel_unlock(channel);

@ -153,8 +153,9 @@ ares_status_t ares_send_ex(ares_channel_t *channel, const unsigned char *qbuf,
void ares_send(ares_channel_t *channel, const unsigned char *qbuf, int qlen,
ares_callback callback, void *arg)
{
if (channel == NULL)
if (channel == NULL) {
return;
}
ares__channel_lock(channel);

@ -47,8 +47,8 @@ static void remaining_time(struct timeval *remaining, const struct timeval *now,
remaining->tv_sec = tout->tv_sec - now->tv_sec;
if (tout->tv_usec < now->tv_usec) {
remaining->tv_sec -= 1;
remaining->tv_usec = (tout->tv_usec + 1000000) - now->tv_usec;
remaining->tv_sec -= 1;
remaining->tv_usec = (tout->tv_usec + 1000000) - now->tv_usec;
} else {
remaining->tv_usec = tout->tv_usec - now->tv_usec;
}

44
test/ares-test.h vendored

@ -67,9 +67,9 @@ extern std::vector<std::pair<int, bool>> families_modes;
// Process all pending work on ares-owned file descriptors, plus
// optionally the given set-of-FDs + work function.
void ProcessWork(ares_channel_t *channel,
std::function<std::set<ares_socket_t>()> get_extrafds,
std::function<void(ares_socket_t)> process_extra);
void ProcessWork(ares_channel_t *channel,
std::function<std::set<ares_socket_t>()> get_extrafds,
std::function<void(ares_socket_t)> process_extra);
std::set<ares_socket_t> NoExtraFDs();
// Test fixture that ensures library initialization, and allows
@ -115,8 +115,8 @@ public:
/* Enable query cache for live tests */
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.qcache_max_ttl = 300;
int optmask = ARES_OPT_QUERY_CACHE;
opts.qcache_max_ttl = 300;
int optmask = ARES_OPT_QUERY_CACHE;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
EXPECT_NE(nullptr, channel_);
}
@ -141,8 +141,8 @@ public:
{
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.lookups = strdup("f");
int optmask = ARES_OPT_LOOKUPS;
opts.lookups = strdup("f");
int optmask = ARES_OPT_LOOKUPS;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
EXPECT_NE(nullptr, channel_);
free(opts.lookups);
@ -170,8 +170,8 @@ public:
{
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.lookups = strdup(GetParam().c_str());
int optmask = ARES_OPT_LOOKUPS;
opts.lookups = strdup(GetParam().c_str());
int optmask = ARES_OPT_LOOKUPS;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
EXPECT_NE(nullptr, channel_);
free(opts.lookups);
@ -232,10 +232,10 @@ public:
std::set<ares_socket_t> fds() const;
// Process activity on a file descriptor.
void ProcessFD(ares_socket_t fd);
void ProcessFD(ares_socket_t fd);
// Ports the server is responding to
unsigned short udpport() const
unsigned short udpport() const
{
return udpport_;
}
@ -246,19 +246,20 @@ public:
}
private:
void ProcessRequest(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen,
int qid, const std::string &name, int rrtype);
void ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen,
byte *data, int len);
void ProcessRequest(ares_socket_t fd, struct sockaddr_storage *addr,
ares_socklen_t addrlen, int qid, const std::string &name,
int rrtype);
void ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr,
ares_socklen_t addrlen, byte *data, int len);
unsigned short udpport_;
unsigned short tcpport_;
ares_socket_t udpfd_;
ares_socket_t tcpfd_;
std::set<ares_socket_t> connfds_;
std::vector<byte> reply_;
int qid_;
unsigned char *tcp_data_;
size_t tcp_data_len_;
std::vector<byte> reply_;
int qid_;
unsigned char *tcp_data_;
size_t tcp_data_len_;
};
// Test fixture that uses a mock DNS server.
@ -278,9 +279,10 @@ protected:
typedef std::vector<std::unique_ptr<NiceMockServer>> NiceMockServers;
std::set<ares_socket_t> fds() const;
void ProcessFD(ares_socket_t fd);
void ProcessFD(ares_socket_t fd);
static NiceMockServers BuildServers(int count, int family, unsigned short base_port);
static NiceMockServers BuildServers(int count, int family,
unsigned short base_port);
NiceMockServers servers_;
// Convenience reference to first server.

Loading…
Cancel
Save