opal-up 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 all
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- /* 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
- }
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
- /* 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
- }
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
- 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
- }
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
- 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
- }
408
+ uWS::App *uwsApp = (uWS::App *)app;
409
+ delete uwsApp;
410
+ }
411
+ }
454
412
 
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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- bool uws_req_is_ancient(uws_req_t *res)
1234
- {
1235
- uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
1236
- return uwsReq->isAncient();
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
- bool uws_req_get_yield(uws_req_t *res)
1240
- {
1241
- uWS::HttpRequest *uwsReq = (uWS::HttpRequest *)res;
1242
- return uwsReq->getYield();
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- 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;
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
- 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
- }
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
- 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;
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
- std::string_view value = uwsReq->getQuery(std::string_view(key, key_length));
1306
- *dest = value.data();
1307
- return value.length();
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
- 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
- }
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
- 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
- }
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
- 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
- }
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
- struct us_loop_t *uws_get_loop()
1358
- {
1359
- return (struct us_loop_t *)uWS::Loop::get();
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
- 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
- });
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
  }