llhttp-ffi 0.0.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4678d77c685112f6ab6a1b5d4ef297b185eed3982ccc8749a4b5f2a37121a7f
4
- data.tar.gz: 6868df85901e8ffc520f60a449ca4324077a8c4d0b2479da8608ef1c5e79c53f
3
+ metadata.gz: ec9725ef7398a6548859c7aab1dfb17a3bfc1aa1db2824d6f917a44528df130a
4
+ data.tar.gz: 790e594a54a2c0b5ffac84c3f88ee83d8190b2f159b2e535e302c13b92211dfd
5
5
  SHA512:
6
- metadata.gz: 30aa5d452b0fef2a16fc2c614376e6454890b6959293d556cad031aa6c719ba8582d109a548db23f21f8f26e05072328948b63d36a71475b398127c6e8909d6a
7
- data.tar.gz: a68bbe6ed83d95c24c532824cf64eb7087059aaa37b94e8e734a8c6d29cae2211012e242f0938bfe585755f7e0994e90c1414810b56f1572c809e55188b1deea
6
+ metadata.gz: dbefe79c2c76d2bed5aab900924f1ae7d45f9a7b5a21b19f0773e0e594c3123c7aefbad04af2418bf85d3f5d9e1a1c200b0cc37e6b3f74a4224dfbd84ef771a0
7
+ data.tar.gz: 655d99b69334d5b9471aab8a43142d021e556d20813805b95508f556bd6f990bbaa8d7a634b293435978971ae8c66233def9ba49be892bf25d9d9b50a8c90f01
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## [v0.3.1](https://github.com/metabahn/llhttp/releases/tag/2021-06-25)
2
+
3
+ *released on 2021-06-25*
4
+
5
+ * `fix` [#22](https://github.com/metabahn/llhttp/pull/22) Fix call to ffi free ([bryanp](https://github.com/bryanp))
6
+
7
+ ## [v0.3.0](https://github.com/metabahn/llhttp/releases/tag/2021-05-13)
8
+
9
+ *released on 2021-05-13*
10
+
11
+ * `chg` [#19](https://github.com/metabahn/llhttp/pull/19) Add back support for Ruby 2.5 in ffi ([bryanp](https://github.com/bryanp))
12
+
13
+ ## [v0.2.0](https://github.com/metabahn/llhttp/releases/tag/2021-05-06)
14
+
15
+ *released on 2021-05-06*
16
+
17
+ * `chg` [#17](https://github.com/metabahn/llhttp/pull/17) Update ffi to llhttp 6.0.1 ([bryanp](https://github.com/bryanp))
18
+ * `chg` [#18](https://github.com/metabahn/llhttp/pull/18) Drop support for Ruby 2.5 ([bryanp](https://github.com/bryanp))
19
+
20
+ ## [v0.1.0](https://github.com/metabahn/llhttp/releases/tag/2021-04-06)
21
+
22
+ *released on 2021-04-06*
23
+
24
+ * `chg` [#14](https://github.com/metabahn/llhttp/pull/14) Update ffi to llhttp 5.1.0 ([bryanp](https://github.com/bryanp))
25
+
26
+ ## [v0.0.1](https://github.com/metabahn/llhttp/releases/tag/2021-03-04)
27
+
28
+ *released on 2021-03-04*
29
+
30
+ * `fix` [#13](https://github.com/metabahn/llhttp/pull/13) Resolve an issue with the parser finalizer ([bryanp](https://github.com/bryanp))
31
+
1
32
  ## [v0.0.0](https://github.com/metabahn/llhttp/releases/tag/2021-03-03)
2
33
 
3
34
  *released on 2021-03-03*
data/ext/llhttp/api.c CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  #include "llhttp.h"
29
29
 
30
- #define CALLBACK_MAYBE(PARSER, NAME, ...) \
30
+ #define CALLBACK_MAYBE(PARSER, NAME) \
31
31
  do { \
32
32
  const llhttp_settings_t* settings; \
33
33
  settings = (const llhttp_settings_t*) (PARSER)->settings; \
@@ -35,7 +35,22 @@
35
35
  err = 0; \
36
36
  break; \
37
37
  } \
38
- err = settings->NAME(__VA_ARGS__); \
38
+ err = settings->NAME((PARSER)); \
39
+ } while (0)
40
+
41
+ #define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \
42
+ do { \
43
+ const llhttp_settings_t* settings; \
44
+ settings = (const llhttp_settings_t*) (PARSER)->settings; \
45
+ if (settings == NULL || settings->NAME == NULL) { \
46
+ err = 0; \
47
+ break; \
48
+ } \
49
+ err = settings->NAME((PARSER), (START), (LEN)); \
50
+ if (err == -1) { \
51
+ err = HPE_USER; \
52
+ llhttp_set_error_reason((PARSER), "Span callback error in " #NAME); \
53
+ } \
39
54
  } while (0)
40
55
 
41
56
  void llhttp_init(llhttp_t* parser, llhttp_type_t type,
@@ -47,6 +62,70 @@ void llhttp_init(llhttp_t* parser, llhttp_type_t type,
47
62
  }
48
63
 
49
64
 
65
+ #if defined(__wasm__)
66
+
67
+ extern int wasm_on_message_begin(llhttp_t * p);
68
+ extern int wasm_on_url(llhttp_t* p, const char* at, size_t length);
69
+ extern int wasm_on_status(llhttp_t* p, const char* at, size_t length);
70
+ extern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length);
71
+ extern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length);
72
+ extern int wasm_on_headers_complete(llhttp_t * p);
73
+ extern int wasm_on_body(llhttp_t* p, const char* at, size_t length);
74
+ extern int wasm_on_message_complete(llhttp_t * p);
75
+
76
+ const llhttp_settings_t wasm_settings = {
77
+ wasm_on_message_begin,
78
+ wasm_on_url,
79
+ wasm_on_status,
80
+ wasm_on_header_field,
81
+ wasm_on_header_value,
82
+ wasm_on_headers_complete,
83
+ wasm_on_body,
84
+ wasm_on_message_complete,
85
+ NULL,
86
+ NULL,
87
+ };
88
+
89
+
90
+ llhttp_t* llhttp_alloc(llhttp_type_t type) {
91
+ llhttp_t* parser = malloc(sizeof(llhttp_t));
92
+ llhttp_init(parser, type, &wasm_settings);
93
+ return parser;
94
+ }
95
+
96
+ void llhttp_free(llhttp_t* parser) {
97
+ free(parser);
98
+ }
99
+
100
+ /* Some getters required to get stuff from the parser */
101
+
102
+ uint8_t llhttp_get_type(llhttp_t* parser) {
103
+ return parser->type;
104
+ }
105
+
106
+ uint8_t llhttp_get_http_major(llhttp_t* parser) {
107
+ return parser->http_major;
108
+ }
109
+
110
+ uint8_t llhttp_get_http_minor(llhttp_t* parser) {
111
+ return parser->http_minor;
112
+ }
113
+
114
+ uint8_t llhttp_get_method(llhttp_t* parser) {
115
+ return parser->method;
116
+ }
117
+
118
+ int llhttp_get_status_code(llhttp_t* parser) {
119
+ return parser->status_code;
120
+ }
121
+
122
+ uint8_t llhttp_get_upgrade(llhttp_t* parser) {
123
+ return parser->upgrade;
124
+ }
125
+
126
+ #endif // defined(__wasm__)
127
+
128
+
50
129
  void llhttp_reset(llhttp_t* parser) {
51
130
  llhttp_type_t type = parser->type;
52
131
  const llhttp_settings_t* settings = parser->settings;
@@ -82,7 +161,7 @@ llhttp_errno_t llhttp_finish(llhttp_t* parser) {
82
161
 
83
162
  switch (parser->finish) {
84
163
  case HTTP_FINISH_SAFE_WITH_CB:
85
- CALLBACK_MAYBE(parser, on_message_complete, parser);
164
+ CALLBACK_MAYBE(parser, on_message_complete);
86
165
  if (err != HPE_OK) return err;
87
166
 
88
167
  /* FALLTHROUGH */
@@ -158,7 +237,7 @@ const char* llhttp_errno_name(llhttp_errno_t err) {
158
237
  const char* llhttp_method_name(llhttp_method_t method) {
159
238
  #define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING;
160
239
  switch (method) {
161
- HTTP_METHOD_MAP(HTTP_METHOD_GEN)
240
+ HTTP_ALL_METHOD_MAP(HTTP_METHOD_GEN)
162
241
  default: abort();
163
242
  }
164
243
  #undef HTTP_METHOD_GEN
@@ -173,6 +252,7 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
173
252
  }
174
253
  }
175
254
 
255
+
176
256
  void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
177
257
  if (enabled) {
178
258
  parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
@@ -182,103 +262,111 @@ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
182
262
  }
183
263
 
184
264
 
265
+ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) {
266
+ if (enabled) {
267
+ parser->lenient_flags |= LENIENT_KEEP_ALIVE;
268
+ } else {
269
+ parser->lenient_flags &= ~LENIENT_KEEP_ALIVE;
270
+ }
271
+ }
272
+
185
273
  /* Callbacks */
186
274
 
187
275
 
188
276
  int llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) {
189
277
  int err;
190
- CALLBACK_MAYBE(s, on_message_begin, s);
278
+ CALLBACK_MAYBE(s, on_message_begin);
191
279
  return err;
192
280
  }
193
281
 
194
282
 
195
283
  int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) {
196
284
  int err;
197
- CALLBACK_MAYBE(s, on_url, s, p, endp - p);
285
+ SPAN_CALLBACK_MAYBE(s, on_url, p, endp - p);
198
286
  return err;
199
287
  }
200
288
 
201
289
 
202
290
  int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) {
203
291
  int err;
204
- CALLBACK_MAYBE(s, on_url_complete, s);
292
+ CALLBACK_MAYBE(s, on_url_complete);
205
293
  return err;
206
294
  }
207
295
 
208
296
 
209
297
  int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) {
210
298
  int err;
211
- CALLBACK_MAYBE(s, on_status, s, p, endp - p);
299
+ SPAN_CALLBACK_MAYBE(s, on_status, p, endp - p);
212
300
  return err;
213
301
  }
214
302
 
215
303
 
216
304
  int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) {
217
305
  int err;
218
- CALLBACK_MAYBE(s, on_status_complete, s);
306
+ CALLBACK_MAYBE(s, on_status_complete);
219
307
  return err;
220
308
  }
221
309
 
222
310
 
223
311
  int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) {
224
312
  int err;
225
- CALLBACK_MAYBE(s, on_header_field, s, p, endp - p);
313
+ SPAN_CALLBACK_MAYBE(s, on_header_field, p, endp - p);
226
314
  return err;
227
315
  }
228
316
 
229
317
 
230
318
  int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) {
231
319
  int err;
232
- CALLBACK_MAYBE(s, on_header_field_complete, s);
320
+ CALLBACK_MAYBE(s, on_header_field_complete);
233
321
  return err;
234
322
  }
235
323
 
236
324
 
237
325
  int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) {
238
326
  int err;
239
- CALLBACK_MAYBE(s, on_header_value, s, p, endp - p);
327
+ SPAN_CALLBACK_MAYBE(s, on_header_value, p, endp - p);
240
328
  return err;
241
329
  }
242
330
 
243
331
 
244
332
  int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) {
245
333
  int err;
246
- CALLBACK_MAYBE(s, on_header_value_complete, s);
334
+ CALLBACK_MAYBE(s, on_header_value_complete);
247
335
  return err;
248
336
  }
249
337
 
250
338
 
251
339
  int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) {
252
340
  int err;
253
- CALLBACK_MAYBE(s, on_headers_complete, s);
341
+ CALLBACK_MAYBE(s, on_headers_complete);
254
342
  return err;
255
343
  }
256
344
 
257
345
 
258
346
  int llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) {
259
347
  int err;
260
- CALLBACK_MAYBE(s, on_message_complete, s);
348
+ CALLBACK_MAYBE(s, on_message_complete);
261
349
  return err;
262
350
  }
263
351
 
264
352
 
265
353
  int llhttp__on_body(llhttp_t* s, const char* p, const char* endp) {
266
354
  int err;
267
- CALLBACK_MAYBE(s, on_body, s, p, endp - p);
355
+ SPAN_CALLBACK_MAYBE(s, on_body, p, endp - p);
268
356
  return err;
269
357
  }
270
358
 
271
359
 
272
360
  int llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) {
273
361
  int err;
274
- CALLBACK_MAYBE(s, on_chunk_header, s);
362
+ CALLBACK_MAYBE(s, on_chunk_header);
275
363
  return err;
276
364
  }
277
365
 
278
366
 
279
367
  int llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) {
280
368
  int err;
281
- CALLBACK_MAYBE(s, on_chunk_complete, s);
369
+ CALLBACK_MAYBE(s, on_chunk_complete);
282
370
  return err;
283
371
  }
284
372
 
data/ext/llhttp/llhttp.c CHANGED
@@ -650,6 +650,13 @@ int llhttp__internal__c_update_finish_1(
650
650
  return 0;
651
651
  }
652
652
 
653
+ int llhttp__internal__c_test_lenient_flags(
654
+ llhttp__internal_t* state,
655
+ const unsigned char* p,
656
+ const unsigned char* endp) {
657
+ return (state->lenient_flags & 4) == 4;
658
+ }
659
+
653
660
  int llhttp__internal__c_test_flags_1(
654
661
  llhttp__internal_t* state,
655
662
  const unsigned char* p,
@@ -657,7 +664,7 @@ int llhttp__internal__c_test_flags_1(
657
664
  return (state->flags & 544) == 544;
658
665
  }
659
666
 
660
- int llhttp__internal__c_test_lenient_flags(
667
+ int llhttp__internal__c_test_lenient_flags_1(
661
668
  llhttp__internal_t* state,
662
669
  const unsigned char* p,
663
670
  const unsigned char* endp) {
@@ -825,7 +832,7 @@ int llhttp__internal__c_update_header_state_2(
825
832
  return 0;
826
833
  }
827
834
 
828
- int llhttp__internal__c_test_lenient_flags_1(
835
+ int llhttp__internal__c_test_lenient_flags_2(
829
836
  llhttp__internal_t* state,
830
837
  const unsigned char* p,
831
838
  const unsigned char* endp) {
@@ -1684,7 +1691,7 @@ static llparse_state_t llhttp__internal__run(
1684
1691
  goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2;
1685
1692
  }
1686
1693
  default: {
1687
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
1694
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2;
1688
1695
  }
1689
1696
  }
1690
1697
  /* UNREACHABLE */;
@@ -5756,10 +5763,20 @@ static llparse_state_t llhttp__internal__run(
5756
5763
  /* UNREACHABLE */;
5757
5764
  abort();
5758
5765
  }
5766
+ s_n_llhttp__internal__n_invoke_test_lenient_flags: {
5767
+ switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
5768
+ case 1:
5769
+ goto s_n_llhttp__internal__n_invoke_update_finish_2;
5770
+ default:
5771
+ goto s_n_llhttp__internal__n_closed;
5772
+ }
5773
+ /* UNREACHABLE */;
5774
+ abort();
5775
+ }
5759
5776
  s_n_llhttp__internal__n_invoke_update_finish_1: {
5760
5777
  switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
5761
5778
  default:
5762
- goto s_n_llhttp__internal__n_closed;
5779
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
5763
5780
  }
5764
5781
  /* UNREACHABLE */;
5765
5782
  abort();
@@ -6121,8 +6138,8 @@ static llparse_state_t llhttp__internal__run(
6121
6138
  /* UNREACHABLE */;
6122
6139
  abort();
6123
6140
  }
6124
- s_n_llhttp__internal__n_invoke_test_lenient_flags: {
6125
- switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
6141
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
6142
+ switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
6126
6143
  case 0:
6127
6144
  goto s_n_llhttp__internal__n_error_15;
6128
6145
  default:
@@ -6134,7 +6151,7 @@ static llparse_state_t llhttp__internal__run(
6134
6151
  s_n_llhttp__internal__n_invoke_test_flags_1: {
6135
6152
  switch (llhttp__internal__c_test_flags_1(state, p, endp)) {
6136
6153
  case 1:
6137
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
6154
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
6138
6155
  default:
6139
6156
  goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete;
6140
6157
  }
@@ -6388,8 +6405,8 @@ static llparse_state_t llhttp__internal__run(
6388
6405
  /* UNREACHABLE */;
6389
6406
  abort();
6390
6407
  }
6391
- s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
6392
- switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
6408
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_2: {
6409
+ switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) {
6393
6410
  case 1:
6394
6411
  goto s_n_llhttp__internal__n_header_value_lenient;
6395
6412
  default:
@@ -6750,7 +6767,7 @@ static llparse_state_t llhttp__internal__run(
6750
6767
  abort();
6751
6768
  }
6752
6769
  s_n_llhttp__internal__n_error_29: {
6753
- state->error = 0x16;
6770
+ state->error = 0x17;
6754
6771
  state->reason = "Pause on PRI/Upgrade";
6755
6772
  state->error_pos = (const char*) p;
6756
6773
  state->_current = (void*) (intptr_t) s_error;
@@ -7929,6 +7946,7 @@ reset:
7929
7946
 
7930
7947
  enum llparse_state_e {
7931
7948
  s_error,
7949
+ s_n_llhttp__internal__n_closed,
7932
7950
  s_n_llhttp__internal__n_invoke_llhttp__after_message_complete,
7933
7951
  s_n_llhttp__internal__n_pause_1,
7934
7952
  s_n_llhttp__internal__n_invoke_is_equal_upgrade,
@@ -8222,6 +8240,13 @@ int llhttp__internal__c_update_finish_1(
8222
8240
  return 0;
8223
8241
  }
8224
8242
 
8243
+ int llhttp__internal__c_test_lenient_flags(
8244
+ llhttp__internal_t* state,
8245
+ const unsigned char* p,
8246
+ const unsigned char* endp) {
8247
+ return (state->lenient_flags & 4) == 4;
8248
+ }
8249
+
8225
8250
  int llhttp__internal__c_test_flags_1(
8226
8251
  llhttp__internal_t* state,
8227
8252
  const unsigned char* p,
@@ -8229,7 +8254,7 @@ int llhttp__internal__c_test_flags_1(
8229
8254
  return (state->flags & 544) == 544;
8230
8255
  }
8231
8256
 
8232
- int llhttp__internal__c_test_lenient_flags(
8257
+ int llhttp__internal__c_test_lenient_flags_1(
8233
8258
  llhttp__internal_t* state,
8234
8259
  const unsigned char* p,
8235
8260
  const unsigned char* endp) {
@@ -8301,7 +8326,7 @@ int llhttp__internal__c_or_flags(
8301
8326
  return 0;
8302
8327
  }
8303
8328
 
8304
- int llhttp__internal__c_update_finish_2(
8329
+ int llhttp__internal__c_update_finish_3(
8305
8330
  llhttp__internal_t* state,
8306
8331
  const unsigned char* p,
8307
8332
  const unsigned char* endp) {
@@ -8397,7 +8422,7 @@ int llhttp__internal__c_update_header_state_2(
8397
8422
  return 0;
8398
8423
  }
8399
8424
 
8400
- int llhttp__internal__c_test_lenient_flags_1(
8425
+ int llhttp__internal__c_test_lenient_flags_2(
8401
8426
  llhttp__internal_t* state,
8402
8427
  const unsigned char* p,
8403
8428
  const unsigned char* endp) {
@@ -8597,9 +8622,21 @@ static llparse_state_t llhttp__internal__run(
8597
8622
  const unsigned char* endp) {
8598
8623
  int match;
8599
8624
  switch ((llparse_state_t) (intptr_t) state->_current) {
8625
+ case s_n_llhttp__internal__n_closed:
8626
+ s_n_llhttp__internal__n_closed: {
8627
+ if (p == endp) {
8628
+ return s_n_llhttp__internal__n_closed;
8629
+ }
8630
+ p++;
8631
+ goto s_n_llhttp__internal__n_closed;
8632
+ /* UNREACHABLE */;
8633
+ abort();
8634
+ }
8600
8635
  case s_n_llhttp__internal__n_invoke_llhttp__after_message_complete:
8601
8636
  s_n_llhttp__internal__n_invoke_llhttp__after_message_complete: {
8602
8637
  switch (llhttp__after_message_complete(state, p, endp)) {
8638
+ case 1:
8639
+ goto s_n_llhttp__internal__n_invoke_update_finish_2;
8603
8640
  default:
8604
8641
  goto s_n_llhttp__internal__n_invoke_update_finish_1;
8605
8642
  }
@@ -9068,7 +9105,7 @@ static llparse_state_t llhttp__internal__run(
9068
9105
  case 3:
9069
9106
  goto s_n_llhttp__internal__n_span_start_llhttp__on_body_1;
9070
9107
  case 4:
9071
- goto s_n_llhttp__internal__n_invoke_update_finish_2;
9108
+ goto s_n_llhttp__internal__n_invoke_update_finish_3;
9072
9109
  case 5:
9073
9110
  goto s_n_llhttp__internal__n_error_10;
9074
9111
  default:
@@ -9207,7 +9244,7 @@ static llparse_state_t llhttp__internal__run(
9207
9244
  goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2;
9208
9245
  }
9209
9246
  default: {
9210
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
9247
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2;
9211
9248
  }
9212
9249
  }
9213
9250
  /* UNREACHABLE */;
@@ -13100,7 +13137,7 @@ static llparse_state_t llhttp__internal__run(
13100
13137
  /* UNREACHABLE */;
13101
13138
  abort();
13102
13139
  }
13103
- s_n_llhttp__internal__n_invoke_update_finish_1: {
13140
+ s_n_llhttp__internal__n_invoke_update_finish_2: {
13104
13141
  switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
13105
13142
  default:
13106
13143
  goto s_n_llhttp__internal__n_start;
@@ -13108,6 +13145,24 @@ static llparse_state_t llhttp__internal__run(
13108
13145
  /* UNREACHABLE */;
13109
13146
  abort();
13110
13147
  }
13148
+ s_n_llhttp__internal__n_invoke_test_lenient_flags: {
13149
+ switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
13150
+ case 1:
13151
+ goto s_n_llhttp__internal__n_invoke_update_finish_2;
13152
+ default:
13153
+ goto s_n_llhttp__internal__n_closed;
13154
+ }
13155
+ /* UNREACHABLE */;
13156
+ abort();
13157
+ }
13158
+ s_n_llhttp__internal__n_invoke_update_finish_1: {
13159
+ switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
13160
+ default:
13161
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
13162
+ }
13163
+ /* UNREACHABLE */;
13164
+ abort();
13165
+ }
13111
13166
  s_n_llhttp__internal__n_pause_5: {
13112
13167
  state->error = 0x15;
13113
13168
  state->reason = "on_message_complete pause";
@@ -13334,8 +13389,8 @@ static llparse_state_t llhttp__internal__run(
13334
13389
  /* UNREACHABLE */;
13335
13390
  abort();
13336
13391
  }
13337
- s_n_llhttp__internal__n_invoke_update_finish_2: {
13338
- switch (llhttp__internal__c_update_finish_2(state, p, endp)) {
13392
+ s_n_llhttp__internal__n_invoke_update_finish_3: {
13393
+ switch (llhttp__internal__c_update_finish_3(state, p, endp)) {
13339
13394
  default:
13340
13395
  goto s_n_llhttp__internal__n_span_start_llhttp__on_body_2;
13341
13396
  }
@@ -13447,8 +13502,8 @@ static llparse_state_t llhttp__internal__run(
13447
13502
  /* UNREACHABLE */;
13448
13503
  abort();
13449
13504
  }
13450
- s_n_llhttp__internal__n_invoke_test_lenient_flags: {
13451
- switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
13505
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
13506
+ switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
13452
13507
  case 0:
13453
13508
  goto s_n_llhttp__internal__n_error_11;
13454
13509
  default:
@@ -13460,7 +13515,7 @@ static llparse_state_t llhttp__internal__run(
13460
13515
  s_n_llhttp__internal__n_invoke_test_flags_1: {
13461
13516
  switch (llhttp__internal__c_test_flags_1(state, p, endp)) {
13462
13517
  case 1:
13463
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
13518
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
13464
13519
  default:
13465
13520
  goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete;
13466
13521
  }
@@ -13696,8 +13751,8 @@ static llparse_state_t llhttp__internal__run(
13696
13751
  /* UNREACHABLE */;
13697
13752
  abort();
13698
13753
  }
13699
- s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
13700
- switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
13754
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_2: {
13755
+ switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) {
13701
13756
  case 1:
13702
13757
  goto s_n_llhttp__internal__n_header_value_lenient;
13703
13758
  default:
@@ -14058,7 +14113,7 @@ static llparse_state_t llhttp__internal__run(
14058
14113
  abort();
14059
14114
  }
14060
14115
  s_n_llhttp__internal__n_error_23: {
14061
- state->error = 0x16;
14116
+ state->error = 0x17;
14062
14117
  state->reason = "Pause on PRI/Upgrade";
14063
14118
  state->error_pos = (const char*) p;
14064
14119
  state->_current = (void*) (intptr_t) s_error;
data/ext/llhttp/llhttp.h CHANGED
@@ -24,9 +24,9 @@
24
24
  #ifndef INCLUDE_LLHTTP_H_
25
25
  #define INCLUDE_LLHTTP_H_
26
26
 
27
- #define LLHTTP_VERSION_MAJOR 4
27
+ #define LLHTTP_VERSION_MAJOR 6
28
28
  #define LLHTTP_VERSION_MINOR 0
29
- #define LLHTTP_VERSION_PATCH 0
29
+ #define LLHTTP_VERSION_PATCH 1
30
30
 
31
31
  #ifndef LLHTTP_STRICT_MODE
32
32
  # define LLHTTP_STRICT_MODE 0
@@ -102,7 +102,8 @@ enum llhttp_errno {
102
102
  HPE_CB_CHUNK_COMPLETE = 20,
103
103
  HPE_PAUSED = 21,
104
104
  HPE_PAUSED_UPGRADE = 22,
105
- HPE_USER = 23
105
+ HPE_PAUSED_H2_UPGRADE = 23,
106
+ HPE_USER = 24
106
107
  };
107
108
  typedef enum llhttp_errno llhttp_errno_t;
108
109
 
@@ -121,7 +122,8 @@ typedef enum llhttp_flags llhttp_flags_t;
121
122
 
122
123
  enum llhttp_lenient_flags {
123
124
  LENIENT_HEADERS = 0x1,
124
- LENIENT_CHUNKED_LENGTH = 0x2
125
+ LENIENT_CHUNKED_LENGTH = 0x2,
126
+ LENIENT_KEEP_ALIVE = 0x4
125
127
  };
126
128
  typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
127
129
 
@@ -213,7 +215,8 @@ typedef enum llhttp_method llhttp_method_t;
213
215
  XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
214
216
  XX(21, PAUSED, PAUSED) \
215
217
  XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
216
- XX(23, USER, USER) \
218
+ XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
219
+ XX(24, USER, USER) \
217
220
 
218
221
 
219
222
  #define HTTP_METHOD_MAP(XX) \
@@ -251,7 +254,12 @@ typedef enum llhttp_method llhttp_method_t;
251
254
  XX(31, LINK, LINK) \
252
255
  XX(32, UNLINK, UNLINK) \
253
256
  XX(33, SOURCE, SOURCE) \
254
- XX(34, PRI, PRI) \
257
+
258
+
259
+ #define RTSP_METHOD_MAP(XX) \
260
+ XX(1, GET, GET) \
261
+ XX(3, POST, POST) \
262
+ XX(6, OPTIONS, OPTIONS) \
255
263
  XX(35, DESCRIBE, DESCRIBE) \
256
264
  XX(36, ANNOUNCE, ANNOUNCE) \
257
265
  XX(37, SETUP, SETUP) \
@@ -265,6 +273,54 @@ typedef enum llhttp_method llhttp_method_t;
265
273
  XX(45, FLUSH, FLUSH) \
266
274
 
267
275
 
276
+ #define HTTP_ALL_METHOD_MAP(XX) \
277
+ XX(0, DELETE, DELETE) \
278
+ XX(1, GET, GET) \
279
+ XX(2, HEAD, HEAD) \
280
+ XX(3, POST, POST) \
281
+ XX(4, PUT, PUT) \
282
+ XX(5, CONNECT, CONNECT) \
283
+ XX(6, OPTIONS, OPTIONS) \
284
+ XX(7, TRACE, TRACE) \
285
+ XX(8, COPY, COPY) \
286
+ XX(9, LOCK, LOCK) \
287
+ XX(10, MKCOL, MKCOL) \
288
+ XX(11, MOVE, MOVE) \
289
+ XX(12, PROPFIND, PROPFIND) \
290
+ XX(13, PROPPATCH, PROPPATCH) \
291
+ XX(14, SEARCH, SEARCH) \
292
+ XX(15, UNLOCK, UNLOCK) \
293
+ XX(16, BIND, BIND) \
294
+ XX(17, REBIND, REBIND) \
295
+ XX(18, UNBIND, UNBIND) \
296
+ XX(19, ACL, ACL) \
297
+ XX(20, REPORT, REPORT) \
298
+ XX(21, MKACTIVITY, MKACTIVITY) \
299
+ XX(22, CHECKOUT, CHECKOUT) \
300
+ XX(23, MERGE, MERGE) \
301
+ XX(24, MSEARCH, M-SEARCH) \
302
+ XX(25, NOTIFY, NOTIFY) \
303
+ XX(26, SUBSCRIBE, SUBSCRIBE) \
304
+ XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
305
+ XX(28, PATCH, PATCH) \
306
+ XX(29, PURGE, PURGE) \
307
+ XX(30, MKCALENDAR, MKCALENDAR) \
308
+ XX(31, LINK, LINK) \
309
+ XX(32, UNLINK, UNLINK) \
310
+ XX(33, SOURCE, SOURCE) \
311
+ XX(34, PRI, PRI) \
312
+ XX(35, DESCRIBE, DESCRIBE) \
313
+ XX(36, ANNOUNCE, ANNOUNCE) \
314
+ XX(37, SETUP, SETUP) \
315
+ XX(38, PLAY, PLAY) \
316
+ XX(39, PAUSE, PAUSE) \
317
+ XX(40, TEARDOWN, TEARDOWN) \
318
+ XX(41, GET_PARAMETER, GET_PARAMETER) \
319
+ XX(42, SET_PARAMETER, SET_PARAMETER) \
320
+ XX(43, REDIRECT, REDIRECT) \
321
+ XX(44, RECORD, RECORD) \
322
+ XX(45, FLUSH, FLUSH) \
323
+
268
324
 
269
325
  #ifdef __cplusplus
270
326
  } /* extern "C" */
@@ -278,6 +334,12 @@ extern "C" {
278
334
  #endif
279
335
  #include <stddef.h>
280
336
 
337
+ #if defined(__wasm__)
338
+ #define LLHTTP_EXPORT __attribute__((visibility("default")))
339
+ #else
340
+ #define LLHTTP_EXPORT
341
+ #endif
342
+
281
343
  typedef llhttp__internal_t llhttp_t;
282
344
  typedef struct llhttp_settings_s llhttp_settings_t;
283
345
 
@@ -288,6 +350,7 @@ struct llhttp_settings_s {
288
350
  /* Possible return values 0, -1, `HPE_PAUSED` */
289
351
  llhttp_cb on_message_begin;
290
352
 
353
+ /* Possible return values 0, -1, HPE_USER */
291
354
  llhttp_data_cb on_url;
292
355
  llhttp_data_cb on_status;
293
356
  llhttp_data_cb on_header_field;
@@ -304,6 +367,7 @@ struct llhttp_settings_s {
304
367
  */
305
368
  llhttp_cb on_headers_complete;
306
369
 
370
+ /* Possible return values 0, -1, HPE_USER */
307
371
  llhttp_data_cb on_body;
308
372
 
309
373
  /* Possible return values 0, -1, `HPE_PAUSED` */
@@ -316,6 +380,7 @@ struct llhttp_settings_s {
316
380
  llhttp_cb on_chunk_header;
317
381
  llhttp_cb on_chunk_complete;
318
382
 
383
+ /* Information-only callbacks, return value is ignored */
319
384
  llhttp_cb on_url_complete;
320
385
  llhttp_cb on_status_complete;
321
386
  llhttp_cb on_header_field_complete;
@@ -328,15 +393,46 @@ struct llhttp_settings_s {
328
393
  * the `parser` here. In practice, `settings` has to be either a static
329
394
  * variable or be allocated with `malloc`, `new`, etc.
330
395
  */
396
+ LLHTTP_EXPORT
331
397
  void llhttp_init(llhttp_t* parser, llhttp_type_t type,
332
398
  const llhttp_settings_t* settings);
333
399
 
400
+ #if defined(__wasm__)
401
+
402
+ LLHTTP_EXPORT
403
+ llhttp_t* llhttp_alloc(llhttp_type_t type);
404
+
405
+ LLHTTP_EXPORT
406
+ void llhttp_free(llhttp_t* parser);
407
+
408
+ LLHTTP_EXPORT
409
+ uint8_t llhttp_get_type(llhttp_t* parser);
410
+
411
+ LLHTTP_EXPORT
412
+ uint8_t llhttp_get_http_major(llhttp_t* parser);
413
+
414
+ LLHTTP_EXPORT
415
+ uint8_t llhttp_get_http_minor(llhttp_t* parser);
416
+
417
+ LLHTTP_EXPORT
418
+ uint8_t llhttp_get_method(llhttp_t* parser);
419
+
420
+ LLHTTP_EXPORT
421
+ int llhttp_get_status_code(llhttp_t* parser);
422
+
423
+ LLHTTP_EXPORT
424
+ uint8_t llhttp_get_upgrade(llhttp_t* parser);
425
+
426
+ #endif // defined(__wasm__)
427
+
334
428
  /* Reset an already initialized parser back to the start state, preserving the
335
429
  * existing parser type, callback settings, user data, and lenient flags.
336
430
  */
431
+ LLHTTP_EXPORT
337
432
  void llhttp_reset(llhttp_t* parser);
338
433
 
339
434
  /* Initialize the settings object */
435
+ LLHTTP_EXPORT
340
436
  void llhttp_settings_init(llhttp_settings_t* settings);
341
437
 
342
438
  /* Parse full or partial request/response, invoking user callbacks along the
@@ -355,6 +451,7 @@ void llhttp_settings_init(llhttp_settings_t* settings);
355
451
  * to return the same error upon each successive call up until `llhttp_init()`
356
452
  * is called.
357
453
  */
454
+ LLHTTP_EXPORT
358
455
  llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
359
456
 
360
457
  /* This method should be called when the other side has no further bytes to
@@ -365,16 +462,19 @@ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
365
462
  * connection. This method will invoke `on_message_complete()` callback if the
366
463
  * request was terminated safely. Otherwise a error code would be returned.
367
464
  */
465
+ LLHTTP_EXPORT
368
466
  llhttp_errno_t llhttp_finish(llhttp_t* parser);
369
467
 
370
468
  /* Returns `1` if the incoming message is parsed until the last byte, and has
371
469
  * to be completed by calling `llhttp_finish()` on EOF
372
470
  */
471
+ LLHTTP_EXPORT
373
472
  int llhttp_message_needs_eof(const llhttp_t* parser);
374
473
 
375
474
  /* Returns `1` if there might be any other messages following the last that was
376
475
  * successfully parsed.
377
476
  */
477
+ LLHTTP_EXPORT
378
478
  int llhttp_should_keep_alive(const llhttp_t* parser);
379
479
 
380
480
  /* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
@@ -383,6 +483,7 @@ int llhttp_should_keep_alive(const llhttp_t* parser);
383
483
  * Important: do not call this from user callbacks! User callbacks must return
384
484
  * `HPE_PAUSED` if pausing is required.
385
485
  */
486
+ LLHTTP_EXPORT
386
487
  void llhttp_pause(llhttp_t* parser);
387
488
 
388
489
  /* Might be called to resume the execution after the pause in user's callback.
@@ -390,6 +491,7 @@ void llhttp_pause(llhttp_t* parser);
390
491
  *
391
492
  * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
392
493
  */
494
+ LLHTTP_EXPORT
393
495
  void llhttp_resume(llhttp_t* parser);
394
496
 
395
497
  /* Might be called to resume the execution after the pause in user's callback.
@@ -397,9 +499,11 @@ void llhttp_resume(llhttp_t* parser);
397
499
  *
398
500
  * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
399
501
  */
502
+ LLHTTP_EXPORT
400
503
  void llhttp_resume_after_upgrade(llhttp_t* parser);
401
504
 
402
505
  /* Returns the latest return error */
506
+ LLHTTP_EXPORT
403
507
  llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
404
508
 
405
509
  /* Returns the verbal explanation of the latest returned error.
@@ -407,6 +511,7 @@ llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
407
511
  * Note: User callback should set error reason when returning the error. See
408
512
  * `llhttp_set_error_reason()` for details.
409
513
  */
514
+ LLHTTP_EXPORT
410
515
  const char* llhttp_get_error_reason(const llhttp_t* parser);
411
516
 
412
517
  /* Assign verbal description to the returned error. Must be called in user
@@ -414,6 +519,7 @@ const char* llhttp_get_error_reason(const llhttp_t* parser);
414
519
  *
415
520
  * Note: `HPE_USER` error code might be useful in user callbacks.
416
521
  */
522
+ LLHTTP_EXPORT
417
523
  void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
418
524
 
419
525
  /* Returns the pointer to the last parsed byte before the returned error. The
@@ -421,12 +527,15 @@ void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
421
527
  *
422
528
  * Note: this method might be useful for counting the number of parsed bytes.
423
529
  */
530
+ LLHTTP_EXPORT
424
531
  const char* llhttp_get_error_pos(const llhttp_t* parser);
425
532
 
426
533
  /* Returns textual name of error code */
534
+ LLHTTP_EXPORT
427
535
  const char* llhttp_errno_name(llhttp_errno_t err);
428
536
 
429
537
  /* Returns textual name of HTTP method */
538
+ LLHTTP_EXPORT
430
539
  const char* llhttp_method_name(llhttp_method_t method);
431
540
 
432
541
 
@@ -439,6 +548,7 @@ const char* llhttp_method_name(llhttp_method_t method);
439
548
  *
440
549
  * **(USE AT YOUR OWN RISK)**
441
550
  */
551
+ LLHTTP_EXPORT
442
552
  void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
443
553
 
444
554
 
@@ -452,8 +562,23 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
452
562
  *
453
563
  * **(USE AT YOUR OWN RISK)**
454
564
  */
565
+ LLHTTP_EXPORT
455
566
  void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
456
567
 
568
+
569
+ /* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
570
+ * requests responses.
571
+ *
572
+ * Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
573
+ * the HTTP request/response after the request/response with `Connection: close`
574
+ * and `Content-Length`. This is important to prevent cache poisoning attacks,
575
+ * but might interact badly with outdated and insecure clients. With this flag
576
+ * the extra request/response will be parsed normally.
577
+ *
578
+ * **(USE AT YOUR OWN RISK)**
579
+ */
580
+ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
581
+
457
582
  #ifdef __cplusplus
458
583
  } /* extern "C" */
459
584
  #endif
@@ -62,36 +62,5 @@ module LLHttp
62
62
  # end
63
63
  #
64
64
  class Delegate
65
- # private def internal_on_message_begin
66
- # on_message_begin
67
-
68
- # 0
69
- # rescue
70
- # -1
71
- # end
72
-
73
- # private def internal_on_headers_complete
74
- # on_headers_complete
75
-
76
- # 0
77
- # rescue
78
- # -1
79
- # end
80
-
81
- # private def internal_on_message_complete
82
- # on_message_complete
83
-
84
- # 0
85
- # rescue
86
- # -1
87
- # end
88
-
89
- # private def internal_on_chunk_header
90
- # on_chunk_header
91
-
92
- # 0
93
- # rescue
94
- # -1
95
- # end
96
65
  end
97
66
  end
data/lib/llhttp/parser.rb CHANGED
@@ -152,7 +152,7 @@ module LLHttp
152
152
  end
153
153
 
154
154
  def self.free(pointer)
155
- proc { LLHttp.llhttp_free(@pointer) }
155
+ proc { LLHttp.rb_llhttp_free(pointer) }
156
156
  end
157
157
  end
158
158
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLHttp
4
- VERSION = "0.0.0"
4
+ VERSION = "0.3.1"
5
5
 
6
6
  # [public] LLHttp's current version.
7
7
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llhttp-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-compiler
@@ -55,11 +55,6 @@ files:
55
55
  - ext/llhttp/llhttp.c
56
56
  - ext/llhttp/llhttp.h
57
57
  - ext/llhttp/llhttp_ext.c
58
- - ext/x86_64-darwin/libllhttp-ext.bundle
59
- - ext/x86_64-darwin/llhttp/api.o
60
- - ext/x86_64-darwin/llhttp/http.o
61
- - ext/x86_64-darwin/llhttp/llhttp.o
62
- - ext/x86_64-darwin/llhttp/llhttp_ext.o
63
58
  - lib/llhttp.rb
64
59
  - lib/llhttp/delegate.rb
65
60
  - lib/llhttp/error.rb
@@ -84,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
79
  - !ruby/object:Gem::Version
85
80
  version: '0'
86
81
  requirements: []
87
- rubygems_version: 3.2.4
82
+ rubygems_version: 3.2.15
88
83
  signing_key:
89
84
  specification_version: 4
90
85
  summary: Ruby FFI bindings for llhttp.
Binary file
Binary file
Binary file
Binary file
Binary file