xref: /aosp_15_r20/external/curl/docs/libcurl/curl_ws_meta.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_ws_meta
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - curl_easy_getinfo (3)
9*6236dae4SAndroid Build Coastguard Worker  - curl_easy_setopt (3)
10*6236dae4SAndroid Build Coastguard Worker  - curl_ws_recv (3)
11*6236dae4SAndroid Build Coastguard Worker  - curl_ws_send (3)
12*6236dae4SAndroid Build Coastguard Worker  - libcurl-ws (3)
13*6236dae4SAndroid Build Coastguard WorkerProtocol:
14*6236dae4SAndroid Build Coastguard Worker  - WS
15*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.86.0
16*6236dae4SAndroid Build Coastguard Worker---
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard Worker# NAME
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard Workercurl_ws_meta - meta data WebSocket information
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
23*6236dae4SAndroid Build Coastguard Worker
24*6236dae4SAndroid Build Coastguard Worker~~~c
25*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
26*6236dae4SAndroid Build Coastguard Worker
27*6236dae4SAndroid Build Coastguard Workerconst struct curl_ws_frame *curl_ws_meta(CURL *curl);
28*6236dae4SAndroid Build Coastguard Worker~~~
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
31*6236dae4SAndroid Build Coastguard Worker
32*6236dae4SAndroid Build Coastguard WorkerThis function call is EXPERIMENTAL.
33*6236dae4SAndroid Build Coastguard Worker
34*6236dae4SAndroid Build Coastguard WorkerWhen the write callback (CURLOPT_WRITEFUNCTION(3)) is invoked on
35*6236dae4SAndroid Build Coastguard Workerreceived WebSocket traffic, curl_ws_meta(3) can be called from within
36*6236dae4SAndroid Build Coastguard Workerthe callback to provide additional information about the current frame.
37*6236dae4SAndroid Build Coastguard Worker
38*6236dae4SAndroid Build Coastguard WorkerThis function only works from within the callback, and only when receiving
39*6236dae4SAndroid Build Coastguard WorkerWebSocket data.
40*6236dae4SAndroid Build Coastguard Worker
41*6236dae4SAndroid Build Coastguard WorkerThis function requires an easy handle as input argument for libcurl to know
42*6236dae4SAndroid Build Coastguard Workerwhat transfer the question is about, but as there is no such pointer provided
43*6236dae4SAndroid Build Coastguard Workerto the callback by libcurl itself, applications that want to use
44*6236dae4SAndroid Build Coastguard Workercurl_ws_meta(3) need to pass it on to the callback on its own.
45*6236dae4SAndroid Build Coastguard Worker
46*6236dae4SAndroid Build Coastguard Worker# struct curl_ws_frame
47*6236dae4SAndroid Build Coastguard Worker
48*6236dae4SAndroid Build Coastguard Worker~~~c
49*6236dae4SAndroid Build Coastguard Workerstruct curl_ws_frame {
50*6236dae4SAndroid Build Coastguard Worker  int age;
51*6236dae4SAndroid Build Coastguard Worker  int flags;
52*6236dae4SAndroid Build Coastguard Worker  curl_off_t offset;
53*6236dae4SAndroid Build Coastguard Worker  curl_off_t bytesleft;
54*6236dae4SAndroid Build Coastguard Worker};
55*6236dae4SAndroid Build Coastguard Worker~~~
56*6236dae4SAndroid Build Coastguard Worker
57*6236dae4SAndroid Build Coastguard Worker## `age`
58*6236dae4SAndroid Build Coastguard Worker
59*6236dae4SAndroid Build Coastguard WorkerThis field specify the age of this struct. It is always zero for now.
60*6236dae4SAndroid Build Coastguard Worker
61*6236dae4SAndroid Build Coastguard Worker## `flags`
62*6236dae4SAndroid Build Coastguard Worker
63*6236dae4SAndroid Build Coastguard WorkerThis is a bitmask with individual bits set that describes the WebSocket data.
64*6236dae4SAndroid Build Coastguard WorkerSee the list below.
65*6236dae4SAndroid Build Coastguard Worker
66*6236dae4SAndroid Build Coastguard Worker## `offset`
67*6236dae4SAndroid Build Coastguard Worker
68*6236dae4SAndroid Build Coastguard WorkerWhen this frame is a continuation of fragment data already delivered, this is
69*6236dae4SAndroid Build Coastguard Workerthe offset into the final fragment where this piece belongs.
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard Worker## `bytesleft`
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard WorkerIf this is not a complete fragment, the *bytesleft* field informs about how
74*6236dae4SAndroid Build Coastguard Workermany additional bytes are expected to arrive before this fragment is complete.
75*6236dae4SAndroid Build Coastguard Worker
76*6236dae4SAndroid Build Coastguard Worker# FLAGS
77*6236dae4SAndroid Build Coastguard Worker
78*6236dae4SAndroid Build Coastguard Worker## CURLWS_TEXT
79*6236dae4SAndroid Build Coastguard Worker
80*6236dae4SAndroid Build Coastguard WorkerThe buffer contains text data. Note that this makes a difference to WebSocket
81*6236dae4SAndroid Build Coastguard Workerbut libcurl itself does not make any verification of the content or
82*6236dae4SAndroid Build Coastguard Workerprecautions that you actually receive valid UTF-8 content.
83*6236dae4SAndroid Build Coastguard Worker
84*6236dae4SAndroid Build Coastguard Worker## CURLWS_BINARY
85*6236dae4SAndroid Build Coastguard Worker
86*6236dae4SAndroid Build Coastguard WorkerThis is binary data.
87*6236dae4SAndroid Build Coastguard Worker
88*6236dae4SAndroid Build Coastguard Worker## CURLWS_CONT
89*6236dae4SAndroid Build Coastguard Worker
90*6236dae4SAndroid Build Coastguard WorkerThis is not the final fragment of the message, it implies that there is
91*6236dae4SAndroid Build Coastguard Workeranother fragment coming as part of the same message.
92*6236dae4SAndroid Build Coastguard Worker
93*6236dae4SAndroid Build Coastguard Worker## CURLWS_CLOSE
94*6236dae4SAndroid Build Coastguard Worker
95*6236dae4SAndroid Build Coastguard WorkerThis transfer is now closed.
96*6236dae4SAndroid Build Coastguard Worker
97*6236dae4SAndroid Build Coastguard Worker## CURLWS_PING
98*6236dae4SAndroid Build Coastguard Worker
99*6236dae4SAndroid Build Coastguard WorkerThis as an incoming ping message, that expects a pong response.
100*6236dae4SAndroid Build Coastguard Worker
101*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
102*6236dae4SAndroid Build Coastguard Worker
103*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
104*6236dae4SAndroid Build Coastguard Worker
105*6236dae4SAndroid Build Coastguard Worker~~~c
106*6236dae4SAndroid Build Coastguard Worker
107*6236dae4SAndroid Build Coastguard Worker/* we pass a pointer to this struct to the callback */
108*6236dae4SAndroid Build Coastguard Workerstruct customdata {
109*6236dae4SAndroid Build Coastguard Worker  CURL *easy;
110*6236dae4SAndroid Build Coastguard Worker  void *ptr;
111*6236dae4SAndroid Build Coastguard Worker};
112*6236dae4SAndroid Build Coastguard Worker
113*6236dae4SAndroid Build Coastguard Workerstatic size_t writecb(unsigned char *buffer,
114*6236dae4SAndroid Build Coastguard Worker                      size_t size, size_t nitems, void *p)
115*6236dae4SAndroid Build Coastguard Worker{
116*6236dae4SAndroid Build Coastguard Worker  struct customdata *c = (struct customdata *)p;
117*6236dae4SAndroid Build Coastguard Worker  const struct curl_ws_frame *m = curl_ws_meta(c->easy);
118*6236dae4SAndroid Build Coastguard Worker
119*6236dae4SAndroid Build Coastguard Worker  printf("flags: %x\n", m->flags);
120*6236dae4SAndroid Build Coastguard Worker}
121*6236dae4SAndroid Build Coastguard Worker
122*6236dae4SAndroid Build Coastguard Workerint main(void)
123*6236dae4SAndroid Build Coastguard Worker{
124*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
125*6236dae4SAndroid Build Coastguard Worker  if(curl) {
126*6236dae4SAndroid Build Coastguard Worker    struct customdata custom;
127*6236dae4SAndroid Build Coastguard Worker    custom.easy = curl;
128*6236dae4SAndroid Build Coastguard Worker    custom.ptr = NULL;
129*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
130*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &custom);
131*6236dae4SAndroid Build Coastguard Worker
132*6236dae4SAndroid Build Coastguard Worker    curl_easy_perform(curl);
133*6236dae4SAndroid Build Coastguard Worker
134*6236dae4SAndroid Build Coastguard Worker  }
135*6236dae4SAndroid Build Coastguard Worker}
136*6236dae4SAndroid Build Coastguard Worker~~~
137*6236dae4SAndroid Build Coastguard Worker
138*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
139*6236dae4SAndroid Build Coastguard Worker
140*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
141*6236dae4SAndroid Build Coastguard Worker
142*6236dae4SAndroid Build Coastguard WorkerThis function returns a pointer to a *curl_ws_frame* struct with read-only
143*6236dae4SAndroid Build Coastguard Workerinformation that is valid for this specific callback invocation. If it cannot
144*6236dae4SAndroid Build Coastguard Workerreturn this information, or if the function is called in the wrong context, it
145*6236dae4SAndroid Build Coastguard Workerreturns NULL.
146