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