quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

CURLMOPT_PUSHDATA.md (1845B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: CURLMOPT_PUSHDATA
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - CURLMOPT_PIPELINING (3)
      9   - CURLMOPT_PUSHFUNCTION (3)
     10   - CURLOPT_PIPEWAIT (3)
     11   - RFC 7540
     12 Protocol:
     13   - HTTP
     14 Added-in: 7.44.0
     15 ---
     16 
     17 # NAME
     18 
     19 CURLMOPT_PUSHDATA - pointer to pass to push callback
     20 
     21 # SYNOPSIS
     22 
     23 ~~~c
     24 #include <curl/curl.h>
     25 
     26 CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_PUSHDATA, void *pointer);
     27 ~~~
     28 
     29 # DESCRIPTION
     30 
     31 Set a *pointer* to pass as the last argument to the
     32 CURLMOPT_PUSHFUNCTION(3) callback. The pointer is not touched or used by
     33 libcurl itself, only passed on to the callback function.
     34 
     35 # DEFAULT
     36 
     37 NULL
     38 
     39 # %PROTOCOLS%
     40 
     41 # EXAMPLE
     42 
     43 ~~~c
     44 #include <string.h>
     45 
     46 /* only allow pushes for filenames starting with "push-" */
     47 int push_callback(CURL *parent,
     48                   CURL *easy,
     49                   size_t num_headers,
     50                   struct curl_pushheaders *headers,
     51                   void *clientp)
     52 {
     53   char *headp;
     54   int *transfers = (int *)clientp;
     55   FILE *out;
     56   headp = curl_pushheader_byname(headers, ":path");
     57   if(headp && !strncmp(headp, "/push-", 6)) {
     58     fprintf(stderr, "The PATH is %s\n", headp);
     59 
     60     /* save the push here */
     61     out = fopen("pushed-stream", "wb");
     62 
     63     /* write to this file */
     64     curl_easy_setopt(easy, CURLOPT_WRITEDATA, out);
     65 
     66     (*transfers)++; /* one more */
     67 
     68     return CURL_PUSH_OK;
     69   }
     70   return CURL_PUSH_DENY;
     71 }
     72 
     73 int main(void)
     74 {
     75   int counter;
     76   CURLM *multi = curl_multi_init();
     77   curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback);
     78   curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
     79 }
     80 ~~~
     81 
     82 # %AVAILABILITY%
     83 
     84 # RETURN VALUE
     85 
     86 curl_multi_setopt(3) returns a CURLMcode indicating success or error.
     87 
     88 CURLM_OK (0) means everything was OK, non-zero means an error occurred, see
     89 libcurl-errors(3).