-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmongoose.nelua
567 lines (567 loc) · 28.3 KB
/
mongoose.nelua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
##[[
if MONGOOSE_MBEDTLS then
cdefine 'MG_ENABLE_MBEDTLS 1'
linklib 'mbedtls'
linklib 'mbedcrypto'
linklib 'mbedx509'
elseif MONGOOSE_OPENSSL then
cdefine 'MG_ENABLE_OPENSSL 1'
linklib 'ssl'
linklib 'crypto'
end
cinclude 'mongoose.h'
if not MONGOOSE_NO_IMPL then
cinclude 'mongoose.c'
end
if ccinfo.is_windows then
linklib 'ws2_32'
end
]]
global timeval: type <cimport,nodecl,ctypedef> = @record{
tv_sec: ctime_t,
tv_usec: clong
}
global FILE: type <cimport,nodecl,forwarddecl> = @record{}
global mg_str: type <cimport,nodecl,ctypedef> = @record{
ptr: cstring,
len: csize
}
global function mg_str_s(s: cstring): mg_str <cimport,nodecl> end
global function mg_str_n(s: cstring, n: csize): mg_str <cimport,nodecl> end
global function mg_lower(s: cstring): cint <cimport,nodecl> end
global function mg_ncasecmp(s1: cstring, s2: cstring, len: csize): cint <cimport,nodecl> end
global function mg_casecmp(s1: cstring, s2: cstring): cint <cimport,nodecl> end
global function mg_vcmp(s1: *mg_str, s2: cstring): cint <cimport,nodecl> end
global function mg_vcasecmp(str1: *mg_str, str2: cstring): cint <cimport,nodecl> end
global function mg_strcmp(str1: mg_str, str2: mg_str): cint <cimport,nodecl> end
global function mg_strstrip(s: mg_str): mg_str <cimport,nodecl> end
global function mg_strdup(s: mg_str): mg_str <cimport,nodecl> end
global function mg_strstr(haystack: mg_str, needle: mg_str): cstring <cimport,nodecl> end
global function mg_match(str: mg_str, pattern: mg_str, caps: *mg_str): boolean <cimport,nodecl> end
global function mg_globmatch(pattern: cstring, plen: csize, s: cstring, n: csize): boolean <cimport,nodecl> end
global function mg_commalist(s: *mg_str, k: *mg_str, v: *mg_str): boolean <cimport,nodecl> end
global function mg_split(s: *mg_str, k: *mg_str, v: *mg_str, delim: cchar): boolean <cimport,nodecl> end
global function mg_hex(buf: pointer, len: csize, dst: cstring): cstring <cimport,nodecl> end
global function mg_unhex(buf: cstring, len: csize, to: *cuchar): void <cimport,nodecl> end
global function mg_unhexn(s: cstring, len: csize): culong <cimport,nodecl> end
global function mg_check_ip_acl(acl: mg_str, remote_ip: uint32): cint <cimport,nodecl> end
global function mg_to64(str: mg_str): int64 <cimport,nodecl> end
global function mg_tou64(str: mg_str): uint64 <cimport,nodecl> end
global function mg_remove_double_dots(s: cstring): cstring <cimport,nodecl> end
global mg_queue: type <cimport,nodecl,ctypedef> = @record{
buf: cstring,
size: csize,
tail: csize,
head: csize
}
global function mg_queue_init(a1: *mg_queue, a2: cstring, a3: csize): void <cimport,nodecl> end
global function mg_queue_book(a1: *mg_queue, buf: *cstring, a3: csize): csize <cimport,nodecl> end
global function mg_queue_add(a1: *mg_queue, a2: csize): void <cimport,nodecl> end
global function mg_queue_next(a1: *mg_queue, a2: *cstring): csize <cimport,nodecl> end
global function mg_queue_del(a1: *mg_queue, a2: csize): void <cimport,nodecl> end
global mg_pfn_t: type <cimport,nodecl> = @function(cchar, pointer): void
global mg_pm_t: type <cimport,nodecl> = @function(mg_pfn_t, pointer, *cvalist): csize
global function mg_vxprintf(a1: function(cchar, pointer): void, a2: pointer, fmt: cstring, a4: *cvalist): csize <cimport,nodecl> end
global function mg_xprintf(fn: function(cchar, pointer): void, a2: pointer, fmt: cstring, ...: cvarargs): csize <cimport,nodecl> end
global function mg_vsnprintf(buf: cstring, len: csize, fmt: cstring, ap: *cvalist): csize <cimport,nodecl> end
global function mg_snprintf(a1: cstring, a2: csize, fmt: cstring, ...: cvarargs): csize <cimport,nodecl> end
global function mg_vmprintf(fmt: cstring, ap: *cvalist): cstring <cimport,nodecl> end
global function mg_mprintf(fmt: cstring, ...: cvarargs): cstring <cimport,nodecl> end
global function mg_queue_vprintf(a1: *mg_queue, fmt: cstring, a3: *cvalist): csize <cimport,nodecl> end
global function mg_queue_printf(a1: *mg_queue, fmt: cstring, ...: cvarargs): csize <cimport,nodecl> end
global function mg_print_ip(out: function(cchar, pointer): void, arg: pointer, ap: *cvalist): csize <cimport,nodecl> end
global function mg_print_ip_port(out: function(cchar, pointer): void, arg: pointer, ap: *cvalist): csize <cimport,nodecl> end
global function mg_print_ip4(out: function(cchar, pointer): void, arg: pointer, ap: *cvalist): csize <cimport,nodecl> end
global function mg_print_ip6(out: function(cchar, pointer): void, arg: pointer, ap: *cvalist): csize <cimport,nodecl> end
global function mg_print_mac(out: function(cchar, pointer): void, arg: pointer, ap: *cvalist): csize <cimport,nodecl> end
global function mg_pfn_iobuf(ch: cchar, param: pointer): void <cimport,nodecl> end
global function mg_pfn_stdout(c: cchar, param: pointer): void <cimport,nodecl> end
global MG_LL_NONE: cint <comptime> = 0
global MG_LL_ERROR: cint <comptime> = 1
global MG_LL_INFO: cint <comptime> = 2
global MG_LL_DEBUG: cint <comptime> = 3
global MG_LL_VERBOSE: cint <comptime> = 4
global function mg_log(fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global function mg_log_prefix(ll: cint, file: cstring, line: cint, fname: cstring): boolean <cimport,nodecl> end
global function mg_log_set(log_level: cint): void <cimport,nodecl> end
global function mg_hexdump(buf: pointer, len: csize): void <cimport,nodecl> end
global function mg_log_set_fn(fn: mg_pfn_t, param: pointer): void <cimport,nodecl> end
global mg_timer: type <cimport,nodecl,forwarddecl,ctypedef> = @record{}
mg_timer = @record{
id: culong,
period_ms: uint64,
expire: uint64,
flags: cuint,
fn: function(pointer): void,
arg: pointer,
next: *mg_timer
}
global function mg_timer_init(head: **mg_timer, timer: *mg_timer, milliseconds: uint64, flags: cuint, fn: function(pointer): void, arg: pointer): void <cimport,nodecl> end
global function mg_timer_free(head: **mg_timer, a2: *mg_timer): void <cimport,nodecl> end
global function mg_timer_poll(head: **mg_timer, new_ms: uint64): void <cimport,nodecl> end
global function mg_timer_expired(expiration: *uint64, period: uint64, now: uint64): boolean <cimport,nodecl> end
global MG_FS_READ: cint <comptime> = 1
global MG_FS_WRITE: cint <comptime> = 2
global MG_FS_DIR: cint <comptime> = 4
global mg_fs: type <cimport,nodecl,ctypedef> = @record{
st: function(cstring, *csize, *ctime_t): cint,
ls: function(cstring, function(cstring, pointer): void, pointer): void,
op: function(cstring, cint): pointer,
cl: function(pointer): void,
rd: function(pointer, pointer, csize): csize,
wr: function(pointer, pointer, csize): csize,
sk: function(pointer, csize): csize,
mv: function(cstring, cstring): boolean,
rm: function(cstring): boolean,
mkd: function(cstring): boolean
}
global mg_fs_posix: mg_fs <cimport,nodecl>
global mg_fs_packed: mg_fs <cimport,nodecl>
global mg_fs_fat: mg_fs <cimport,nodecl>
global mg_fd: type <cimport,nodecl,ctypedef> = @record{
fd: pointer,
fs: *mg_fs
}
global function mg_fs_open(fs: *mg_fs, path: cstring, flags: cint): *mg_fd <cimport,nodecl> end
global function mg_fs_close(fd: *mg_fd): void <cimport,nodecl> end
global function mg_file_read(fs: *mg_fs, path: cstring, size: *csize): cstring <cimport,nodecl> end
global function mg_file_write(fs: *mg_fs, path: cstring, a3: pointer, a4: csize): boolean <cimport,nodecl> end
global function mg_file_printf(fs: *mg_fs, path: cstring, fmt: cstring, ...: cvarargs): boolean <cimport,nodecl> end
global function mg_random(buf: pointer, len: csize): void <cimport,nodecl> end
global function mg_random_str(buf: cstring, len: csize): cstring <cimport,nodecl> end
global function mg_ntohs(net: uint16): uint16 <cimport,nodecl> end
global function mg_ntohl(net: uint32): uint32 <cimport,nodecl> end
global function mg_crc32(crc: uint32, buf: cstring, len: csize): uint32 <cimport,nodecl> end
global function mg_millis(): uint64 <cimport,nodecl> end
global function mg_url_port(url: cstring): cushort <cimport,nodecl> end
global function mg_url_is_ssl(url: cstring): cint <cimport,nodecl> end
global function mg_url_host(url: cstring): mg_str <cimport,nodecl> end
global function mg_url_user(url: cstring): mg_str <cimport,nodecl> end
global function mg_url_pass(url: cstring): mg_str <cimport,nodecl> end
global function mg_url_uri(url: cstring): cstring <cimport,nodecl> end
global mg_iobuf: type <cimport,nodecl,ctypedef> = @record{
buf: *cuchar,
size: csize,
len: csize,
align: csize
}
global function mg_iobuf_init(a1: *mg_iobuf, a2: csize, a3: csize): cint <cimport,nodecl> end
global function mg_iobuf_resize(a1: *mg_iobuf, a2: csize): cint <cimport,nodecl> end
global function mg_iobuf_free(a1: *mg_iobuf): void <cimport,nodecl> end
global function mg_iobuf_add(a1: *mg_iobuf, a2: csize, a3: pointer, a4: csize): csize <cimport,nodecl> end
global function mg_iobuf_del(a1: *mg_iobuf, ofs: csize, len: csize): csize <cimport,nodecl> end
global function mg_base64_update(p: cuchar, to: cstring, len: cint): cint <cimport,nodecl> end
global function mg_base64_final(to: cstring, len: cint): cint <cimport,nodecl> end
global function mg_base64_encode(p: *cuchar, n: cint, to: cstring): cint <cimport,nodecl> end
global function mg_base64_decode(src: cstring, n: cint, dst: cstring): cint <cimport,nodecl> end
global mg_md5_ctx: type <cimport,nodecl> = @record{
buf: [4]uint32,
bits: [2]uint32,
In: [64]cuchar
}
global function mg_md5_init(c: *mg_md5_ctx): void <cimport,nodecl> end
global function mg_md5_update(c: *mg_md5_ctx, data: *cuchar, len: csize): void <cimport,nodecl> end
global function mg_md5_final(c: *mg_md5_ctx, a2: *cuchar): void <cimport,nodecl> end
global mg_sha1_ctx: type <cimport,nodecl> = @record{
state: [5]uint32,
count: [2]uint32,
buffer: [64]cuchar
}
global function mg_sha1_init(a1: *mg_sha1_ctx): void <cimport,nodecl> end
global function mg_sha1_update(a1: *mg_sha1_ctx, data: *cuchar, len: csize): void <cimport,nodecl> end
global function mg_sha1_final(digest: *cuchar, a2: *mg_sha1_ctx): void <cimport,nodecl> end
global mg_connection: type <cimport,nodecl,forwarddecl,cincomplete,ctypedef> = @record{}
global mg_event_handler_t: type <cimport,nodecl> = @function(*mg_connection, cint, pointer, pointer): void
global function mg_call(c: *mg_connection, ev: cint, ev_data: pointer): void <cimport,nodecl> end
global function mg_error(c: *mg_connection, fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global MG_EV_ERROR: cint <comptime> = 0
global MG_EV_OPEN: cint <comptime> = 1
global MG_EV_POLL: cint <comptime> = 2
global MG_EV_RESOLVE: cint <comptime> = 3
global MG_EV_CONNECT: cint <comptime> = 4
global MG_EV_ACCEPT: cint <comptime> = 5
global MG_EV_TLS_HS: cint <comptime> = 6
global MG_EV_READ: cint <comptime> = 7
global MG_EV_WRITE: cint <comptime> = 8
global MG_EV_CLOSE: cint <comptime> = 9
global MG_EV_HTTP_MSG: cint <comptime> = 10
global MG_EV_HTTP_CHUNK: cint <comptime> = 11
global MG_EV_WS_OPEN: cint <comptime> = 12
global MG_EV_WS_MSG: cint <comptime> = 13
global MG_EV_WS_CTL: cint <comptime> = 14
global MG_EV_MQTT_CMD: cint <comptime> = 15
global MG_EV_MQTT_MSG: cint <comptime> = 16
global MG_EV_MQTT_OPEN: cint <comptime> = 17
global MG_EV_SNTP_TIME: cint <comptime> = 18
global MG_EV_USER: cint <comptime> = 19
global mg_dns: type <cimport,nodecl,ctypedef> = @record{
url: cstring,
c: *mg_connection
}
global mg_addr: type <cimport,nodecl,ctypedef> = @record{
port: uint16,
ip: uint32,
ip6: [16]uint8,
is_ip6: boolean
}
global mg_mgr: type <cimport,nodecl,ctypedef> = @record{
conns: *mg_connection,
dns4: mg_dns,
dns6: mg_dns,
dnstimeout: cint,
use_dns6: boolean,
nextid: culong,
timerid: culong,
userdata: pointer,
mqtt_id: uint16,
active_dns_requests: pointer,
timers: *mg_timer,
epoll_fd: cint,
priv: pointer,
extraconnsize: csize
}
mg_connection = @record{
next: *mg_connection,
mgr: *mg_mgr,
loc: mg_addr,
rem: mg_addr,
fd: pointer,
id: culong,
recv: mg_iobuf,
send: mg_iobuf,
fn: mg_event_handler_t,
fn_data: pointer,
pfn: mg_event_handler_t,
pfn_data: pointer,
data: [32]cchar,
tls: pointer,
is_listening: cuint,
is_client: cuint,
is_accepted: cuint,
is_resolving: cuint,
is_arplooking: cuint,
is_connecting: cuint,
is_tls: cuint,
is_tls_hs: cuint,
is_udp: cuint,
is_websocket: cuint,
is_mqtt5: cuint,
is_hexdumping: cuint,
is_draining: cuint,
is_closing: cuint,
is_full: cuint,
is_resp: cuint,
is_readable: cuint,
is_writable: cuint
}
global function mg_mgr_poll(a1: *mg_mgr, ms: cint): void <cimport,nodecl> end
global function mg_mgr_init(a1: *mg_mgr): void <cimport,nodecl> end
global function mg_mgr_free(a1: *mg_mgr): void <cimport,nodecl> end
global function mg_listen(a1: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_connect(a1: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_wrapfd(mgr: *mg_mgr, fd: cint, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_connect_resolved(a1: *mg_connection): void <cimport,nodecl> end
global function mg_send(a1: *mg_connection, a2: pointer, a3: csize): boolean <cimport,nodecl> end
global function mg_printf(a1: *mg_connection, fmt: cstring, ...: cvarargs): csize <cimport,nodecl> end
global function mg_vprintf(a1: *mg_connection, fmt: cstring, ap: *cvalist): csize <cimport,nodecl> end
global function mg_aton(str: mg_str, addr: *mg_addr): boolean <cimport,nodecl> end
global function mg_mkpipe(a1: *mg_mgr, a2: mg_event_handler_t, a3: pointer, udp: boolean): cint <cimport,nodecl> end
global function mg_alloc_conn(a1: *mg_mgr): *mg_connection <cimport,nodecl> end
global function mg_close_conn(c: *mg_connection): void <cimport,nodecl> end
global function mg_open_listener(c: *mg_connection, url: cstring): boolean <cimport,nodecl> end
global function mg_timer_add(mgr: *mg_mgr, milliseconds: uint64, flags: cuint, fn: function(pointer): void, arg: pointer): *mg_timer <cimport,nodecl> end
global MG_IO_ERR: cint <comptime> = -1
global MG_IO_WAIT: cint <comptime> = -2
global MG_IO_RESET: cint <comptime> = -3
global function mg_io_send(c: *mg_connection, buf: pointer, len: csize): clong <cimport,nodecl> end
global function mg_io_recv(c: *mg_connection, buf: pointer, len: csize): clong <cimport,nodecl> end
global mg_http_header: type <cimport,nodecl,ctypedef> = @record{
name: mg_str,
value: mg_str
}
global mg_http_message: type <cimport,nodecl,ctypedef> = @record{
method: mg_str,
uri: mg_str,
query: mg_str,
proto: mg_str,
headers: [30]mg_http_header,
body: mg_str,
head: mg_str,
chunk: mg_str,
message: mg_str
}
global mg_http_serve_opts: type <cimport,nodecl,ctypedef> = @record{
root_dir: cstring,
ssi_pattern: cstring,
extra_headers: cstring,
mime_types: cstring,
page404: cstring,
fs: *mg_fs
}
global mg_http_part: type <cimport,nodecl,ctypedef> = @record{
name: mg_str,
filename: mg_str,
body: mg_str
}
global function mg_http_parse(s: cstring, len: csize, a3: *mg_http_message): cint <cimport,nodecl> end
global function mg_http_get_request_len(buf: *cuchar, buf_len: csize): cint <cimport,nodecl> end
global function mg_http_printf_chunk(cnn: *mg_connection, fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global function mg_http_write_chunk(c: *mg_connection, buf: cstring, len: csize): void <cimport,nodecl> end
global function mg_http_delete_chunk(c: *mg_connection, hm: *mg_http_message): void <cimport,nodecl> end
global function mg_http_listen(a1: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_http_connect(a1: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_http_serve_dir(a1: *mg_connection, hm: *mg_http_message, a3: *mg_http_serve_opts): void <cimport,nodecl> end
global function mg_http_serve_file(a1: *mg_connection, hm: *mg_http_message, path: cstring, a4: *mg_http_serve_opts): void <cimport,nodecl> end
global function mg_http_reply(a1: *mg_connection, status_code: cint, headers: cstring, body_fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global function mg_http_get_header(a1: *mg_http_message, name: cstring): *mg_str <cimport,nodecl> end
global function mg_http_var(buf: mg_str, name: mg_str): mg_str <cimport,nodecl> end
global function mg_http_get_var(a1: *mg_str, name: cstring, a3: cstring, a4: csize): cint <cimport,nodecl> end
global function mg_url_decode(s: cstring, n: csize, to: cstring, to_len: csize, form: cint): cint <cimport,nodecl> end
global function mg_url_encode(s: cstring, n: csize, buf: cstring, len: csize): csize <cimport,nodecl> end
global function mg_http_creds(a1: *mg_http_message, a2: cstring, a3: csize, a4: cstring, a5: csize): void <cimport,nodecl> end
global function mg_http_match_uri(a1: *mg_http_message, glob: cstring): boolean <cimport,nodecl> end
global function mg_http_upload(c: *mg_connection, hm: *mg_http_message, fs: *mg_fs, path: cstring, max_size: csize): clong <cimport,nodecl> end
global function mg_http_bauth(a1: *mg_connection, user: cstring, pass: cstring): void <cimport,nodecl> end
global function mg_http_get_header_var(s: mg_str, v: mg_str): mg_str <cimport,nodecl> end
global function mg_http_next_multipart(a1: mg_str, a2: csize, a3: *mg_http_part): csize <cimport,nodecl> end
global function mg_http_status(hm: *mg_http_message): cint <cimport,nodecl> end
global function mg_hello(url: cstring): void <cimport,nodecl> end
global function mg_http_serve_ssi(c: *mg_connection, root: cstring, fullpath: cstring): void <cimport,nodecl> end
global mg_tls_opts: type <cimport,nodecl,ctypedef> = @record{
ca: cstring,
crl: cstring,
cert: cstring,
certkey: cstring,
ciphers: cstring,
srvname: mg_str,
fs: *mg_fs
}
global function mg_tls_init(a1: *mg_connection, a2: *mg_tls_opts): void <cimport,nodecl> end
global function mg_tls_free(a1: *mg_connection): void <cimport,nodecl> end
global function mg_tls_send(a1: *mg_connection, buf: pointer, len: csize): clong <cimport,nodecl> end
global function mg_tls_recv(a1: *mg_connection, buf: pointer, len: csize): clong <cimport,nodecl> end
global function mg_tls_pending(a1: *mg_connection): csize <cimport,nodecl> end
global function mg_tls_handshake(a1: *mg_connection): void <cimport,nodecl> end
global mg_ws_message: type <cimport,nodecl,ctypedef> = @record{
data: mg_str,
flags: uint8
}
global function mg_ws_connect(a1: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer, fmt: cstring, ...: cvarargs): *mg_connection <cimport,nodecl> end
global function mg_ws_upgrade(a1: *mg_connection, a2: *mg_http_message, fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global function mg_ws_send(a1: *mg_connection, buf: pointer, len: csize, op: cint): csize <cimport,nodecl> end
global function mg_ws_wrap(a1: *mg_connection, len: csize, op: cint): csize <cimport,nodecl> end
global function mg_ws_printf(c: *mg_connection, op: cint, fmt: cstring, ...: cvarargs): csize <cimport,nodecl> end
global function mg_ws_vprintf(c: *mg_connection, op: cint, fmt: cstring, a4: *cvalist): csize <cimport,nodecl> end
global function mg_sntp_connect(mgr: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_sntp_request(c: *mg_connection): void <cimport,nodecl> end
global function mg_sntp_parse(buf: *cuchar, len: csize): int64 <cimport,nodecl> end
global mg_mqtt_opts: type <cimport,nodecl,ctypedef> = @record{
user: mg_str,
pass: mg_str,
client_id: mg_str,
will_topic: mg_str,
will_message: mg_str,
will_qos: uint8,
version: uint8,
keepalive: uint16,
will_retain: boolean,
clean: boolean
}
global mg_mqtt_message: type <cimport,nodecl,ctypedef> = @record{
topic: mg_str,
data: mg_str,
dgram: mg_str,
id: uint16,
cmd: uint8,
qos: uint8,
ack: uint8
}
global function mg_mqtt_connect(a1: *mg_mgr, url: cstring, opts: *mg_mqtt_opts, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_mqtt_listen(mgr: *mg_mgr, url: cstring, fn: mg_event_handler_t, fn_data: pointer): *mg_connection <cimport,nodecl> end
global function mg_mqtt_login(c: *mg_connection, opts: *mg_mqtt_opts): void <cimport,nodecl> end
global function mg_mqtt_pub(c: *mg_connection, topic: mg_str, data: mg_str, qos: cint, retain: boolean): void <cimport,nodecl> end
global function mg_mqtt_sub(a1: *mg_connection, topic: mg_str, qos: cint): void <cimport,nodecl> end
global function mg_mqtt_parse(a1: *uint8, a2: csize, a3: uint8, a4: *mg_mqtt_message): cint <cimport,nodecl> end
global function mg_mqtt_send_header(a1: *mg_connection, cmd: uint8, flags: uint8, len: uint32): void <cimport,nodecl> end
global function mg_mqtt_ping(a1: *mg_connection): void <cimport,nodecl> end
global function mg_mqtt_pong(a1: *mg_connection): void <cimport,nodecl> end
global function mg_mqtt_disconnect(a1: *mg_connection): void <cimport,nodecl> end
global mg_dns_message: type <cimport,nodecl,ctypedef> = @record{
txnid: uint16,
resolved: boolean,
addr: mg_addr,
name: [256]cchar
}
global mg_dns_header: type <cimport,nodecl,ctypedef> = @record{
txnid: uint16,
flags: uint16,
num_questions: uint16,
num_answers: uint16,
num_authority_prs: uint16,
num_other_prs: uint16
}
global mg_dns_rr: type <cimport,nodecl,ctypedef> = @record{
nlen: uint16,
atype: uint16,
aclass: uint16,
alen: uint16
}
global function mg_resolve(a1: *mg_connection, url: cstring): void <cimport,nodecl> end
global function mg_resolve_cancel(a1: *mg_connection): void <cimport,nodecl> end
global function mg_dns_parse(buf: *uint8, len: csize, a3: *mg_dns_message): boolean <cimport,nodecl> end
global function mg_dns_parse_rr(buf: *uint8, len: csize, ofs: csize, is_question: boolean, a5: *mg_dns_rr): csize <cimport,nodecl> end
global MG_JSON_TOO_DEEP: cint <comptime> = -1
global MG_JSON_INVALID: cint <comptime> = -2
global MG_JSON_NOT_FOUND: cint <comptime> = -3
global function mg_json_get(json: mg_str, path: cstring, toklen: *cint): cint <cimport,nodecl> end
global function mg_json_get_num(json: mg_str, path: cstring, v: *float64): boolean <cimport,nodecl> end
global function mg_json_get_bool(json: mg_str, path: cstring, v: *boolean): boolean <cimport,nodecl> end
global function mg_json_get_long(json: mg_str, path: cstring, dflt: clong): clong <cimport,nodecl> end
global function mg_json_get_str(json: mg_str, path: cstring): cstring <cimport,nodecl> end
global function mg_json_get_hex(json: mg_str, path: cstring, len: *cint): cstring <cimport,nodecl> end
global function mg_json_get_b64(json: mg_str, path: cstring, len: *cint): cstring <cimport,nodecl> end
global mg_rpc: type <cimport,nodecl,forwarddecl,ctypedef> = @record{}
global mg_rpc_req: type <cimport,nodecl,ctypedef> = @record{
head: **mg_rpc,
rpc: *mg_rpc,
pfn: mg_pfn_t,
pfn_data: pointer,
req_data: pointer,
frame: mg_str
}
mg_rpc = @record{
next: *mg_rpc,
method: mg_str,
fn: function(*mg_rpc_req): void,
fn_data: pointer
}
global function mg_rpc_add(head: **mg_rpc, method_pattern: mg_str, handler: function(*mg_rpc_req): void, handler_data: pointer): void <cimport,nodecl> end
global function mg_rpc_del(head: **mg_rpc, handler: function(*mg_rpc_req): void): void <cimport,nodecl> end
global function mg_rpc_process(a1: *mg_rpc_req): void <cimport,nodecl> end
global function mg_rpc_ok(a1: *mg_rpc_req, fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global function mg_rpc_vok(a1: *mg_rpc_req, fmt: cstring, ap: *cvalist): void <cimport,nodecl> end
global function mg_rpc_err(a1: *mg_rpc_req, code: cint, fmt: cstring, ...: cvarargs): void <cimport,nodecl> end
global function mg_rpc_verr(a1: *mg_rpc_req, code: cint, fmt: cstring, a4: *cvalist): void <cimport,nodecl> end
global function mg_rpc_list(r: *mg_rpc_req): void <cimport,nodecl> end
global mg_tcpip_if: type <cimport,nodecl,forwarddecl,ctypedef> = @record{}
global mg_tcpip_driver: type <cimport,nodecl,ctypedef> = @record{
init: function(*mg_tcpip_if): boolean,
tx: function(pointer, csize, *mg_tcpip_if): csize,
rx: function(pointer, csize, *mg_tcpip_if): csize,
up: function(*mg_tcpip_if): boolean
}
mg_tcpip_if = @record{
mac: [6]uint8,
ip: uint32,
mask: uint32,
gw: uint32,
tx: mg_str,
enable_dhcp_client: boolean,
enable_dhcp_server: boolean,
enable_crc32_check: boolean,
enable_mac_check: boolean,
driver: *mg_tcpip_driver,
driver_data: pointer,
mgr: *mg_mgr,
recv_queue: mg_queue,
gwmac: [6]uint8,
now: uint64,
timer_1000ms: uint64,
lease_expire: uint64,
eport: uint16,
ndrop: uint32,
nrecv: uint32,
nsent: uint32,
nerr: uint32,
state: uint8
}
global function mg_tcpip_init(a1: *mg_mgr, a2: *mg_tcpip_if): void <cimport,nodecl> end
global function mg_tcpip_free(a1: *mg_tcpip_if): void <cimport,nodecl> end
global function mg_tcpip_qwrite(buf: pointer, len: csize, ifp: *mg_tcpip_if): void <cimport,nodecl> end
global mg_tcpip_driver_stm32: mg_tcpip_driver <cimport,nodecl>
global mg_tcpip_driver_w5500: mg_tcpip_driver <cimport,nodecl>
global mg_tcpip_driver_tm4c: mg_tcpip_driver <cimport,nodecl>
global mg_tcpip_driver_stm32h: mg_tcpip_driver <cimport,nodecl>
global mg_tcpip_driver_imxrt: mg_tcpip_driver <cimport,nodecl>
global mg_tcpip_spi: type <cimport,nodecl,ctypedef> = @record{
spi: pointer,
begin: function(pointer): void,
End: function(pointer): void,
txn: function(pointer, uint8): uint8
}
global mg_tcpip_driver_imxrt1020_data: type <cimport,nodecl,ctypedef> = @record{
mdc_cr: cint
}
global mg_tcpip_driver_stm32_data: type <cimport,nodecl,ctypedef> = @record{
mdc_cr: cint
}
global mg_tcpip_driver_stm32h_data: type <cimport,nodecl,ctypedef> = @record{
mdc_cr: cint
}
global mg_tcpip_driver_tm4c_data: type <cimport,nodecl,ctypedef> = @record{
mdc_cr: cint
}
global MG_VERSION: cstring <comptime> = "7.9"
global MG_ARCH_CUSTOM: cint <comptime> = 0
global MG_ARCH_UNIX: cint <comptime> = 1
global MG_ARCH_WIN32: cint <comptime> = 2
global MG_ARCH_ESP32: cint <comptime> = 3
global MG_ARCH_ESP8266: cint <comptime> = 4
global MG_ARCH_FREERTOS: cint <comptime> = 5
global MG_ARCH_AZURERTOS: cint <comptime> = 6
global MG_ARCH_ZEPHYR: cint <comptime> = 7
global MG_ARCH_NEWLIB: cint <comptime> = 8
global MG_ARCH_CMSIS_RTOS1: cint <comptime> = 9
global MG_ARCH_TIRTOS: cint <comptime> = 10
global MG_ARCH_RP2040: cint <comptime> = 11
global MG_ARCH_ARMCC: cint <comptime> = 12
global MG_ARCH_CMSIS_RTOS2: cint <comptime> = 13
global MG_ARCH: cint <comptime> = MG_ARCH_UNIX
global MG_BIG_ENDIAN: cint <cimport,nodecl,const>
global MG_ENABLE_EPOLL: cint <comptime> = 1
global MG_ENABLE_DIRLIST: cint <comptime> = 1
global MG_PATH_MAX: cint <cimport,nodecl,const>
global MG_ENABLE_LOG: cint <comptime> = 1
global MG_ENABLE_TCPIP: cint <comptime> = 0
global MG_ENABLE_LWIP: cint <comptime> = 0
global MG_ENABLE_FREERTOS_TCP: cint <comptime> = 0
global MG_ENABLE_RL: cint <comptime> = 0
global MG_ENABLE_SOCKET: cint <cimport,nodecl,const>
global MG_ENABLE_POLL: cint <comptime> = 0
global MG_ENABLE_FATFS: cint <comptime> = 0
global MG_ENABLE_MBEDTLS: cint <comptime> = 0
global MG_ENABLE_OPENSSL: cint <comptime> = 0
global MG_ENABLE_CUSTOM_TLS: cint <comptime> = 0
global MG_ENABLE_SSI: cint <comptime> = 0
global MG_ENABLE_IPV6: cint <comptime> = 0
global MG_ENABLE_MD5: cint <comptime> = 1
global MG_ENABLE_WINSOCK: cint <comptime> = 1
global MG_ENABLE_CUSTOM_RANDOM: cint <comptime> = 0
global MG_ENABLE_CUSTOM_MILLIS: cint <comptime> = 0
global MG_ENABLE_PACKED_FS: cint <comptime> = 0
global MG_ENABLE_ASSERT: cint <comptime> = 0
global MG_IO_SIZE: cint <comptime> = 2048
global MG_MAX_RECV_SIZE: cint <cimport,nodecl,const>
global MG_DATA_SIZE: cint <comptime> = 32
global MG_MAX_HTTP_HEADERS: cint <comptime> = 30
global MG_HTTP_INDEX: cstring <comptime> = "index.html"
global MG_SOCK_LISTEN_BACKLOG_SIZE: cint <comptime> = 3
global MG_DIRSEP: cint <cimport,nodecl,const>
global MG_ENABLE_FILE: cint <comptime> = 1
global MG_INVALID_SOCKET: cint <comptime> = -1
global MG_SOCKET_TYPE: cint <cimport,nodecl,const>
global MG_SOCKET_ERRNO: cint <cimport,nodecl,const>
global MG_NULL_STR: cint <cimport,nodecl,const>
global MG_TIMER_ONCE: cint <comptime> = 0
global MG_TIMER_REPEAT: cint <comptime> = 1
global MG_TIMER_RUN_NOW: cint <comptime> = 2
global WEBSOCKET_OP_CONTINUE: cint <comptime> = 0
global WEBSOCKET_OP_TEXT: cint <comptime> = 1
global WEBSOCKET_OP_BINARY: cint <comptime> = 2
global WEBSOCKET_OP_CLOSE: cint <comptime> = 8
global WEBSOCKET_OP_PING: cint <comptime> = 9
global WEBSOCKET_OP_PONG: cint <comptime> = 10
global MG_JSON_MAX_DEPTH: cint <comptime> = 30
global MG_TCPIP_STATE_DOWN: cint <comptime> = 0
global MG_TCPIP_STATE_UP: cint <comptime> = 1
global MG_TCPIP_STATE_READY: cint <comptime> = 2