libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-secure-streams-client.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 *
24 * This is the headers for secure stream api variants that deal with clients in
25 * different threads or even different processes.
26 *
27 * lws_ss_ when client is directly using the event loop
28 * lws_sstc_ when client is in a different thread to the event loop
29 * lws_sspc_ when client is in a different process to the event loop
30 *
31 * The client api is almost the same except the slightly diffent names.
32 *
33 * This header is included as part of libwebsockets.h, for link against the
34 * libwebsockets library.
35 */
36
37/*
38 * lws_sspc_ apis... different process
39 */
40
41/*
42 * The longest streamtype string (excluding NUL) that the serialization to
43 * the proxy can carry; lws_sspc_create() refuses longer streamtypes.
44 */
45#define LWS_SS_SER_STREAMTYPE_MAX_LEN 31
46
47/*
48 * Helper translation so user code written to lws_ss_ can be built for
49 * lws_sspc_ in one step by #define LWS_SS_USE_SSPC before including
50 */
51
52
53struct lws_sspc_handle;
54
55#if defined(LWS_SS_USE_SSPC)
56#define lws_ss_handle lws_sspc_handle
57#define lws_ss_create lws_sspc_create
58#define lws_ss_destroy lws_sspc_destroy
59#define lws_ss_request_tx lws_sspc_request_tx
60#define lws_ss_request_tx_len lws_sspc_request_tx_len
61#define lws_ss_client_connect lws_sspc_client_connect
62#define lws_ss_get_sequencer lws_sspc_get_sequencer
63#define lws_ss_proxy_create lws_sspc_proxy_create
64#define lws_ss_get_context lws_sspc_get_context
65#define lws_ss_rideshare lws_sspc_rideshare
66#define lws_ss_set_metadata lws_sspc_set_metadata
67#define lws_ss_get_metadata lws_sspc_get_metadata
68#define lws_ss_add_peer_tx_credit lws_sspc_add_peer_tx_credit
69#define lws_ss_get_est_peer_tx_credit lws_sspc_get_est_peer_tx_credit
70#define lws_ss_start_timeout lws_sspc_start_timeout
71#define lws_ss_cancel_timeout lws_sspc_cancel_timeout
72#define lws_ss_to_user_object lws_sspc_to_user_object
73#define lws_ss_change_handlers lws_sspc_change_handlers
74#define lws_smd_ss_rx_forward lws_smd_sspc_rx_forward
75#define lws_ss_server_ack lws_sspc_server_ack
76#define lws_ss_tag lws_sspc_tag
77#define _lws_fi_user_ss_fi _lws_fi_user_sspc_fi
78#define lwsl_ss_get_cx lwsl_sspc_get_cx
79
80#undef lwsl_ss
81#define lwsl_ss lwsl_sspc
82
83#undef lwsl_hexdump_ss
84#define lwsl_hexdump_ss lwsl_hexdump_sspc
85#endif
86
88lws_log_prepend_sspc(struct lws_log_cx *cx, void *obj, char **p, char *e);
89
91lwsl_sspc_get_cx(struct lws_sspc_handle *ss);
92
93#define lwsl_sspc(_h, _fil, ...) \
94 _lws_log_cx(lwsl_sspc_get_cx(_h), lws_log_prepend_sspc, _h, \
95 _fil, __func__, __VA_ARGS__)
96
97#define lwsl_hexdump_sspc(_h, _fil, _buf, _len) \
98 lwsl_hexdump_level_cx(lwsl_sspc_get_cx(_h), \
99 lws_log_prepend_sspc, \
100 _h, _fil, _buf, _len)
101
102/*
103 * lwsl_sspc
104 */
105
106#if (_LWS_ENABLED_LOGS & LLL_ERR)
107#define lwsl_sspc_err(_w, ...) lwsl_sspc(_w, LLL_ERR, __VA_ARGS__)
108#else
109#define lwsl_sspc_err(_w, ...) do {} while(0)
110#endif
111
112#if (_LWS_ENABLED_LOGS & LLL_WARN)
113#define lwsl_sspc_warn(_w, ...) lwsl_sspc(_w, LLL_WARN, __VA_ARGS__)
114#else
115#define lwsl_sspc_warn(_w, ...) do {} while(0)
116#endif
117
118#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
119#define lwsl_sspc_notice(_w, ...) lwsl_sspc(_w, LLL_NOTICE, __VA_ARGS__)
120#else
121#define lwsl_sspc_notice(_w, ...) do {} while(0)
122#endif
123
124#if (_LWS_ENABLED_LOGS & LLL_INFO)
125#define lwsl_sspc_info(_w, ...) lwsl_sspc(_w, LLL_INFO, __VA_ARGS__)
126#else
127#define lwsl_sspc_info(_w, ...) do {} while(0)
128#endif
129
130#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
131#define lwsl_sspc_debug(_w, ...) lwsl_sspc(_w, LLL_DEBUG, __VA_ARGS__)
132#else
133#define lwsl_sspc_debug(_w, ...) do {} while(0)
134#endif
135
136#if (_LWS_ENABLED_LOGS & LLL_PARSER)
137#define lwsl_sspc_parser(_w, ...) lwsl_sspc(_w, LLL_PARSER, __VA_ARGS__)
138#else
139#define lwsl_sspc_parser(_w, ...) do {} while(0)
140#endif
141
142#if (_LWS_ENABLED_LOGS & LLL_HEADER)
143#define lwsl_sspc_header(_w, ...) lwsl_sspc(_w, LLL_HEADER, __VA_ARGS__)
144#else
145#define lwsl_sspc_header(_w, ...) do {} while(0)
146#endif
147
148#if (_LWS_ENABLED_LOGS & LLL_EXT)
149#define lwsl_sspc_ext(_w, ...) lwsl_sspc(_w, LLL_EXT, __VA_ARGS__)
150#else
151#define lwsl_sspc_ext(_w, ...) do {} while(0)
152#endif
153
154#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
155#define lwsl_sspc_client(_w, ...) lwsl_sspc(_w, LLL_CLIENT, __VA_ARGS__)
156#else
157#define lwsl_sspc_client(_w, ...) do {} while(0)
158#endif
159
160#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
161#define lwsl_sspc_latency(_w, ...) lwsl_sspc(_w, LLL_LATENCY, __VA_ARGS__)
162#else
163#define lwsl_sspc_latency(_w, ...) do {} while(0)
164#endif
165
166#if (_LWS_ENABLED_LOGS & LLL_THREAD)
167#define lwsl_sspc_thread(_w, ...) lwsl_sspc(_w, LLL_THREAD, __VA_ARGS__)
168#else
169#define lwsl_sspc_thread(_w, ...) do {} while(0)
170#endif
171
172#if (_LWS_ENABLED_LOGS & LLL_USER)
173#define lwsl_sspc_user(_w, ...) lwsl_sspc(_w, LLL_USER, __VA_ARGS__)
174#else
175#define lwsl_sspc_user(_w, ...) do {} while(0)
176#endif
177
178#define lwsl_hexdump_sspc_err(_v, ...) lwsl_hexdump_sspc(_v, LLL_ERR, __VA_ARGS__)
179#define lwsl_hexdump_sspc_warn(_v, ...) lwsl_hexdump_sspc(_v, LLL_WARN, __VA_ARGS__)
180#define lwsl_hexdump_sspc_notice(_v, ...) lwsl_hexdump_sspc(_v, LLL_NOTICE, __VA_ARGS__)
181#define lwsl_hexdump_sspc_info(_v, ...) lwsl_hexdump_sspc(_v, LLL_INFO, __VA_ARGS__)
182#define lwsl_hexdump_sspc_debug(_v, ...) lwsl_hexdump_sspc(_v, LLL_DEBUG, __VA_ARGS__)
183
184/*
185 * How lws refers to your per-proxy-link private data... not allocated or freed
186 * by lws, nor used except to pass a pointer to it through to ops callbacks
187 * below. Should be set to your transport private instance object, it's set to
188 * the wsi for the wsi transport. Notice it is provided as a ** (ptr-to-ptr) in
189 * most apis.
190 */
191
192/*
193 * Stub context when using LWS_ONLY_SSPC
194 */
195
201
202#if defined(STANDALONE)
203#define lws_context lws_context_standalone
205#endif
206
208lws_sspc_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi,
209 void *opaque_user_data, struct lws_sspc_handle **ppss,
210 void *reserved, const char **ppayload_fmt);
211
220lws_sspc_destroy(struct lws_sspc_handle **ppss);
221
232lws_sspc_request_tx(struct lws_sspc_handle *pss);
233
252lws_sspc_request_tx_len(struct lws_sspc_handle *h, unsigned long len);
253
262lws_sspc_client_connect(struct lws_sspc_handle *h);
263
273lws_sspc_proxy_create(struct lws_context *context);
274
283
284LWS_VISIBLE LWS_EXTERN struct lws_context *
285lws_sspc_get_context(struct lws_sspc_handle *h);
286
287#if defined(LWS_WITH_NETWORK)
288LWS_VISIBLE LWS_EXTERN_FOR_DATA const struct lws_protocols lws_sspc_protocols[2];
289#endif
290
291LWS_VISIBLE LWS_EXTERN const char *
292lws_sspc_rideshare(struct lws_sspc_handle *h);
293
294
319lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name,
320 const void *value, size_t len);
321
323lws_sspc_get_metadata(struct lws_sspc_handle *h, const char *name,
324 const void **value, size_t *len);
325
327lws_sspc_add_peer_tx_credit(struct lws_sspc_handle *h, int32_t add);
328
330lws_sspc_get_est_peer_tx_credit(struct lws_sspc_handle *h);
331
333lws_sspc_start_timeout(struct lws_sspc_handle *h, unsigned int timeout_ms);
334
336lws_sspc_cancel_timeout(struct lws_sspc_handle *h);
337
339lws_sspc_to_user_object(struct lws_sspc_handle *h);
340
342lws_sspc_change_handlers(struct lws_sspc_handle *h,
344
346lws_sspc_server_ack(struct lws_sspc_handle *h, int nack);
347
348
349/*
350 * Helpers offered by lws to handle transport SSPC-side proxy link events
351 */
352
360LWS_VISIBLE LWS_EXTERN const char *
361lws_sspc_tag(struct lws_sspc_handle *h);
362
363
364#if defined(STANDALONE)
365#undef lws_context
366#endif
367
368
struct lws_dll2_owner lws_dll2_owner_t
lws_ss_state_return_t(* lws_sscb_state)(void *userobj, void *h_src, lws_ss_constate_t state, lws_ss_tx_ordinal_t ack)
struct lws_ss_info lws_ss_info_t
enum lws_ss_state_return lws_ss_state_return_t
lws_ss_state_return_t(* lws_sscb_tx)(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf, size_t *len, int *flags)
lws_ss_state_return_t(* lws_sscb_rx)(void *userobj, const uint8_t *buf, size_t len, int flags)
#define LWS_EXTERN_FOR_DATA
unsigned int uint32_t
#define LWS_EXTERN
#define LWS_VISIBLE
LWS_VISIBLE LWS_EXTERN int lws_sspc_get_est_peer_tx_credit(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN void lws_sspc_change_handlers(struct lws_sspc_handle *h, lws_sscb_rx rx, lws_sscb_tx tx, lws_sscb_state state)
LWS_VISIBLE LWS_EXTERN void lws_sspc_server_ack(struct lws_sspc_handle *h, int nack)
LWS_VISIBLE LWS_EXTERN int lws_sspc_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi, void *opaque_user_data, struct lws_sspc_handle **ppss, void *reserved, const char **ppayload_fmt)
LWS_VISIBLE LWS_EXTERN struct lws_log_cx * lwsl_sspc_get_cx(struct lws_sspc_handle *ss)
LWS_VISIBLE LWS_EXTERN int lws_sspc_get_metadata(struct lws_sspc_handle *h, const char *name, const void **value, size_t *len)
LWS_VISIBLE LWS_EXTERN const char * lws_sspc_rideshare(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN void lws_sspc_destroy(struct lws_sspc_handle **ppss)
LWS_VISIBLE LWS_EXTERN struct lws_context * lws_sspc_get_context(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN int lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name, const void *value, size_t len)
LWS_VISIBLE LWS_EXTERN int lws_sspc_proxy_create(struct lws_context *context)
LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t lws_sspc_request_tx_len(struct lws_sspc_handle *h, unsigned long len)
LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t lws_sspc_client_connect(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN void lws_sspc_cancel_timeout(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN void lws_sspc_start_timeout(struct lws_sspc_handle *h, unsigned int timeout_ms)
LWS_VISIBLE LWS_EXTERN void * lws_sspc_to_user_object(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN const char * lws_sspc_tag(struct lws_sspc_handle *h)
LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t lws_sspc_request_tx(struct lws_sspc_handle *pss)
LWS_VISIBLE LWS_EXTERN void lws_log_prepend_sspc(struct lws_log_cx *cx, void *obj, char **p, char *e)
LWS_VISIBLE LWS_EXTERN int lws_sspc_add_peer_tx_credit(struct lws_sspc_handle *h, int32_t add)
struct lws_txp_path_client lws_txp_path_client_t