aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/c-ares/ares_options.c
diff options
context:
space:
mode:
authorsnermolaev <snermolaev@yandex-team.ru>2022-02-10 16:45:53 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:53 +0300
commit2015790ac9fcc04caab83fccc23ab2460310a797 (patch)
treee644e9bc3f6f688561a871793b59bf8a637e0f72 /contrib/libs/c-ares/ares_options.c
parentc768a99151e47c3a4bb7b92c514d256abd301c4d (diff)
downloadydb-2015790ac9fcc04caab83fccc23ab2460310a797.tar.gz
Restoring authorship annotation for <snermolaev@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/c-ares/ares_options.c')
-rw-r--r--contrib/libs/c-ares/ares_options.c286
1 files changed, 143 insertions, 143 deletions
diff --git a/contrib/libs/c-ares/ares_options.c b/contrib/libs/c-ares/ares_options.c
index de49de4625..4907d3f76d 100644
--- a/contrib/libs/c-ares/ares_options.c
+++ b/contrib/libs/c-ares/ares_options.c
@@ -83,63 +83,63 @@ int ares_get_servers(ares_channel channel,
return status;
}
-int ares_get_servers_ports(ares_channel channel,
- struct ares_addr_port_node **servers)
-{
- struct ares_addr_port_node *srvr_head = NULL;
- struct ares_addr_port_node *srvr_last = NULL;
- struct ares_addr_port_node *srvr_curr;
- int status = ARES_SUCCESS;
- int i;
-
- if (!channel)
- return ARES_ENODATA;
-
- for (i = 0; i < channel->nservers; i++)
- {
- /* Allocate storage for this server node appending it to the list */
- srvr_curr = ares_malloc_data(ARES_DATATYPE_ADDR_PORT_NODE);
- if (!srvr_curr)
- {
- status = ARES_ENOMEM;
- break;
- }
- if (srvr_last)
- {
- srvr_last->next = srvr_curr;
- }
- else
- {
- srvr_head = srvr_curr;
- }
- srvr_last = srvr_curr;
-
- /* Fill this server node data */
- srvr_curr->family = channel->servers[i].addr.family;
- srvr_curr->udp_port = ntohs((unsigned short)channel->servers[i].addr.udp_port);
- srvr_curr->tcp_port = ntohs((unsigned short)channel->servers[i].addr.tcp_port);
- if (srvr_curr->family == AF_INET)
- memcpy(&srvr_curr->addrV4, &channel->servers[i].addr.addrV4,
- sizeof(srvr_curr->addrV4));
- else
- memcpy(&srvr_curr->addrV6, &channel->servers[i].addr.addrV6,
- sizeof(srvr_curr->addrV6));
- }
-
- if (status != ARES_SUCCESS)
- {
- if (srvr_head)
- {
- ares_free_data(srvr_head);
- srvr_head = NULL;
- }
- }
-
- *servers = srvr_head;
-
- return status;
-}
-
+int ares_get_servers_ports(ares_channel channel,
+ struct ares_addr_port_node **servers)
+{
+ struct ares_addr_port_node *srvr_head = NULL;
+ struct ares_addr_port_node *srvr_last = NULL;
+ struct ares_addr_port_node *srvr_curr;
+ int status = ARES_SUCCESS;
+ int i;
+
+ if (!channel)
+ return ARES_ENODATA;
+
+ for (i = 0; i < channel->nservers; i++)
+ {
+ /* Allocate storage for this server node appending it to the list */
+ srvr_curr = ares_malloc_data(ARES_DATATYPE_ADDR_PORT_NODE);
+ if (!srvr_curr)
+ {
+ status = ARES_ENOMEM;
+ break;
+ }
+ if (srvr_last)
+ {
+ srvr_last->next = srvr_curr;
+ }
+ else
+ {
+ srvr_head = srvr_curr;
+ }
+ srvr_last = srvr_curr;
+
+ /* Fill this server node data */
+ srvr_curr->family = channel->servers[i].addr.family;
+ srvr_curr->udp_port = ntohs((unsigned short)channel->servers[i].addr.udp_port);
+ srvr_curr->tcp_port = ntohs((unsigned short)channel->servers[i].addr.tcp_port);
+ if (srvr_curr->family == AF_INET)
+ memcpy(&srvr_curr->addrV4, &channel->servers[i].addr.addrV4,
+ sizeof(srvr_curr->addrV4));
+ else
+ memcpy(&srvr_curr->addrV6, &channel->servers[i].addr.addrV6,
+ sizeof(srvr_curr->addrV6));
+ }
+
+ if (status != ARES_SUCCESS)
+ {
+ if (srvr_head)
+ {
+ ares_free_data(srvr_head);
+ srvr_head = NULL;
+ }
+ }
+
+ *servers = srvr_head;
+
+ return status;
+}
+
int ares_set_servers(ares_channel channel,
struct ares_addr_node *servers)
{
@@ -148,7 +148,7 @@ int ares_set_servers(ares_channel channel,
int i;
if (ares_library_initialized() != ARES_SUCCESS)
- return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
+ return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
if (!channel)
return ARES_ENODATA;
@@ -166,7 +166,7 @@ int ares_set_servers(ares_channel channel,
if (num_srvrs > 0)
{
/* Allocate storage for servers state */
- channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
+ channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
if (!channel->servers)
{
return ARES_ENOMEM;
@@ -176,8 +176,8 @@ int ares_set_servers(ares_channel channel,
for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
{
channel->servers[i].addr.family = srvr->family;
- channel->servers[i].addr.udp_port = 0;
- channel->servers[i].addr.tcp_port = 0;
+ channel->servers[i].addr.udp_port = 0;
+ channel->servers[i].addr.tcp_port = 0;
if (srvr->family == AF_INET)
memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4,
sizeof(srvr->addrV4));
@@ -192,62 +192,62 @@ int ares_set_servers(ares_channel channel,
return ARES_SUCCESS;
}
-int ares_set_servers_ports(ares_channel channel,
- struct ares_addr_port_node *servers)
-{
- struct ares_addr_port_node *srvr;
- int num_srvrs = 0;
- int i;
-
- if (ares_library_initialized() != ARES_SUCCESS)
- return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
-
- if (!channel)
- return ARES_ENODATA;
-
+int ares_set_servers_ports(ares_channel channel,
+ struct ares_addr_port_node *servers)
+{
+ struct ares_addr_port_node *srvr;
+ int num_srvrs = 0;
+ int i;
+
+ if (ares_library_initialized() != ARES_SUCCESS)
+ return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
+
+ if (!channel)
+ return ARES_ENODATA;
+
if (!ares__is_list_empty(&channel->all_queries))
return ARES_ENOTIMP;
- ares__destroy_servers_state(channel);
-
- for (srvr = servers; srvr; srvr = srvr->next)
- {
- num_srvrs++;
- }
-
- if (num_srvrs > 0)
- {
- /* Allocate storage for servers state */
- channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
- if (!channel->servers)
- {
- return ARES_ENOMEM;
- }
- channel->nservers = num_srvrs;
- /* Fill servers state address data */
- for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
- {
- channel->servers[i].addr.family = srvr->family;
- channel->servers[i].addr.udp_port = htons((unsigned short)srvr->udp_port);
- channel->servers[i].addr.tcp_port = htons((unsigned short)srvr->tcp_port);
- if (srvr->family == AF_INET)
- memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4,
- sizeof(srvr->addrV4));
- else
- memcpy(&channel->servers[i].addr.addrV6, &srvr->addrV6,
- sizeof(srvr->addrV6));
- }
- /* Initialize servers state remaining data */
- ares__init_servers_state(channel);
- }
-
- return ARES_SUCCESS;
-}
-
+ ares__destroy_servers_state(channel);
+
+ for (srvr = servers; srvr; srvr = srvr->next)
+ {
+ num_srvrs++;
+ }
+
+ if (num_srvrs > 0)
+ {
+ /* Allocate storage for servers state */
+ channel->servers = ares_malloc(num_srvrs * sizeof(struct server_state));
+ if (!channel->servers)
+ {
+ return ARES_ENOMEM;
+ }
+ channel->nservers = num_srvrs;
+ /* Fill servers state address data */
+ for (i = 0, srvr = servers; srvr; i++, srvr = srvr->next)
+ {
+ channel->servers[i].addr.family = srvr->family;
+ channel->servers[i].addr.udp_port = htons((unsigned short)srvr->udp_port);
+ channel->servers[i].addr.tcp_port = htons((unsigned short)srvr->tcp_port);
+ if (srvr->family == AF_INET)
+ memcpy(&channel->servers[i].addr.addrV4, &srvr->addrV4,
+ sizeof(srvr->addrV4));
+ else
+ memcpy(&channel->servers[i].addr.addrV6, &srvr->addrV6,
+ sizeof(srvr->addrV6));
+ }
+ /* Initialize servers state remaining data */
+ ares__init_servers_state(channel);
+ }
+
+ return ARES_SUCCESS;
+}
+
/* Incomming string format: host[:port][,host[:port]]... */
/* IPv6 addresses with ports require square brackets [fe80::1%lo0]:53 */
-static int set_servers_csv(ares_channel channel,
- const char* _csv, int use_port)
+static int set_servers_csv(ares_channel channel,
+ const char* _csv, int use_port)
{
size_t i;
char* csv = NULL;
@@ -255,11 +255,11 @@ static int set_servers_csv(ares_channel channel,
char* start_host;
int cc = 0;
int rv = ARES_SUCCESS;
- struct ares_addr_port_node *servers = NULL;
- struct ares_addr_port_node *last = NULL;
+ struct ares_addr_port_node *servers = NULL;
+ struct ares_addr_port_node *last = NULL;
if (ares_library_initialized() != ARES_SUCCESS)
- return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
+ return ARES_ENOTINITIALIZED; /* LCOV_EXCL_LINE: n/a on non-WinSock */
if (!channel)
return ARES_ENODATA;
@@ -268,10 +268,10 @@ static int set_servers_csv(ares_channel channel,
if (i == 0)
return ARES_SUCCESS; /* blank all servers */
- csv = ares_malloc(i + 2);
- if (!csv)
- return ARES_ENOMEM;
-
+ csv = ares_malloc(i + 2);
+ if (!csv)
+ return ARES_ENOMEM;
+
strcpy(csv, _csv);
if (csv[i-1] != ',') { /* make parsing easier by ensuring ending ',' */
csv[i] = ',';
@@ -293,10 +293,10 @@ static int set_servers_csv(ares_channel channel,
else if (*ptr == ',') {
char* pp = ptr - 1;
char* p = ptr;
- int port = 0;
+ int port = 0;
struct in_addr in4;
struct ares_in6_addr in6;
- struct ares_addr_port_node *s = NULL;
+ struct ares_addr_port_node *s = NULL;
*ptr = 0; /* null terminate host:port string */
/* Got an entry..see if the port was specified. */
@@ -325,7 +325,7 @@ static int set_servers_csv(ares_channel channel,
if (*pp == ']')
p++; /* move p before ':' */
/* p will point to the start of the port */
- port = (int)strtol(p, NULL, 10);
+ port = (int)strtol(p, NULL, 10);
*pp = 0; /* null terminate host */
}
}
@@ -339,7 +339,7 @@ static int set_servers_csv(ares_channel channel,
goto out;
}
/* was ipv6, add new server */
- s = ares_malloc(sizeof(*s));
+ s = ares_malloc(sizeof(*s));
if (!s) {
rv = ARES_ENOMEM;
goto out;
@@ -349,7 +349,7 @@ static int set_servers_csv(ares_channel channel,
}
else {
/* was ipv4, add new server */
- s = ares_malloc(sizeof(*s));
+ s = ares_malloc(sizeof(*s));
if (!s) {
rv = ARES_ENOMEM;
goto out;
@@ -358,8 +358,8 @@ static int set_servers_csv(ares_channel channel,
memcpy(&s->addr, &in4, sizeof(struct in_addr));
}
if (s) {
- s->udp_port = use_port ? port: 0;
- s->tcp_port = s->udp_port;
+ s->udp_port = use_port ? port: 0;
+ s->tcp_port = s->udp_port;
s->next = NULL;
if (last) {
last->next = s;
@@ -378,29 +378,29 @@ static int set_servers_csv(ares_channel channel,
}
}
- rv = ares_set_servers_ports(channel, servers);
+ rv = ares_set_servers_ports(channel, servers);
out:
if (csv)
- ares_free(csv);
+ ares_free(csv);
while (servers) {
- struct ares_addr_port_node *s = servers;
+ struct ares_addr_port_node *s = servers;
servers = servers->next;
- ares_free(s);
+ ares_free(s);
}
return rv;
}
-
-int ares_set_servers_csv(ares_channel channel,
- const char* _csv)
-{
- return set_servers_csv(channel, _csv, FALSE);
-}
-
-int ares_set_servers_ports_csv(ares_channel channel,
- const char* _csv)
-{
- return set_servers_csv(channel, _csv, TRUE);
-}
-
+
+int ares_set_servers_csv(ares_channel channel,
+ const char* _csv)
+{
+ return set_servers_csv(channel, _csv, FALSE);
+}
+
+int ares_set_servers_ports_csv(ares_channel channel,
+ const char* _csv)
+{
+ return set_servers_csv(channel, _csv, TRUE);
+}
+