llhttp 0.0.1 → 0.3.0

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: c367e8870364d3400220233c434081a75a6467ff864f50d1a24a83ee0abf90dd
4
- data.tar.gz: 74628e99e4c978fcbaa6a37ba2b9bb3473cacaab0fd69ca1196384aa8781024a
3
+ metadata.gz: c3049572a0a42b0303696570fc91b7b657c716b014fc068ae549133b69aa6869
4
+ data.tar.gz: 4122c65a1c18f2f3d07cadb2e5b95089d4fd142382e9cb9a47138eec6d7a6b20
5
5
  SHA512:
6
- metadata.gz: c2e2249e81dee3cc6036debf2144f0ca64597a17dd66de4ceaa4b889860070bc09476bfa1a0f5a82b05bb9941d5719f8adcf28f01a2d665314e41860f49bed68
7
- data.tar.gz: 06dccd9bb5b78bc7f62d06293d98fab34b325382ed0873b4702d9ef3fd04a73075e102358655c72474a0a1dc92eee20791e29895ce8c6c8a63b2bb9926cf5693
6
+ metadata.gz: 9ea99585b4658d2520a61cc00df75a3a298c8c7b8f850928da65ae49d2ce3501e25e2b3659140859617135f7af933ec4e20639ad49e81ef335019892b1a553ff
7
+ data.tar.gz: 923b8dafbcd575d5fa27c722c52b4c7ae8a5be13044a589e045e8f4666913521539fbf808169e1beb9a6f345186a26bbc2285ea3643eb2197f1eaa3c2812a598
data/CHANGELOG.md CHANGED
@@ -0,0 +1,44 @@
1
+ ## v0.3.0
2
+
3
+ *released on 2021-05-06*
4
+
5
+ * `chg` [#16](https://github.com/metabahn/llhttp/pull/16) Update mri to llhttp 6.0.1 ([bryanp](https://github.com/bryanp))
6
+ * `chg` [#18](https://github.com/metabahn/llhttp/pull/18) Drop support for Ruby 2.5 ([bryanp](https://github.com/bryanp))
7
+
8
+ ## [v0.2.0](https://github.com/metabahn/llhttp/releases/tag/2021-04-06)
9
+
10
+ *released on 2021-04-06*
11
+
12
+ * `chg` [#15](https://github.com/metabahn/llhttp/pull/15) Update mri to llhttp 5.1.0 ([bryanp](https://github.com/bryanp))
13
+
14
+ ## [v0.1.0](https://github.com/metabahn/llhttp/releases/tag/2021-03-03)
15
+
16
+ *released on 2021-03-03*
17
+
18
+ * `chg` [#11](https://github.com/metabahn/llhttp/pull/11) Rename Parser#method to Parser#method_name ([bryanp](https://github.com/bryanp))
19
+ * `chg` [#10](https://github.com/metabahn/llhttp/pull/10) Only setup callbacks if they are defined on the delegate ([bryanp](https://github.com/bryanp))
20
+ * `chg` [#9](https://github.com/metabahn/llhttp/pull/9) Update llhttp to 4.0.0 ([bryanp](https://github.com/bryanp))
21
+ * `add` [#2](https://github.com/metabahn/llhttp/pull/2) Support introspection of http major/minor version ([midnight-wonderer](https://github.com/midnight-wonderer))
22
+ * `add` [#8](https://github.com/metabahn/llhttp/pull/8) Support new *_complete callbacks ([bryanp](https://github.com/bryanp))
23
+ * `chg` [#7](https://github.com/metabahn/llhttp/pull/7) Return an error status from the appropriate callbacks ([bryanp](https://github.com/bryanp))
24
+ * `chg` [#6](https://github.com/metabahn/llhttp/pull/6) Update llhttp to 3.0.1 ([bryanp](https://github.com/bryanp))
25
+
26
+ ## [v0.0.3](https://github.com/metabahn/llhttp/releases/tag/v0.0.3)
27
+
28
+ *released on 2020-12-30*
29
+
30
+ * `fix` [#5](https://github.com/metabahn/llhttp/pull/5) Build the extension correctly ([bryanp](https://github.com/bryanp))
31
+
32
+ ## [v0.0.2](https://github.com/metabahn/llhttp/releases/tag/v0.0.2)
33
+
34
+ *released on 2020-10-11*
35
+
36
+ * `fix` Correctly free parser settings when freeing the parser.
37
+
38
+ ## [v0.0.1](https://github.com/metabahn/llhttp/releases/tag/v0.0.1)
39
+
40
+ *released on 2020-10-11*
41
+
42
+ * Initial release.
43
+
44
+
data/LICENSE CHANGED
@@ -1,22 +1,353 @@
1
- This software is licensed under the MIT License.
2
-
3
- Copyright Bryan Powell, 2020.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a
6
- copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to permit
10
- persons to whom the Software is furnished to do so, subject to the
11
- following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included
14
- in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
- NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
- USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Mozilla Public License, version 2.0
2
+
3
+ 1. Definitions
4
+
5
+ 1.1. “Contributor”
6
+
7
+ means each individual or legal entity that creates, contributes to the
8
+ creation of, or owns Covered Software.
9
+
10
+ 1.2. “Contributor Version”
11
+
12
+ means the combination of the Contributions of others (if any) used by a
13
+ Contributor and that particular Contributor’s Contribution.
14
+
15
+ 1.3. “Contribution”
16
+
17
+ means Covered Software of a particular Contributor.
18
+
19
+ 1.4. “Covered Software”
20
+
21
+ means Source Code Form to which the initial Contributor has attached the
22
+ notice in Exhibit A, the Executable Form of such Source Code Form, and
23
+ Modifications of such Source Code Form, in each case including portions
24
+ thereof.
25
+
26
+ 1.5. “Incompatible With Secondary Licenses”
27
+ means
28
+
29
+ a. that the initial Contributor has attached the notice described in
30
+ Exhibit B to the Covered Software; or
31
+
32
+ b. that the Covered Software was made available under the terms of version
33
+ 1.1 or earlier of the License, but not also under the terms of a
34
+ Secondary License.
35
+
36
+ 1.6. “Executable Form”
37
+
38
+ means any form of the work other than Source Code Form.
39
+
40
+ 1.7. “Larger Work”
41
+
42
+ means a work that combines Covered Software with other material, in a separate
43
+ file or files, that is not Covered Software.
44
+
45
+ 1.8. “License”
46
+
47
+ means this document.
48
+
49
+ 1.9. “Licensable”
50
+
51
+ means having the right to grant, to the maximum extent possible, whether at the
52
+ time of the initial grant or subsequently, any and all of the rights conveyed by
53
+ this License.
54
+
55
+ 1.10. “Modifications”
56
+
57
+ means any of the following:
58
+
59
+ a. any file in Source Code Form that results from an addition to, deletion
60
+ from, or modification of the contents of Covered Software; or
61
+
62
+ b. any new file in Source Code Form that contains any Covered Software.
63
+
64
+ 1.11. “Patent Claims” of a Contributor
65
+
66
+ means any patent claim(s), including without limitation, method, process,
67
+ and apparatus claims, in any patent Licensable by such Contributor that
68
+ would be infringed, but for the grant of the License, by the making,
69
+ using, selling, offering for sale, having made, import, or transfer of
70
+ either its Contributions or its Contributor Version.
71
+
72
+ 1.12. “Secondary License”
73
+
74
+ means either the GNU General Public License, Version 2.0, the GNU Lesser
75
+ General Public License, Version 2.1, the GNU Affero General Public
76
+ License, Version 3.0, or any later versions of those licenses.
77
+
78
+ 1.13. “Source Code Form”
79
+
80
+ means the form of the work preferred for making modifications.
81
+
82
+ 1.14. “You” (or “Your”)
83
+
84
+ means an individual or a legal entity exercising rights under this
85
+ License. For legal entities, “You” includes any entity that controls, is
86
+ controlled by, or is under common control with You. For purposes of this
87
+ definition, “control” means (a) the power, direct or indirect, to cause
88
+ the direction or management of such entity, whether by contract or
89
+ otherwise, or (b) ownership of more than fifty percent (50%) of the
90
+ outstanding shares or beneficial ownership of such entity.
91
+
92
+
93
+ 2. License Grants and Conditions
94
+
95
+ 2.1. Grants
96
+
97
+ Each Contributor hereby grants You a world-wide, royalty-free,
98
+ non-exclusive license:
99
+
100
+ a. under intellectual property rights (other than patent or trademark)
101
+ Licensable by such Contributor to use, reproduce, make available,
102
+ modify, display, perform, distribute, and otherwise exploit its
103
+ Contributions, either on an unmodified basis, with Modifications, or as
104
+ part of a Larger Work; and
105
+
106
+ b. under Patent Claims of such Contributor to make, use, sell, offer for
107
+ sale, have made, import, and otherwise transfer either its Contributions
108
+ or its Contributor Version.
109
+
110
+ 2.2. Effective Date
111
+
112
+ The licenses granted in Section 2.1 with respect to any Contribution become
113
+ effective for each Contribution on the date the Contributor first distributes
114
+ such Contribution.
115
+
116
+ 2.3. Limitations on Grant Scope
117
+
118
+ The licenses granted in this Section 2 are the only rights granted under this
119
+ License. No additional rights or licenses will be implied from the distribution
120
+ or licensing of Covered Software under this License. Notwithstanding Section
121
+ 2.1(b) above, no patent license is granted by a Contributor:
122
+
123
+ a. for any code that a Contributor has removed from Covered Software; or
124
+
125
+ b. for infringements caused by: (i) Your and any other third party’s
126
+ modifications of Covered Software, or (ii) the combination of its
127
+ Contributions with other software (except as part of its Contributor
128
+ Version); or
129
+
130
+ c. under Patent Claims infringed by Covered Software in the absence of its
131
+ Contributions.
132
+
133
+ This License does not grant any rights in the trademarks, service marks, or
134
+ logos of any Contributor (except as may be necessary to comply with the
135
+ notice requirements in Section 3.4).
136
+
137
+ 2.4. Subsequent Licenses
138
+
139
+ No Contributor makes additional grants as a result of Your choice to
140
+ distribute the Covered Software under a subsequent version of this License
141
+ (see Section 10.2) or under the terms of a Secondary License (if permitted
142
+ under the terms of Section 3.3).
143
+
144
+ 2.5. Representation
145
+
146
+ Each Contributor represents that the Contributor believes its Contributions
147
+ are its original creation(s) or it has sufficient rights to grant the
148
+ rights to its Contributions conveyed by this License.
149
+
150
+ 2.6. Fair Use
151
+
152
+ This License is not intended to limit any rights You have under applicable
153
+ copyright doctrines of fair use, fair dealing, or other equivalents.
154
+
155
+ 2.7. Conditions
156
+
157
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
158
+ Section 2.1.
159
+
160
+
161
+ 3. Responsibilities
162
+
163
+ 3.1. Distribution of Source Form
164
+
165
+ All distribution of Covered Software in Source Code Form, including any
166
+ Modifications that You create or to which You contribute, must be under the
167
+ terms of this License. You must inform recipients that the Source Code Form
168
+ of the Covered Software is governed by the terms of this License, and how
169
+ they can obtain a copy of this License. You may not attempt to alter or
170
+ restrict the recipients’ rights in the Source Code Form.
171
+
172
+ 3.2. Distribution of Executable Form
173
+
174
+ If You distribute Covered Software in Executable Form then:
175
+
176
+ a. such Covered Software must also be made available in Source Code Form,
177
+ as described in Section 3.1, and You must inform recipients of the
178
+ Executable Form how they can obtain a copy of such Source Code Form by
179
+ reasonable means in a timely manner, at a charge no more than the cost
180
+ of distribution to the recipient; and
181
+
182
+ b. You may distribute such Executable Form under the terms of this License,
183
+ or sublicense it under different terms, provided that the license for
184
+ the Executable Form does not attempt to limit or alter the recipients’
185
+ rights in the Source Code Form under this License.
186
+
187
+ 3.3. Distribution of a Larger Work
188
+
189
+ You may create and distribute a Larger Work under terms of Your choice,
190
+ provided that You also comply with the requirements of this License for the
191
+ Covered Software. If the Larger Work is a combination of Covered Software
192
+ with a work governed by one or more Secondary Licenses, and the Covered
193
+ Software is not Incompatible With Secondary Licenses, this License permits
194
+ You to additionally distribute such Covered Software under the terms of
195
+ such Secondary License(s), so that the recipient of the Larger Work may, at
196
+ their option, further distribute the Covered Software under the terms of
197
+ either this License or such Secondary License(s).
198
+
199
+ 3.4. Notices
200
+
201
+ You may not remove or alter the substance of any license notices (including
202
+ copyright notices, patent notices, disclaimers of warranty, or limitations
203
+ of liability) contained within the Source Code Form of the Covered
204
+ Software, except that You may alter any license notices to the extent
205
+ required to remedy known factual inaccuracies.
206
+
207
+ 3.5. Application of Additional Terms
208
+
209
+ You may choose to offer, and to charge a fee for, warranty, support,
210
+ indemnity or liability obligations to one or more recipients of Covered
211
+ Software. However, You may do so only on Your own behalf, and not on behalf
212
+ of any Contributor. You must make it absolutely clear that any such
213
+ warranty, support, indemnity, or liability obligation is offered by You
214
+ alone, and You hereby agree to indemnify every Contributor for any
215
+ liability incurred by such Contributor as a result of warranty, support,
216
+ indemnity or liability terms You offer. You may include additional
217
+ disclaimers of warranty and limitations of liability specific to any
218
+ jurisdiction.
219
+
220
+ 4. Inability to Comply Due to Statute or Regulation
221
+
222
+ If it is impossible for You to comply with any of the terms of this License
223
+ with respect to some or all of the Covered Software due to statute, judicial
224
+ order, or regulation then You must: (a) comply with the terms of this License
225
+ to the maximum extent possible; and (b) describe the limitations and the code
226
+ they affect. Such description must be placed in a text file included with all
227
+ distributions of the Covered Software under this License. Except to the
228
+ extent prohibited by statute or regulation, such description must be
229
+ sufficiently detailed for a recipient of ordinary skill to be able to
230
+ understand it.
231
+
232
+ 5. Termination
233
+
234
+ 5.1. The rights granted under this License will terminate automatically if You
235
+ fail to comply with any of its terms. However, if You become compliant,
236
+ then the rights granted under this License from a particular Contributor
237
+ are reinstated (a) provisionally, unless and until such Contributor
238
+ explicitly and finally terminates Your grants, and (b) on an ongoing basis,
239
+ if such Contributor fails to notify You of the non-compliance by some
240
+ reasonable means prior to 60 days after You have come back into compliance.
241
+ Moreover, Your grants from a particular Contributor are reinstated on an
242
+ ongoing basis if such Contributor notifies You of the non-compliance by
243
+ some reasonable means, this is the first time You have received notice of
244
+ non-compliance with this License from such Contributor, and You become
245
+ compliant prior to 30 days after Your receipt of the notice.
246
+
247
+ 5.2. If You initiate litigation against any entity by asserting a patent
248
+ infringement claim (excluding declaratory judgment actions, counter-claims,
249
+ and cross-claims) alleging that a Contributor Version directly or
250
+ indirectly infringes any patent, then the rights granted to You by any and
251
+ all Contributors for the Covered Software under Section 2.1 of this License
252
+ shall terminate.
253
+
254
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
255
+ license agreements (excluding distributors and resellers) which have been
256
+ validly granted by You or Your distributors under this License prior to
257
+ termination shall survive termination.
258
+
259
+ 6. Disclaimer of Warranty
260
+
261
+ Covered Software is provided under this License on an “as is” basis, without
262
+ warranty of any kind, either expressed, implied, or statutory, including,
263
+ without limitation, warranties that the Covered Software is free of defects,
264
+ merchantable, fit for a particular purpose or non-infringing. The entire
265
+ risk as to the quality and performance of the Covered Software is with You.
266
+ Should any Covered Software prove defective in any respect, You (not any
267
+ Contributor) assume the cost of any necessary servicing, repair, or
268
+ correction. This disclaimer of warranty constitutes an essential part of this
269
+ License. No use of any Covered Software is authorized under this License
270
+ except under this disclaimer.
271
+
272
+ 7. Limitation of Liability
273
+
274
+ Under no circumstances and under no legal theory, whether tort (including
275
+ negligence), contract, or otherwise, shall any Contributor, or anyone who
276
+ distributes Covered Software as permitted above, be liable to You for any
277
+ direct, indirect, special, incidental, or consequential damages of any
278
+ character including, without limitation, damages for lost profits, loss of
279
+ goodwill, work stoppage, computer failure or malfunction, or any and all
280
+ other commercial damages or losses, even if such party shall have been
281
+ informed of the possibility of such damages. This limitation of liability
282
+ shall not apply to liability for death or personal injury resulting from such
283
+ party’s negligence to the extent applicable law prohibits such limitation.
284
+ Some jurisdictions do not allow the exclusion or limitation of incidental or
285
+ consequential damages, so this exclusion and limitation may not apply to You.
286
+
287
+ 8. Litigation
288
+
289
+ Any litigation relating to this License may be brought only in the courts of
290
+ a jurisdiction where the defendant maintains its principal place of business
291
+ and such litigation shall be governed by laws of that jurisdiction, without
292
+ reference to its conflict-of-law provisions. Nothing in this Section shall
293
+ prevent a party’s ability to bring cross-claims or counter-claims.
294
+
295
+ 9. Miscellaneous
296
+
297
+ This License represents the complete agreement concerning the subject matter
298
+ hereof. If any provision of this License is held to be unenforceable, such
299
+ provision shall be reformed only to the extent necessary to make it
300
+ enforceable. Any law or regulation which provides that the language of a
301
+ contract shall be construed against the drafter shall not be used to construe
302
+ this License against a Contributor.
303
+
304
+
305
+ 10. Versions of the License
306
+
307
+ 10.1. New Versions
308
+
309
+ Mozilla Foundation is the license steward. Except as provided in Section
310
+ 10.3, no one other than the license steward has the right to modify or
311
+ publish new versions of this License. Each version will be given a
312
+ distinguishing version number.
313
+
314
+ 10.2. Effect of New Versions
315
+
316
+ You may distribute the Covered Software under the terms of the version of
317
+ the License under which You originally received the Covered Software, or
318
+ under the terms of any subsequent version published by the license
319
+ steward.
320
+
321
+ 10.3. Modified Versions
322
+
323
+ If you create software not governed by this License, and you want to
324
+ create a new license for such software, you may create and use a modified
325
+ version of this License if you rename the license and remove any
326
+ references to the name of the license steward (except to note that such
327
+ modified license differs from this License).
328
+
329
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
330
+ If You choose to distribute Source Code Form that is Incompatible With
331
+ Secondary Licenses under the terms of this version of the License, the
332
+ notice described in Exhibit B of this License must be attached.
333
+
334
+ Exhibit A - Source Code Form License Notice
335
+
336
+ This Source Code Form is subject to the
337
+ terms of the Mozilla Public License, v.
338
+ 2.0. If a copy of the MPL was not
339
+ distributed with this file, You can
340
+ obtain one at
341
+ http://mozilla.org/MPL/2.0/.
342
+
343
+ If it is not possible or desirable to put the notice in a particular file, then
344
+ You may include the notice in a location (such as a LICENSE file in a relevant
345
+ directory) where a recipient would be likely to look for such a notice.
346
+
347
+ You may add additional accurate notices of copyright ownership.
348
+
349
+ Exhibit B - “Incompatible With Secondary Licenses” Notice
350
+
351
+ This Source Code Form is “Incompatible
352
+ With Secondary Licenses”, as defined by
353
+ the Mozilla Public License, v. 2.0.
data/ext/llhttp/api.c ADDED
@@ -0,0 +1,386 @@
1
+ // This software is licensed under the MIT License.
2
+
3
+ // Copyright Fedor Indutny, 2018.
4
+
5
+ // Permission is hereby granted, free of charge, to any person obtaining a
6
+ // copy of this software and associated documentation files (the
7
+ // "Software"), to deal in the Software without restriction, including
8
+ // without limitation the rights to use, copy, modify, merge, publish,
9
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
10
+ // persons to whom the Software is furnished to do so, subject to the
11
+ // following conditions:
12
+
13
+ // The above copyright notice and this permission notice shall be included
14
+ // in all copies or substantial portions of the Software.
15
+
16
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ #include <stdlib.h>
25
+ #include <stdio.h>
26
+ #include <string.h>
27
+
28
+ #include "llhttp.h"
29
+
30
+ #define CALLBACK_MAYBE(PARSER, NAME) \
31
+ do { \
32
+ const llhttp_settings_t* settings; \
33
+ settings = (const llhttp_settings_t*) (PARSER)->settings; \
34
+ if (settings == NULL || settings->NAME == NULL) { \
35
+ err = 0; \
36
+ break; \
37
+ } \
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
+ } \
54
+ } while (0)
55
+
56
+ void llhttp_init(llhttp_t* parser, llhttp_type_t type,
57
+ const llhttp_settings_t* settings) {
58
+ llhttp__internal_init(parser);
59
+
60
+ parser->type = type;
61
+ parser->settings = (void*) settings;
62
+ }
63
+
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
+
129
+ void llhttp_reset(llhttp_t* parser) {
130
+ llhttp_type_t type = parser->type;
131
+ const llhttp_settings_t* settings = parser->settings;
132
+ void* data = parser->data;
133
+ uint8_t lenient_flags = parser->lenient_flags;
134
+
135
+ llhttp__internal_init(parser);
136
+
137
+ parser->type = type;
138
+ parser->settings = (void*) settings;
139
+ parser->data = data;
140
+ parser->lenient_flags = lenient_flags;
141
+ }
142
+
143
+
144
+ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) {
145
+ return llhttp__internal_execute(parser, data, data + len);
146
+ }
147
+
148
+
149
+ void llhttp_settings_init(llhttp_settings_t* settings) {
150
+ memset(settings, 0, sizeof(*settings));
151
+ }
152
+
153
+
154
+ llhttp_errno_t llhttp_finish(llhttp_t* parser) {
155
+ int err;
156
+
157
+ /* We're in an error state. Don't bother doing anything. */
158
+ if (parser->error != 0) {
159
+ return 0;
160
+ }
161
+
162
+ switch (parser->finish) {
163
+ case HTTP_FINISH_SAFE_WITH_CB:
164
+ CALLBACK_MAYBE(parser, on_message_complete);
165
+ if (err != HPE_OK) return err;
166
+
167
+ /* FALLTHROUGH */
168
+ case HTTP_FINISH_SAFE:
169
+ return HPE_OK;
170
+ case HTTP_FINISH_UNSAFE:
171
+ parser->reason = "Invalid EOF state";
172
+ return HPE_INVALID_EOF_STATE;
173
+ default:
174
+ abort();
175
+ }
176
+ }
177
+
178
+
179
+ void llhttp_pause(llhttp_t* parser) {
180
+ if (parser->error != HPE_OK) {
181
+ return;
182
+ }
183
+
184
+ parser->error = HPE_PAUSED;
185
+ parser->reason = "Paused";
186
+ }
187
+
188
+
189
+ void llhttp_resume(llhttp_t* parser) {
190
+ if (parser->error != HPE_PAUSED) {
191
+ return;
192
+ }
193
+
194
+ parser->error = 0;
195
+ }
196
+
197
+
198
+ void llhttp_resume_after_upgrade(llhttp_t* parser) {
199
+ if (parser->error != HPE_PAUSED_UPGRADE) {
200
+ return;
201
+ }
202
+
203
+ parser->error = 0;
204
+ }
205
+
206
+
207
+ llhttp_errno_t llhttp_get_errno(const llhttp_t* parser) {
208
+ return parser->error;
209
+ }
210
+
211
+
212
+ const char* llhttp_get_error_reason(const llhttp_t* parser) {
213
+ return parser->reason;
214
+ }
215
+
216
+
217
+ void llhttp_set_error_reason(llhttp_t* parser, const char* reason) {
218
+ parser->reason = reason;
219
+ }
220
+
221
+
222
+ const char* llhttp_get_error_pos(const llhttp_t* parser) {
223
+ return parser->error_pos;
224
+ }
225
+
226
+
227
+ const char* llhttp_errno_name(llhttp_errno_t err) {
228
+ #define HTTP_ERRNO_GEN(CODE, NAME, _) case HPE_##NAME: return "HPE_" #NAME;
229
+ switch (err) {
230
+ HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
231
+ default: abort();
232
+ }
233
+ #undef HTTP_ERRNO_GEN
234
+ }
235
+
236
+
237
+ const char* llhttp_method_name(llhttp_method_t method) {
238
+ #define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING;
239
+ switch (method) {
240
+ HTTP_ALL_METHOD_MAP(HTTP_METHOD_GEN)
241
+ default: abort();
242
+ }
243
+ #undef HTTP_METHOD_GEN
244
+ }
245
+
246
+
247
+ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
248
+ if (enabled) {
249
+ parser->lenient_flags |= LENIENT_HEADERS;
250
+ } else {
251
+ parser->lenient_flags &= ~LENIENT_HEADERS;
252
+ }
253
+ }
254
+
255
+
256
+ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
257
+ if (enabled) {
258
+ parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
259
+ } else {
260
+ parser->lenient_flags &= ~LENIENT_CHUNKED_LENGTH;
261
+ }
262
+ }
263
+
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
+
273
+ /* Callbacks */
274
+
275
+
276
+ int llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) {
277
+ int err;
278
+ CALLBACK_MAYBE(s, on_message_begin);
279
+ return err;
280
+ }
281
+
282
+
283
+ int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) {
284
+ int err;
285
+ SPAN_CALLBACK_MAYBE(s, on_url, p, endp - p);
286
+ return err;
287
+ }
288
+
289
+
290
+ int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) {
291
+ int err;
292
+ CALLBACK_MAYBE(s, on_url_complete);
293
+ return err;
294
+ }
295
+
296
+
297
+ int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) {
298
+ int err;
299
+ SPAN_CALLBACK_MAYBE(s, on_status, p, endp - p);
300
+ return err;
301
+ }
302
+
303
+
304
+ int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) {
305
+ int err;
306
+ CALLBACK_MAYBE(s, on_status_complete);
307
+ return err;
308
+ }
309
+
310
+
311
+ int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) {
312
+ int err;
313
+ SPAN_CALLBACK_MAYBE(s, on_header_field, p, endp - p);
314
+ return err;
315
+ }
316
+
317
+
318
+ int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) {
319
+ int err;
320
+ CALLBACK_MAYBE(s, on_header_field_complete);
321
+ return err;
322
+ }
323
+
324
+
325
+ int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) {
326
+ int err;
327
+ SPAN_CALLBACK_MAYBE(s, on_header_value, p, endp - p);
328
+ return err;
329
+ }
330
+
331
+
332
+ int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) {
333
+ int err;
334
+ CALLBACK_MAYBE(s, on_header_value_complete);
335
+ return err;
336
+ }
337
+
338
+
339
+ int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) {
340
+ int err;
341
+ CALLBACK_MAYBE(s, on_headers_complete);
342
+ return err;
343
+ }
344
+
345
+
346
+ int llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) {
347
+ int err;
348
+ CALLBACK_MAYBE(s, on_message_complete);
349
+ return err;
350
+ }
351
+
352
+
353
+ int llhttp__on_body(llhttp_t* s, const char* p, const char* endp) {
354
+ int err;
355
+ SPAN_CALLBACK_MAYBE(s, on_body, p, endp - p);
356
+ return err;
357
+ }
358
+
359
+
360
+ int llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) {
361
+ int err;
362
+ CALLBACK_MAYBE(s, on_chunk_header);
363
+ return err;
364
+ }
365
+
366
+
367
+ int llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) {
368
+ int err;
369
+ CALLBACK_MAYBE(s, on_chunk_complete);
370
+ return err;
371
+ }
372
+
373
+
374
+ /* Private */
375
+
376
+
377
+ void llhttp__debug(llhttp_t* s, const char* p, const char* endp,
378
+ const char* msg) {
379
+ if (p == endp) {
380
+ fprintf(stderr, "p=%p type=%d flags=%02x next=null debug=%s\n", s, s->type,
381
+ s->flags, msg);
382
+ } else {
383
+ fprintf(stderr, "p=%p type=%d flags=%02x next=%02x debug=%s\n", s,
384
+ s->type, s->flags, *p, msg);
385
+ }
386
+ }