| 1 | /***************************************************************************
|
|---|
| 2 | * _ _ ____ _
|
|---|
| 3 | * Project ___| | | | _ \| |
|
|---|
| 4 | * / __| | | | |_) | |
|
|---|
| 5 | * | (__| |_| | _ <| |___
|
|---|
| 6 | * \___|\___/|_| \_\_____|
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright (C) 1998 - 2022, 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 | #include "urldata.h"
|
|---|
| 28 | #include "strerror.h"
|
|---|
| 29 | #include "cfilters.h"
|
|---|
| 30 | #include "connect.h"
|
|---|
| 31 | #include "url.h" /* for Curl_safefree() */
|
|---|
| 32 | #include "sendf.h"
|
|---|
| 33 | #include "sockaddr.h" /* required for Curl_sockaddr_storage */
|
|---|
| 34 | #include "multiif.h"
|
|---|
| 35 | #include "progress.h"
|
|---|
| 36 | #include "warnless.h"
|
|---|
| 37 | #include "http_proxy.h"
|
|---|
| 38 | #include "socks.h"
|
|---|
| 39 | #include "vtls/vtls.h"
|
|---|
| 40 |
|
|---|
| 41 | /* The last 3 #include files should be in this order */
|
|---|
| 42 | #include "curl_printf.h"
|
|---|
| 43 | #include "curl_memory.h"
|
|---|
| 44 | #include "memdebug.h"
|
|---|
| 45 |
|
|---|
| 46 | #ifndef ARRAYSIZE
|
|---|
| 47 | #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
|---|
| 48 | #endif
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 | void Curl_cf_def_destroy_this(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|---|
| 52 | {
|
|---|
| 53 | (void)cf;
|
|---|
| 54 | (void)data;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | CURLcode Curl_cf_def_setup(struct Curl_cfilter *cf,
|
|---|
| 58 | struct Curl_easy *data,
|
|---|
| 59 | const struct Curl_dns_entry *remotehost)
|
|---|
| 60 | {
|
|---|
| 61 | DEBUGASSERT(cf->next);
|
|---|
| 62 | return cf->next->cft->setup(cf->next, data, remotehost);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | void Curl_cf_def_attach_data(struct Curl_cfilter *cf,
|
|---|
| 66 | struct Curl_easy *data)
|
|---|
| 67 | {
|
|---|
| 68 | (void)cf;
|
|---|
| 69 | (void)data;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void Curl_cf_def_detach_data(struct Curl_cfilter *cf,
|
|---|
| 73 | struct Curl_easy *data)
|
|---|
| 74 | {
|
|---|
| 75 | (void)cf;
|
|---|
| 76 | (void)data;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void Curl_cf_def_close(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|---|
| 80 | {
|
|---|
| 81 | DEBUGASSERT(cf->next);
|
|---|
| 82 | cf->connected = FALSE;
|
|---|
| 83 | cf->next->cft->close(cf->next, data);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | CURLcode Curl_cf_def_connect(struct Curl_cfilter *cf,
|
|---|
| 87 | struct Curl_easy *data,
|
|---|
| 88 | bool blocking, bool *done)
|
|---|
| 89 | {
|
|---|
| 90 | DEBUGASSERT(cf->next);
|
|---|
| 91 | return cf->next->cft->connect(cf->next, data, blocking, done);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | void Curl_cf_def_get_host(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|---|
| 95 | const char **phost, const char **pdisplay_host,
|
|---|
| 96 | int *pport)
|
|---|
| 97 | {
|
|---|
| 98 | DEBUGASSERT(cf->next);
|
|---|
| 99 | cf->next->cft->get_host(cf->next, data, phost, pdisplay_host, pport);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | int Curl_cf_def_get_select_socks(struct Curl_cfilter *cf,
|
|---|
| 103 | struct Curl_easy *data,
|
|---|
| 104 | curl_socket_t *socks)
|
|---|
| 105 | {
|
|---|
| 106 | DEBUGASSERT(cf->next);
|
|---|
| 107 | return cf->next->cft->get_select_socks(cf->next, data, socks);
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | bool Curl_cf_def_data_pending(struct Curl_cfilter *cf,
|
|---|
| 111 | const struct Curl_easy *data)
|
|---|
| 112 | {
|
|---|
| 113 | DEBUGASSERT(cf->next);
|
|---|
| 114 | return cf->next->cft->has_data_pending(cf->next, data);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | ssize_t Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|---|
| 118 | const void *buf, size_t len, CURLcode *err)
|
|---|
| 119 | {
|
|---|
| 120 | DEBUGASSERT(cf->next);
|
|---|
| 121 | return cf->next->cft->do_send(cf->next, data, buf, len, err);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | ssize_t Curl_cf_def_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|---|
| 125 | char *buf, size_t len, CURLcode *err)
|
|---|
| 126 | {
|
|---|
| 127 | DEBUGASSERT(cf->next);
|
|---|
| 128 | return cf->next->cft->do_recv(cf->next, data, buf, len, err);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | void Curl_conn_cf_discard_all(struct Curl_easy *data,
|
|---|
| 132 | struct connectdata *conn, int index)
|
|---|
| 133 | {
|
|---|
| 134 | struct Curl_cfilter *cfn, *cf = conn->cfilter[index];
|
|---|
| 135 |
|
|---|
| 136 | if(cf) {
|
|---|
| 137 | conn->cfilter[index] = NULL;
|
|---|
| 138 | while(cf) {
|
|---|
| 139 | cfn = cf->next;
|
|---|
| 140 | cf->cft->destroy(cf, data);
|
|---|
| 141 | free(cf);
|
|---|
| 142 | cf = cfn;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | void Curl_conn_close(struct Curl_easy *data, int index)
|
|---|
| 148 | {
|
|---|
| 149 | struct Curl_cfilter *cf;
|
|---|
| 150 |
|
|---|
| 151 | DEBUGASSERT(data->conn);
|
|---|
| 152 | /* it is valid to call that without filters being present */
|
|---|
| 153 | cf = data->conn->cfilter[index];
|
|---|
| 154 | if(cf) {
|
|---|
| 155 | cf->cft->close(cf, data);
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | ssize_t Curl_conn_recv(struct Curl_easy *data, int num, char *buf,
|
|---|
| 160 | size_t len, CURLcode *code)
|
|---|
| 161 | {
|
|---|
| 162 | struct Curl_cfilter *cf;
|
|---|
| 163 | ssize_t nread;
|
|---|
| 164 |
|
|---|
| 165 | DEBUGASSERT(data);
|
|---|
| 166 | DEBUGASSERT(data->conn);
|
|---|
| 167 | cf = data->conn->cfilter[num];
|
|---|
| 168 | while(cf && !cf->connected) {
|
|---|
| 169 | cf = cf->next;
|
|---|
| 170 | }
|
|---|
| 171 | if(cf) {
|
|---|
| 172 | nread = cf->cft->do_recv(cf, data, buf, len, code);
|
|---|
| 173 | /* DEBUGF(infof(data, "Curl_conn_recv(handle=%p, index=%d)"
|
|---|
| 174 | "-> %ld, err=%d", data, num, nread, *code));*/
|
|---|
| 175 | return nread;
|
|---|
| 176 | }
|
|---|
| 177 | failf(data, "no filter connected, conn=%ld, sockindex=%d",
|
|---|
| 178 | data->conn->connection_id, num);
|
|---|
| 179 | *code = CURLE_FAILED_INIT;
|
|---|
| 180 | return -1;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | ssize_t Curl_conn_send(struct Curl_easy *data, int num,
|
|---|
| 184 | const void *mem, size_t len, CURLcode *code)
|
|---|
| 185 | {
|
|---|
| 186 | struct Curl_cfilter *cf;
|
|---|
| 187 | ssize_t nwritten;
|
|---|
| 188 |
|
|---|
| 189 | DEBUGASSERT(data);
|
|---|
| 190 | DEBUGASSERT(data->conn);
|
|---|
| 191 | cf = data->conn->cfilter[num];
|
|---|
| 192 | while(cf && !cf->connected) {
|
|---|
| 193 | cf = cf->next;
|
|---|
| 194 | }
|
|---|
| 195 | if(cf) {
|
|---|
| 196 | nwritten = cf->cft->do_send(cf, data, mem, len, code);
|
|---|
| 197 | /* DEBUGF(infof(data, "Curl_conn_send(handle=%p, index=%d, len=%ld)"
|
|---|
| 198 | " -> %ld, err=%d", data, num, len, nwritten, *code));*/
|
|---|
| 199 | return nwritten;
|
|---|
| 200 | }
|
|---|
| 201 | failf(data, "no filter connected, conn=%ld, sockindex=%d",
|
|---|
| 202 | data->conn->connection_id, num);
|
|---|
| 203 | *code = CURLE_FAILED_INIT;
|
|---|
| 204 | return -1;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | CURLcode Curl_cf_create(struct Curl_cfilter **pcf,
|
|---|
| 208 | const struct Curl_cftype *cft,
|
|---|
| 209 | void *ctx)
|
|---|
| 210 | {
|
|---|
| 211 | struct Curl_cfilter *cf;
|
|---|
| 212 | CURLcode result = CURLE_OUT_OF_MEMORY;
|
|---|
| 213 |
|
|---|
| 214 | DEBUGASSERT(cft);
|
|---|
| 215 | cf = calloc(sizeof(*cf), 1);
|
|---|
| 216 | if(!cf)
|
|---|
| 217 | goto out;
|
|---|
| 218 |
|
|---|
| 219 | cf->cft = cft;
|
|---|
| 220 | cf->ctx = ctx;
|
|---|
| 221 | result = CURLE_OK;
|
|---|
| 222 | out:
|
|---|
| 223 | *pcf = cf;
|
|---|
| 224 | return result;
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | void Curl_conn_cf_add(struct Curl_easy *data,
|
|---|
| 228 | struct connectdata *conn,
|
|---|
| 229 | int index,
|
|---|
| 230 | struct Curl_cfilter *cf)
|
|---|
| 231 | {
|
|---|
| 232 | (void)data;
|
|---|
| 233 | DEBUGASSERT(conn);
|
|---|
| 234 | DEBUGASSERT(!cf->conn);
|
|---|
| 235 | DEBUGASSERT(!cf->next);
|
|---|
| 236 |
|
|---|
| 237 | DEBUGF(infof(data, CMSGI(conn, index, "cf_add(filter=%s)"),
|
|---|
| 238 | cf->cft->name));
|
|---|
| 239 | cf->next = conn->cfilter[index];
|
|---|
| 240 | cf->conn = conn;
|
|---|
| 241 | cf->sockindex = index;
|
|---|
| 242 | conn->cfilter[index] = cf;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | void Curl_conn_cf_discard(struct Curl_cfilter *cf, struct Curl_easy *data)
|
|---|
| 246 | {
|
|---|
| 247 | struct Curl_cfilter **pprev = &cf->conn->cfilter[cf->sockindex];
|
|---|
| 248 |
|
|---|
| 249 | /* remove from chain if still in there */
|
|---|
| 250 | DEBUGASSERT(cf);
|
|---|
| 251 | while (*pprev) {
|
|---|
| 252 | if (*pprev == cf) {
|
|---|
| 253 | *pprev = cf->next;
|
|---|
| 254 | break;
|
|---|
| 255 | }
|
|---|
| 256 | pprev = &((*pprev)->next);
|
|---|
| 257 | }
|
|---|
| 258 | cf->cft->destroy(cf, data);
|
|---|
| 259 | free(cf);
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | ssize_t Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|---|
| 263 | const void *buf, size_t len, CURLcode *err)
|
|---|
| 264 | {
|
|---|
| 265 | return cf->cft->do_send(cf, data, buf, len, err);
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | ssize_t Curl_conn_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
|
|---|
| 269 | char *buf, size_t len, CURLcode *err)
|
|---|
| 270 | {
|
|---|
| 271 | return cf->cft->do_recv(cf, data, buf, len, err);
|
|---|
| 272 | }
|
|---|
| 273 |
|
|---|
| 274 | CURLcode Curl_conn_setup(struct Curl_easy *data,
|
|---|
| 275 | struct connectdata *conn,
|
|---|
| 276 | int sockindex,
|
|---|
| 277 | const struct Curl_dns_entry *remotehost,
|
|---|
| 278 | int ssl_mode)
|
|---|
| 279 | {
|
|---|
| 280 | struct Curl_cfilter *cf;
|
|---|
| 281 | CURLcode result;
|
|---|
| 282 |
|
|---|
| 283 | DEBUGASSERT(data);
|
|---|
| 284 | /* If no filter is set, we have the "default" setup of connection filters.
|
|---|
| 285 | * The filter chain from botton to top will be:
|
|---|
| 286 | * - SOCKET socket filter for outgoing connection to remotehost
|
|---|
| 287 | * if http_proxy tunneling is engaged:
|
|---|
| 288 | * - SSL if proxytype is CURLPROXY_HTTPS
|
|---|
| 289 | * - HTTP_PROXY_TUNNEL
|
|---|
| 290 | * otherwise, if socks_proxy is engaged:
|
|---|
| 291 | * - SOCKS_PROXY_TUNNEL
|
|---|
| 292 | * - SSL if conn->handler has PROTOPT_SSL
|
|---|
| 293 | */
|
|---|
| 294 | if(!conn->cfilter[sockindex]) {
|
|---|
| 295 | DEBUGF(infof(data, DMSGI(data, sockindex, "setup, init filter chain")));
|
|---|
| 296 | result = Curl_conn_socket_set(data, conn, sockindex);
|
|---|
| 297 | if(result)
|
|---|
| 298 | goto out;
|
|---|
| 299 |
|
|---|
| 300 | #ifndef CURL_DISABLE_PROXY
|
|---|
| 301 | if(conn->bits.socksproxy) {
|
|---|
| 302 | result = Curl_conn_socks_proxy_add(data, conn, sockindex);
|
|---|
| 303 | if(result)
|
|---|
| 304 | goto out;
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | if(conn->bits.httpproxy) {
|
|---|
| 308 | #ifdef USE_SSL
|
|---|
| 309 | if(conn->http_proxy.proxytype == CURLPROXY_HTTPS) {
|
|---|
| 310 | result = Curl_ssl_cfilter_proxy_add(data, conn, sockindex);
|
|---|
| 311 | if(result)
|
|---|
| 312 | goto out;
|
|---|
| 313 | }
|
|---|
| 314 | #endif /* USE_SSL */
|
|---|
| 315 |
|
|---|
| 316 | #if !defined(CURL_DISABLE_HTTP)
|
|---|
| 317 | if(conn->bits.tunnel_proxy) {
|
|---|
| 318 | result = Curl_conn_http_proxy_add(data, conn, sockindex);
|
|---|
| 319 | if(result)
|
|---|
| 320 | goto out;
|
|---|
| 321 | }
|
|---|
| 322 | #endif /* !CURL_DISABLE_HTTP */
|
|---|
| 323 | }
|
|---|
| 324 | #endif /* !CURL_DISABLE_PROXY */
|
|---|
| 325 |
|
|---|
| 326 | #ifdef USE_SSL
|
|---|
| 327 | if(ssl_mode == CURL_CF_SSL_ENABLE
|
|---|
| 328 | || (ssl_mode != CURL_CF_SSL_DISABLE
|
|---|
| 329 | && conn->handler->flags & PROTOPT_SSL)) {
|
|---|
| 330 | result = Curl_ssl_cfilter_add(data, conn, sockindex);
|
|---|
| 331 | if(result)
|
|---|
| 332 | goto out;
|
|---|
| 333 | }
|
|---|
| 334 | #else
|
|---|
| 335 | (void)ssl_mode;
|
|---|
| 336 | #endif /* USE_SSL */
|
|---|
| 337 |
|
|---|
| 338 | #if !defined(CURL_DISABLE_PROXY) && !defined(CURL_DISABLE_HTTP)
|
|---|
| 339 | if(data->set.haproxyprotocol) {
|
|---|
| 340 | result = Curl_conn_haproxy_add(data, conn, sockindex);
|
|---|
| 341 | if(result)
|
|---|
| 342 | goto out;
|
|---|
| 343 | }
|
|---|
| 344 | #endif /* !CURL_DISABLE_PROXY && !CURL_DISABLE_HTTP */
|
|---|
| 345 |
|
|---|
| 346 | }
|
|---|
| 347 | DEBUGASSERT(conn->cfilter[sockindex]);
|
|---|
| 348 | cf = data->conn->cfilter[sockindex];
|
|---|
| 349 | result = cf->cft->setup(cf, data, remotehost);
|
|---|
| 350 |
|
|---|
| 351 | out:
|
|---|
| 352 | return result;
|
|---|
| 353 | }
|
|---|
| 354 |
|
|---|
| 355 | CURLcode Curl_conn_connect(struct Curl_easy *data,
|
|---|
| 356 | int sockindex,
|
|---|
| 357 | bool blocking,
|
|---|
| 358 | bool *done)
|
|---|
| 359 | {
|
|---|
| 360 | struct Curl_cfilter *cf;
|
|---|
| 361 | CURLcode result;
|
|---|
| 362 |
|
|---|
| 363 | DEBUGASSERT(data);
|
|---|
| 364 |
|
|---|
| 365 | cf = data->conn->cfilter[sockindex];
|
|---|
| 366 | DEBUGASSERT(cf);
|
|---|
| 367 | result = cf->cft->connect(cf, data, blocking, done);
|
|---|
| 368 |
|
|---|
| 369 | DEBUGF(infof(data, DMSGI(data, sockindex, "connect(block=%d)-> %d, done=%d"),
|
|---|
| 370 | blocking, result, *done));
|
|---|
| 371 | return result;
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | bool Curl_conn_is_connected(struct connectdata *conn, int sockindex)
|
|---|
| 375 | {
|
|---|
| 376 | struct Curl_cfilter *cf;
|
|---|
| 377 |
|
|---|
| 378 | cf = conn->cfilter[sockindex];
|
|---|
| 379 | return cf && cf->connected;
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | bool Curl_conn_is_ip_connected(struct Curl_easy *data, int sockindex)
|
|---|
| 383 | {
|
|---|
| 384 | struct Curl_cfilter *cf;
|
|---|
| 385 |
|
|---|
| 386 | cf = data->conn->cfilter[sockindex];
|
|---|
| 387 | while(cf) {
|
|---|
| 388 | if(cf->connected)
|
|---|
| 389 | return TRUE;
|
|---|
| 390 | if(cf->cft->flags & CF_TYPE_IP_CONNECT)
|
|---|
| 391 | return FALSE;
|
|---|
| 392 | cf = cf->next;
|
|---|
| 393 | }
|
|---|
| 394 | return FALSE;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | bool Curl_conn_is_ssl(struct Curl_easy *data, int sockindex)
|
|---|
| 398 | {
|
|---|
| 399 | struct Curl_cfilter *cf = data->conn? data->conn->cfilter[sockindex] : NULL;
|
|---|
| 400 |
|
|---|
| 401 | (void)data;
|
|---|
| 402 | for(; cf; cf = cf->next) {
|
|---|
| 403 | if(cf->cft->flags & CF_TYPE_SSL)
|
|---|
| 404 | return TRUE;
|
|---|
| 405 | if(cf->cft->flags & CF_TYPE_IP_CONNECT)
|
|---|
| 406 | return FALSE;
|
|---|
| 407 | }
|
|---|
| 408 | return FALSE;
|
|---|
| 409 | }
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 | bool Curl_conn_data_pending(struct Curl_easy *data, int sockindex)
|
|---|
| 413 | {
|
|---|
| 414 | struct Curl_cfilter *cf;
|
|---|
| 415 |
|
|---|
| 416 | (void)data;
|
|---|
| 417 | DEBUGASSERT(data);
|
|---|
| 418 | DEBUGASSERT(data->conn);
|
|---|
| 419 | if(Curl_recv_has_postponed_data(data->conn, sockindex))
|
|---|
| 420 | return TRUE;
|
|---|
| 421 |
|
|---|
| 422 | cf = data->conn->cfilter[sockindex];
|
|---|
| 423 | while(cf && !cf->connected) {
|
|---|
| 424 | cf = cf->next;
|
|---|
| 425 | }
|
|---|
| 426 | if(cf) {
|
|---|
| 427 | return cf->cft->has_data_pending(cf, data);
|
|---|
| 428 | }
|
|---|
| 429 | return FALSE;
|
|---|
| 430 | }
|
|---|
| 431 |
|
|---|
| 432 | int Curl_conn_get_select_socks(struct Curl_easy *data, int sockindex,
|
|---|
| 433 | curl_socket_t *socks)
|
|---|
| 434 | {
|
|---|
| 435 | struct Curl_cfilter *cf;
|
|---|
| 436 |
|
|---|
| 437 | DEBUGASSERT(data);
|
|---|
| 438 | DEBUGASSERT(data->conn);
|
|---|
| 439 | cf = data->conn->cfilter[sockindex];
|
|---|
| 440 | if(cf) {
|
|---|
| 441 | return cf->cft->get_select_socks(cf, data, socks);
|
|---|
| 442 | }
|
|---|
| 443 | return GETSOCK_BLANK;
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | void Curl_conn_attach_data(struct connectdata *conn,
|
|---|
| 447 | struct Curl_easy *data)
|
|---|
| 448 | {
|
|---|
| 449 | size_t i;
|
|---|
| 450 | struct Curl_cfilter *cf;
|
|---|
| 451 |
|
|---|
| 452 | for(i = 0; i < ARRAYSIZE(conn->cfilter); ++i) {
|
|---|
| 453 | cf = conn->cfilter[i];
|
|---|
| 454 | if(cf) {
|
|---|
| 455 | while(cf) {
|
|---|
| 456 | cf->cft->attach_data(cf, data);
|
|---|
| 457 | cf = cf->next;
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 | }
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | void Curl_conn_detach_data(struct connectdata *conn,
|
|---|
| 464 | struct Curl_easy *data)
|
|---|
| 465 | {
|
|---|
| 466 | size_t i;
|
|---|
| 467 | struct Curl_cfilter *cf;
|
|---|
| 468 |
|
|---|
| 469 | for(i = 0; i < ARRAYSIZE(conn->cfilter); ++i) {
|
|---|
| 470 | cf = conn->cfilter[i];
|
|---|
| 471 | if(cf) {
|
|---|
| 472 | while(cf) {
|
|---|
| 473 | cf->cft->detach_data(cf, data);
|
|---|
| 474 | cf = cf->next;
|
|---|
| 475 | }
|
|---|
| 476 | }
|
|---|
| 477 | }
|
|---|
| 478 | }
|
|---|
| 479 |
|
|---|
| 480 | void Curl_conn_get_host(struct Curl_easy *data, int sockindex,
|
|---|
| 481 | const char **phost, const char **pdisplay_host,
|
|---|
| 482 | int *pport)
|
|---|
| 483 | {
|
|---|
| 484 | struct Curl_cfilter *cf;
|
|---|
| 485 |
|
|---|
| 486 | DEBUGASSERT(data->conn);
|
|---|
| 487 | cf = data->conn->cfilter[sockindex];
|
|---|
| 488 | if(cf) {
|
|---|
| 489 | cf->cft->get_host(cf, data, phost, pdisplay_host, pport);
|
|---|
| 490 | }
|
|---|
| 491 | else {
|
|---|
| 492 | /* Some filter ask during shutdown for this, mainly for debugging
|
|---|
| 493 | * purposes. We hand out the defaults, however this is not always
|
|---|
| 494 | * accurate, as the connction might be tunneled, etc. But all that
|
|---|
| 495 | * state is already gone here. */
|
|---|
| 496 | *phost = data->conn->host.name;
|
|---|
| 497 | *pdisplay_host = data->conn->host.dispname;
|
|---|
| 498 | *pport = data->conn->remote_port;
|
|---|
| 499 | }
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|