Line | Count | Source |
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 | | #include "curl_setup.h" |
25 | | |
26 | | #include "urldata.h" |
27 | | #include "curl_trc.h" |
28 | | #include "strerror.h" |
29 | | #include "cfilters.h" |
30 | | #include "connect.h" |
31 | | #include "cf-https-connect.h" |
32 | | #include "cf-setup.h" |
33 | | #include "multiif.h" |
34 | | #include "progress.h" |
35 | | #include "conncache.h" |
36 | | #include "multihandle.h" |
37 | | #include "select.h" |
38 | | #include "vdns/cf-dns.h" |
39 | | #include "curlx/strparse.h" |
40 | | |
41 | | static struct Curl_peer *cfchain_get_destination(struct Curl_cfchain *chain) |
42 | 0 | { |
43 | 0 | struct connectdata *conn = chain->conn; |
44 | 0 | return chain->primary ? |
45 | 0 | (conn->via_peer ? conn->via_peer : conn->origin) : |
46 | 0 | (conn->via_peer2 ? conn->via_peer2 : conn->origin2); |
47 | 0 | } |
48 | | |
49 | | struct Curl_peer *Curl_cf_get_destination(struct Curl_cfilter *cf) |
50 | 0 | { |
51 | 0 | return cfchain_get_destination(cf->chain); |
52 | 0 | } |
53 | | |
54 | | static struct Curl_peer *cfchain_get_first_peer(struct Curl_cfchain *chain) |
55 | 4.68k | { |
56 | 4.68k | struct connectdata *conn = chain->conn; |
57 | 4.68k | #ifndef CURL_DISABLE_PROXY |
58 | 4.68k | if(conn->socks_proxy.peer) |
59 | 0 | return conn->socks_proxy.peer; |
60 | 4.68k | if(conn->http_proxy.peer) |
61 | 0 | return conn->http_proxy.peer; |
62 | 4.68k | #endif |
63 | 4.68k | return !chain->primary ? |
64 | 0 | (conn->via_peer2 ? conn->via_peer2 : conn->origin2) : |
65 | 4.68k | (conn->via_peer ? conn->via_peer : conn->origin); |
66 | 4.68k | } |
67 | | |
68 | | struct Curl_peer *Curl_cf_get_first_peer(struct Curl_cfilter *cf) |
69 | 2.26k | { |
70 | 2.26k | return cfchain_get_first_peer(cf->chain); |
71 | 2.26k | } |
72 | | |
73 | | struct Curl_peer *Curl_cfchain_get_via_peer(struct Curl_cfchain *chain) |
74 | 0 | { |
75 | 0 | struct connectdata *conn = chain->conn; |
76 | 0 | return chain->primary ? conn->via_peer : conn->via_peer2; |
77 | 0 | } |
78 | | |
79 | | #if !defined(CURL_DISABLE_ALTSVC) || defined(USE_HTTPSRR) |
80 | | |
81 | | enum alpnid Curl_alpn2alpnid(const unsigned char *name, size_t len) |
82 | 0 | { |
83 | 0 | if(len == 2) { |
84 | 0 | if(!memcmp(name, "h1", 2)) |
85 | 0 | return ALPN_h1; |
86 | 0 | if(!memcmp(name, "h2", 2)) |
87 | 0 | return ALPN_h2; |
88 | 0 | if(!memcmp(name, "h3", 2)) |
89 | 0 | return ALPN_h3; |
90 | 0 | } |
91 | 0 | else if(len == 8 && !memcmp(name, "http/1.1", 8)) |
92 | 0 | return ALPN_h1; |
93 | 0 | return ALPN_none; /* unknown, probably rubbish input */ |
94 | 0 | } |
95 | | |
96 | | #endif |
97 | | |
98 | | /* Milliseconds left of the connect timeout. */ |
99 | | static timediff_t connect_left_ms(struct Curl_easy *data, |
100 | | const struct curltime *pnow) |
101 | 0 | { |
102 | 0 | timediff_t timeout_ms = (data->set.connecttimeout > 0) ? |
103 | 0 | data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT; |
104 | 0 | timediff_t elapsed_ms = |
105 | 0 | curlx_ptimediff_ms(pnow, &data->conn->created) - |
106 | 0 | data->conn->connect_start_ms; |
107 | 0 | timediff_t left_ms = timeout_ms - elapsed_ms; |
108 | 0 | DEBUGASSERT(data->conn->connect_start_ms >= 0); |
109 | 0 | return left_ms ? left_ms : -1; /* 0 is "no limit", fake 1 ms expiry */ |
110 | 0 | } |
111 | | |
112 | | /* Common code for timeleft_now_ms() and Curl_timeleft_total_now_ms(): |
113 | | `with_connect` controls whether the connect timeout is considered. */ |
114 | | static timediff_t timeleft_now_ms_int(struct Curl_easy *data, |
115 | | const struct curltime *pnow, |
116 | | bool with_connect) |
117 | 38.0k | { |
118 | 38.0k | struct Curl_cfchain *chain = data->conn ? |
119 | 38.0k | &data->conn->chain : NULL; |
120 | 38.0k | timediff_t timeleft_ms = 0; |
121 | 38.0k | timediff_t ctimeleft_ms = 0; |
122 | | |
123 | 38.0k | if(chain && CURL_CFCHAIN_IN_SHUTDOWN(chain)) |
124 | 0 | return Curl_cshutdn_timeleft_ms(data, chain); |
125 | 38.0k | else if(with_connect && Curl_is_connecting(data)) { |
126 | | /* transfer has not reached DO phase yet */ |
127 | 11.0k | timediff_t ctimeout_ms = (data->set.connecttimeout > 0) ? |
128 | 11.0k | data->set.connecttimeout : DEFAULT_CONNECT_TIMEOUT; |
129 | 11.0k | ctimeleft_ms = ctimeout_ms - |
130 | 11.0k | Curl_pgrs_since_ms(data, pnow, TIMER_STARTSINGLE); |
131 | 11.0k | if(!ctimeleft_ms) |
132 | 0 | ctimeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */ |
133 | 11.0k | } |
134 | 27.0k | else if(with_connect && data->conn && data->conn->connect_start_ms >= 0) { |
135 | | /* ongoing connect of filters, pbly FTP second socket */ |
136 | 0 | ctimeleft_ms = connect_left_ms(data, pnow); |
137 | 0 | } |
138 | 27.0k | else if(!data->set.timeout || |
139 | 27.0k | (data->set.connect_only && !Curl_is_connecting(data))) { |
140 | | /* no timeout in place, or a CONNECT_ONLY transfer that is done |
141 | | connecting: return "no limit" */ |
142 | 27.0k | return 0; |
143 | 27.0k | } |
144 | | |
145 | 11.0k | if(data->set.timeout) { |
146 | 0 | timeleft_ms = data->set.timeout - |
147 | 0 | Curl_pgrs_since_ms(data, pnow, TIMER_STARTOP); |
148 | 0 | if(!timeleft_ms) |
149 | 0 | timeleft_ms = -1; /* 0 is "no limit", fake 1 ms expiry */ |
150 | 0 | } |
151 | | |
152 | 11.0k | if(!ctimeleft_ms) |
153 | 0 | return timeleft_ms; |
154 | 11.0k | else if(!timeleft_ms) |
155 | 11.0k | return ctimeleft_ms; |
156 | 0 | return CURLMIN(ctimeleft_ms, timeleft_ms); |
157 | 11.0k | } |
158 | | |
159 | | /* |
160 | | * timeleft_now_ms() returns the amount of milliseconds left allowed for the |
161 | | * transfer/connection. If the value is 0, there is no timeout (ie there is |
162 | | * infinite time left). If the value is negative, the timeout time has already |
163 | | * elapsed. |
164 | | * |
165 | | * @unittest 1303 |
166 | | */ |
167 | | UNITTEST timediff_t timeleft_now_ms(struct Curl_easy *data, |
168 | | const struct curltime *pnow); |
169 | | UNITTEST timediff_t timeleft_now_ms(struct Curl_easy *data, |
170 | | const struct curltime *pnow) |
171 | 21.4k | { |
172 | 21.4k | return timeleft_now_ms_int(data, pnow, TRUE); |
173 | 21.4k | } |
174 | | |
175 | | timediff_t Curl_timeleft_ms(struct Curl_easy *data) |
176 | 12.9k | { |
177 | 12.9k | return timeleft_now_ms(data, Curl_pgrs_now(data)); |
178 | 12.9k | } |
179 | | |
180 | | /* Like Curl_timeleft_now_ms() but without the connect timeout: only the |
181 | | overall timeout is considered. */ |
182 | | timediff_t Curl_timeleft_total_now_ms(struct Curl_easy *data, |
183 | | const struct curltime *pnow) |
184 | 16.5k | { |
185 | 16.5k | return timeleft_now_ms_int(data, pnow, FALSE); |
186 | 16.5k | } |
187 | | |
188 | | timediff_t Curl_timeleft_now_ms(struct Curl_easy *data, |
189 | | const struct curltime *pnow) |
190 | 8.56k | { |
191 | 8.56k | return timeleft_now_ms(data, pnow); |
192 | 8.56k | } |
193 | | |
194 | | /* |
195 | | * Used to extract socket and connectdata struct for the most recent |
196 | | * transfer on the given Curl_easy. |
197 | | * |
198 | | * The returned socket will be CURL_SOCKET_BAD in case of failure! |
199 | | */ |
200 | | curl_socket_t Curl_getconnectinfo(struct Curl_easy *data, |
201 | | struct connectdata **connp) |
202 | 2.94k | { |
203 | | /* this works for an easy handle: |
204 | | * - that has been used for curl_easy_perform() |
205 | | * - that is associated with a multi handle, and whose connection |
206 | | * was detached with CURLOPT_CONNECT_ONLY |
207 | | */ |
208 | 2.94k | struct connectdata *conn = Curl_cpool_get_last_conn(data); |
209 | 2.94k | if(connp) |
210 | 0 | *connp = conn; |
211 | 2.94k | return conn ? conn->chain.sock : CURL_SOCKET_BAD; |
212 | 2.94k | } |
213 | | |
214 | | void Curl_conncontrol(struct connectdata *conn, int ctrl) |
215 | 2.46k | { |
216 | 2.46k | if(!conn) { |
217 | 0 | DEBUGASSERT(0); |
218 | 0 | return; |
219 | 0 | } |
220 | 2.46k | switch(ctrl) { |
221 | 0 | case CONNCTRL_CONN_KEEP: |
222 | 0 | conn->bits.close = FALSE; |
223 | 0 | break; |
224 | 2.41k | case CONNCTRL_CONN_CLOSE: |
225 | 2.41k | conn->bits.close = TRUE; |
226 | 2.41k | break; |
227 | 53 | case CONNCTRL_STREAM_CLOSE: |
228 | | /* stream close when multiplexing does not affect connection */ |
229 | 53 | if(!Curl_conn_is_multiplex(conn)) |
230 | 53 | conn->bits.close = TRUE; |
231 | 53 | break; |
232 | 0 | default: |
233 | 0 | DEBUGASSERT(0); |
234 | 0 | break; |
235 | 2.46k | } |
236 | 2.46k | } |
237 | | |
238 | | CURLcode Curl_conn_setup(struct Curl_easy *data, |
239 | | struct connectdata *conn, |
240 | | struct Curl_cfchain *chain, |
241 | | int ssl_mode) |
242 | 2.42k | { |
243 | 2.42k | struct Curl_peer *first_peer = cfchain_get_first_peer(chain); |
244 | 2.42k | CURLcode result = CURLE_OK; |
245 | 2.42k | uint8_t dns_queries; |
246 | | |
247 | 2.42k | DEBUGASSERT(data); |
248 | 2.42k | DEBUGASSERT(conn->scheme); |
249 | 2.42k | DEBUGASSERT(!chain->cf); |
250 | | |
251 | 2.42k | if(!first_peer) |
252 | 0 | return CURLE_FAILED_INIT; |
253 | | |
254 | 2.42k | #ifndef CURL_DISABLE_HTTP |
255 | 2.42k | if(!chain->cf && |
256 | 2.42k | conn->scheme->protocol == CURLPROTO_HTTPS) { |
257 | 0 | DEBUGASSERT(ssl_mode != CURL_CF_SSL_DISABLE); |
258 | 0 | result = Curl_cf_https_setup( |
259 | 0 | data, cfchain_get_destination(chain), chain); |
260 | 0 | if(result) |
261 | 0 | goto out; |
262 | 0 | } |
263 | 2.42k | #endif /* !CURL_DISABLE_HTTP */ |
264 | | |
265 | | /* Still no cfilter set, apply default. */ |
266 | 2.42k | if(!chain->cf) { |
267 | 2.42k | result = Curl_cf_setup_add(chain, data, conn->transport_wanted, ssl_mode); |
268 | 2.42k | if(result) |
269 | 8 | goto out; |
270 | 2.42k | } |
271 | | |
272 | 2.41k | DEBUGASSERT(chain->cf); |
273 | | /* Whatever the filter chain will be in the end, it will need the |
274 | | * resolving of `first_peer`. Add that now so the resolve is started |
275 | | * right away. */ |
276 | 2.41k | dns_queries = Curl_resolv_dns_queries(data, conn->ip_version); |
277 | 2.41k | result = Curl_dns_cf_add_addr_resolve(data, chain->cf, |
278 | 2.41k | first_peer, dns_queries, |
279 | 2.41k | conn->transport_wanted); |
280 | 2.41k | if(result) |
281 | 2 | goto out; |
282 | | |
283 | 2.42k | out: |
284 | 2.42k | return result; |
285 | 2.41k | } |
286 | | |
287 | | #ifdef CURLVERBOSE |
288 | | static CURLcode conn_connect_trace(struct Curl_easy *data, |
289 | | struct Curl_cfilter *cf) |
290 | 2.24k | { |
291 | 2.24k | if(Curl_trc_is_verbose(data)) { |
292 | 343 | struct ip_quadruple ipquad; |
293 | 343 | bool is_ipv6; |
294 | 343 | CURLcode result; |
295 | | |
296 | 343 | result = Curl_conn_cf_get_ip_info(cf, data, &is_ipv6, &ipquad); |
297 | 343 | if(result) |
298 | 0 | return result; |
299 | | |
300 | 343 | infof(data, "Established %sconnection to %s (%s port %u) from %s port %u ", |
301 | 343 | !CF_IS_PRIMARY(cf) ? "2nd " : "", |
302 | 343 | CURL_CONN_HOST_DISPNAME(data->conn), |
303 | 343 | ipquad.remote_ip, ipquad.remote_port, |
304 | 343 | ipquad.local_ip, ipquad.local_port); |
305 | 343 | } |
306 | 2.24k | return CURLE_OK; |
307 | 2.24k | } |
308 | | #endif |
309 | | |
310 | | /** |
311 | | * Update connection statistics |
312 | | */ |
313 | | static void conn_report_stats(struct Curl_easy *data, |
314 | | struct Curl_cfchain *chain) |
315 | 2.27k | { |
316 | | /* We only gather stats for the primary chain */ |
317 | 2.27k | if(chain->primary) |
318 | 2.27k | Curl_cfchain_cntrl_report_stats(data, chain); |
319 | 2.27k | } |
320 | | |
321 | | void Curl_cfchain_report_failed(struct Curl_easy *data, |
322 | | struct Curl_cfchain *chain) |
323 | 29 | { |
324 | 29 | if(!chain->primary) |
325 | 0 | return; |
326 | | /* Only filters connected at IP level have info to update. Filters |
327 | | * still racing for a connection, like happy eyeballing, pass it on |
328 | | * to a connected one only. */ |
329 | 29 | (void)Curl_conn_cf_cntrl(chain->cf, data, TRUE, |
330 | 29 | CF_CTRL_CONN_INFO_UPDATE, 0, NULL); |
331 | 29 | conn_report_stats(data, chain); |
332 | 29 | } |
333 | | |
334 | | CURLcode Curl_cfchain_connect(struct Curl_easy *data, |
335 | | struct Curl_cfchain *chain, |
336 | | bool blocking, |
337 | | bool *done) |
338 | 3.36k | { |
339 | 3.36k | #define CF_CONN_NUM_POLLS_ON_STACK 5 |
340 | 3.36k | struct pollfd a_few_on_stack[CF_CONN_NUM_POLLS_ON_STACK]; |
341 | 3.36k | struct easy_pollset ps; |
342 | 3.36k | struct curl_pollfds cpfds; |
343 | 3.36k | struct Curl_cfilter *cf; |
344 | 3.36k | CURLcode result = CURLE_OK; |
345 | | |
346 | 3.36k | DEBUGASSERT(data); |
347 | 3.36k | DEBUGASSERT(data->conn); |
348 | | |
349 | 3.36k | if(data->conn->scheme->flags & PROTOPT_NONETWORK) { |
350 | 0 | *done = TRUE; |
351 | 0 | return CURLE_OK; |
352 | 0 | } |
353 | | |
354 | 3.36k | cf = chain->cf; |
355 | 3.36k | if(!cf) { |
356 | 0 | *done = FALSE; |
357 | 0 | return CURLE_FAILED_INIT; |
358 | 0 | } |
359 | | |
360 | 3.36k | *done = (bool)cf->connected; |
361 | 3.36k | if(*done) |
362 | 0 | return CURLE_OK; |
363 | | |
364 | 3.36k | if(data->conn->connect_start_ms < 0) { |
365 | 2.41k | data->conn->connect_start_ms = |
366 | 2.41k | curlx_ptimediff_ms(Curl_pgrs_now(data), &data->conn->created); |
367 | 2.41k | } |
368 | | |
369 | 3.36k | Curl_pollset_init(&ps); |
370 | 3.36k | Curl_pollfds_init(&cpfds, a_few_on_stack, CF_CONN_NUM_POLLS_ON_STACK); |
371 | 3.36k | while(!*done) { |
372 | 3.36k | if(Curl_cfchain_needs_flush(data, chain)) { |
373 | 0 | DEBUGF(infof(data, "Curl_conn_connect(%s), flush", |
374 | 0 | chain->primary ? "" : "2nd")); |
375 | 0 | result = Curl_cfchain_flush(data, chain); |
376 | 0 | if(result && (result != CURLE_AGAIN)) |
377 | 0 | goto out; |
378 | 0 | } |
379 | | |
380 | 3.36k | result = cf->cft->do_connect(cf, data, done); |
381 | 3.36k | CURL_TRC_CF(data, cf, "Curl_conn_connect(block=%d) -> %d, done=%d", |
382 | 3.36k | blocking, (int)result, *done); |
383 | 3.36k | if(!result && *done) { |
384 | | /* A final sanity check on connection security */ |
385 | 2.24k | if((data->state.origin->scheme->flags & PROTOPT_SSL) && |
386 | 0 | chain->primary && !Curl_conn_is_ssl(data->conn)) { |
387 | 0 | DEBUGASSERT(0); |
388 | 0 | failf(data, "transfer requires SSL, but not connected via SSL"); |
389 | 0 | result = CURLE_FAILED_INIT; |
390 | 0 | goto out; |
391 | 0 | } |
392 | | /* Now that the complete filter chain is connected, let all filters |
393 | | * persist information at the connection. E.g. cf-socket sets the |
394 | | * socket and ip related information. */ |
395 | 2.24k | Curl_conn_cntrl_update_info(data, data->conn); |
396 | 2.24k | conn_report_stats(data, chain); |
397 | 2.24k | Curl_cpool_conn_was_used(data, data->conn, Curl_pgrs_now(data)); |
398 | 2.24k | VERBOSE(result = conn_connect_trace(data, cf)); |
399 | 2.24k | VERBOSE(Curl_cfchain_trc(data, NULL, chain, "connected")); |
400 | 2.24k | Curl_cfchain_remove_setup_filters(data, chain); |
401 | 2.24k | VERBOSE(Curl_cfchain_trc(data, NULL, chain, "reduced to")); |
402 | 2.24k | data->conn->connect_start_ms = -1; |
403 | 2.24k | goto out; |
404 | 2.24k | } |
405 | 1.11k | else if(result) { |
406 | 29 | CURL_TRC_CF(data, cf, "Curl_conn_connect(), filter returned %d", |
407 | 29 | (int)result); |
408 | 29 | VERBOSE(Curl_cfchain_trc(data, NULL, chain, "failed to connect")); |
409 | 29 | Curl_cfchain_report_failed(data, chain); |
410 | 29 | goto out; |
411 | 29 | } |
412 | | |
413 | 1.08k | if(!blocking) |
414 | 1.08k | goto out; |
415 | 0 | else { |
416 | | /* check allowed time left */ |
417 | 0 | const struct curltime *pnow = Curl_pgrs_now(data); |
418 | 0 | timediff_t timeout_ms = Curl_timeleft_now_ms(data, pnow); |
419 | 0 | curl_socket_t sockfd = cf->chain->sock; |
420 | 0 | int rc; |
421 | |
|
422 | 0 | if(timeout_ms < 0) { |
423 | | /* no need to continue if time already is up */ |
424 | 0 | failf(data, "connect timeout"); |
425 | 0 | result = CURLE_OPERATION_TIMEDOUT; |
426 | 0 | goto out; |
427 | 0 | } |
428 | | |
429 | 0 | CURL_TRC_CF(data, cf, "Curl_conn_connect(block=1), do poll"); |
430 | 0 | Curl_pollset_reset(&ps); |
431 | 0 | Curl_pollfds_reset(&cpfds); |
432 | | /* In general, we want to send after connect, wait on that. */ |
433 | 0 | if(sockfd != CURL_SOCKET_BAD) |
434 | 0 | result = Curl_pollset_set_out_only(data, &ps, sockfd); |
435 | 0 | if(!result) |
436 | 0 | result = Curl_conn_adjust_pollset(data, data->conn, &ps); |
437 | 0 | if(result) |
438 | 0 | goto out; |
439 | 0 | result = Curl_pollfds_add_ps(&cpfds, &ps); |
440 | 0 | if(result) |
441 | 0 | goto out; |
442 | | |
443 | 0 | rc = Curl_poll(cpfds.pfds, cpfds.n, |
444 | 0 | CURLMIN(timeout_ms ? timeout_ms : 1000, |
445 | 0 | (cpfds.n ? 1000 : 10))); |
446 | 0 | CURL_TRC_CF(data, cf, "Curl_conn_connect(block=1), Curl_poll() -> %d", |
447 | 0 | rc); |
448 | 0 | if(rc < 0) { |
449 | 0 | result = CURLE_COULDNT_CONNECT; |
450 | 0 | goto out; |
451 | 0 | } |
452 | | /* continue iterating */ |
453 | 0 | } |
454 | 1.08k | } |
455 | | |
456 | 3.36k | out: |
457 | 3.36k | Curl_pollset_cleanup(&ps); |
458 | 3.36k | Curl_pollfds_cleanup(&cpfds); |
459 | 3.36k | return result; |
460 | 3.36k | } |
461 | | |
462 | | CURLcode Curl_conn_connect(struct Curl_easy *data, |
463 | | bool blocking, |
464 | | bool *done) |
465 | 3.36k | { |
466 | 3.36k | return Curl_cfchain_connect(data, &data->conn->chain, |
467 | 3.36k | blocking, done); |
468 | 3.36k | } |
469 | | |
470 | | void Curl_conn_set_multiplex(struct Curl_cfchain *chain, uint8_t http_version) |
471 | 0 | { |
472 | 0 | if(chain->primary) { |
473 | 0 | chain->conn->httpversion_seen = http_version; |
474 | 0 | if(!chain->conn->bits.multiplex) { |
475 | 0 | chain->conn->bits.multiplex = TRUE; |
476 | 0 | if(chain->conn->attached_multi) { |
477 | 0 | Curl_multi_connchanged(chain->conn->attached_multi); |
478 | 0 | } |
479 | 0 | } |
480 | 0 | } |
481 | 0 | } |
482 | | |
483 | | struct Curl_peer *Curl_conn_get_origin(struct connectdata *conn) |
484 | 0 | { |
485 | 0 | return conn->origin; |
486 | 0 | } |
487 | | |
488 | | struct Curl_peer *Curl_conn_get_destination(struct connectdata *conn) |
489 | 2.44k | { |
490 | 2.44k | return conn->via_peer ? conn->via_peer : conn->origin; |
491 | 2.44k | } |
492 | | |
493 | | struct Curl_peer *Curl_conn_get_first_peer(struct connectdata *conn) |
494 | 4.86k | { |
495 | 4.86k | #ifndef CURL_DISABLE_PROXY |
496 | 4.86k | if(conn->socks_proxy.peer) |
497 | 0 | return conn->socks_proxy.peer; |
498 | 4.86k | if(conn->http_proxy.peer) |
499 | 0 | return conn->http_proxy.peer; |
500 | 4.86k | #endif |
501 | 4.86k | return conn->via_peer ? conn->via_peer : conn->origin; |
502 | 4.86k | } |
503 | | |
504 | | struct Curl_peer *Curl_cf_get_origin(struct Curl_cfilter *cf) |
505 | 0 | { |
506 | 0 | struct connectdata *conn = CF_CONN(cf); |
507 | 0 | return CF_IS_PRIMARY(cf) ? conn->origin : conn->origin2; |
508 | 0 | } |