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/* sspc always takes a copy of the metadata value */
68#define lws_ss_alloc_set_metadata lws_sspc_set_metadata
69#define lws_ss_get_metadata lws_sspc_get_metadata
70#define lws_ss_add_peer_tx_credit lws_sspc_add_peer_tx_credit
71#define lws_ss_get_est_peer_tx_credit lws_sspc_get_est_peer_tx_credit
72#define lws_ss_start_timeout lws_sspc_start_timeout
73#define lws_ss_cancel_timeout lws_sspc_cancel_timeout
74#define lws_ss_to_user_object lws_sspc_to_user_object
75#define lws_ss_change_handlers lws_sspc_change_handlers
76#define lws_smd_ss_rx_forward lws_smd_sspc_rx_forward
77#define lws_ss_server_ack lws_sspc_server_ack
78#define lws_ss_tag lws_sspc_tag
79#define _lws_fi_user_ss_fi _lws_fi_user_sspc_fi
80#define lwsl_ss_get_cx lwsl_sspc_get_cx
81
82#undef lwsl_ss
83#define lwsl_ss lwsl_sspc
84
85#undef lwsl_hexdump_ss
86#define lwsl_hexdump_ss lwsl_hexdump_sspc
87#endif
88
90lws_log_prepend_sspc(struct lws_log_cx *cx, void *obj, char **p, char *e);
91
93lwsl_sspc_get_cx(struct lws_sspc_handle *ss);
94
95#define lwsl_sspc(_h, _fil, ...) \
96 _lws_log_cx(lwsl_sspc_get_cx(_h), lws_log_prepend_sspc, _h, \
97 _fil, __func__, __VA_ARGS__)
98
99#define lwsl_hexdump_sspc(_h, _fil, _buf, _len) \
100 lwsl_hexdump_level_cx(lwsl_sspc_get_cx(_h), \
101 lws_log_prepend_sspc, \
102 _h, _fil, _buf, _len)
103
104/*
105 * lwsl_sspc
106 */
107
108#if (_LWS_ENABLED_LOGS & LLL_ERR)
109#define lwsl_sspc_err(_w, ...) lwsl_sspc(_w, LLL_ERR, __VA_ARGS__)
110#else
111#define lwsl_sspc_err(_w, ...) do {} while(0)
112#endif
113
114#if (_LWS_ENABLED_LOGS & LLL_WARN)
115#define lwsl_sspc_warn(_w, ...) lwsl_sspc(_w, LLL_WARN, __VA_ARGS__)
116#else
117#define lwsl_sspc_warn(_w, ...) do {} while(0)
118#endif
119
120#if (_LWS_ENABLED_LOGS & LLL_NOTICE)
121#define lwsl_sspc_notice(_w, ...) lwsl_sspc(_w, LLL_NOTICE, __VA_ARGS__)
122#else
123#define lwsl_sspc_notice(_w, ...) do {} while(0)
124#endif
125
126#if (_LWS_ENABLED_LOGS & LLL_INFO)
127#define lwsl_sspc_info(_w, ...) lwsl_sspc(_w, LLL_INFO, __VA_ARGS__)
128#else
129#define lwsl_sspc_info(_w, ...) do {} while(0)
130#endif
131
132#if (_LWS_ENABLED_LOGS & LLL_DEBUG)
133#define lwsl_sspc_debug(_w, ...) lwsl_sspc(_w, LLL_DEBUG, __VA_ARGS__)
134#else
135#define lwsl_sspc_debug(_w, ...) do {} while(0)
136#endif
137
138#if (_LWS_ENABLED_LOGS & LLL_PARSER)
139#define lwsl_sspc_parser(_w, ...) lwsl_sspc(_w, LLL_PARSER, __VA_ARGS__)
140#else
141#define lwsl_sspc_parser(_w, ...) do {} while(0)
142#endif
143
144#if (_LWS_ENABLED_LOGS & LLL_HEADER)
145#define lwsl_sspc_header(_w, ...) lwsl_sspc(_w, LLL_HEADER, __VA_ARGS__)
146#else
147#define lwsl_sspc_header(_w, ...) do {} while(0)
148#endif
149
150#if (_LWS_ENABLED_LOGS & LLL_EXT)
151#define lwsl_sspc_ext(_w, ...) lwsl_sspc(_w, LLL_EXT, __VA_ARGS__)
152#else
153#define lwsl_sspc_ext(_w, ...) do {} while(0)
154#endif
155
156#if (_LWS_ENABLED_LOGS & LLL_CLIENT)
157#define lwsl_sspc_client(_w, ...) lwsl_sspc(_w, LLL_CLIENT, __VA_ARGS__)
158#else
159#define lwsl_sspc_client(_w, ...) do {} while(0)
160#endif
161
162#if (_LWS_ENABLED_LOGS & LLL_LATENCY)
163#define lwsl_sspc_latency(_w, ...) lwsl_sspc(_w, LLL_LATENCY, __VA_ARGS__)
164#else
165#define lwsl_sspc_latency(_w, ...) do {} while(0)
166#endif
167
168#if (_LWS_ENABLED_LOGS & LLL_THREAD)
169#define lwsl_sspc_thread(_w, ...) lwsl_sspc(_w, LLL_THREAD, __VA_ARGS__)
170#else
171#define lwsl_sspc_thread(_w, ...) do {} while(0)
172#endif
173
174#if (_LWS_ENABLED_LOGS & LLL_USER)
175#define lwsl_sspc_user(_w, ...) lwsl_sspc(_w, LLL_USER, __VA_ARGS__)
176#else
177#define lwsl_sspc_user(_w, ...) do {} while(0)
178#endif
179
180#define lwsl_hexdump_sspc_err(_v, ...) lwsl_hexdump_sspc(_v, LLL_ERR, __VA_ARGS__)
181#define lwsl_hexdump_sspc_warn(_v, ...) lwsl_hexdump_sspc(_v, LLL_WARN, __VA_ARGS__)
182#define lwsl_hexdump_sspc_notice(_v, ...) lwsl_hexdump_sspc(_v, LLL_NOTICE, __VA_ARGS__)
183#define lwsl_hexdump_sspc_info(_v, ...) lwsl_hexdump_sspc(_v, LLL_INFO, __VA_ARGS__)
184#define lwsl_hexdump_sspc_debug(_v, ...) lwsl_hexdump_sspc(_v, LLL_DEBUG, __VA_ARGS__)
185
186/*
187 * How lws refers to your per-proxy-link private data... not allocated or freed
188 * by lws, nor used except to pass a pointer to it through to ops callbacks
189 * below. Should be set to your transport private instance object, it's set to
190 * the wsi for the wsi transport. Notice it is provided as a ** (ptr-to-ptr) in
191 * most apis.
192 */
193
194/*
195 * Stub context when using LWS_ONLY_SSPC
196 */
197
203
204#if defined(STANDALONE)
205#define lws_context lws_context_standalone
207#endif
208
210lws_sspc_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi,
211 void *opaque_user_data, struct lws_sspc_handle **ppss,
212 void *reserved, const char **ppayload_fmt);
213
222lws_sspc_destroy(struct lws_sspc_handle **ppss);
223
234lws_sspc_request_tx(struct lws_sspc_handle *pss);
235
254lws_sspc_request_tx_len(struct lws_sspc_handle *h, unsigned long len);
255
264lws_sspc_client_connect(struct lws_sspc_handle *h);
265
275lws_sspc_proxy_create(struct lws_context *context);
276
285
286LWS_VISIBLE LWS_EXTERN struct lws_context *
287lws_sspc_get_context(struct lws_sspc_handle *h);
288
289#if defined(LWS_WITH_NETWORK)
290LWS_VISIBLE LWS_EXTERN_FOR_DATA const struct lws_protocols lws_sspc_protocols[2];
291#endif
292
293LWS_VISIBLE LWS_EXTERN const char *
294lws_sspc_rideshare(struct lws_sspc_handle *h);
295
296
321lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name,
322 const void *value, size_t len);
323
325lws_sspc_get_metadata(struct lws_sspc_handle *h, const char *name,
326 const void **value, size_t *len);
327
329lws_sspc_add_peer_tx_credit(struct lws_sspc_handle *h, int32_t add);
330
332lws_sspc_get_est_peer_tx_credit(struct lws_sspc_handle *h);
333
335lws_sspc_start_timeout(struct lws_sspc_handle *h, unsigned int timeout_ms);
336
338lws_sspc_cancel_timeout(struct lws_sspc_handle *h);
339
341lws_sspc_to_user_object(struct lws_sspc_handle *h);
342
344lws_sspc_change_handlers(struct lws_sspc_handle *h,
346
348lws_sspc_server_ack(struct lws_sspc_handle *h, int nack);
349
350
351/*
352 * Helpers offered by lws to handle transport SSPC-side proxy link events
353 */
354
362LWS_VISIBLE LWS_EXTERN const char *
363lws_sspc_tag(struct lws_sspc_handle *h);
364
365
366#if defined(STANDALONE)
367#undef lws_context
368#endif
369
370
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