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