cmake/Utilities/cmcurl/lib/hostasyn.c

124 lines
3.8 KiB
C
Raw Normal View History

/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
2022-11-16 20:14:03 +01:00
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
2021-09-14 00:13:48 +02:00
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
2022-11-16 20:14:03 +01:00
* SPDX-License-Identifier: curl
*
***************************************************************************/
2015-04-27 22:25:09 +02:00
#include "curl_setup.h"
2018-04-23 21:13:27 +02:00
/***********************************************************************
* Only for builds using asynchronous name resolves
**********************************************************************/
#ifdef CURLRES_ASYNCH
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
2015-04-27 22:25:09 +02:00
#ifdef __VMS
#include <in.h>
#include <inet.h>
#endif
#include "urldata.h"
#include "sendf.h"
#include "hostip.h"
#include "hash.h"
#include "share.h"
#include "url.h"
2015-04-27 22:25:09 +02:00
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
/*
2015-04-27 22:25:09 +02:00
* Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
* or getaddrinfo_thread() when we got the name resolved (or not!).
*
2015-04-27 22:25:09 +02:00
* If the status argument is CURL_ASYNC_SUCCESS, this function takes
* ownership of the Curl_addrinfo passed, storing the resolved data
* in the DNS cache.
*
* The storage operation locks and unlocks the DNS cache.
*/
2021-09-14 00:13:48 +02:00
CURLcode Curl_addrinfo_callback(struct Curl_easy *data,
2015-04-27 22:25:09 +02:00
int status,
struct Curl_addrinfo *ai)
{
struct Curl_dns_entry *dns = NULL;
2015-11-17 17:22:37 +01:00
CURLcode result = CURLE_OK;
2021-09-14 00:13:48 +02:00
data->state.async.status = status;
if(CURL_ASYNC_SUCCESS == status) {
if(ai) {
if(data->share)
Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
dns = Curl_cache_addr(data, ai,
2021-09-14 00:13:48 +02:00
data->state.async.hostname,
data->state.async.port);
2019-11-11 23:01:05 +01:00
if(data->share)
Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
if(!dns) {
/* failed to store, cleanup and return error */
Curl_freeaddrinfo(ai);
2015-11-17 17:22:37 +01:00
result = CURLE_OUT_OF_MEMORY;
}
}
2015-04-27 22:25:09 +02:00
else {
2015-11-17 17:22:37 +01:00
result = CURLE_OUT_OF_MEMORY;
2015-04-27 22:25:09 +02:00
}
}
2021-09-14 00:13:48 +02:00
data->state.async.dns = dns;
/* Set async.done TRUE last in this function since it may be used multi-
threaded and once this is TRUE the other thread may read fields from the
async struct */
2021-09-14 00:13:48 +02:00
data->state.async.done = TRUE;
2015-11-17 17:22:37 +01:00
/* IPv4: The input hostent struct will be freed by ares when we return from
this function */
2015-11-17 17:22:37 +01:00
return result;
}
2015-04-27 22:25:09 +02:00
/*
* Curl_getaddrinfo() is the generic low-level name resolve API within this
* source file. There are several versions of this function - for different
* name resolve layers (selected at build-time). They all take this same set
* of arguments
*/
2021-09-14 00:13:48 +02:00
struct Curl_addrinfo *Curl_getaddrinfo(struct Curl_easy *data,
2020-08-30 11:54:41 +02:00
const char *hostname,
int port,
int *waitp)
{
2021-09-14 00:13:48 +02:00
return Curl_resolver_getaddrinfo(data, hostname, port, waitp);
}
2015-04-27 22:25:09 +02:00
#endif /* CURLRES_ASYNCH */