Line | Count | Source (jump to first uncovered line) |
1 | | /*************************************************************************** |
2 | | * _ _ ____ _ |
3 | | * Project ___| | | | _ \| | |
4 | | * / __| | | | |_) | | |
5 | | * | (__| |_| | _ <| |___ |
6 | | * \___|\___/|_| \_\_____| |
7 | | * |
8 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
9 | | * |
10 | | * This software is licensed as described in the file COPYING, which |
11 | | * you should have received as part of this distribution. The terms |
12 | | * are also available at https://curl.se/docs/copyright.html. |
13 | | * |
14 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
15 | | * copies of the Software, and permit persons to whom the Software is |
16 | | * furnished to do so, under the terms of the COPYING file. |
17 | | * |
18 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | | * KIND, either express or implied. |
20 | | * |
21 | | * SPDX-License-Identifier: curl |
22 | | * |
23 | | ***************************************************************************/ |
24 | | |
25 | | #include "curl_setup.h" |
26 | | |
27 | | /*********************************************************************** |
28 | | * Only for builds using asynchronous name resolves |
29 | | **********************************************************************/ |
30 | | #ifdef CURLRES_ASYNCH |
31 | | |
32 | | #ifdef HAVE_NETINET_IN_H |
33 | | #include <netinet/in.h> |
34 | | #endif |
35 | | #ifdef HAVE_NETDB_H |
36 | | #include <netdb.h> |
37 | | #endif |
38 | | #ifdef HAVE_ARPA_INET_H |
39 | | #include <arpa/inet.h> |
40 | | #endif |
41 | | #ifdef __VMS |
42 | | #include <in.h> |
43 | | #include <inet.h> |
44 | | #endif |
45 | | |
46 | | #include "urldata.h" |
47 | | #include "sendf.h" |
48 | | #include "hostip.h" |
49 | | #include "hash.h" |
50 | | #include "share.h" |
51 | | #include "url.h" |
52 | | #include "curl_memory.h" |
53 | | /* The last #include file should be: */ |
54 | | #include "memdebug.h" |
55 | | |
56 | | /* |
57 | | * Curl_addrinfo_callback() gets called by ares, gethostbyname_thread() |
58 | | * or getaddrinfo_thread() when we got the name resolved (or not!). |
59 | | * |
60 | | * If the status argument is CURL_ASYNC_SUCCESS, this function takes |
61 | | * ownership of the Curl_addrinfo passed, storing the resolved data |
62 | | * in the DNS cache. |
63 | | * |
64 | | * The storage operation locks and unlocks the DNS cache. |
65 | | */ |
66 | | CURLcode Curl_addrinfo_callback(struct Curl_easy *data, |
67 | | int status, |
68 | | struct Curl_addrinfo *ai) |
69 | 0 | { |
70 | 0 | struct connectdata *conn = data->conn; |
71 | 0 | struct Curl_dns_entry *dns = NULL; |
72 | 0 | CURLcode result = CURLE_OK; |
73 | |
|
74 | 0 | conn->resolve_async.status = status; |
75 | |
|
76 | 0 | if(CURL_ASYNC_SUCCESS == status) { |
77 | 0 | if(ai) { |
78 | 0 | if(data->share) |
79 | 0 | Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE); |
80 | |
|
81 | 0 | dns = Curl_cache_addr(data, ai, |
82 | 0 | conn->resolve_async.hostname, 0, |
83 | 0 | conn->resolve_async.port); |
84 | 0 | if(data->share) |
85 | 0 | Curl_share_unlock(data, CURL_LOCK_DATA_DNS); |
86 | |
|
87 | 0 | if(!dns) { |
88 | | /* failed to store, cleanup and return error */ |
89 | 0 | Curl_freeaddrinfo(ai); |
90 | 0 | result = CURLE_OUT_OF_MEMORY; |
91 | 0 | } |
92 | 0 | } |
93 | 0 | else { |
94 | 0 | result = CURLE_OUT_OF_MEMORY; |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | 0 | conn->resolve_async.dns = dns; |
99 | | |
100 | | /* Set async.done TRUE last in this function since it may be used multi- |
101 | | threaded and once this is TRUE the other thread may read fields from the |
102 | | async struct */ |
103 | 0 | conn->resolve_async.done = TRUE; |
104 | | |
105 | | /* IPv4: The input hostent struct will be freed by ares when we return from |
106 | | this function */ |
107 | 0 | return result; |
108 | 0 | } |
109 | | |
110 | | /* |
111 | | * Curl_getaddrinfo() is the generic low-level name resolve API within this |
112 | | * source file. There are several versions of this function - for different |
113 | | * name resolve layers (selected at build-time). They all take this same set |
114 | | * of arguments |
115 | | */ |
116 | | struct Curl_addrinfo *Curl_getaddrinfo(struct Curl_easy *data, |
117 | | const char *hostname, |
118 | | int port, |
119 | | int *waitp) |
120 | 0 | { |
121 | 0 | return Curl_resolver_getaddrinfo(data, hostname, port, waitp); |
122 | 0 | } |
123 | | |
124 | | #endif /* CURLRES_ASYNCH */ |