opal-up 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +209 -0
- data/README.md +108 -23
- data/bin/up +5 -22
- data/bin/up_bun +5 -16
- data/bin/up_cluster +12 -0
- data/bin/up_node +12 -0
- data/bin/up_node_cluster +12 -0
- data/bin/up_ruby +4 -0
- data/bin/up_ruby_cluster +4 -0
- data/ext/up_ext/App.h +606 -0
- data/ext/up_ext/AsyncSocket.h +355 -0
- data/ext/up_ext/AsyncSocketData.h +87 -0
- data/ext/up_ext/BloomFilter.h +83 -0
- data/ext/up_ext/ChunkedEncoding.h +236 -0
- data/ext/up_ext/ClientApp.h +36 -0
- data/ext/up_ext/HttpContext.h +502 -0
- data/ext/up_ext/HttpContextData.h +56 -0
- data/ext/up_ext/HttpErrors.h +53 -0
- data/ext/up_ext/HttpParser.h +680 -0
- data/ext/up_ext/HttpResponse.h +578 -0
- data/ext/up_ext/HttpResponseData.h +95 -0
- data/ext/up_ext/HttpRouter.h +380 -0
- data/ext/up_ext/Loop.h +204 -0
- data/ext/up_ext/LoopData.h +112 -0
- data/ext/up_ext/MoveOnlyFunction.h +377 -0
- data/ext/up_ext/PerMessageDeflate.h +315 -0
- data/ext/up_ext/ProxyParser.h +163 -0
- data/ext/up_ext/QueryParser.h +120 -0
- data/ext/up_ext/TopicTree.h +363 -0
- data/ext/up_ext/Utilities.h +66 -0
- data/ext/up_ext/WebSocket.h +381 -0
- data/ext/up_ext/WebSocketContext.h +434 -0
- data/ext/up_ext/WebSocketContextData.h +109 -0
- data/ext/up_ext/WebSocketData.h +86 -0
- data/ext/up_ext/WebSocketExtensions.h +256 -0
- data/ext/up_ext/WebSocketHandshake.h +145 -0
- data/ext/up_ext/WebSocketProtocol.h +506 -0
- data/ext/up_ext/bsd.c +767 -0
- data/ext/up_ext/bsd.h +109 -0
- data/ext/up_ext/context.c +524 -0
- data/ext/up_ext/epoll_kqueue.c +458 -0
- data/ext/up_ext/epoll_kqueue.h +67 -0
- data/ext/up_ext/extconf.rb +5 -0
- data/ext/up_ext/internal.h +224 -0
- data/ext/up_ext/libusockets.h +350 -0
- data/ext/up_ext/libuwebsockets.cpp +1374 -0
- data/ext/up_ext/libuwebsockets.h +260 -0
- data/ext/up_ext/loop.c +386 -0
- data/ext/up_ext/loop_data.h +38 -0
- data/ext/up_ext/socket.c +231 -0
- data/ext/up_ext/up_ext.c +278 -0
- data/lib/up/bun/rack_env.rb +104 -0
- data/lib/up/bun/rack_server.rb +25 -0
- data/lib/up/bun/server.rb +89 -0
- data/lib/up/bun/server_cli.rb +15 -0
- data/lib/up/cli.rb +151 -0
- data/lib/up/node/cluster.rb +39 -0
- data/lib/up/node/cluster_cli.rb +15 -0
- data/lib/up/node/rack_cluster.rb +25 -0
- data/lib/up/node/rack_env.rb +106 -0
- data/lib/up/node/rack_server.rb +25 -0
- data/lib/up/node/server.rb +84 -0
- data/lib/up/node/server_cli.rb +15 -0
- data/lib/up/ruby/cluster_cli.rb +10 -0
- data/lib/up/ruby/rack_cluster.rb +26 -0
- data/lib/up/ruby/rack_env.rb +97 -0
- data/lib/up/ruby/rack_server.rb +26 -0
- data/lib/up/ruby/server_cli.rb +10 -0
- data/lib/up/u_web_socket/cluster.rb +39 -0
- data/lib/up/u_web_socket/cluster_cli.rb +15 -0
- data/lib/up/u_web_socket/rack_cluster.rb +25 -0
- data/lib/up/u_web_socket/rack_env.rb +101 -0
- data/lib/up/u_web_socket/rack_server.rb +25 -0
- data/lib/up/u_web_socket/server.rb +82 -0
- data/lib/up/u_web_socket/server_cli.rb +15 -0
- data/lib/up/version.rb +1 -1
- metadata +96 -29
- data/.gitignore +0 -5
- data/Gemfile +0 -2
- data/example_rack_app/Gemfile +0 -3
- data/example_rack_app/config.ru +0 -6
- data/example_rack_app/rack_app.rb +0 -5
- data/example_roda_app/Gemfile +0 -6
- data/example_roda_app/config.ru +0 -6
- data/example_roda_app/roda_app.rb +0 -35
- data/example_sinatra_app/Gemfile +0 -6
- data/example_sinatra_app/config.ru +0 -6
- data/example_sinatra_app/sinatra_app.rb +0 -7
- data/lib/up/bun.rb +0 -91
- data/lib/up/bun_cli.rb +0 -32
- data/lib/up/bun_rack.rb +0 -19
- data/lib/up/bun_rack_env.rb +0 -102
- data/lib/up/u_web_socket.rb +0 -83
- data/lib/up/u_web_socket_cluster.rb +0 -89
- data/lib/up/uws_cli.rb +0 -32
- data/lib/up/uws_rack.rb +0 -19
- data/lib/up/uws_rack_env.rb +0 -99
- data/lib/up-bun.rb +0 -7
- data/lib/up-node.rb +0 -7
- data/opal-up.gemspec +0 -27
- data/up_logo.svg +0 -256
@@ -0,0 +1,1374 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2022 Ciro Spaciari
|
3
|
+
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
10
|
+
*
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
12
|
+
* copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
* SOFTWARE.
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include "libuwebsockets.h"
|
24
|
+
#include <string_view>
|
25
|
+
#include "App.h"
|
26
|
+
#include "ClientApp.h"
|
27
|
+
#include <optional>
|
28
|
+
extern "C"
|
29
|
+
{
|
30
|
+
|
31
|
+
uws_app_t *uws_create_app(int ssl, struct us_socket_context_options_t options)
|
32
|
+
{
|
33
|
+
if (ssl)
|
34
|
+
{
|
35
|
+
uWS::SocketContextOptions sco;
|
36
|
+
sco.ca_file_name = options.ca_file_name;
|
37
|
+
sco.cert_file_name = options.cert_file_name;
|
38
|
+
sco.dh_params_file_name = options.dh_params_file_name;
|
39
|
+
sco.key_file_name = options.key_file_name;
|
40
|
+
sco.passphrase = options.passphrase;
|
41
|
+
sco.ssl_prefer_low_memory_usage = options.ssl_prefer_low_memory_usage;
|
42
|
+
sco.ssl_ciphers = options.ssl_ciphers;
|
43
|
+
|
44
|
+
return (uws_app_t *)new uWS::SSLApp(sco);
|
45
|
+
}
|
46
|
+
|
47
|
+
return (uws_app_t *)new uWS::App();
|
48
|
+
}
|
49
|
+
|
50
|
+
void uws_app_get(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
51
|
+
{
|
52
|
+
if (ssl)
|
53
|
+
{
|
54
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
55
|
+
if (handler == nullptr)
|
56
|
+
{
|
57
|
+
uwsApp->get(pattern, nullptr);
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
uwsApp->get(pattern, [handler, user_data](auto *res, auto *req)
|
61
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
62
|
+
}
|
63
|
+
else
|
64
|
+
{
|
65
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
66
|
+
if (handler == nullptr)
|
67
|
+
{
|
68
|
+
uwsApp->get(pattern, nullptr);
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
uwsApp->get(pattern, [handler, user_data](auto *res, auto *req)
|
72
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
73
|
+
}
|
74
|
+
}
|
75
|
+
void uws_app_post(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
76
|
+
{
|
77
|
+
|
78
|
+
if (ssl)
|
79
|
+
{
|
80
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
81
|
+
if (handler == nullptr)
|
82
|
+
{
|
83
|
+
uwsApp->post(pattern, nullptr);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
uwsApp->post(pattern, [handler, user_data](auto *res, auto *req)
|
87
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
88
|
+
}
|
89
|
+
else
|
90
|
+
{
|
91
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
92
|
+
if (handler == nullptr)
|
93
|
+
{
|
94
|
+
uwsApp->post(pattern, nullptr);
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
uwsApp->post(pattern, [handler, user_data](auto *res, auto *req)
|
98
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
99
|
+
}
|
100
|
+
}
|
101
|
+
void uws_app_options(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
102
|
+
{
|
103
|
+
if (ssl)
|
104
|
+
{
|
105
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
106
|
+
if (handler == nullptr)
|
107
|
+
{
|
108
|
+
uwsApp->options(pattern, nullptr);
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
uwsApp->options(pattern, [handler, user_data](auto *res, auto *req)
|
112
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
113
|
+
}
|
114
|
+
else
|
115
|
+
{
|
116
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
117
|
+
if (handler == nullptr)
|
118
|
+
{
|
119
|
+
uwsApp->options(pattern, nullptr);
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
uwsApp->options(pattern, [handler, user_data](auto *res, auto *req)
|
123
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
124
|
+
}
|
125
|
+
}
|
126
|
+
void uws_app_delete(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
127
|
+
{
|
128
|
+
if (ssl)
|
129
|
+
{
|
130
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
131
|
+
if (handler == nullptr)
|
132
|
+
{
|
133
|
+
uwsApp->del(pattern, nullptr);
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
uwsApp->del(pattern, [handler, user_data](auto *res, auto *req)
|
137
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
138
|
+
}
|
139
|
+
else
|
140
|
+
{
|
141
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
142
|
+
if (handler == nullptr)
|
143
|
+
{
|
144
|
+
uwsApp->del(pattern, nullptr);
|
145
|
+
return;
|
146
|
+
}
|
147
|
+
uwsApp->del(pattern, [handler, user_data](auto *res, auto *req)
|
148
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
149
|
+
}
|
150
|
+
}
|
151
|
+
void uws_app_patch(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
152
|
+
{
|
153
|
+
if (ssl)
|
154
|
+
{
|
155
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
156
|
+
if (handler == nullptr)
|
157
|
+
{
|
158
|
+
uwsApp->patch(pattern, nullptr);
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
uwsApp->patch(pattern, [handler, user_data](auto *res, auto *req)
|
162
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
163
|
+
}
|
164
|
+
else
|
165
|
+
{
|
166
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
167
|
+
if (handler == nullptr)
|
168
|
+
{
|
169
|
+
uwsApp->patch(pattern, nullptr);
|
170
|
+
return;
|
171
|
+
}
|
172
|
+
uwsApp->patch(pattern, [handler, user_data](auto *res, auto *req)
|
173
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
174
|
+
}
|
175
|
+
}
|
176
|
+
void uws_app_put(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
177
|
+
{
|
178
|
+
if (ssl)
|
179
|
+
{
|
180
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
181
|
+
if (handler == nullptr)
|
182
|
+
{
|
183
|
+
uwsApp->put(pattern, nullptr);
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
uwsApp->put(pattern, [handler, user_data](auto *res, auto *req)
|
187
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
188
|
+
}
|
189
|
+
else
|
190
|
+
{
|
191
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
192
|
+
if (handler == nullptr)
|
193
|
+
{
|
194
|
+
uwsApp->put(pattern, nullptr);
|
195
|
+
return;
|
196
|
+
}
|
197
|
+
uwsApp->put(pattern, [handler, user_data](auto *res, auto *req)
|
198
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
199
|
+
}
|
200
|
+
}
|
201
|
+
void uws_app_head(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
202
|
+
{
|
203
|
+
if (ssl)
|
204
|
+
{
|
205
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
206
|
+
if (handler == nullptr)
|
207
|
+
{
|
208
|
+
uwsApp->head(pattern, nullptr);
|
209
|
+
return;
|
210
|
+
}
|
211
|
+
uwsApp->head(pattern, [handler, user_data](auto *res, auto *req)
|
212
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
213
|
+
}
|
214
|
+
else
|
215
|
+
{
|
216
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
217
|
+
if (handler == nullptr)
|
218
|
+
{
|
219
|
+
uwsApp->head(pattern, nullptr);
|
220
|
+
return;
|
221
|
+
}
|
222
|
+
uwsApp->head(pattern, [handler, user_data](auto *res, auto *req)
|
223
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
224
|
+
}
|
225
|
+
}
|
226
|
+
void uws_app_connect(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
227
|
+
{
|
228
|
+
if (ssl)
|
229
|
+
{
|
230
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
231
|
+
if (handler == nullptr)
|
232
|
+
{
|
233
|
+
uwsApp->connect(pattern, nullptr);
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
uwsApp->connect(pattern, [handler, user_data](auto *res, auto *req)
|
237
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
238
|
+
}
|
239
|
+
else
|
240
|
+
{
|
241
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
242
|
+
if (handler == nullptr)
|
243
|
+
{
|
244
|
+
uwsApp->connect(pattern, nullptr);
|
245
|
+
return;
|
246
|
+
}
|
247
|
+
uwsApp->connect(pattern, [handler, user_data](auto *res, auto *req)
|
248
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
void uws_app_trace(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
253
|
+
{
|
254
|
+
if (ssl)
|
255
|
+
{
|
256
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
257
|
+
if (handler == nullptr)
|
258
|
+
{
|
259
|
+
uwsApp->trace(pattern, nullptr);
|
260
|
+
return;
|
261
|
+
}
|
262
|
+
uwsApp->trace(pattern, [handler, user_data](auto *res, auto *req)
|
263
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
264
|
+
}
|
265
|
+
else
|
266
|
+
{
|
267
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
268
|
+
if (handler == nullptr)
|
269
|
+
{
|
270
|
+
uwsApp->trace(pattern, nullptr);
|
271
|
+
return;
|
272
|
+
}
|
273
|
+
uwsApp->trace(pattern, [handler, user_data](auto *res, auto *req)
|
274
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
275
|
+
}
|
276
|
+
}
|
277
|
+
void uws_app_any(int ssl, uws_app_t *app, const char *pattern, uws_method_handler handler, void *user_data)
|
278
|
+
{
|
279
|
+
if (ssl)
|
280
|
+
{
|
281
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
282
|
+
if (handler == nullptr)
|
283
|
+
{
|
284
|
+
uwsApp->any(pattern, nullptr);
|
285
|
+
return;
|
286
|
+
}
|
287
|
+
uwsApp->any(pattern, [handler, user_data](auto *res, auto *req)
|
288
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
289
|
+
}
|
290
|
+
else
|
291
|
+
{
|
292
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
293
|
+
if (handler == nullptr)
|
294
|
+
{
|
295
|
+
uwsApp->any(pattern, nullptr);
|
296
|
+
return;
|
297
|
+
}
|
298
|
+
uwsApp->any(pattern, [handler, user_data](auto *res, auto *req)
|
299
|
+
{ handler((uws_res_t *)res, (uws_req_t *)req, user_data); });
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
void uws_app_run(int ssl, uws_app_t *app)
|
304
|
+
{
|
305
|
+
if (ssl)
|
306
|
+
{
|
307
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
308
|
+
uwsApp->run();
|
309
|
+
}
|
310
|
+
else
|
311
|
+
{
|
312
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
313
|
+
uwsApp->run();
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
void uws_app_listen(int ssl, uws_app_t *app, int port, uws_listen_handler handler, void *user_data)
|
318
|
+
{
|
319
|
+
uws_app_listen_config_t config;
|
320
|
+
config.port = port;
|
321
|
+
config.host = nullptr;
|
322
|
+
config.options = 0;
|
323
|
+
|
324
|
+
if (ssl)
|
325
|
+
{
|
326
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
327
|
+
uwsApp->listen(port, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
|
328
|
+
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
|
329
|
+
}
|
330
|
+
else
|
331
|
+
{
|
332
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
333
|
+
|
334
|
+
uwsApp->listen(port, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
|
335
|
+
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
void uws_app_listen_with_config(int ssl, uws_app_t *app, uws_app_listen_config_t config, uws_listen_handler handler, void *user_data)
|
340
|
+
{
|
341
|
+
if (ssl)
|
342
|
+
{
|
343
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
344
|
+
uwsApp->listen(config.host, config.port, config.options, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
|
345
|
+
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
|
346
|
+
}
|
347
|
+
else
|
348
|
+
{
|
349
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
350
|
+
uwsApp->listen(config.host, config.port, config.options, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
|
351
|
+
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
|
352
|
+
}
|
353
|
+
}
|
354
|
+
|
355
|
+
/* callback, path to unix domain socket */
|
356
|
+
void uws_app_listen_domain(int ssl, uws_app_t *app, const char *domain, size_t domain_length, uws_listen_domain_handler handler, void *user_data)
|
357
|
+
{
|
358
|
+
|
359
|
+
if (ssl)
|
360
|
+
{
|
361
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
362
|
+
uwsApp->listen([handler, domain, domain_length, user_data](struct us_listen_socket_t *listen_socket)
|
363
|
+
{ handler((struct us_listen_socket_t *)listen_socket, domain, domain_length, 0, user_data); },
|
364
|
+
std::string(domain, domain_length));
|
365
|
+
}
|
366
|
+
else
|
367
|
+
{
|
368
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
369
|
+
|
370
|
+
uwsApp->listen([handler, domain, domain_length, user_data](struct us_listen_socket_t *listen_socket)
|
371
|
+
{ handler((struct us_listen_socket_t *)listen_socket, domain, domain_length, 0, user_data); },
|
372
|
+
std::string(domain, domain_length));
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
376
|
+
/* callback, path to unix domain socket */
|
377
|
+
void uws_app_listen_domain_with_options(int ssl, uws_app_t *app, const char *domain, size_t domain_length, int options, uws_listen_domain_handler handler, void *user_data)
|
378
|
+
{
|
379
|
+
|
380
|
+
if (ssl)
|
381
|
+
{
|
382
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
383
|
+
uwsApp->listen(
|
384
|
+
options, [handler, domain, domain_length, options, user_data](struct us_listen_socket_t *listen_socket)
|
385
|
+
{ handler((struct us_listen_socket_t *)listen_socket, domain, domain_length, options, user_data); },
|
386
|
+
std::string(domain, domain_length));
|
387
|
+
}
|
388
|
+
else
|
389
|
+
{
|
390
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
391
|
+
|
392
|
+
uwsApp->listen(
|
393
|
+
options, [handler, domain, domain_length, options, user_data](struct us_listen_socket_t *listen_socket)
|
394
|
+
{ handler((struct us_listen_socket_t *)listen_socket, domain, domain_length, options, user_data); },
|
395
|
+
std::string(domain, domain_length));
|
396
|
+
}
|
397
|
+
}
|
398
|
+
void uws_app_domain(int ssl, uws_app_t *app, const char *server_name, size_t server_name_length)
|
399
|
+
{
|
400
|
+
if (ssl)
|
401
|
+
{
|
402
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
403
|
+
uwsApp->domain(std::string(server_name, server_name_length));
|
404
|
+
}
|
405
|
+
else
|
406
|
+
{
|
407
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
408
|
+
uwsApp->domain(std::string(server_name, server_name_length));
|
409
|
+
}
|
410
|
+
}
|
411
|
+
void uws_app_close(int ssl, uws_app_t *app)
|
412
|
+
{
|
413
|
+
if (ssl)
|
414
|
+
{
|
415
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
416
|
+
uwsApp->close();
|
417
|
+
}
|
418
|
+
else
|
419
|
+
{
|
420
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
421
|
+
uwsApp->close();
|
422
|
+
}
|
423
|
+
}
|
424
|
+
|
425
|
+
void uws_app_destroy(int ssl, uws_app_t *app)
|
426
|
+
{
|
427
|
+
if (ssl)
|
428
|
+
{
|
429
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
430
|
+
delete uwsApp;
|
431
|
+
}
|
432
|
+
else
|
433
|
+
{
|
434
|
+
|
435
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
436
|
+
delete uwsApp;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
bool uws_constructor_failed(int ssl, uws_app_t *app)
|
441
|
+
{
|
442
|
+
if (ssl)
|
443
|
+
{
|
444
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
445
|
+
if (!uwsApp)
|
446
|
+
return true;
|
447
|
+
return uwsApp->constructorFailed();
|
448
|
+
}
|
449
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
450
|
+
if (!uwsApp)
|
451
|
+
return true;
|
452
|
+
return uwsApp->constructorFailed();
|
453
|
+
}
|
454
|
+
|
455
|
+
unsigned int uws_num_subscribers(int ssl, uws_app_t *app, const char *topic, size_t topic_length)
|
456
|
+
{
|
457
|
+
if (ssl)
|
458
|
+
{
|
459
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
460
|
+
return uwsApp->numSubscribers(std::string_view(topic, topic_length));
|
461
|
+
}
|
462
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
463
|
+
return uwsApp->numSubscribers(std::string_view(topic, topic_length));
|
464
|
+
}
|
465
|
+
bool uws_publish(int ssl, uws_app_t *app, const char *topic, size_t topic_length, const char *message, size_t message_length, uws_opcode_t opcode, bool compress)
|
466
|
+
{
|
467
|
+
if (ssl)
|
468
|
+
{
|
469
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
470
|
+
return uwsApp->publish(std::string_view(topic, topic_length), std::string_view(message, message_length), (uWS::OpCode)(unsigned char)opcode, compress);
|
471
|
+
}
|
472
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
473
|
+
return uwsApp->publish(std::string_view(topic, topic_length), std::string_view(message, message_length), (uWS::OpCode)(unsigned char)opcode, compress);
|
474
|
+
}
|
475
|
+
void *uws_get_native_handle(int ssl, uws_app_t *app)
|
476
|
+
{
|
477
|
+
if (ssl)
|
478
|
+
{
|
479
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
480
|
+
return uwsApp->getNativeHandle();
|
481
|
+
}
|
482
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
483
|
+
return uwsApp->getNativeHandle();
|
484
|
+
}
|
485
|
+
void uws_remove_server_name(int ssl, uws_app_t *app, const char *hostname_pattern, size_t hostname_pattern_length)
|
486
|
+
{
|
487
|
+
if (ssl)
|
488
|
+
{
|
489
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
490
|
+
uwsApp->removeServerName(std::string(hostname_pattern, hostname_pattern_length));
|
491
|
+
}
|
492
|
+
else
|
493
|
+
{
|
494
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
495
|
+
uwsApp->removeServerName(std::string(hostname_pattern, hostname_pattern_length));
|
496
|
+
}
|
497
|
+
}
|
498
|
+
void uws_add_server_name(int ssl, uws_app_t *app, const char *hostname_pattern, size_t hostname_pattern_length)
|
499
|
+
{
|
500
|
+
if (ssl)
|
501
|
+
{
|
502
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
503
|
+
uwsApp->addServerName(std::string(hostname_pattern, hostname_pattern_length));
|
504
|
+
}
|
505
|
+
else
|
506
|
+
{
|
507
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
508
|
+
uwsApp->addServerName(std::string(hostname_pattern, hostname_pattern_length));
|
509
|
+
}
|
510
|
+
}
|
511
|
+
void uws_add_server_name_with_options(int ssl, uws_app_t *app, const char *hostname_pattern, size_t hostname_pattern_length, struct us_socket_context_options_t options)
|
512
|
+
{
|
513
|
+
uWS::SocketContextOptions sco;
|
514
|
+
sco.ca_file_name = options.ca_file_name;
|
515
|
+
sco.cert_file_name = options.cert_file_name;
|
516
|
+
sco.dh_params_file_name = options.dh_params_file_name;
|
517
|
+
sco.key_file_name = options.key_file_name;
|
518
|
+
sco.passphrase = options.passphrase;
|
519
|
+
sco.ssl_prefer_low_memory_usage = options.ssl_prefer_low_memory_usage;
|
520
|
+
|
521
|
+
if (ssl)
|
522
|
+
{
|
523
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
524
|
+
uwsApp->addServerName(std::string(hostname_pattern, hostname_pattern_length), sco);
|
525
|
+
}
|
526
|
+
else
|
527
|
+
{
|
528
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
529
|
+
uwsApp->addServerName(std::string(hostname_pattern, hostname_pattern_length), sco);
|
530
|
+
}
|
531
|
+
}
|
532
|
+
|
533
|
+
void uws_missing_server_name(int ssl, uws_app_t *app, uws_missing_server_handler handler, void *user_data)
|
534
|
+
{
|
535
|
+
if (ssl)
|
536
|
+
{
|
537
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
538
|
+
uwsApp->missingServerName([handler, user_data](auto hostname)
|
539
|
+
{ handler(hostname, strlen(hostname), user_data); });
|
540
|
+
}
|
541
|
+
else
|
542
|
+
{
|
543
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
544
|
+
uwsApp->missingServerName([handler, user_data](auto hostname)
|
545
|
+
{ handler(hostname, strlen(hostname), user_data); });
|
546
|
+
}
|
547
|
+
}
|
548
|
+
void uws_filter(int ssl, uws_app_t *app, uws_filter_handler handler, void *user_data)
|
549
|
+
{
|
550
|
+
if (ssl)
|
551
|
+
{
|
552
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
553
|
+
uwsApp->filter([handler, user_data](auto res, auto i)
|
554
|
+
{ handler((uws_res_t *)res, i, user_data); });
|
555
|
+
}
|
556
|
+
else
|
557
|
+
{
|
558
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
559
|
+
|
560
|
+
uwsApp->filter([handler, user_data](auto res, auto i)
|
561
|
+
{ handler((uws_res_t *)res, i, user_data); });
|
562
|
+
}
|
563
|
+
}
|
564
|
+
|
565
|
+
void uws_ws(int ssl, uws_app_t *app, const char *pattern, uws_socket_behavior_t behavior, void *user_data)
|
566
|
+
{
|
567
|
+
if (ssl)
|
568
|
+
{
|
569
|
+
auto generic_handler = uWS::SSLApp::WebSocketBehavior<void *>{
|
570
|
+
.compression = (uWS::CompressOptions)(uint64_t)behavior.compression,
|
571
|
+
.maxPayloadLength = behavior.maxPayloadLength,
|
572
|
+
.idleTimeout = behavior.idleTimeout,
|
573
|
+
.maxBackpressure = behavior.maxBackpressure,
|
574
|
+
.closeOnBackpressureLimit = behavior.closeOnBackpressureLimit,
|
575
|
+
.resetIdleTimeoutOnSend = behavior.resetIdleTimeoutOnSend,
|
576
|
+
.sendPingsAutomatically = behavior.sendPingsAutomatically,
|
577
|
+
.maxLifetime = behavior.maxLifetime,
|
578
|
+
};
|
579
|
+
|
580
|
+
if (behavior.upgrade)
|
581
|
+
generic_handler.upgrade = [behavior, user_data](auto *res, auto *req, auto *context)
|
582
|
+
{
|
583
|
+
behavior.upgrade((uws_res_t *)res, (uws_req_t *)req, (uws_socket_context_t *)context, user_data);
|
584
|
+
};
|
585
|
+
if (behavior.open)
|
586
|
+
generic_handler.open = [behavior, user_data](auto *ws)
|
587
|
+
{
|
588
|
+
behavior.open((uws_websocket_t *)ws, user_data);
|
589
|
+
};
|
590
|
+
if (behavior.message)
|
591
|
+
generic_handler.message = [behavior, user_data](auto *ws, auto message, auto opcode)
|
592
|
+
{
|
593
|
+
behavior.message((uws_websocket_t *)ws, message.data(), message.length(), (uws_opcode_t)opcode, user_data);
|
594
|
+
};
|
595
|
+
if (behavior.drain)
|
596
|
+
generic_handler.drain = [behavior, user_data](auto *ws)
|
597
|
+
{
|
598
|
+
behavior.drain((uws_websocket_t *)ws, user_data);
|
599
|
+
};
|
600
|
+
if (behavior.ping)
|
601
|
+
generic_handler.ping = [behavior, user_data](auto *ws, auto message)
|
602
|
+
{
|
603
|
+
behavior.ping((uws_websocket_t *)ws, message.data(), message.length(), user_data);
|
604
|
+
};
|
605
|
+
if (behavior.pong)
|
606
|
+
generic_handler.pong = [behavior, user_data](auto *ws, auto message)
|
607
|
+
{
|
608
|
+
behavior.pong((uws_websocket_t *)ws, message.data(), message.length(), user_data);
|
609
|
+
};
|
610
|
+
if (behavior.close)
|
611
|
+
generic_handler.close = [behavior, user_data](auto *ws, int code, auto message)
|
612
|
+
{
|
613
|
+
behavior.close((uws_websocket_t *)ws, code, message.data(), message.length(), user_data);
|
614
|
+
};
|
615
|
+
if (behavior.subscription)
|
616
|
+
generic_handler.subscription = [behavior, user_data](auto *ws, auto topic, int subscribers, int old_subscribers)
|
617
|
+
{
|
618
|
+
behavior.subscription((uws_websocket_t *)ws, topic.data(), topic.length(), subscribers, old_subscribers, user_data);
|
619
|
+
};
|
620
|
+
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
|
621
|
+
|
622
|
+
uwsApp->ws<void *>(pattern, std::move(generic_handler));
|
623
|
+
}
|
624
|
+
else
|
625
|
+
{
|
626
|
+
auto generic_handler = uWS::App::WebSocketBehavior<void *>{
|
627
|
+
.compression = (uWS::CompressOptions)(uint64_t)behavior.compression,
|
628
|
+
.maxPayloadLength = behavior.maxPayloadLength,
|
629
|
+
.idleTimeout = behavior.idleTimeout,
|
630
|
+
.maxBackpressure = behavior.maxBackpressure,
|
631
|
+
.closeOnBackpressureLimit = behavior.closeOnBackpressureLimit,
|
632
|
+
.resetIdleTimeoutOnSend = behavior.resetIdleTimeoutOnSend,
|
633
|
+
.sendPingsAutomatically = behavior.sendPingsAutomatically,
|
634
|
+
.maxLifetime = behavior.maxLifetime,
|
635
|
+
};
|
636
|
+
|
637
|
+
if (behavior.upgrade)
|
638
|
+
generic_handler.upgrade = [behavior, user_data](auto *res, auto *req, auto *context)
|
639
|
+
{
|
640
|
+
behavior.upgrade((uws_res_t *)res, (uws_req_t *)req, (uws_socket_context_t *)context, user_data);
|
641
|
+
};
|
642
|
+
if (behavior.open)
|
643
|
+
generic_handler.open = [behavior, user_data](auto *ws)
|
644
|
+
{
|
645
|
+
behavior.open((uws_websocket_t *)ws, user_data);
|
646
|
+
};
|
647
|
+
if (behavior.message)
|
648
|
+
generic_handler.message = [behavior, user_data](auto *ws, auto message, auto opcode)
|
649
|
+
{
|
650
|
+
behavior.message((uws_websocket_t *)ws, message.data(), message.length(), (uws_opcode_t)opcode, user_data);
|
651
|
+
};
|
652
|
+
if (behavior.drain)
|
653
|
+
generic_handler.drain = [behavior, user_data](auto *ws)
|
654
|
+
{
|
655
|
+
behavior.drain((uws_websocket_t *)ws, user_data);
|
656
|
+
};
|
657
|
+
if (behavior.ping)
|
658
|
+
generic_handler.ping = [behavior, user_data](auto *ws, auto message)
|
659
|
+
{
|
660
|
+
behavior.ping((uws_websocket_t *)ws, message.data(), message.length(), user_data);
|
661
|
+
};
|
662
|
+
if (behavior.pong)
|
663
|
+
generic_handler.pong = [behavior, user_data](auto *ws, auto message)
|
664
|
+
{
|
665
|
+
behavior.pong((uws_websocket_t *)ws, message.data(), message.length(), user_data);
|
666
|
+
};
|
667
|
+
if (behavior.close)
|
668
|
+
generic_handler.close = [behavior, user_data](auto *ws, int code, auto message)
|
669
|
+
{
|
670
|
+
behavior.close((uws_websocket_t *)ws, code, message.data(), message.length(), user_data);
|
671
|
+
};
|
672
|
+
if (behavior.subscription)
|
673
|
+
generic_handler.subscription = [behavior, user_data](auto *ws, auto topic, int subscribers, int old_subscribers)
|
674
|
+
{
|
675
|
+
behavior.subscription((uws_websocket_t *)ws, topic.data(), topic.length(), subscribers, old_subscribers, user_data);
|
676
|
+
};
|
677
|
+
uWS::App *uwsApp = (uWS::App *)app;
|
678
|
+
uwsApp->ws<void *>(pattern, std::move(generic_handler));
|
679
|
+
}
|
680
|
+
}
|
681
|
+
|
682
|
+
void *uws_ws_get_user_data(int ssl, uws_websocket_t *ws)
|
683
|
+
{
|
684
|
+
if (ssl)
|
685
|
+
{
|
686
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
687
|
+
return *uws->getUserData();
|
688
|
+
}
|
689
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
690
|
+
return *uws->getUserData();
|
691
|
+
}
|
692
|
+
|
693
|
+
void uws_ws_close(int ssl, uws_websocket_t *ws)
|
694
|
+
{
|
695
|
+
if (ssl)
|
696
|
+
{
|
697
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
698
|
+
uws->close();
|
699
|
+
}
|
700
|
+
else
|
701
|
+
{
|
702
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
703
|
+
uws->close();
|
704
|
+
}
|
705
|
+
}
|
706
|
+
|
707
|
+
uws_sendstatus_t uws_ws_send(int ssl, uws_websocket_t *ws, const char *message, size_t length, uws_opcode_t opcode)
|
708
|
+
{
|
709
|
+
if (ssl)
|
710
|
+
{
|
711
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
712
|
+
return (uws_sendstatus_t)uws->send(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode);
|
713
|
+
}
|
714
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
715
|
+
return (uws_sendstatus_t)uws->send(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode);
|
716
|
+
}
|
717
|
+
|
718
|
+
uws_sendstatus_t uws_ws_send_with_options(int ssl, uws_websocket_t *ws, const char *message, size_t length, uws_opcode_t opcode, bool compress, bool fin)
|
719
|
+
{
|
720
|
+
if (ssl)
|
721
|
+
{
|
722
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
723
|
+
return (uws_sendstatus_t)uws->send(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode, compress, fin);
|
724
|
+
}
|
725
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
726
|
+
return (uws_sendstatus_t)uws->send(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode, compress, fin);
|
727
|
+
}
|
728
|
+
|
729
|
+
uws_sendstatus_t uws_ws_send_fragment(int ssl, uws_websocket_t *ws, const char *message, size_t length, bool compress)
|
730
|
+
{
|
731
|
+
if (ssl)
|
732
|
+
{
|
733
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
734
|
+
return (uws_sendstatus_t)uws->sendFragment(std::string_view(message, length), compress);
|
735
|
+
}
|
736
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
737
|
+
return (uws_sendstatus_t)uws->sendFragment(std::string_view(message, length), compress);
|
738
|
+
}
|
739
|
+
uws_sendstatus_t uws_ws_send_first_fragment(int ssl, uws_websocket_t *ws, const char *message, size_t length, bool compress)
|
740
|
+
{
|
741
|
+
if (ssl)
|
742
|
+
{
|
743
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
744
|
+
return (uws_sendstatus_t)uws->sendFirstFragment(std::string_view(message, length), uWS::OpCode::BINARY, compress);
|
745
|
+
}
|
746
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
747
|
+
return (uws_sendstatus_t)uws->sendFirstFragment(std::string_view(message, length), uWS::OpCode::BINARY, compress);
|
748
|
+
}
|
749
|
+
uws_sendstatus_t uws_ws_send_first_fragment_with_opcode(int ssl, uws_websocket_t *ws, const char *message, size_t length, uws_opcode_t opcode, bool compress)
|
750
|
+
{
|
751
|
+
if (ssl)
|
752
|
+
{
|
753
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
754
|
+
return (uws_sendstatus_t)uws->sendFirstFragment(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode, compress);
|
755
|
+
}
|
756
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
757
|
+
return (uws_sendstatus_t)uws->sendFirstFragment(std::string_view(message, length), (uWS::OpCode)(unsigned char)opcode, compress);
|
758
|
+
}
|
759
|
+
uws_sendstatus_t uws_ws_send_last_fragment(int ssl, uws_websocket_t *ws, const char *message, size_t length, bool compress)
|
760
|
+
{
|
761
|
+
if (ssl)
|
762
|
+
{
|
763
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
764
|
+
return (uws_sendstatus_t)uws->sendLastFragment(std::string_view(message, length), compress);
|
765
|
+
}
|
766
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
767
|
+
return (uws_sendstatus_t)uws->sendLastFragment(std::string_view(message, length), compress);
|
768
|
+
}
|
769
|
+
|
770
|
+
void uws_ws_end(int ssl, uws_websocket_t *ws, int code, const char *message, size_t length)
|
771
|
+
{
|
772
|
+
if (ssl)
|
773
|
+
{
|
774
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
775
|
+
uws->end(code, std::string_view(message, length));
|
776
|
+
}
|
777
|
+
else
|
778
|
+
{
|
779
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
780
|
+
uws->end(code, std::string_view(message, length));
|
781
|
+
}
|
782
|
+
}
|
783
|
+
|
784
|
+
void uws_ws_cork(int ssl, uws_websocket_t *ws, void (*handler)(void *user_data), void *user_data)
|
785
|
+
{
|
786
|
+
if (ssl)
|
787
|
+
{
|
788
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
789
|
+
uws->cork([handler, user_data]()
|
790
|
+
{ handler(user_data); });
|
791
|
+
}
|
792
|
+
else
|
793
|
+
{
|
794
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
795
|
+
|
796
|
+
uws->cork([handler, user_data]()
|
797
|
+
{ handler(user_data); });
|
798
|
+
}
|
799
|
+
}
|
800
|
+
bool uws_ws_subscribe(int ssl, uws_websocket_t *ws, const char *topic, size_t length)
|
801
|
+
{
|
802
|
+
if (ssl)
|
803
|
+
{
|
804
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
805
|
+
return uws->subscribe(std::string_view(topic, length));
|
806
|
+
}
|
807
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
808
|
+
return uws->subscribe(std::string_view(topic, length));
|
809
|
+
}
|
810
|
+
bool uws_ws_unsubscribe(int ssl, uws_websocket_t *ws, const char *topic, size_t length)
|
811
|
+
{
|
812
|
+
if (ssl)
|
813
|
+
{
|
814
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
815
|
+
return uws->unsubscribe(std::string_view(topic, length));
|
816
|
+
}
|
817
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
818
|
+
return uws->unsubscribe(std::string_view(topic, length));
|
819
|
+
}
|
820
|
+
|
821
|
+
bool uws_ws_is_subscribed(int ssl, uws_websocket_t *ws, const char *topic, size_t length)
|
822
|
+
{
|
823
|
+
if (ssl)
|
824
|
+
{
|
825
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
826
|
+
return uws->isSubscribed(std::string_view(topic, length));
|
827
|
+
}
|
828
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
829
|
+
return uws->isSubscribed(std::string_view(topic, length));
|
830
|
+
}
|
831
|
+
void uws_ws_iterate_topics(int ssl, uws_websocket_t *ws, void (*callback)(const char *topic, size_t length, void *user_data), void *user_data)
|
832
|
+
{
|
833
|
+
if (ssl)
|
834
|
+
{
|
835
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
836
|
+
uws->iterateTopics([callback, user_data](auto topic)
|
837
|
+
{ callback(topic.data(), topic.length(), user_data); });
|
838
|
+
}
|
839
|
+
else
|
840
|
+
{
|
841
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
842
|
+
|
843
|
+
uws->iterateTopics([callback, user_data](auto topic)
|
844
|
+
{ callback(topic.data(), topic.length(), user_data); });
|
845
|
+
}
|
846
|
+
}
|
847
|
+
|
848
|
+
bool uws_ws_publish(int ssl, uws_websocket_t *ws, const char *topic, size_t topic_length, const char *message, size_t message_length)
|
849
|
+
{
|
850
|
+
if (ssl)
|
851
|
+
{
|
852
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
853
|
+
return uws->publish(std::string_view(topic, topic_length), std::string_view(message, message_length));
|
854
|
+
}
|
855
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
856
|
+
return uws->publish(std::string_view(topic, topic_length), std::string_view(message, message_length));
|
857
|
+
}
|
858
|
+
|
859
|
+
bool uws_ws_publish_with_options(int ssl, uws_websocket_t *ws, const char *topic, size_t topic_length, const char *message, size_t message_length, uws_opcode_t opcode, bool compress)
|
860
|
+
{
|
861
|
+
if (ssl)
|
862
|
+
{
|
863
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
864
|
+
return uws->publish(std::string_view(topic, topic_length), std::string_view(message, message_length), (uWS::OpCode)(unsigned char)opcode, compress);
|
865
|
+
}
|
866
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
867
|
+
return uws->publish(std::string_view(topic, topic_length), std::string_view(message, message_length), (uWS::OpCode)(unsigned char)opcode, compress);
|
868
|
+
}
|
869
|
+
|
870
|
+
unsigned int uws_ws_get_buffered_amount(int ssl, uws_websocket_t *ws)
|
871
|
+
{
|
872
|
+
if (ssl)
|
873
|
+
{
|
874
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
875
|
+
return uws->getBufferedAmount();
|
876
|
+
}
|
877
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
878
|
+
return uws->getBufferedAmount();
|
879
|
+
}
|
880
|
+
|
881
|
+
size_t uws_ws_get_remote_address(int ssl, uws_websocket_t *ws, const char **dest)
|
882
|
+
{
|
883
|
+
if (ssl)
|
884
|
+
{
|
885
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
886
|
+
std::string_view value = uws->getRemoteAddress();
|
887
|
+
*dest = value.data();
|
888
|
+
return value.length();
|
889
|
+
}
|
890
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
891
|
+
|
892
|
+
std::string_view value = uws->getRemoteAddress();
|
893
|
+
*dest = value.data();
|
894
|
+
return value.length();
|
895
|
+
}
|
896
|
+
|
897
|
+
size_t uws_ws_get_remote_address_as_text(int ssl, uws_websocket_t *ws, const char **dest)
|
898
|
+
{
|
899
|
+
if (ssl)
|
900
|
+
{
|
901
|
+
uWS::WebSocket<true, true, void *> *uws = (uWS::WebSocket<true, true, void *> *)ws;
|
902
|
+
|
903
|
+
std::string_view value = uws->getRemoteAddressAsText();
|
904
|
+
*dest = value.data();
|
905
|
+
return value.length();
|
906
|
+
}
|
907
|
+
uWS::WebSocket<false, true, void *> *uws = (uWS::WebSocket<false, true, void *> *)ws;
|
908
|
+
|
909
|
+
std::string_view value = uws->getRemoteAddressAsText();
|
910
|
+
*dest = value.data();
|
911
|
+
return value.length();
|
912
|
+
}
|
913
|
+
void uws_res_close(int ssl, uws_res_t *res)
|
914
|
+
{
|
915
|
+
if (ssl)
|
916
|
+
{
|
917
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
918
|
+
uwsRes->close();
|
919
|
+
}
|
920
|
+
else
|
921
|
+
{
|
922
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
923
|
+
uwsRes->close();
|
924
|
+
}
|
925
|
+
}
|
926
|
+
void uws_res_end(int ssl, uws_res_t *res, const char *data, size_t length, bool close_connection)
|
927
|
+
{
|
928
|
+
if (ssl)
|
929
|
+
{
|
930
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
931
|
+
uwsRes->end(std::string_view(data, length), close_connection);
|
932
|
+
}
|
933
|
+
else
|
934
|
+
{
|
935
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
936
|
+
uwsRes->end(std::string_view(data, length), close_connection);
|
937
|
+
}
|
938
|
+
}
|
939
|
+
|
940
|
+
size_t uws_res_get_remote_address(int ssl, uws_res_t *res, const char **dest)
|
941
|
+
{
|
942
|
+
if (ssl)
|
943
|
+
{
|
944
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
945
|
+
std::string_view value = uwsRes->getRemoteAddress();
|
946
|
+
*dest = value.data();
|
947
|
+
return value.length();
|
948
|
+
}
|
949
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
950
|
+
|
951
|
+
std::string_view value = uwsRes->getRemoteAddress();
|
952
|
+
*dest = value.data();
|
953
|
+
return value.length();
|
954
|
+
}
|
955
|
+
|
956
|
+
size_t uws_res_get_remote_address_as_text(int ssl, uws_res_t *res, const char **dest)
|
957
|
+
{
|
958
|
+
if (ssl)
|
959
|
+
{
|
960
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
961
|
+
std::string_view value = uwsRes->getRemoteAddressAsText();
|
962
|
+
*dest = value.data();
|
963
|
+
return value.length();
|
964
|
+
}
|
965
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
966
|
+
|
967
|
+
std::string_view value = uwsRes->getRemoteAddressAsText();
|
968
|
+
*dest = value.data();
|
969
|
+
return value.length();
|
970
|
+
}
|
971
|
+
#ifdef UWS_WITH_PROXY
|
972
|
+
size_t uws_res_get_proxied_remote_address(int ssl, uws_res_t *res, const char **dest)
|
973
|
+
{
|
974
|
+
if (ssl)
|
975
|
+
{
|
976
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
977
|
+
std::string_view value = uwsRes->getProxiedRemoteAddress();
|
978
|
+
*dest = value.data();
|
979
|
+
return value.length();
|
980
|
+
}
|
981
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
982
|
+
|
983
|
+
std::string_view value = uwsRes->getProxiedRemoteAddress();
|
984
|
+
*dest = value.data();
|
985
|
+
return value.length();
|
986
|
+
}
|
987
|
+
|
988
|
+
size_t uws_res_get_proxied_remote_address_as_text(int ssl, uws_res_t *res, const char **dest)
|
989
|
+
{
|
990
|
+
if (ssl)
|
991
|
+
{
|
992
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
993
|
+
std::string_view value = uwsRes->getProxiedRemoteAddressAsText();
|
994
|
+
*dest = value.data();
|
995
|
+
return value.length();
|
996
|
+
}
|
997
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
998
|
+
|
999
|
+
std::string_view value = uwsRes->getProxiedRemoteAddressAsText();
|
1000
|
+
*dest = value.data();
|
1001
|
+
return value.length();
|
1002
|
+
}
|
1003
|
+
#endif
|
1004
|
+
uws_try_end_result_t uws_res_try_end(int ssl, uws_res_t *res, const char *data, size_t length, uintmax_t total_size, bool close_connection)
|
1005
|
+
{
|
1006
|
+
if (ssl)
|
1007
|
+
{
|
1008
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1009
|
+
// uwsRes->end(std::string_view(data, length), close_connection);
|
1010
|
+
std::pair<bool, bool> result = uwsRes->tryEnd(std::string_view(data, length), total_size, close_connection);
|
1011
|
+
return uws_try_end_result_t{
|
1012
|
+
.ok = result.first,
|
1013
|
+
.has_responded = result.second,
|
1014
|
+
};
|
1015
|
+
}
|
1016
|
+
else
|
1017
|
+
{
|
1018
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1019
|
+
std::pair<bool, bool> result = uwsRes->tryEnd(std::string_view(data, length), total_size);
|
1020
|
+
return uws_try_end_result_t{
|
1021
|
+
.ok = result.first,
|
1022
|
+
.has_responded = result.second,
|
1023
|
+
};
|
1024
|
+
}
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
void uws_res_cork(int ssl, uws_res_t *res, void (*callback)(uws_res_t *res, void *user_data), void *user_data)
|
1028
|
+
{
|
1029
|
+
if (ssl)
|
1030
|
+
{
|
1031
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1032
|
+
uwsRes->cork([=]()
|
1033
|
+
{ callback(res, user_data); });
|
1034
|
+
}
|
1035
|
+
else
|
1036
|
+
{
|
1037
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1038
|
+
uwsRes->cork([=]()
|
1039
|
+
{ callback(res, user_data); });
|
1040
|
+
}
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
void uws_res_pause(int ssl, uws_res_t *res)
|
1044
|
+
{
|
1045
|
+
if (ssl)
|
1046
|
+
{
|
1047
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1048
|
+
uwsRes->pause();
|
1049
|
+
}
|
1050
|
+
else
|
1051
|
+
{
|
1052
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1053
|
+
uwsRes->pause();
|
1054
|
+
}
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
void uws_res_resume(int ssl, uws_res_t *res)
|
1058
|
+
{
|
1059
|
+
if (ssl)
|
1060
|
+
{
|
1061
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1062
|
+
uwsRes->resume();
|
1063
|
+
}
|
1064
|
+
else
|
1065
|
+
{
|
1066
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1067
|
+
uwsRes->resume();
|
1068
|
+
}
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
void uws_res_write_continue(int ssl, uws_res_t *res)
|
1072
|
+
{
|
1073
|
+
if (ssl)
|
1074
|
+
{
|
1075
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1076
|
+
uwsRes->writeContinue();
|
1077
|
+
}
|
1078
|
+
else
|
1079
|
+
{
|
1080
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1081
|
+
uwsRes->writeContinue();
|
1082
|
+
}
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
void uws_res_write_status(int ssl, uws_res_t *res, const char *status, size_t length)
|
1086
|
+
{
|
1087
|
+
if (ssl)
|
1088
|
+
{
|
1089
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1090
|
+
uwsRes->writeStatus(std::string_view(status, length));
|
1091
|
+
}
|
1092
|
+
else
|
1093
|
+
{
|
1094
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1095
|
+
uwsRes->writeStatus(std::string_view(status, length));
|
1096
|
+
}
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
void uws_res_write_header(int ssl, uws_res_t *res, const char *key, size_t key_length, const char *value, size_t value_length)
|
1100
|
+
{
|
1101
|
+
if (ssl)
|
1102
|
+
{
|
1103
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1104
|
+
uwsRes->writeHeader(std::string_view(key, key_length), std::string_view(value, value_length));
|
1105
|
+
}
|
1106
|
+
else
|
1107
|
+
{
|
1108
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1109
|
+
uwsRes->writeHeader(std::string_view(key, key_length), std::string_view(value, value_length));
|
1110
|
+
}
|
1111
|
+
}
|
1112
|
+
void uws_res_write_header_int(int ssl, uws_res_t *res, const char *key, size_t key_length, uint64_t value)
|
1113
|
+
{
|
1114
|
+
if (ssl)
|
1115
|
+
{
|
1116
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1117
|
+
uwsRes->writeHeader(std::string_view(key, key_length), value);
|
1118
|
+
}
|
1119
|
+
else
|
1120
|
+
{
|
1121
|
+
|
1122
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1123
|
+
uwsRes->writeHeader(std::string_view(key, key_length), value);
|
1124
|
+
}
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
void uws_res_end_without_body(int ssl, uws_res_t *res, bool close_connection)
|
1128
|
+
{
|
1129
|
+
if (ssl)
|
1130
|
+
{
|
1131
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1132
|
+
uwsRes->endWithoutBody(std::nullopt, close_connection);
|
1133
|
+
}
|
1134
|
+
else
|
1135
|
+
{
|
1136
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1137
|
+
uwsRes->endWithoutBody(std::nullopt, close_connection);
|
1138
|
+
}
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
bool uws_res_write(int ssl, uws_res_t *res, const char *data, size_t length)
|
1142
|
+
{
|
1143
|
+
if (ssl)
|
1144
|
+
{
|
1145
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1146
|
+
return uwsRes->write(std::string_view(data, length));
|
1147
|
+
}
|
1148
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1149
|
+
return uwsRes->write(std::string_view(data, length));
|
1150
|
+
}
|
1151
|
+
uintmax_t uws_res_get_write_offset(int ssl, uws_res_t *res)
|
1152
|
+
{
|
1153
|
+
if (ssl)
|
1154
|
+
{
|
1155
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1156
|
+
return uwsRes->getWriteOffset();
|
1157
|
+
}
|
1158
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1159
|
+
return uwsRes->getWriteOffset();
|
1160
|
+
}
|
1161
|
+
void uws_res_override_write_offset(int ssl, uws_res_t *res, uintmax_t offset)
|
1162
|
+
{
|
1163
|
+
if (ssl)
|
1164
|
+
{
|
1165
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1166
|
+
uwsRes->overrideWriteOffset(offset);
|
1167
|
+
}
|
1168
|
+
else
|
1169
|
+
{
|
1170
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1171
|
+
uwsRes->overrideWriteOffset(offset);
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
bool uws_res_has_responded(int ssl, uws_res_t *res)
|
1175
|
+
{
|
1176
|
+
if (ssl)
|
1177
|
+
{
|
1178
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1179
|
+
return uwsRes->hasResponded();
|
1180
|
+
}
|
1181
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1182
|
+
return uwsRes->hasResponded();
|
1183
|
+
}
|
1184
|
+
|
1185
|
+
void uws_res_on_writable(int ssl, uws_res_t *res, bool (*handler)(uws_res_t *res, uintmax_t, void *optional_data), void *optional_data)
|
1186
|
+
{
|
1187
|
+
if (ssl)
|
1188
|
+
{
|
1189
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1190
|
+
uwsRes->onWritable([handler, res, optional_data](uintmax_t a)
|
1191
|
+
{ return handler(res, a, optional_data); });
|
1192
|
+
}
|
1193
|
+
else
|
1194
|
+
{
|
1195
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1196
|
+
uwsRes->onWritable([handler, res, optional_data](uintmax_t a)
|
1197
|
+
{ return handler(res, a, optional_data); });
|
1198
|
+
}
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
void uws_res_on_aborted(int ssl, uws_res_t *res, void (*handler)(uws_res_t *res, void *optional_data), void *optional_data)
|
1202
|
+
{
|
1203
|
+
if (ssl)
|
1204
|
+
{
|
1205
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1206
|
+
uwsRes->onAborted([handler, res, optional_data]
|
1207
|
+
{ handler(res, optional_data); });
|
1208
|
+
}
|
1209
|
+
else
|
1210
|
+
{
|
1211
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1212
|
+
uwsRes->onAborted([handler, res, optional_data]
|
1213
|
+
{ handler(res, optional_data); });
|
1214
|
+
}
|
1215
|
+
}
|
1216
|
+
|
1217
|
+
void uws_res_on_data(int ssl, uws_res_t *res, void (*handler)(uws_res_t *res, const char *chunk, size_t chunk_length, bool is_end, void *optional_data), void *optional_data)
|
1218
|
+
{
|
1219
|
+
if (ssl)
|
1220
|
+
{
|
1221
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1222
|
+
uwsRes->onData([handler, res, optional_data](auto chunk, bool is_end)
|
1223
|
+
{ handler(res, chunk.data(), chunk.length(), is_end, optional_data); });
|
1224
|
+
}
|
1225
|
+
else
|
1226
|
+
{
|
1227
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1228
|
+
uwsRes->onData([handler, res, optional_data](auto chunk, bool is_end)
|
1229
|
+
{ handler(res, chunk.data(), chunk.length(), is_end, optional_data); });
|
1230
|
+
}
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
bool uws_req_is_ancient(uws_req_t *res)
|
1234
|
+
{
|
1235
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1236
|
+
return uwsReq->isAncient();
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
bool uws_req_get_yield(uws_req_t *res)
|
1240
|
+
{
|
1241
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1242
|
+
return uwsReq->getYield();
|
1243
|
+
}
|
1244
|
+
|
1245
|
+
void uws_req_set_yield(uws_req_t *res, bool yield)
|
1246
|
+
{
|
1247
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1248
|
+
return uwsReq->setYield(yield);
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
size_t uws_req_get_url(uws_req_t *res, const char **dest)
|
1252
|
+
{
|
1253
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1254
|
+
std::string_view value = uwsReq->getUrl();
|
1255
|
+
*dest = value.data();
|
1256
|
+
return value.length();
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
size_t uws_req_get_full_url(uws_req_t *res, const char **dest)
|
1260
|
+
{
|
1261
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1262
|
+
std::string_view value = uwsReq->getFullUrl();
|
1263
|
+
*dest = value.data();
|
1264
|
+
return value.length();
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
size_t uws_req_get_method(uws_req_t *res, const char **dest)
|
1268
|
+
{
|
1269
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1270
|
+
std::string_view value = uwsReq->getMethod();
|
1271
|
+
*dest = value.data();
|
1272
|
+
return value.length();
|
1273
|
+
}
|
1274
|
+
|
1275
|
+
size_t uws_req_get_case_sensitive_method(uws_req_t *res, const char **dest)
|
1276
|
+
{
|
1277
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1278
|
+
std::string_view value = uwsReq->getCaseSensitiveMethod();
|
1279
|
+
*dest = value.data();
|
1280
|
+
return value.length();
|
1281
|
+
}
|
1282
|
+
|
1283
|
+
void uws_req_for_each_header(uws_req_t *res, uws_get_headers_server_handler handler, void *user_data)
|
1284
|
+
{
|
1285
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1286
|
+
for (auto header : *uwsReq)
|
1287
|
+
{
|
1288
|
+
handler(header.first.data(), header.first.length(), header.second.data(), header.second.length(), user_data);
|
1289
|
+
}
|
1290
|
+
}
|
1291
|
+
|
1292
|
+
size_t uws_req_get_header(uws_req_t *res, const char *lower_case_header, size_t lower_case_header_length, const char **dest)
|
1293
|
+
{
|
1294
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1295
|
+
|
1296
|
+
std::string_view value = uwsReq->getHeader(std::string_view(lower_case_header, lower_case_header_length));
|
1297
|
+
*dest = value.data();
|
1298
|
+
return value.length();
|
1299
|
+
}
|
1300
|
+
|
1301
|
+
size_t uws_req_get_query(uws_req_t *res, const char *key, size_t key_length, const char **dest)
|
1302
|
+
{
|
1303
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1304
|
+
|
1305
|
+
std::string_view value = uwsReq->getQuery(std::string_view(key, key_length));
|
1306
|
+
*dest = value.data();
|
1307
|
+
return value.length();
|
1308
|
+
}
|
1309
|
+
|
1310
|
+
size_t uws_req_get_parameter(uws_req_t *res, unsigned short index, const char **dest)
|
1311
|
+
{
|
1312
|
+
uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
|
1313
|
+
std::string_view value = uwsReq->getParameter(index);
|
1314
|
+
*dest = value.data();
|
1315
|
+
return value.length();
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
void uws_res_upgrade(int ssl, uws_res_t *res, void *data, const char *sec_web_socket_key, size_t sec_web_socket_key_length, const char *sec_web_socket_protocol, size_t sec_web_socket_protocol_length, const char *sec_web_socket_extensions, size_t sec_web_socket_extensions_length, uws_socket_context_t *ws)
|
1319
|
+
{
|
1320
|
+
|
1321
|
+
if (ssl)
|
1322
|
+
{
|
1323
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1324
|
+
|
1325
|
+
uwsRes->template upgrade<void *>(data ? std::move(data) : NULL,
|
1326
|
+
std::string_view(sec_web_socket_key, sec_web_socket_key_length),
|
1327
|
+
std::string_view(sec_web_socket_protocol, sec_web_socket_protocol_length),
|
1328
|
+
std::string_view(sec_web_socket_extensions, sec_web_socket_extensions_length),
|
1329
|
+
(struct us_socket_context_t *)ws);
|
1330
|
+
}
|
1331
|
+
else
|
1332
|
+
{
|
1333
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1334
|
+
|
1335
|
+
uwsRes->template upgrade<void *>(data ? std::move(data) : NULL,
|
1336
|
+
std::string_view(sec_web_socket_key, sec_web_socket_key_length),
|
1337
|
+
std::string_view(sec_web_socket_protocol, sec_web_socket_protocol_length),
|
1338
|
+
std::string_view(sec_web_socket_extensions, sec_web_socket_extensions_length),
|
1339
|
+
(struct us_socket_context_t *)ws);
|
1340
|
+
}
|
1341
|
+
}
|
1342
|
+
|
1343
|
+
void *uws_res_get_native_handle(int ssl, uws_res_t *res)
|
1344
|
+
{
|
1345
|
+
if (ssl)
|
1346
|
+
{
|
1347
|
+
uWS::HttpResponse<true> *uwsRes = (uWS::HttpResponse<true> *)res;
|
1348
|
+
return uwsRes->getNativeHandle();
|
1349
|
+
}
|
1350
|
+
else
|
1351
|
+
{
|
1352
|
+
uWS::HttpResponse<false> *uwsRes = (uWS::HttpResponse<false> *)res;
|
1353
|
+
return uwsRes->getNativeHandle();
|
1354
|
+
}
|
1355
|
+
}
|
1356
|
+
|
1357
|
+
struct us_loop_t *uws_get_loop()
|
1358
|
+
{
|
1359
|
+
return (struct us_loop_t *)uWS::Loop::get();
|
1360
|
+
}
|
1361
|
+
|
1362
|
+
struct us_loop_t *uws_get_loop_with_native(void *existing_native_loop)
|
1363
|
+
{
|
1364
|
+
return (struct us_loop_t *)uWS::Loop::get(existing_native_loop);
|
1365
|
+
}
|
1366
|
+
void uws_loop_defer(us_loop_t *loop, void( cb(void *user_data) ), void *user_data)
|
1367
|
+
{
|
1368
|
+
uWS::Loop *loop_instance = (uWS::Loop *)loop;
|
1369
|
+
loop_instance->defer([cb, user_data](){
|
1370
|
+
cb(user_data);
|
1371
|
+
});
|
1372
|
+
|
1373
|
+
}
|
1374
|
+
}
|