Skip to content

Commit

Permalink
deps: sync with upstream c-ares/c-ares@2bae2d5
Browse files Browse the repository at this point in the history
PR-URL: #5090
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
  • Loading branch information
indutny authored and rvagg committed Feb 9, 2016
1 parent ec62789 commit f1a0827
Show file tree
Hide file tree
Showing 41 changed files with 958 additions and 451 deletions.
50 changes: 44 additions & 6 deletions deps/cares/include/ares.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define ARES__H

#include "ares_version.h" /* c-ares version defines */
#include "ares_build.h" /* c-ares build definitions */
#include "ares_rules.h" /* c-ares rules enforcement */

/*
* Define WIN32 when build target is Win32 API
Expand All @@ -29,9 +31,6 @@
# define WIN32
#endif

/* Data type definition of ares_socklen_t. */
typedef unsigned ares_socklen_t;

#include <sys/types.h>

/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
Expand Down Expand Up @@ -297,6 +296,13 @@ typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,

CARES_EXTERN int ares_library_init(int flags);

CARES_EXTERN int ares_library_init_mem(int flags,
void *(*amalloc)(size_t size),
void (*afree)(void *ptr),
void *(*arealloc)(void *ptr, size_t size));

CARES_EXTERN int ares_library_initialized(void);

CARES_EXTERN void ares_library_cleanup(void);

CARES_EXTERN const char *ares_version(int *version);
Expand Down Expand Up @@ -338,6 +344,9 @@ CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
ares_sock_create_callback callback,
void *user_data);

CARES_EXTERN int ares_set_sortlist(ares_channel channel,
const char *sortstr);

CARES_EXTERN void ares_send(ares_channel channel,
const unsigned char *qbuf,
int qlen,
Expand Down Expand Up @@ -473,8 +482,17 @@ struct ares_txt_reply {
struct ares_txt_reply *next;
unsigned char *txt;
size_t length; /* length excludes null termination */
unsigned char record_start; /* 1 - if start of new record
* 0 - if a chunk in the same record */
};

/* NOTE: This structure is a superset of ares_txt_reply
*/
struct ares_txt_ext {
struct ares_txt_ext *next;
unsigned char *txt;
size_t length;
/* 1 - if start of new record
* 0 - if a chunk in the same record */
unsigned char record_start;
};

struct ares_naptr_reply {
Expand Down Expand Up @@ -540,6 +558,10 @@ CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
int alen,
struct ares_txt_reply** txt_out);

CARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char* abuf,
int alen,
struct ares_txt_ext** txt_out);

CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
int alen,
struct ares_naptr_reply** naptr_out);
Expand All @@ -556,7 +578,6 @@ CARES_EXTERN void ares_free_data(void *dataptr);

CARES_EXTERN const char *ares_strerror(int code);

/* TODO: Hold port here as well. */
struct ares_addr_node {
struct ares_addr_node *next;
int family;
Expand All @@ -566,15 +587,32 @@ struct ares_addr_node {
} addr;
};

struct ares_addr_port_node {
struct ares_addr_port_node *next;
int family;
union {
struct in_addr addr4;
struct ares_in6_addr addr6;
} addr;
int udp_port;
int tcp_port;
};

CARES_EXTERN int ares_set_servers(ares_channel channel,
struct ares_addr_node *servers);
CARES_EXTERN int ares_set_servers_ports(ares_channel channel,
struct ares_addr_port_node *servers);

/* Incomming string format: host[:port][,host[:port]]... */
CARES_EXTERN int ares_set_servers_csv(ares_channel channel,
const char* servers);
CARES_EXTERN int ares_set_servers_ports_csv(ares_channel channel,
const char* servers);

CARES_EXTERN int ares_get_servers(ares_channel channel,
struct ares_addr_node **servers);
CARES_EXTERN int ares_get_servers_ports(ares_channel channel,
struct ares_addr_port_node **servers);

CARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst,
ares_socklen_t size);
Expand Down
117 changes: 117 additions & 0 deletions deps/cares/include/ares_build.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/* ares_build.h. Generated from ares_build.h.in by configure. */
#ifndef __CARES_BUILD_H
#define __CARES_BUILD_H


/* Copyright (C) 2009 by Daniel Stenberg et al
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. M.I.T. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/

/* ================================================================ */
/* NOTES FOR CONFIGURE CAPABLE SYSTEMS */
/* ================================================================ */

/*
* NOTE 1:
* -------
*
* Nothing in this file is intended to be modified or adjusted by the
* c-ares library user nor by the c-ares library builder.
*
* If you think that something actually needs to be changed, adjusted
* or fixed in this file, then, report it on the c-ares development
* mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
*
* This header file shall only export symbols which are 'cares' or 'CARES'
* prefixed, otherwise public name space would be polluted.
*
* NOTE 2:
* -------
*
* Right now you might be staring at file ares_build.h.in or ares_build.h,
* this is due to the following reason:
*
* On systems capable of running the configure script, the configure process
* will overwrite the distributed ares_build.h file with one that is suitable
* and specific to the library being configured and built, which is generated
* from the ares_build.h.in template file.
*
*/

/* ================================================================ */
/* DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE */
/* ================================================================ */

#ifdef CARES_SIZEOF_LONG
# error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
#endif

#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
# error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
#endif

#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
# error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
#endif

/* ================================================================ */
/* EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY */
/* ================================================================ */

/* Configure process defines this to 1 when it finds out that system */
/* header file ws2tcpip.h must be included by the external interface. */

#ifdef WIN32
# define CARES_PULL_WS2TCPIP_H 1
#else
# define CARES_PULL_SYS_TYPES_H 1
# define CARES_PULL_SYS_SOCKET_H 1
#endif

/* #undef CARES_PULL_WS2TCPIP_H */
#ifdef CARES_PULL_WS2TCPIP_H
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
#endif

/* Configure process defines this to 1 when it finds out that system */
/* header file sys/types.h must be included by the external interface. */
#ifdef CARES_PULL_SYS_TYPES_H
# include <sys/types.h>
#endif

/* Configure process defines this to 1 when it finds out that system */
/* header file sys/socket.h must be included by the external interface. */
#ifdef CARES_PULL_SYS_SOCKET_H
# include <sys/socket.h>
#endif

/* The size of `long', as computed by sizeof. */
/* #undef CARES_SIZEOF_LONG */

/* Integral data type used for ares_socklen_t. */
#define CARES_TYPEOF_ARES_SOCKLEN_T socklen_t

/* The size of `ares_socklen_t', as computed by sizeof. */
#define CARES_SIZEOF_ARES_SOCKLEN_T 4

/* Data type definition of ares_socklen_t. */
typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;

#endif /* __CARES_BUILD_H */
File renamed without changes.
6 changes: 3 additions & 3 deletions deps/cares/src/ares__close_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ void ares__close_sockets(ares_channel channel, struct server_state *server)
sendreq = server->qhead;
server->qhead = sendreq->next;
if (sendreq->data_storage != NULL)
free(sendreq->data_storage);
free(sendreq);
ares_free(sendreq->data_storage);
ares_free(sendreq);
}
server->qtail = NULL;

/* Reset any existing input buffer. */
if (server->tcp_buffer)
free(server->tcp_buffer);
ares_free(server->tcp_buffer);
server->tcp_buffer = NULL;
server->tcp_lenbuf_pos = 0;

Expand Down
30 changes: 15 additions & 15 deletions deps/cares/src/ares__get_hostent.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
p++;
if (!*p)
/* Ignore line if reached end of line. */
continue;
continue; /* LCOV_EXCL_LINE: trailing whitespace already stripped */

/* Pointer to start of host name. */
txthost = p;
Expand Down Expand Up @@ -164,7 +164,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
*/

/* Allocate memory for the hostent structure. */
hostent = malloc(sizeof(struct hostent));
hostent = ares_malloc(sizeof(struct hostent));
if (!hostent)
break;

Expand All @@ -173,16 +173,16 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
hostent->h_addr_list = NULL;

/* Copy official host name. */
hostent->h_name = strdup(txthost);
hostent->h_name = ares_strdup(txthost);
if (!hostent->h_name)
break;

/* Copy network address. */
hostent->h_addr_list = malloc(2 * sizeof(char *));
hostent->h_addr_list = ares_malloc(2 * sizeof(char *));
if (!hostent->h_addr_list)
break;
hostent->h_addr_list[1] = NULL;
hostent->h_addr_list[0] = malloc(addrlen);
hostent->h_addr_list[0] = ares_malloc(addrlen);
if (!hostent->h_addr_list[0])
break;
if (addr.family == AF_INET)
Expand All @@ -191,7 +191,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
memcpy(hostent->h_addr_list[0], &addr.addrV6, sizeof(addr.addrV6));

/* Copy aliases. */
hostent->h_aliases = malloc((naliases + 1) * sizeof(char *));
hostent->h_aliases = ares_malloc((naliases + 1) * sizeof(char *));
if (!hostent->h_aliases)
break;
alias = hostent->h_aliases;
Expand All @@ -207,7 +207,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
while (*q && ISSPACE(*q))
q++;
*p = '\0';
if ((*alias = strdup(txtalias)) == NULL)
if ((*alias = ares_strdup(txtalias)) == NULL)
break;
alias++;
txtalias = *q ? q : NULL;
Expand All @@ -221,7 +221,7 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)
hostent->h_length = aresx_uztoss(addrlen);

/* Free line buffer. */
free(line);
ares_free(line);

/* Return hostent successfully */
*host = hostent;
Expand All @@ -231,28 +231,28 @@ int ares__get_hostent(FILE *fp, int family, struct hostent **host)

/* If allocated, free line buffer. */
if (line)
free(line);
ares_free(line);

if (status == ARES_SUCCESS)
{
/* Memory allocation failure; clean up. */
if (hostent)
{
if (hostent->h_name)
free((char *) hostent->h_name);
ares_free((char *) hostent->h_name);
if (hostent->h_aliases)
{
for (alias = hostent->h_aliases; *alias; alias++)
free(*alias);
free(hostent->h_aliases);
ares_free(*alias);
ares_free(hostent->h_aliases);
}
if (hostent->h_addr_list)
{
if (hostent->h_addr_list[0])
free(hostent->h_addr_list[0]);
free(hostent->h_addr_list);
ares_free(hostent->h_addr_list[0]);
ares_free(hostent->h_addr_list);
}
free(hostent);
ares_free(hostent);
}
return ARES_ENOMEM;
}
Expand Down
7 changes: 4 additions & 3 deletions deps/cares/src/ares__read_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)

if (*buf == NULL)
{
*buf = malloc(128);
*buf = ares_malloc(128);
if (!*buf)
return ARES_ENOMEM;
*bufsize = 128;
Expand All @@ -59,10 +59,11 @@ int ares__read_line(FILE *fp, char **buf, size_t *bufsize)
continue;

/* Allocate more space. */
newbuf = realloc(*buf, *bufsize * 2);
newbuf = ares_realloc(*buf, *bufsize * 2);
if (!newbuf)
{
free(*buf);
ares_free(*buf);
*buf = NULL;
return ARES_ENOMEM;
}
*buf = newbuf;
Expand Down
2 changes: 1 addition & 1 deletion deps/cares/src/ares__timeval.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct timeval ares__tvnow(void)
*/
#ifdef HAVE_GETTIMEOFDAY
else
(void)gettimeofday(&now, NULL);
(void)gettimeofday(&now, NULL); /* LCOV_EXCL_LINE */
#else
else {
now.tv_sec = (long)time(NULL);
Expand Down
2 changes: 1 addition & 1 deletion deps/cares/src/ares_create_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int ares_create_query(const char *name, int dnsclass, int type,
return ARES_EBADNAME;

*buflen = len + HFIXEDSZ + QFIXEDSZ + (max_udp_size ? EDNSFIXEDSZ : 0);
*buf = malloc(*buflen);
*buf = ares_malloc(*buflen);
if (!*buf)
return ARES_ENOMEM;

Expand Down
Loading

0 comments on commit f1a0827

Please sign in to comment.