xref: /curl/docs/libcurl/opts/CURLMOPT_PUSHDATA.md (revision 5a488251)
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
14Added-in: 7.44.0
15---
16
17# NAME
18
19CURLMOPT_PUSHDATA - pointer to pass to push callback
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_PUSHDATA, void *pointer);
27~~~
28
29# DESCRIPTION
30
31Set a *pointer* to pass as the last argument to the
32CURLMOPT_PUSHFUNCTION(3) callback. The pointer is not touched or used by
33libcurl itself, only passed on to the callback function.
34
35# DEFAULT
36
37NULL
38
39# %PROTOCOLS%
40
41# EXAMPLE
42
43~~~c
44#include <string.h>
45
46/* only allow pushes for filenames starting with "push-" */
47int 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
73int 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
86Returns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not.
87