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