libwebsockets
Lightweight C library for HTML5 websockets
lws-secure-streams-client.h
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 
34 /*
35  * lws_sspc_ apis... different process
36  */
37 
38 /*
39  * Helper translation so user code written to lws_ss_ can be built for
40  * lws_sspc_ in one step by #define LWS_SS_USE_SSPC before including
41  */
42 
43 struct lws_sspc_handle;
44 
45 #if defined(LWS_SS_USE_SSPC)
46 #define lws_ss_handle lws_sspc_handle
47 #define lws_ss_create lws_sspc_create
48 #define lws_ss_destroy lws_sspc_destroy
49 #define lws_ss_request_tx lws_sspc_request_tx
50 #define lws_ss_request_tx_len lws_sspc_request_tx_len
51 #define lws_ss_client_connect lws_sspc_client_connect
52 #define lws_ss_get_sequencer lws_sspc_get_sequencer
53 #define lws_ss_proxy_create lws_sspc_proxy_create
54 #define lws_ss_get_context lws_sspc_get_context
55 #define lws_ss_rideshare lws_sspc_rideshare
56 #define lws_ss_set_metadata lws_sspc_set_metadata
57 #define lws_ss_get_metadata lws_sspc_get_metadata
58 #define lws_ss_add_peer_tx_credit lws_sspc_add_peer_tx_credit
59 #define lws_ss_get_est_peer_tx_credit lws_sspc_get_est_peer_tx_credit
60 #define lws_ss_start_timeout lws_sspc_start_timeout
61 #define lws_ss_cancel_timeout lws_sspc_cancel_timeout
62 #define lws_ss_to_user_object lws_sspc_to_user_object
63 #define lws_ss_change_handlers lws_sspc_change_handlers
64 #define lws_smd_ss_rx_forward lws_smd_sspc_rx_forward
65 #define lws_ss_tag lws_sspc_tag
66 #define _lws_fi_user_ss_fi _lws_fi_user_sspc_fi
67 #define lwsl_ss_get_cx lwsl_sspc_get_cx
68 
69 LWS_VISIBLE LWS_EXTERN void
70 lws_log_prepend_sspc(struct lws_log_cx *cx, void *obj, char **p, char *e);
71 
72 LWS_VISIBLE LWS_EXTERN struct lws_log_cx *
73 lwsl_sspc_get_cx(struct lws_sspc_handle *ss);
74 
75 #undef lwsl_ss
76 #define lwsl_ss lwsl_sspc
77 
78 #undef lwsl_hexdump_ss
79 #define lwsl_hexdump_ss lwsl_hexdump_sspc
80 #endif
81 
82 #define lwsl_sspc(_h, _fil, ...) \
83  _lws_log_cx(lwsl_sspc_get_cx(_h), lws_log_prepend_sspc, _h, \
84  _fil, __func__, __VA_ARGS__)
85 
86 #define lwsl_hexdump_sspc(_h, _fil, _buf, _len) \
87  lwsl_hexdump_level_cx(lwsl_sspc_get_cx(_h), \
88  lws_log_prepend_sspc, \
89  _h, _fil, _buf, _len)
90 
91 /*
92  * lwsl_sspc
93  */
94 
95 #if (_LWS_ENABLED_LOGS & LLL_ERR)
96 #define lwsl_sspc_err(_w, ...) lwsl_sspc(_w, LLL_ERR, __VA_ARGS__)
97 #else
98 #define lwsl_sspc_err(_w, ...) do {} while(0)
99 #endif
100 
101 #if (_LWS_ENABLED_LOGS & LLL_WARN)
102 #define lwsl_sspc_warn(_w, ...) lwsl_sspc(_w, LLL_WARN, __VA_ARGS__)
103 #else
104 #define lwsl_sspc_warn(_w, ...) do {} while(0)
105 #endif
106 
107 #if (_LWS_ENABLED_LOGS & LLL_NOTICE)
108 #define lwsl_sspc_notice(_w, ...) lwsl_sspc(_w, LLL_NOTICE, __VA_ARGS__)
109 #else
110 #define lwsl_sspc_notice(_w, ...) do {} while(0)
111 #endif
112 
113 #if (_LWS_ENABLED_LOGS & LLL_INFO)
114 #define lwsl_sspc_info(_w, ...) lwsl_sspc(_w, LLL_INFO, __VA_ARGS__)
115 #else
116 #define lwsl_sspc_info(_w, ...) do {} while(0)
117 #endif
118 
119 #if (_LWS_ENABLED_LOGS & LLL_DEBUG)
120 #define lwsl_sspc_debug(_w, ...) lwsl_sspc(_w, LLL_DEBUG, __VA_ARGS__)
121 #else
122 #define lwsl_sspc_debug(_w, ...) do {} while(0)
123 #endif
124 
125 #if (_LWS_ENABLED_LOGS & LLL_PARSER)
126 #define lwsl_sspc_parser(_w, ...) lwsl_sspc(_w, LLL_PARSER, __VA_ARGS__)
127 #else
128 #define lwsl_sspc_parser(_w, ...) do {} while(0)
129 #endif
130 
131 #if (_LWS_ENABLED_LOGS & LLL_HEADER)
132 #define lwsl_sspc_header(_w, ...) lwsl_sspc(_w, LLL_HEADER, __VA_ARGS__)
133 #else
134 #define lwsl_sspc_header(_w, ...) do {} while(0)
135 #endif
136 
137 #if (_LWS_ENABLED_LOGS & LLL_EXT)
138 #define lwsl_sspc_ext(_w, ...) lwsl_sspc(_w, LLL_EXT, __VA_ARGS__)
139 #else
140 #define lwsl_sspc_ext(_w, ...) do {} while(0)
141 #endif
142 
143 #if (_LWS_ENABLED_LOGS & LLL_CLIENT)
144 #define lwsl_sspc_client(_w, ...) lwsl_sspc(_w, LLL_CLIENT, __VA_ARGS__)
145 #else
146 #define lwsl_sspc_client(_w, ...) do {} while(0)
147 #endif
148 
149 #if (_LWS_ENABLED_LOGS & LLL_LATENCY)
150 #define lwsl_sspc_latency(_w, ...) lwsl_sspc(_w, LLL_LATENCY, __VA_ARGS__)
151 #else
152 #define lwsl_sspc_latency(_w, ...) do {} while(0)
153 #endif
154 
155 #if (_LWS_ENABLED_LOGS & LLL_THREAD)
156 #define lwsl_sspc_thread(_w, ...) lwsl_sspc(_w, LLL_THREAD, __VA_ARGS__)
157 #else
158 #define lwsl_sspc_thread(_w, ...) do {} while(0)
159 #endif
160 
161 #if (_LWS_ENABLED_LOGS & LLL_USER)
162 #define lwsl_sspc_user(_w, ...) lwsl_sspc(_w, LLL_USER, __VA_ARGS__)
163 #else
164 #define lwsl_sspc_user(_w, ...) do {} while(0)
165 #endif
166 
167 #define lwsl_hexdump_sspc_err(_v, ...) lwsl_hexdump_sspc(_v, LLL_ERR, __VA_ARGS__)
168 #define lwsl_hexdump_sspc_warn(_v, ...) lwsl_hexdump_sspc(_v, LLL_WARN, __VA_ARGS__)
169 #define lwsl_hexdump_sspc_notice(_v, ...) lwsl_hexdump_sspc(_v, LLL_NOTICE, __VA_ARGS__)
170 #define lwsl_hexdump_sspc_info(_v, ...) lwsl_hexdump_sspc(_v, LLL_INFO, __VA_ARGS__)
171 #define lwsl_hexdump_sspc_debug(_v, ...) lwsl_hexdump_sspc(_v, LLL_DEBUG, __VA_ARGS__)
172 
173 
174 LWS_VISIBLE LWS_EXTERN int
175 lws_sspc_create(struct lws_context *context, int tsi, const lws_ss_info_t *ssi,
176  void *opaque_user_data, struct lws_sspc_handle **ppss,
177  struct lws_sequencer *seq_owner, const char **ppayload_fmt);
178 
186 LWS_VISIBLE LWS_EXTERN void
187 lws_sspc_destroy(struct lws_sspc_handle **ppss);
188 
198 LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t
199 lws_sspc_request_tx(struct lws_sspc_handle *pss);
200 
218 LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t
219 lws_sspc_request_tx_len(struct lws_sspc_handle *h, unsigned long len);
220 
229 LWS_VISIBLE LWS_EXTERN lws_ss_state_return_t
230 lws_sspc_client_connect(struct lws_sspc_handle *h);
231 
242 LWS_VISIBLE LWS_EXTERN struct lws_sequencer *
243 lws_sspc_get_sequencer(struct lws_sspc_handle *h);
244 
253 LWS_VISIBLE LWS_EXTERN int
254 lws_sspc_proxy_create(struct lws_context *context);
255 
265 LWS_VISIBLE LWS_EXTERN struct lws_context *
266 lws_sspc_get_context(struct lws_sspc_handle *h);
267 
268 LWS_VISIBLE extern const struct lws_protocols lws_sspc_protocols[2];
269 
270 LWS_VISIBLE LWS_EXTERN const char *
271 lws_sspc_rideshare(struct lws_sspc_handle *h);
272 
273 
297 LWS_VISIBLE LWS_EXTERN int
298 lws_sspc_set_metadata(struct lws_sspc_handle *h, const char *name,
299  const void *value, size_t len);
300 
301 LWS_VISIBLE LWS_EXTERN int
302 lws_sspc_get_metadata(struct lws_sspc_handle *h, const char *name,
303  const void **value, size_t *len);
304 
305 LWS_VISIBLE LWS_EXTERN int
306 lws_sspc_add_peer_tx_credit(struct lws_sspc_handle *h, int32_t add);
307 
308 LWS_VISIBLE LWS_EXTERN int
309 lws_sspc_get_est_peer_tx_credit(struct lws_sspc_handle *h);
310 
311 LWS_VISIBLE LWS_EXTERN void
312 lws_sspc_start_timeout(struct lws_sspc_handle *h, unsigned int timeout_ms);
313 
314 LWS_VISIBLE LWS_EXTERN void
315 lws_sspc_cancel_timeout(struct lws_sspc_handle *h);
316 
317 LWS_VISIBLE LWS_EXTERN void *
318 lws_sspc_to_user_object(struct lws_sspc_handle *h);
319 
320 LWS_VISIBLE LWS_EXTERN void
321 lws_sspc_change_handlers(struct lws_sspc_handle *h,
322  lws_ss_state_return_t (*rx)(void *userobj, const uint8_t *buf,
323  size_t len, int flags),
324  lws_ss_state_return_t (*tx)(void *userobj, lws_ss_tx_ordinal_t ord,
325  uint8_t *buf, size_t *len, int *flags),
326  lws_ss_state_return_t (*state)(void *userobj, void *h_src
327  /* ss handle type */,
328  lws_ss_constate_t state,
329  lws_ss_tx_ordinal_t ack));
330 
331 const char *
332 lws_sspc_tag(struct lws_sspc_handle *h);
Definition: lws-logs.h:80
Definition: lws-protocols-plugins.h:44
const char * name
Definition: lws-protocols-plugins.h:45
Definition: lws-secure-streams.h:364