|
4 | 4 |
|
5 | 5 | #include "llhttp.h" |
6 | 6 |
|
7 | | -#define CALLBACK_MAYBE(PARSER, NAME, ...) \ |
| 7 | +#define CALLBACK_MAYBE(PARSER, NAME) \ |
8 | 8 | do { \ |
9 | 9 | const llhttp_settings_t* settings; \ |
10 | 10 | settings = (const llhttp_settings_t*) (PARSER)->settings; \ |
11 | 11 | if (settings == NULL || settings->NAME == NULL) { \ |
12 | 12 | err = 0; \ |
13 | 13 | break; \ |
14 | 14 | } \ |
15 | | - err = settings->NAME(__VA_ARGS__); \ |
| 15 | + err = settings->NAME((PARSER)); \ |
| 16 | + } while (0) |
| 17 | + |
| 18 | +#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \ |
| 19 | + do { \ |
| 20 | + const llhttp_settings_t* settings; \ |
| 21 | + settings = (const llhttp_settings_t*) (PARSER)->settings; \ |
| 22 | + if (settings == NULL || settings->NAME == NULL) { \ |
| 23 | + err = 0; \ |
| 24 | + break; \ |
| 25 | + } \ |
| 26 | + err = settings->NAME((PARSER), (START), (LEN)); \ |
| 27 | + if (err == -1) { \ |
| 28 | + err = HPE_USER; \ |
| 29 | + llhttp_set_error_reason((PARSER), "Span callback error in " #NAME); \ |
| 30 | + } \ |
16 | 31 | } while (0) |
17 | 32 |
|
18 | 33 | void llhttp_init(llhttp_t* parser, llhttp_type_t type, |
@@ -123,7 +138,7 @@ llhttp_errno_t llhttp_finish(llhttp_t* parser) { |
123 | 138 |
|
124 | 139 | switch (parser->finish) { |
125 | 140 | case HTTP_FINISH_SAFE_WITH_CB: |
126 | | - CALLBACK_MAYBE(parser, on_message_complete, parser); |
| 141 | + CALLBACK_MAYBE(parser, on_message_complete); |
127 | 142 | if (err != HPE_OK) return err; |
128 | 143 |
|
129 | 144 | /* FALLTHROUGH */ |
@@ -237,98 +252,98 @@ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) { |
237 | 252 |
|
238 | 253 | int llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) { |
239 | 254 | int err; |
240 | | - CALLBACK_MAYBE(s, on_message_begin, s); |
| 255 | + CALLBACK_MAYBE(s, on_message_begin); |
241 | 256 | return err; |
242 | 257 | } |
243 | 258 |
|
244 | 259 |
|
245 | 260 | int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) { |
246 | 261 | int err; |
247 | | - CALLBACK_MAYBE(s, on_url, s, p, endp - p); |
| 262 | + SPAN_CALLBACK_MAYBE(s, on_url, p, endp - p); |
248 | 263 | return err; |
249 | 264 | } |
250 | 265 |
|
251 | 266 |
|
252 | 267 | int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) { |
253 | 268 | int err; |
254 | | - CALLBACK_MAYBE(s, on_url_complete, s); |
| 269 | + CALLBACK_MAYBE(s, on_url_complete); |
255 | 270 | return err; |
256 | 271 | } |
257 | 272 |
|
258 | 273 |
|
259 | 274 | int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) { |
260 | 275 | int err; |
261 | | - CALLBACK_MAYBE(s, on_status, s, p, endp - p); |
| 276 | + SPAN_CALLBACK_MAYBE(s, on_status, p, endp - p); |
262 | 277 | return err; |
263 | 278 | } |
264 | 279 |
|
265 | 280 |
|
266 | 281 | int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) { |
267 | 282 | int err; |
268 | | - CALLBACK_MAYBE(s, on_status_complete, s); |
| 283 | + CALLBACK_MAYBE(s, on_status_complete); |
269 | 284 | return err; |
270 | 285 | } |
271 | 286 |
|
272 | 287 |
|
273 | 288 | int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) { |
274 | 289 | int err; |
275 | | - CALLBACK_MAYBE(s, on_header_field, s, p, endp - p); |
| 290 | + SPAN_CALLBACK_MAYBE(s, on_header_field, p, endp - p); |
276 | 291 | return err; |
277 | 292 | } |
278 | 293 |
|
279 | 294 |
|
280 | 295 | int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) { |
281 | 296 | int err; |
282 | | - CALLBACK_MAYBE(s, on_header_field_complete, s); |
| 297 | + CALLBACK_MAYBE(s, on_header_field_complete); |
283 | 298 | return err; |
284 | 299 | } |
285 | 300 |
|
286 | 301 |
|
287 | 302 | int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) { |
288 | 303 | int err; |
289 | | - CALLBACK_MAYBE(s, on_header_value, s, p, endp - p); |
| 304 | + SPAN_CALLBACK_MAYBE(s, on_header_value, p, endp - p); |
290 | 305 | return err; |
291 | 306 | } |
292 | 307 |
|
293 | 308 |
|
294 | 309 | int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) { |
295 | 310 | int err; |
296 | | - CALLBACK_MAYBE(s, on_header_value_complete, s); |
| 311 | + CALLBACK_MAYBE(s, on_header_value_complete); |
297 | 312 | return err; |
298 | 313 | } |
299 | 314 |
|
300 | 315 |
|
301 | 316 | int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) { |
302 | 317 | int err; |
303 | | - CALLBACK_MAYBE(s, on_headers_complete, s); |
| 318 | + CALLBACK_MAYBE(s, on_headers_complete); |
304 | 319 | return err; |
305 | 320 | } |
306 | 321 |
|
307 | 322 |
|
308 | 323 | int llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) { |
309 | 324 | int err; |
310 | | - CALLBACK_MAYBE(s, on_message_complete, s); |
| 325 | + CALLBACK_MAYBE(s, on_message_complete); |
311 | 326 | return err; |
312 | 327 | } |
313 | 328 |
|
314 | 329 |
|
315 | 330 | int llhttp__on_body(llhttp_t* s, const char* p, const char* endp) { |
316 | 331 | int err; |
317 | | - CALLBACK_MAYBE(s, on_body, s, p, endp - p); |
| 332 | + SPAN_CALLBACK_MAYBE(s, on_body, p, endp - p); |
318 | 333 | return err; |
319 | 334 | } |
320 | 335 |
|
321 | 336 |
|
322 | 337 | int llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) { |
323 | 338 | int err; |
324 | | - CALLBACK_MAYBE(s, on_chunk_header, s); |
| 339 | + CALLBACK_MAYBE(s, on_chunk_header); |
325 | 340 | return err; |
326 | 341 | } |
327 | 342 |
|
328 | 343 |
|
329 | 344 | int llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) { |
330 | 345 | int err; |
331 | | - CALLBACK_MAYBE(s, on_chunk_complete, s); |
| 346 | + CALLBACK_MAYBE(s, on_chunk_complete); |
332 | 347 | return err; |
333 | 348 | } |
334 | 349 |
|
|
0 commit comments