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