1 #ifndef HEADER_CURL_CFILTERS_H 2 #define HEADER_CURL_CFILTERS_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at https://curl.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 * SPDX-License-Identifier: curl 24 * 25 ***************************************************************************/ 26 27 #include "timediff.h" 28 29 struct Curl_cfilter; 30 struct Curl_easy; 31 struct Curl_dns_entry; 32 struct connectdata; 33 34 /* Callback to destroy resources held by this filter instance. 35 * Implementations MUST NOT chain calls to cf->next. 36 */ 37 typedef void Curl_cft_destroy_this(struct Curl_cfilter *cf, 38 struct Curl_easy *data); 39 40 /* Callback to close the connection immediately. */ 41 typedef void Curl_cft_close(struct Curl_cfilter *cf, 42 struct Curl_easy *data); 43 44 /* Callback to close the connection filter gracefully, non-blocking. 45 * Implementations MUST NOT chain calls to cf->next. 46 */ 47 typedef CURLcode Curl_cft_shutdown(struct Curl_cfilter *cf, 48 struct Curl_easy *data, 49 bool *done); 50 51 typedef CURLcode Curl_cft_connect(struct Curl_cfilter *cf, 52 struct Curl_easy *data, 53 bool blocking, bool *done); 54 55 /* Return the hostname and port the connection goes to. 56 * This may change with the connection state of filters when tunneling 57 * is involved. 58 * @param cf the filter to ask 59 * @param data the easy handle currently active 60 * @param phost on return, points to the relevant, real hostname. 61 * this is owned by the connection. 62 * @param pdisplay_host on return, points to the printable hostname. 63 * this is owned by the connection. 64 * @param pport on return, contains the port number 65 */ 66 typedef void Curl_cft_get_host(struct Curl_cfilter *cf, 67 struct Curl_easy *data, 68 const char **phost, 69 const char **pdisplay_host, 70 int *pport); 71 72 struct easy_pollset; 73 74 /* Passing in an easy_pollset for monitoring of sockets, let 75 * filters add or remove sockets actions (CURL_POLL_OUT, CURL_POLL_IN). 76 * This may add a socket or, in case no actions remain, remove 77 * a socket from the set. 78 * 79 * Filter implementations need to call filters "below" *after* they have 80 * made their adjustments. This allows lower filters to override "upper" 81 * actions. If a "lower" filter is unable to write, it needs to be able 82 * to disallow POLL_OUT. 83 * 84 * A filter without own restrictions/preferences should not modify 85 * the pollset. Filters, whose filter "below" is not connected, should 86 * also do no adjustments. 87 * 88 * Examples: a TLS handshake, while ongoing, might remove POLL_IN 89 * when it needs to write, or vice versa. A HTTP/2 filter might remove 90 * POLL_OUT when a stream window is exhausted and a WINDOW_UPDATE needs 91 * to be received first and add instead POLL_IN. 92 * 93 * @param cf the filter to ask 94 * @param data the easy handle the pollset is about 95 * @param ps the pollset (inout) for the easy handle 96 */ 97 typedef void Curl_cft_adjust_pollset(struct Curl_cfilter *cf, 98 struct Curl_easy *data, 99 struct easy_pollset *ps); 100 101 typedef bool Curl_cft_data_pending(struct Curl_cfilter *cf, 102 const struct Curl_easy *data); 103 104 typedef ssize_t Curl_cft_send(struct Curl_cfilter *cf, 105 struct Curl_easy *data, /* transfer */ 106 const void *buf, /* data to write */ 107 size_t len, /* amount to write */ 108 CURLcode *err); /* error to return */ 109 110 typedef ssize_t Curl_cft_recv(struct Curl_cfilter *cf, 111 struct Curl_easy *data, /* transfer */ 112 char *buf, /* store data here */ 113 size_t len, /* amount to read */ 114 CURLcode *err); /* error to return */ 115 116 typedef bool Curl_cft_conn_is_alive(struct Curl_cfilter *cf, 117 struct Curl_easy *data, 118 bool *input_pending); 119 120 typedef CURLcode Curl_cft_conn_keep_alive(struct Curl_cfilter *cf, 121 struct Curl_easy *data); 122 123 /** 124 * Events/controls for connection filters, their arguments and 125 * return code handling. Filter callbacks are invoked "top down". 126 * Return code handling: 127 * "first fail" meaning that the first filter returning != CURLE_OK, will 128 * abort further event distribution and determine the result. 129 * "ignored" meaning return values are ignored and the event is distributed 130 * to all filters in the chain. Overall result is always CURLE_OK. 131 */ 132 /* data event arg1 arg2 return */ 133 #define CF_CTRL_DATA_ATTACH 1 /* 0 NULL ignored */ 134 #define CF_CTRL_DATA_DETACH 2 /* 0 NULL ignored */ 135 #define CF_CTRL_DATA_SETUP 4 /* 0 NULL first fail */ 136 #define CF_CTRL_DATA_IDLE 5 /* 0 NULL first fail */ 137 #define CF_CTRL_DATA_PAUSE 6 /* on/off NULL first fail */ 138 #define CF_CTRL_DATA_DONE 7 /* premature NULL ignored */ 139 #define CF_CTRL_DATA_DONE_SEND 8 /* 0 NULL ignored */ 140 /* update conn info at connection and data */ 141 #define CF_CTRL_CONN_INFO_UPDATE (256+0) /* 0 NULL ignored */ 142 #define CF_CTRL_FORGET_SOCKET (256+1) /* 0 NULL ignored */ 143 144 /** 145 * Handle event/control for the filter. 146 * Implementations MUST NOT chain calls to cf->next. 147 */ 148 typedef CURLcode Curl_cft_cntrl(struct Curl_cfilter *cf, 149 struct Curl_easy *data, 150 int event, int arg1, void *arg2); 151 152 153 /** 154 * Queries to ask via a `Curl_cft_query *query` method on a cfilter chain. 155 * - MAX_CONCURRENT: the maximum number of parallel transfers the filter 156 * chain expects to handle at the same time. 157 * default: 1 if no filter overrides. 158 * - CONNECT_REPLY_MS: milliseconds until the first indication of a server 159 * response was received on a connect. For TCP, this 160 * reflects the time until the socket connected. On UDP 161 * this gives the time the first bytes from the server 162 * were received. 163 * -1 if not determined yet. 164 * - CF_QUERY_SOCKET: the socket used by the filter chain 165 */ 166 /* query res1 res2 */ 167 #define CF_QUERY_MAX_CONCURRENT 1 /* number - */ 168 #define CF_QUERY_CONNECT_REPLY_MS 2 /* number - */ 169 #define CF_QUERY_SOCKET 3 /* - curl_socket_t */ 170 #define CF_QUERY_TIMER_CONNECT 4 /* - struct curltime */ 171 #define CF_QUERY_TIMER_APPCONNECT 5 /* - struct curltime */ 172 #define CF_QUERY_STREAM_ERROR 6 /* error code - */ 173 174 /** 175 * Query the cfilter for properties. Filters ignorant of a query will 176 * pass it "down" the filter chain. 177 */ 178 typedef CURLcode Curl_cft_query(struct Curl_cfilter *cf, 179 struct Curl_easy *data, 180 int query, int *pres1, void *pres2); 181 182 /** 183 * Type flags for connection filters. A filter can have none, one or 184 * many of those. Use to evaluate state/capabilities of a filter chain. 185 * 186 * CF_TYPE_IP_CONNECT: provides an IP connection or sth equivalent, like 187 * a CONNECT tunnel, a UNIX domain socket, a QUIC 188 * connection, etc. 189 * CF_TYPE_SSL: provide SSL/TLS 190 * CF_TYPE_MULTIPLEX: provides multiplexing of easy handles 191 * CF_TYPE_PROXY provides proxying 192 */ 193 #define CF_TYPE_IP_CONNECT (1 << 0) 194 #define CF_TYPE_SSL (1 << 1) 195 #define CF_TYPE_MULTIPLEX (1 << 2) 196 #define CF_TYPE_PROXY (1 << 3) 197 198 /* A connection filter type, e.g. specific implementation. */ 199 struct Curl_cftype { 200 const char *name; /* name of the filter type */ 201 int flags; /* flags of filter type */ 202 int log_level; /* log level for such filters */ 203 Curl_cft_destroy_this *destroy; /* destroy resources of this cf */ 204 Curl_cft_connect *do_connect; /* establish connection */ 205 Curl_cft_close *do_close; /* close conn */ 206 Curl_cft_shutdown *do_shutdown; /* shutdown conn */ 207 Curl_cft_get_host *get_host; /* host filter talks to */ 208 Curl_cft_adjust_pollset *adjust_pollset; /* adjust transfer poll set */ 209 Curl_cft_data_pending *has_data_pending;/* conn has data pending */ 210 Curl_cft_send *do_send; /* send data */ 211 Curl_cft_recv *do_recv; /* receive data */ 212 Curl_cft_cntrl *cntrl; /* events/control */ 213 Curl_cft_conn_is_alive *is_alive; /* FALSE if conn is dead, Jim! */ 214 Curl_cft_conn_keep_alive *keep_alive; /* try to keep it alive */ 215 Curl_cft_query *query; /* query filter chain */ 216 }; 217 218 /* A connection filter instance, e.g. registered at a connection */ 219 struct Curl_cfilter { 220 const struct Curl_cftype *cft; /* the type providing implementation */ 221 struct Curl_cfilter *next; /* next filter in chain */ 222 void *ctx; /* filter type specific settings */ 223 struct connectdata *conn; /* the connection this filter belongs to */ 224 int sockindex; /* the index the filter is installed at */ 225 BIT(connected); /* != 0 iff this filter is connected */ 226 BIT(shutdown); /* != 0 iff this filter has shut down */ 227 }; 228 229 /* Default implementations for the type functions, implementing nop. */ 230 void Curl_cf_def_destroy_this(struct Curl_cfilter *cf, 231 struct Curl_easy *data); 232 233 /* Default implementations for the type functions, implementing pass-through 234 * the filter chain. */ 235 void Curl_cf_def_get_host(struct Curl_cfilter *cf, struct Curl_easy *data, 236 const char **phost, const char **pdisplay_host, 237 int *pport); 238 void Curl_cf_def_adjust_pollset(struct Curl_cfilter *cf, 239 struct Curl_easy *data, 240 struct easy_pollset *ps); 241 bool Curl_cf_def_data_pending(struct Curl_cfilter *cf, 242 const struct Curl_easy *data); 243 ssize_t Curl_cf_def_send(struct Curl_cfilter *cf, struct Curl_easy *data, 244 const void *buf, size_t len, CURLcode *err); 245 ssize_t Curl_cf_def_recv(struct Curl_cfilter *cf, struct Curl_easy *data, 246 char *buf, size_t len, CURLcode *err); 247 CURLcode Curl_cf_def_cntrl(struct Curl_cfilter *cf, 248 struct Curl_easy *data, 249 int event, int arg1, void *arg2); 250 bool Curl_cf_def_conn_is_alive(struct Curl_cfilter *cf, 251 struct Curl_easy *data, 252 bool *input_pending); 253 CURLcode Curl_cf_def_conn_keep_alive(struct Curl_cfilter *cf, 254 struct Curl_easy *data); 255 CURLcode Curl_cf_def_query(struct Curl_cfilter *cf, 256 struct Curl_easy *data, 257 int query, int *pres1, void *pres2); 258 CURLcode Curl_cf_def_shutdown(struct Curl_cfilter *cf, 259 struct Curl_easy *data, bool *done); 260 261 /** 262 * Create a new filter instance, unattached to the filter chain. 263 * Use Curl_conn_cf_add() to add it to the chain. 264 * @param pcf on success holds the created instance 265 * @param cft the filter type 266 * @param ctx the type specific context to use 267 */ 268 CURLcode Curl_cf_create(struct Curl_cfilter **pcf, 269 const struct Curl_cftype *cft, 270 void *ctx); 271 272 /** 273 * Add a filter instance to the `sockindex` filter chain at connection 274 * `conn`. The filter must not already be attached. It is inserted at 275 * the start of the chain (top). 276 */ 277 void Curl_conn_cf_add(struct Curl_easy *data, 278 struct connectdata *conn, 279 int sockindex, 280 struct Curl_cfilter *cf); 281 282 /** 283 * Insert a filter (chain) after `cf_at`. 284 * `cf_new` must not already be attached. 285 */ 286 void Curl_conn_cf_insert_after(struct Curl_cfilter *cf_at, 287 struct Curl_cfilter *cf_new); 288 289 /** 290 * Discard, e.g. remove and destroy `discard` iff 291 * it still is in the filter chain below `cf`. If `discard` 292 * is no longer found beneath `cf` return FALSE. 293 * if `destroy_always` is TRUE, will call `discard`s destroy 294 * function and free it even if not found in the subchain. 295 */ 296 bool Curl_conn_cf_discard_sub(struct Curl_cfilter *cf, 297 struct Curl_cfilter *discard, 298 struct Curl_easy *data, 299 bool destroy_always); 300 301 /** 302 * Discard all cfilters starting with `*pcf` and clearing it afterwards. 303 */ 304 void Curl_conn_cf_discard_chain(struct Curl_cfilter **pcf, 305 struct Curl_easy *data); 306 307 /** 308 * Remove and destroy all filters at chain `sockindex` on connection `conn`. 309 */ 310 void Curl_conn_cf_discard_all(struct Curl_easy *data, 311 struct connectdata *conn, 312 int sockindex); 313 314 315 CURLcode Curl_conn_cf_connect(struct Curl_cfilter *cf, 316 struct Curl_easy *data, 317 bool blocking, bool *done); 318 void Curl_conn_cf_close(struct Curl_cfilter *cf, struct Curl_easy *data); 319 ssize_t Curl_conn_cf_send(struct Curl_cfilter *cf, struct Curl_easy *data, 320 const void *buf, size_t len, CURLcode *err); 321 ssize_t Curl_conn_cf_recv(struct Curl_cfilter *cf, struct Curl_easy *data, 322 char *buf, size_t len, CURLcode *err); 323 CURLcode Curl_conn_cf_cntrl(struct Curl_cfilter *cf, 324 struct Curl_easy *data, 325 bool ignore_result, 326 int event, int arg1, void *arg2); 327 328 /** 329 * Determine if the connection filter chain is using SSL to the remote host 330 * (or will be once connected). 331 */ 332 bool Curl_conn_cf_is_ssl(struct Curl_cfilter *cf); 333 334 /** 335 * Get the socket used by the filter chain starting at `cf`. 336 * Returns CURL_SOCKET_BAD if not available. 337 */ 338 curl_socket_t Curl_conn_cf_get_socket(struct Curl_cfilter *cf, 339 struct Curl_easy *data); 340 341 342 #define CURL_CF_SSL_DEFAULT -1 343 #define CURL_CF_SSL_DISABLE 0 344 #define CURL_CF_SSL_ENABLE 1 345 346 /** 347 * Bring the filter chain at `sockindex` for connection `data->conn` into 348 * connected state. Which will set `*done` to TRUE. 349 * This can be called on an already connected chain with no side effects. 350 * When not `blocking`, calls may return without error and `*done != TRUE`, 351 * while the individual filters negotiated the connection. 352 */ 353 CURLcode Curl_conn_connect(struct Curl_easy *data, int sockindex, 354 bool blocking, bool *done); 355 356 /** 357 * Check if the filter chain at `sockindex` for connection `conn` is 358 * completely connected. 359 */ 360 bool Curl_conn_is_connected(struct connectdata *conn, int sockindex); 361 362 /** 363 * Determine if we have reached the remote host on IP level, e.g. 364 * have a TCP connection. This turns TRUE before a possible SSL 365 * handshake has been started/done. 366 */ 367 bool Curl_conn_is_ip_connected(struct Curl_easy *data, int sockindex); 368 369 /** 370 * Determine if the connection is using SSL to the remote host 371 * (or will be once connected). This will return FALSE, if SSL 372 * is only used in proxying and not for the tunnel itself. 373 */ 374 bool Curl_conn_is_ssl(struct connectdata *conn, int sockindex); 375 376 /** 377 * Connection provides multiplexing of easy handles at `socketindex`. 378 */ 379 bool Curl_conn_is_multiplex(struct connectdata *conn, int sockindex); 380 381 /** 382 * Close the filter chain at `sockindex` for connection `data->conn`. 383 * Filters remain in place and may be connected again afterwards. 384 */ 385 void Curl_conn_close(struct Curl_easy *data, int sockindex); 386 387 /** 388 * Shutdown the connection at `sockindex` non-blocking, using timeout 389 * from `data->set.shutdowntimeout`, default DEFAULT_SHUTDOWN_TIMEOUT_MS. 390 * Will return CURLE_OK and *done == FALSE if not finished. 391 */ 392 CURLcode Curl_conn_shutdown(struct Curl_easy *data, int sockindex, bool *done); 393 394 /** 395 * Return if data is pending in some connection filter at chain 396 * `sockindex` for connection `data->conn`. 397 */ 398 bool Curl_conn_data_pending(struct Curl_easy *data, 399 int sockindex); 400 401 /** 402 * Return the socket used on data's connection for the index. 403 * Returns CURL_SOCKET_BAD if not available. 404 */ 405 curl_socket_t Curl_conn_get_socket(struct Curl_easy *data, int sockindex); 406 407 /** 408 * Tell filters to forget about the socket at sockindex. 409 */ 410 void Curl_conn_forget_socket(struct Curl_easy *data, int sockindex); 411 412 /** 413 * Adjust the pollset for the filter chain startgin at `cf`. 414 */ 415 void Curl_conn_cf_adjust_pollset(struct Curl_cfilter *cf, 416 struct Curl_easy *data, 417 struct easy_pollset *ps); 418 419 /** 420 * Adjust pollset from filters installed at transfer's connection. 421 */ 422 void Curl_conn_adjust_pollset(struct Curl_easy *data, 423 struct easy_pollset *ps); 424 425 /** 426 * Curl_poll() the filter chain at `cf` with timeout `timeout_ms`. 427 * Returns 0 on timeout, negative on error or number of sockets 428 * with requested poll events. 429 */ 430 int Curl_conn_cf_poll(struct Curl_cfilter *cf, 431 struct Curl_easy *data, 432 timediff_t timeout_ms); 433 434 /** 435 * Receive data through the filter chain at `sockindex` for connection 436 * `data->conn`. Copy at most `len` bytes into `buf`. Return the 437 * actual number of bytes copied or a negative value on error. 438 * The error code is placed into `*code`. 439 */ 440 ssize_t Curl_cf_recv(struct Curl_easy *data, int sockindex, char *buf, 441 size_t len, CURLcode *code); 442 443 /** 444 * Send `len` bytes of data from `buf` through the filter chain `sockindex` 445 * at connection `data->conn`. Return the actual number of bytes written 446 * or a negative value on error. 447 * The error code is placed into `*code`. 448 */ 449 ssize_t Curl_cf_send(struct Curl_easy *data, int sockindex, 450 const void *buf, size_t len, CURLcode *code); 451 452 /** 453 * The easy handle `data` is being attached to `conn`. This does 454 * not mean that data will actually do a transfer. Attachment is 455 * also used for temporary actions on the connection. 456 */ 457 void Curl_conn_ev_data_attach(struct connectdata *conn, 458 struct Curl_easy *data); 459 460 /** 461 * The easy handle `data` is being detached (no longer served) 462 * by connection `conn`. All filters are informed to release any resources 463 * related to `data`. 464 * Note: there may be several `data` attached to a connection at the same 465 * time. 466 */ 467 void Curl_conn_ev_data_detach(struct connectdata *conn, 468 struct Curl_easy *data); 469 470 /** 471 * Notify connection filters that they need to setup data for 472 * a transfer. 473 */ 474 CURLcode Curl_conn_ev_data_setup(struct Curl_easy *data); 475 476 /** 477 * Notify connection filters that now would be a good time to 478 * perform any idle, e.g. time related, actions. 479 */ 480 CURLcode Curl_conn_ev_data_idle(struct Curl_easy *data); 481 482 /** 483 * Notify connection filters that the transfer represented by `data` 484 * is done with sending data (e.g. has uploaded everything). 485 */ 486 void Curl_conn_ev_data_done_send(struct Curl_easy *data); 487 488 /** 489 * Notify connection filters that the transfer represented by `data` 490 * is finished - eventually premature, e.g. before being complete. 491 */ 492 void Curl_conn_ev_data_done(struct Curl_easy *data, bool premature); 493 494 /** 495 * Notify connection filters that the transfer of data is paused/unpaused. 496 */ 497 CURLcode Curl_conn_ev_data_pause(struct Curl_easy *data, bool do_pause); 498 499 /** 500 * Inform connection filters to update their info in `conn`. 501 */ 502 void Curl_conn_ev_update_info(struct Curl_easy *data, 503 struct connectdata *conn); 504 505 /** 506 * Check if FIRSTSOCKET's cfilter chain deems connection alive. 507 */ 508 bool Curl_conn_is_alive(struct Curl_easy *data, struct connectdata *conn, 509 bool *input_pending); 510 511 /** 512 * Try to upkeep the connection filters at sockindex. 513 */ 514 CURLcode Curl_conn_keep_alive(struct Curl_easy *data, 515 struct connectdata *conn, 516 int sockindex); 517 518 #ifdef UNITTESTS 519 void Curl_cf_def_close(struct Curl_cfilter *cf, struct Curl_easy *data); 520 #endif 521 void Curl_conn_get_host(struct Curl_easy *data, int sockindex, 522 const char **phost, const char **pdisplay_host, 523 int *pport); 524 525 /** 526 * Get the maximum number of parallel transfers the connection 527 * expects to be able to handle at `sockindex`. 528 */ 529 size_t Curl_conn_get_max_concurrent(struct Curl_easy *data, 530 struct connectdata *conn, 531 int sockindex); 532 533 /** 534 * Get the underlying error code for a transfer stream or 0 if not known. 535 */ 536 int Curl_conn_get_stream_error(struct Curl_easy *data, 537 struct connectdata *conn, 538 int sockindex); 539 540 /** 541 * Get the index of the given socket in the connection's sockets. 542 * Useful in calling `Curl_conn_send()/Curl_conn_recv()` with the 543 * correct socket index. 544 */ 545 int Curl_conn_sockindex(struct Curl_easy *data, curl_socket_t sockfd); 546 547 /* 548 * Receive data on the connection, using FIRSTSOCKET/SECONDARYSOCKET. 549 * Will return CURLE_AGAIN iff blocked on receiving. 550 */ 551 CURLcode Curl_conn_recv(struct Curl_easy *data, int sockindex, 552 char *buf, size_t buffersize, 553 ssize_t *pnread); 554 555 /* 556 * Send data on the connection, using FIRSTSOCKET/SECONDARYSOCKET. 557 * Will return CURLE_AGAIN iff blocked on sending. 558 */ 559 CURLcode Curl_conn_send(struct Curl_easy *data, int sockindex, 560 const void *buf, size_t blen, 561 size_t *pnwritten); 562 563 564 void Curl_pollset_reset(struct Curl_easy *data, 565 struct easy_pollset *ps); 566 567 /* Change the poll flags (CURL_POLL_IN/CURL_POLL_OUT) to the poll set for 568 * socket `sock`. If the socket is not already part of the poll set, it 569 * will be added. 570 * If the socket is present and all poll flags are cleared, it will be removed. 571 */ 572 void Curl_pollset_change(struct Curl_easy *data, 573 struct easy_pollset *ps, curl_socket_t sock, 574 int add_flags, int remove_flags); 575 576 void Curl_pollset_set(struct Curl_easy *data, 577 struct easy_pollset *ps, curl_socket_t sock, 578 bool do_in, bool do_out); 579 580 #define Curl_pollset_add_in(data, ps, sock) \ 581 Curl_pollset_change((data), (ps), (sock), CURL_POLL_IN, 0) 582 #define Curl_pollset_add_out(data, ps, sock) \ 583 Curl_pollset_change((data), (ps), (sock), CURL_POLL_OUT, 0) 584 #define Curl_pollset_add_inout(data, ps, sock) \ 585 Curl_pollset_change((data), (ps), (sock), \ 586 CURL_POLL_IN|CURL_POLL_OUT, 0) 587 #define Curl_pollset_set_in_only(data, ps, sock) \ 588 Curl_pollset_change((data), (ps), (sock), \ 589 CURL_POLL_IN, CURL_POLL_OUT) 590 #define Curl_pollset_set_out_only(data, ps, sock) \ 591 Curl_pollset_change((data), (ps), (sock), \ 592 CURL_POLL_OUT, CURL_POLL_IN) 593 594 void Curl_pollset_add_socks(struct Curl_easy *data, 595 struct easy_pollset *ps, 596 int (*get_socks_cb)(struct Curl_easy *data, 597 curl_socket_t *socks)); 598 599 /** 600 * Check if the pollset, as is, wants to read and/or write regarding 601 * the given socket. 602 */ 603 void Curl_pollset_check(struct Curl_easy *data, 604 struct easy_pollset *ps, curl_socket_t sock, 605 bool *pwant_read, bool *pwant_write); 606 607 /** 608 * Types and macros used to keep the current easy handle in filter calls, 609 * allowing for nested invocations. See #10336. 610 * 611 * `cf_call_data` is intended to be a member of the cfilter's `ctx` type. 612 * A filter defines the macro `CF_CTX_CALL_DATA` to give access to that. 613 * 614 * With all values 0, the default, this indicates that there is no cfilter 615 * call with `data` ongoing. 616 * Macro `CF_DATA_SAVE` preserves the current `cf_call_data` in a local 617 * variable and sets the `data` given, incrementing the `depth` counter. 618 * 619 * Macro `CF_DATA_RESTORE` restores the old values from the local variable, 620 * while checking that `depth` values are as expected (debug build), catching 621 * cases where a "lower" RESTORE was not called. 622 * 623 * Finally, macro `CF_DATA_CURRENT` gives the easy handle of the current 624 * invocation. 625 */ 626 struct cf_call_data { 627 struct Curl_easy *data; 628 #ifdef DEBUGBUILD 629 int depth; 630 #endif 631 }; 632 633 /** 634 * define to access the `struct cf_call_data for a cfilter. Normally 635 * a member in the cfilter's `ctx`. 636 * 637 * #define CF_CTX_CALL_DATA(cf) -> struct cf_call_data instance 638 */ 639 640 #ifdef DEBUGBUILD 641 642 #define CF_DATA_SAVE(save, cf, data) \ 643 do { \ 644 (save) = CF_CTX_CALL_DATA(cf); \ 645 DEBUGASSERT((save).data == NULL || (save).depth > 0); \ 646 CF_CTX_CALL_DATA(cf).depth++; \ 647 CF_CTX_CALL_DATA(cf).data = (struct Curl_easy *)data; \ 648 } while(0) 649 650 #define CF_DATA_RESTORE(cf, save) \ 651 do { \ 652 DEBUGASSERT(CF_CTX_CALL_DATA(cf).depth == (save).depth + 1); \ 653 DEBUGASSERT((save).data == NULL || (save).depth > 0); \ 654 CF_CTX_CALL_DATA(cf) = (save); \ 655 } while(0) 656 657 #else /* DEBUGBUILD */ 658 659 #define CF_DATA_SAVE(save, cf, data) \ 660 do { \ 661 (save) = CF_CTX_CALL_DATA(cf); \ 662 CF_CTX_CALL_DATA(cf).data = (struct Curl_easy *)data; \ 663 } while(0) 664 665 #define CF_DATA_RESTORE(cf, save) \ 666 do { \ 667 CF_CTX_CALL_DATA(cf) = (save); \ 668 } while(0) 669 670 #endif /* !DEBUGBUILD */ 671 672 #define CF_DATA_CURRENT(cf) \ 673 ((cf)? (CF_CTX_CALL_DATA(cf).data) : NULL) 674 675 #endif /* HEADER_CURL_CFILTERS_H */ 676