This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
http_parser.rs
491 lines (322 loc) · 10.1 KB
/
http_parser.rs
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
// Copyright 2013 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/* automatically generated by rust-bindgen */
#[allow(non_uppercase_statics)];
use std::libc::*;
type __u_char = c_uchar;
type __u_short = c_ushort;
type __u_int = c_uint;
type __u_long = c_ulong;
type __int8_t = c_char;
type __uint8_t = c_uchar;
type __int16_t = c_short;
type __uint16_t = c_ushort;
type __int32_t = c_int;
type __uint32_t = c_uint;
type __int64_t = c_long;
type __uint64_t = c_ulong;
type __quad_t = c_long;
type __u_quad_t = c_ulong;
type __dev_t = c_ulong;
type __uid_t = c_uint;
type __gid_t = c_uint;
type __ino_t = c_ulong;
type __ino64_t = c_ulong;
type __mode_t = c_uint;
type __nlink_t = c_ulong;
type __off_t = c_long;
type __off64_t = c_long;
type __pid_t = c_int;
struct __fsid_t {
__val: (c_int,c_int),
}
type __clock_t = c_long;
type __rlim_t = c_ulong;
type __rlim64_t = c_ulong;
type __id_t = c_uint;
type __time_t = c_long;
type __useconds_t = c_uint;
type __suseconds_t = c_long;
type __daddr_t = c_int;
type __swblk_t = c_long;
type __key_t = c_int;
type __clockid_t = c_int;
type __timer_t = *c_void;
type __blksize_t = c_long;
type __blkcnt_t = c_long;
type __blkcnt64_t = c_long;
type __fsblkcnt_t = c_ulong;
type __fsblkcnt64_t = c_ulong;
type __fsfilcnt_t = c_ulong;
type __fsfilcnt64_t = c_ulong;
type __ssize_t = c_long;
type __loff_t = __off64_t;
type __qaddr_t = *__quad_t;
type __caddr_t = *c_char;
type __intptr_t = c_long;
type __socklen_t = c_uint;
type u_char = __u_char;
type u_short = __u_short;
type u_int = __u_int;
type u_long = __u_long;
type quad_t = __quad_t;
type u_quad_t = __u_quad_t;
type fsid_t = __fsid_t;
type loff_t = __loff_t;
type ino_t = __ino_t;
type dev_t = __dev_t;
type gid_t = __gid_t;
type mode_t = __mode_t;
type nlink_t = __nlink_t;
type uid_t = __uid_t;
type off_t = __off_t;
type pid_t = __pid_t;
type id_t = __id_t;
type ssize_t = __ssize_t;
type daddr_t = __daddr_t;
type caddr_t = __caddr_t;
type key_t = __key_t;
type clock_t = __clock_t;
type time_t = __time_t;
type clockid_t = __clockid_t;
type timer_t = __timer_t;
type size_t = c_ulong;
type ulong = c_ulong;
type ushort = c_ushort;
type uint = c_uint;
type int8_t = c_char;
type int16_t = c_short;
type int32_t = c_int;
type int64_t = c_long;
type u_int8_t = c_uchar;
type u_int16_t = c_ushort;
type u_int32_t = c_uint;
type u_int64_t = c_ulong;
type register_t = c_long;
type __sig_atomic_t = c_int;
struct __sigset_t {
__val: (c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong,c_ulong),
}
type sigset_t = __sigset_t;
struct struct_timespec {
tv_sec: __time_t,
tv_nsec: c_long,
}
struct struct_timeval {
tv_sec: __time_t,
tv_usec: __suseconds_t,
}
type suseconds_t = __suseconds_t;
type __fd_mask = c_long;
struct fd_set {
__fds_bits: (__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask,__fd_mask),
}
type fd_mask = __fd_mask;
type blksize_t = __blksize_t;
type blkcnt_t = __blkcnt_t;
type fsblkcnt_t = __fsblkcnt_t;
type fsfilcnt_t = __fsfilcnt_t;
type pthread_t = c_ulong;
type pthread_attr_t = c_void /* FIXME: union type */;
struct struct___pthread_internal_list {
__prev: *c_void /* struct___pthread_internal_list */,
__next: *c_void /* struct___pthread_internal_list */,
}
type __pthread_list_t = struct___pthread_internal_list;
struct struct___pthread_mutex_s {
__lock: c_int,
__count: c_uint,
__owner: c_int,
__nusers: c_uint,
__kind: c_int,
__spins: c_int,
__list: __pthread_list_t,
}
type pthread_mutex_t = c_void /* FIXME: union type */;
type pthread_mutexattr_t = c_void /* FIXME: union type */;
type pthread_cond_t = c_void /* FIXME: union type */;
type pthread_condattr_t = c_void /* FIXME: union type */;
type pthread_key_t = c_uint;
type pthread_once_t = c_int;
type pthread_rwlock_t = c_void /* FIXME: union type */;
type pthread_rwlockattr_t = c_void /* FIXME: union type */;
type pthread_spinlock_t = c_int;
type pthread_barrier_t = c_void /* FIXME: union type */;
type pthread_barrierattr_t = c_void /* FIXME: union type */;
type uint8_t = c_uchar;
type uint16_t = c_ushort;
type uint32_t = c_uint;
type uint64_t = c_ulong;
type int_least8_t = c_char;
type int_least16_t = c_short;
type int_least32_t = c_int;
type int_least64_t = c_long;
type uint_least8_t = c_uchar;
type uint_least16_t = c_ushort;
type uint_least32_t = c_uint;
type uint_least64_t = c_ulong;
type int_fast8_t = c_char;
type int_fast16_t = c_long;
type int_fast32_t = c_long;
type int_fast64_t = c_long;
type uint_fast8_t = c_uchar;
type uint_fast16_t = c_ulong;
type uint_fast32_t = c_ulong;
type uint_fast64_t = c_ulong;
type intptr_t = c_long;
type uintptr_t = c_ulong;
type intmax_t = c_long;
type uintmax_t = c_ulong;
pub type http_parser = struct_http_parser;
pub type http_parser_settings = struct_http_parser_settings;
type http_data_cb = *u8;
type http_cb = *u8;
type enum_http_method = c_uint;
static HTTP_DELETE: u32 = 0_u32;
static HTTP_GET: u32 = 1_u32;
static HTTP_HEAD: u32 = 2_u32;
static HTTP_POST: u32 = 3_u32;
static HTTP_PUT: u32 = 4_u32;
static HTTP_CONNECT: u32 = 5_u32;
static HTTP_OPTIONS: u32 = 6_u32;
static HTTP_TRACE: u32 = 7_u32;
static HTTP_COPY: u32 = 8_u32;
static HTTP_LOCK: u32 = 9_u32;
static HTTP_MKCOL: u32 = 10_u32;
static HTTP_MOVE: u32 = 11_u32;
static HTTP_PROPFIND: u32 = 12_u32;
static HTTP_PROPPATCH: u32 = 13_u32;
static HTTP_SEARCH: u32 = 14_u32;
static HTTP_UNLOCK: u32 = 15_u32;
static HTTP_REPORT: u32 = 16_u32;
static HTTP_MKACTIVITY: u32 = 17_u32;
static HTTP_CHECKOUT: u32 = 18_u32;
static HTTP_MERGE: u32 = 19_u32;
static HTTP_MSEARCH: u32 = 20_u32;
static HTTP_NOTIFY: u32 = 21_u32;
static HTTP_SUBSCRIBE: u32 = 22_u32;
static HTTP_UNSUBSCRIBE: u32 = 23_u32;
static HTTP_PATCH: u32 = 24_u32;
static HTTP_PURGE: u32 = 25_u32;
type enum_http_parser_type = c_uint;
static HTTP_REQUEST: u32 = 0_u32;
pub static HTTP_RESPONSE: u32 = 1_u32;
static HTTP_BOTH: u32 = 2_u32;
type enum_flags = c_uint;
static F_CHUNKED: u32 = 1_u32;
static F_CONNECTION_KEEP_ALIVE: u32 = 2_u32;
static F_CONNECTION_CLOSE: u32 = 4_u32;
static F_TRAILING: u32 = 8_u32;
static F_UPGRADE: u32 = 16_u32;
static F_SKIPBODY: u32 = 32_u32;
type enum_http_errno = c_uint;
static HPE_OK: u32 = 0_u32;
static HPE_CB_message_begin: u32 = 1_u32;
static HPE_CB_url: u32 = 2_u32;
static HPE_CB_header_field: u32 = 3_u32;
static HPE_CB_header_value: u32 = 4_u32;
static HPE_CB_headers_complete: u32 = 5_u32;
static HPE_CB_body: u32 = 6_u32;
static HPE_CB_message_complete: u32 = 7_u32;
static HPE_INVALID_EOF_STATE: u32 = 8_u32;
static HPE_HEADER_OVERFLOW: u32 = 9_u32;
static HPE_CLOSED_CONNECTION: u32 = 10_u32;
static HPE_INVALID_VERSION: u32 = 11_u32;
static HPE_INVALID_STATUS: u32 = 12_u32;
static HPE_INVALID_METHOD: u32 = 13_u32;
static HPE_INVALID_URL: u32 = 14_u32;
static HPE_INVALID_HOST: u32 = 15_u32;
static HPE_INVALID_PORT: u32 = 16_u32;
static HPE_INVALID_PATH: u32 = 17_u32;
static HPE_INVALID_QUERY_STRING: u32 = 18_u32;
static HPE_INVALID_FRAGMENT: u32 = 19_u32;
static HPE_LF_EXPECTED: u32 = 20_u32;
static HPE_INVALID_HEADER_TOKEN: u32 = 21_u32;
static HPE_INVALID_CONTENT_LENGTH: u32 = 22_u32;
static HPE_INVALID_CHUNK_SIZE: u32 = 23_u32;
static HPE_INVALID_CONSTANT: u32 = 24_u32;
static HPE_INVALID_INTERNAL_STATE: u32 = 25_u32;
static HPE_STRICT: u32 = 26_u32;
static HPE_PAUSED: u32 = 27_u32;
static HPE_UNKNOWN: u32 = 28_u32;
pub struct struct_http_parser {
_type_flags: c_uchar,
state: c_uchar,
header_state: c_uchar,
index: c_uchar,
nread: uint32_t,
content_length: uint64_t,
http_major: c_ushort,
http_minor: c_ushort,
status_code: c_ushort,
method: c_uchar,
http_errno_upgrade: c_uchar,
data: *c_void,
}
pub struct struct_http_parser_settings {
on_message_begin: http_cb,
on_url: http_data_cb,
on_header_field: http_data_cb,
on_header_value: http_data_cb,
on_headers_complete: http_cb,
on_body: http_data_cb,
on_message_complete: http_cb,
}
type enum_http_parser_url_fields = c_uint;
static UF_SCHEMA: u32 = 0_u32;
static UF_HOST: u32 = 1_u32;
static UF_PORT: u32 = 2_u32;
static UF_PATH: u32 = 3_u32;
static UF_QUERY: u32 = 4_u32;
static UF_FRAGMENT: u32 = 5_u32;
static UF_MAX: u32 = 6_u32;
struct struct_http_parser_url {
field_set: uint16_t,
port: uint16_t,
field_data: (struct_unnamed1,struct_unnamed1,struct_unnamed1,struct_unnamed1,struct_unnamed1,struct_unnamed1),
}
struct struct_unnamed2 {
__lock: c_int,
__nr_readers: c_uint,
__readers_wakeup: c_uint,
__writer_wakeup: c_uint,
__nr_readers_queued: c_uint,
__nr_writers_queued: c_uint,
__writer: c_int,
__shared: c_int,
__pad1: c_ulong,
__pad2: c_ulong,
__flags: c_uint,
}
struct struct_unnamed3 {
__lock: c_int,
__futex: c_uint,
__total_seq: c_ulonglong,
__wakeup_seq: c_ulonglong,
__woken_seq: c_ulonglong,
__mutex: *c_void,
__nwaiters: c_uint,
__broadcast_seq: c_uint,
}
struct struct_unnamed1 {
off: uint16_t,
len: uint16_t,
}
#[nolink]
#[link_args = "-L. -lhttp_parser"]
extern {
fn http_parser_init(parser: *http_parser, _type: enum_http_parser_type);
fn http_parser_execute(parser: *http_parser, settings: *http_parser_settings, data: *c_char, len: size_t) -> size_t;
fn http_should_keep_alive(parser: *http_parser) -> c_int;
fn http_method_str(m: enum_http_method) -> *c_char;
fn http_errno_name(err: enum_http_errno) -> *c_char;
fn http_errno_description(err: enum_http_errno) -> *c_char;
fn http_parser_parse_url(buf: *c_char, buflen: size_t, is_connect: c_int, u: *struct_http_parser_url) -> c_int;
fn http_parser_pause(parser: *http_parser, paused: c_int);
}