11cb0ef41Sopenharmony_ci#include <stdlib.h>
21cb0ef41Sopenharmony_ci#include <stdio.h>
31cb0ef41Sopenharmony_ci#include <string.h>
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "llhttp.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#define CALLBACK_MAYBE(PARSER, NAME)                                          \
81cb0ef41Sopenharmony_ci  do {                                                                        \
91cb0ef41Sopenharmony_ci    const llhttp_settings_t* settings;                                        \
101cb0ef41Sopenharmony_ci    settings = (const llhttp_settings_t*) (PARSER)->settings;                 \
111cb0ef41Sopenharmony_ci    if (settings == NULL || settings->NAME == NULL) {                         \
121cb0ef41Sopenharmony_ci      err = 0;                                                                \
131cb0ef41Sopenharmony_ci      break;                                                                  \
141cb0ef41Sopenharmony_ci    }                                                                         \
151cb0ef41Sopenharmony_ci    err = settings->NAME((PARSER));                                           \
161cb0ef41Sopenharmony_ci  } while (0)
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN)                         \
191cb0ef41Sopenharmony_ci  do {                                                                        \
201cb0ef41Sopenharmony_ci    const llhttp_settings_t* settings;                                        \
211cb0ef41Sopenharmony_ci    settings = (const llhttp_settings_t*) (PARSER)->settings;                 \
221cb0ef41Sopenharmony_ci    if (settings == NULL || settings->NAME == NULL) {                         \
231cb0ef41Sopenharmony_ci      err = 0;                                                                \
241cb0ef41Sopenharmony_ci      break;                                                                  \
251cb0ef41Sopenharmony_ci    }                                                                         \
261cb0ef41Sopenharmony_ci    err = settings->NAME((PARSER), (START), (LEN));                           \
271cb0ef41Sopenharmony_ci    if (err == -1) {                                                          \
281cb0ef41Sopenharmony_ci      err = HPE_USER;                                                         \
291cb0ef41Sopenharmony_ci      llhttp_set_error_reason((PARSER), "Span callback error in " #NAME);     \
301cb0ef41Sopenharmony_ci    }                                                                         \
311cb0ef41Sopenharmony_ci  } while (0)
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_civoid llhttp_init(llhttp_t* parser, llhttp_type_t type,
341cb0ef41Sopenharmony_ci                 const llhttp_settings_t* settings) {
351cb0ef41Sopenharmony_ci  llhttp__internal_init(parser);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  parser->type = type;
381cb0ef41Sopenharmony_ci  parser->settings = (void*) settings;
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci#if defined(__wasm__)
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ciextern int wasm_on_message_begin(llhttp_t * p);
451cb0ef41Sopenharmony_ciextern int wasm_on_url(llhttp_t* p, const char* at, size_t length);
461cb0ef41Sopenharmony_ciextern int wasm_on_status(llhttp_t* p, const char* at, size_t length);
471cb0ef41Sopenharmony_ciextern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length);
481cb0ef41Sopenharmony_ciextern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length);
491cb0ef41Sopenharmony_ciextern int wasm_on_headers_complete(llhttp_t * p, int status_code,
501cb0ef41Sopenharmony_ci                                    uint8_t upgrade, int should_keep_alive);
511cb0ef41Sopenharmony_ciextern int wasm_on_body(llhttp_t* p, const char* at, size_t length);
521cb0ef41Sopenharmony_ciextern int wasm_on_message_complete(llhttp_t * p);
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_cistatic int wasm_on_headers_complete_wrap(llhttp_t* p) {
551cb0ef41Sopenharmony_ci  return wasm_on_headers_complete(p, p->status_code, p->upgrade,
561cb0ef41Sopenharmony_ci                                  llhttp_should_keep_alive(p));
571cb0ef41Sopenharmony_ci}
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ciconst llhttp_settings_t wasm_settings = {
601cb0ef41Sopenharmony_ci  wasm_on_message_begin,
611cb0ef41Sopenharmony_ci  wasm_on_url,
621cb0ef41Sopenharmony_ci  wasm_on_status,
631cb0ef41Sopenharmony_ci  wasm_on_header_field,
641cb0ef41Sopenharmony_ci  wasm_on_header_value,
651cb0ef41Sopenharmony_ci  wasm_on_headers_complete_wrap,
661cb0ef41Sopenharmony_ci  wasm_on_body,
671cb0ef41Sopenharmony_ci  wasm_on_message_complete,
681cb0ef41Sopenharmony_ci  NULL,
691cb0ef41Sopenharmony_ci  NULL,
701cb0ef41Sopenharmony_ci};
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_cillhttp_t* llhttp_alloc(llhttp_type_t type) {
741cb0ef41Sopenharmony_ci  llhttp_t* parser = malloc(sizeof(llhttp_t));
751cb0ef41Sopenharmony_ci  llhttp_init(parser, type, &wasm_settings);
761cb0ef41Sopenharmony_ci  return parser;
771cb0ef41Sopenharmony_ci}
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_civoid llhttp_free(llhttp_t* parser) {
801cb0ef41Sopenharmony_ci  free(parser);
811cb0ef41Sopenharmony_ci}
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci/* Some getters required to get stuff from the parser */
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ciuint8_t llhttp_get_type(llhttp_t* parser) {
861cb0ef41Sopenharmony_ci  return parser->type;
871cb0ef41Sopenharmony_ci}
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ciuint8_t llhttp_get_http_major(llhttp_t* parser) {
901cb0ef41Sopenharmony_ci  return parser->http_major;
911cb0ef41Sopenharmony_ci}
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ciuint8_t llhttp_get_http_minor(llhttp_t* parser) {
941cb0ef41Sopenharmony_ci  return parser->http_minor;
951cb0ef41Sopenharmony_ci}
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciuint8_t llhttp_get_method(llhttp_t* parser) {
981cb0ef41Sopenharmony_ci  return parser->method;
991cb0ef41Sopenharmony_ci}
1001cb0ef41Sopenharmony_ci
1011cb0ef41Sopenharmony_ciint llhttp_get_status_code(llhttp_t* parser) {
1021cb0ef41Sopenharmony_ci  return parser->status_code;
1031cb0ef41Sopenharmony_ci}
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ciuint8_t llhttp_get_upgrade(llhttp_t* parser) {
1061cb0ef41Sopenharmony_ci  return parser->upgrade;
1071cb0ef41Sopenharmony_ci}
1081cb0ef41Sopenharmony_ci
1091cb0ef41Sopenharmony_ci#endif  // defined(__wasm__)
1101cb0ef41Sopenharmony_ci
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_civoid llhttp_reset(llhttp_t* parser) {
1131cb0ef41Sopenharmony_ci  llhttp_type_t type = parser->type;
1141cb0ef41Sopenharmony_ci  const llhttp_settings_t* settings = parser->settings;
1151cb0ef41Sopenharmony_ci  void* data = parser->data;
1161cb0ef41Sopenharmony_ci  uint8_t lenient_flags = parser->lenient_flags;
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci  llhttp__internal_init(parser);
1191cb0ef41Sopenharmony_ci
1201cb0ef41Sopenharmony_ci  parser->type = type;
1211cb0ef41Sopenharmony_ci  parser->settings = (void*) settings;
1221cb0ef41Sopenharmony_ci  parser->data = data;
1231cb0ef41Sopenharmony_ci  parser->lenient_flags = lenient_flags;
1241cb0ef41Sopenharmony_ci}
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_cillhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) {
1281cb0ef41Sopenharmony_ci  return llhttp__internal_execute(parser, data, data + len);
1291cb0ef41Sopenharmony_ci}
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci
1321cb0ef41Sopenharmony_civoid llhttp_settings_init(llhttp_settings_t* settings) {
1331cb0ef41Sopenharmony_ci  memset(settings, 0, sizeof(*settings));
1341cb0ef41Sopenharmony_ci}
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_cillhttp_errno_t llhttp_finish(llhttp_t* parser) {
1381cb0ef41Sopenharmony_ci  int err;
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ci  /* We're in an error state. Don't bother doing anything. */
1411cb0ef41Sopenharmony_ci  if (parser->error != 0) {
1421cb0ef41Sopenharmony_ci    return 0;
1431cb0ef41Sopenharmony_ci  }
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci  switch (parser->finish) {
1461cb0ef41Sopenharmony_ci    case HTTP_FINISH_SAFE_WITH_CB:
1471cb0ef41Sopenharmony_ci      CALLBACK_MAYBE(parser, on_message_complete);
1481cb0ef41Sopenharmony_ci      if (err != HPE_OK) return err;
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ci    /* FALLTHROUGH */
1511cb0ef41Sopenharmony_ci    case HTTP_FINISH_SAFE:
1521cb0ef41Sopenharmony_ci      return HPE_OK;
1531cb0ef41Sopenharmony_ci    case HTTP_FINISH_UNSAFE:
1541cb0ef41Sopenharmony_ci      parser->reason = "Invalid EOF state";
1551cb0ef41Sopenharmony_ci      return HPE_INVALID_EOF_STATE;
1561cb0ef41Sopenharmony_ci    default:
1571cb0ef41Sopenharmony_ci      abort();
1581cb0ef41Sopenharmony_ci  }
1591cb0ef41Sopenharmony_ci}
1601cb0ef41Sopenharmony_ci
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_civoid llhttp_pause(llhttp_t* parser) {
1631cb0ef41Sopenharmony_ci  if (parser->error != HPE_OK) {
1641cb0ef41Sopenharmony_ci    return;
1651cb0ef41Sopenharmony_ci  }
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci  parser->error = HPE_PAUSED;
1681cb0ef41Sopenharmony_ci  parser->reason = "Paused";
1691cb0ef41Sopenharmony_ci}
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_civoid llhttp_resume(llhttp_t* parser) {
1731cb0ef41Sopenharmony_ci  if (parser->error != HPE_PAUSED) {
1741cb0ef41Sopenharmony_ci    return;
1751cb0ef41Sopenharmony_ci  }
1761cb0ef41Sopenharmony_ci
1771cb0ef41Sopenharmony_ci  parser->error = 0;
1781cb0ef41Sopenharmony_ci}
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci
1811cb0ef41Sopenharmony_civoid llhttp_resume_after_upgrade(llhttp_t* parser) {
1821cb0ef41Sopenharmony_ci  if (parser->error != HPE_PAUSED_UPGRADE) {
1831cb0ef41Sopenharmony_ci    return;
1841cb0ef41Sopenharmony_ci  }
1851cb0ef41Sopenharmony_ci
1861cb0ef41Sopenharmony_ci  parser->error = 0;
1871cb0ef41Sopenharmony_ci}
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_cillhttp_errno_t llhttp_get_errno(const llhttp_t* parser) {
1911cb0ef41Sopenharmony_ci  return parser->error;
1921cb0ef41Sopenharmony_ci}
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ci
1951cb0ef41Sopenharmony_ciconst char* llhttp_get_error_reason(const llhttp_t* parser) {
1961cb0ef41Sopenharmony_ci  return parser->reason;
1971cb0ef41Sopenharmony_ci}
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci
2001cb0ef41Sopenharmony_civoid llhttp_set_error_reason(llhttp_t* parser, const char* reason) {
2011cb0ef41Sopenharmony_ci  parser->reason = reason;
2021cb0ef41Sopenharmony_ci}
2031cb0ef41Sopenharmony_ci
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ciconst char* llhttp_get_error_pos(const llhttp_t* parser) {
2061cb0ef41Sopenharmony_ci  return parser->error_pos;
2071cb0ef41Sopenharmony_ci}
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ciconst char* llhttp_errno_name(llhttp_errno_t err) {
2111cb0ef41Sopenharmony_ci#define HTTP_ERRNO_GEN(CODE, NAME, _) case HPE_##NAME: return "HPE_" #NAME;
2121cb0ef41Sopenharmony_ci  switch (err) {
2131cb0ef41Sopenharmony_ci    HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
2141cb0ef41Sopenharmony_ci    default: abort();
2151cb0ef41Sopenharmony_ci  }
2161cb0ef41Sopenharmony_ci#undef HTTP_ERRNO_GEN
2171cb0ef41Sopenharmony_ci}
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci
2201cb0ef41Sopenharmony_ciconst char* llhttp_method_name(llhttp_method_t method) {
2211cb0ef41Sopenharmony_ci#define HTTP_METHOD_GEN(NUM, NAME, STRING) case HTTP_##NAME: return #STRING;
2221cb0ef41Sopenharmony_ci  switch (method) {
2231cb0ef41Sopenharmony_ci    HTTP_ALL_METHOD_MAP(HTTP_METHOD_GEN)
2241cb0ef41Sopenharmony_ci    default: abort();
2251cb0ef41Sopenharmony_ci  }
2261cb0ef41Sopenharmony_ci#undef HTTP_METHOD_GEN
2271cb0ef41Sopenharmony_ci}
2281cb0ef41Sopenharmony_ci
2291cb0ef41Sopenharmony_ci
2301cb0ef41Sopenharmony_civoid llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
2311cb0ef41Sopenharmony_ci  if (enabled) {
2321cb0ef41Sopenharmony_ci    parser->lenient_flags |= LENIENT_HEADERS;
2331cb0ef41Sopenharmony_ci  } else {
2341cb0ef41Sopenharmony_ci    parser->lenient_flags &= ~LENIENT_HEADERS;
2351cb0ef41Sopenharmony_ci  }
2361cb0ef41Sopenharmony_ci}
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_civoid llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
2401cb0ef41Sopenharmony_ci  if (enabled) {
2411cb0ef41Sopenharmony_ci    parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
2421cb0ef41Sopenharmony_ci  } else {
2431cb0ef41Sopenharmony_ci    parser->lenient_flags &= ~LENIENT_CHUNKED_LENGTH;
2441cb0ef41Sopenharmony_ci  }
2451cb0ef41Sopenharmony_ci}
2461cb0ef41Sopenharmony_ci
2471cb0ef41Sopenharmony_ci
2481cb0ef41Sopenharmony_civoid llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) {
2491cb0ef41Sopenharmony_ci  if (enabled) {
2501cb0ef41Sopenharmony_ci    parser->lenient_flags |= LENIENT_KEEP_ALIVE;
2511cb0ef41Sopenharmony_ci  } else {
2521cb0ef41Sopenharmony_ci    parser->lenient_flags &= ~LENIENT_KEEP_ALIVE;
2531cb0ef41Sopenharmony_ci  }
2541cb0ef41Sopenharmony_ci}
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_civoid llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled) {
2571cb0ef41Sopenharmony_ci  if (enabled) {
2581cb0ef41Sopenharmony_ci    parser->lenient_flags |= LENIENT_TRANSFER_ENCODING;
2591cb0ef41Sopenharmony_ci  } else {
2601cb0ef41Sopenharmony_ci    parser->lenient_flags &= ~LENIENT_TRANSFER_ENCODING;
2611cb0ef41Sopenharmony_ci  }
2621cb0ef41Sopenharmony_ci}
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci/* Callbacks */
2651cb0ef41Sopenharmony_ci
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ciint llhttp__on_message_begin(llhttp_t* s, const char* p, const char* endp) {
2681cb0ef41Sopenharmony_ci  int err;
2691cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_message_begin);
2701cb0ef41Sopenharmony_ci  return err;
2711cb0ef41Sopenharmony_ci}
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci
2741cb0ef41Sopenharmony_ciint llhttp__on_url(llhttp_t* s, const char* p, const char* endp) {
2751cb0ef41Sopenharmony_ci  int err;
2761cb0ef41Sopenharmony_ci  SPAN_CALLBACK_MAYBE(s, on_url, p, endp - p);
2771cb0ef41Sopenharmony_ci  return err;
2781cb0ef41Sopenharmony_ci}
2791cb0ef41Sopenharmony_ci
2801cb0ef41Sopenharmony_ci
2811cb0ef41Sopenharmony_ciint llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) {
2821cb0ef41Sopenharmony_ci  int err;
2831cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_url_complete);
2841cb0ef41Sopenharmony_ci  return err;
2851cb0ef41Sopenharmony_ci}
2861cb0ef41Sopenharmony_ci
2871cb0ef41Sopenharmony_ci
2881cb0ef41Sopenharmony_ciint llhttp__on_status(llhttp_t* s, const char* p, const char* endp) {
2891cb0ef41Sopenharmony_ci  int err;
2901cb0ef41Sopenharmony_ci  SPAN_CALLBACK_MAYBE(s, on_status, p, endp - p);
2911cb0ef41Sopenharmony_ci  return err;
2921cb0ef41Sopenharmony_ci}
2931cb0ef41Sopenharmony_ci
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ciint llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) {
2961cb0ef41Sopenharmony_ci  int err;
2971cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_status_complete);
2981cb0ef41Sopenharmony_ci  return err;
2991cb0ef41Sopenharmony_ci}
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ciint llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) {
3031cb0ef41Sopenharmony_ci  int err;
3041cb0ef41Sopenharmony_ci  SPAN_CALLBACK_MAYBE(s, on_header_field, p, endp - p);
3051cb0ef41Sopenharmony_ci  return err;
3061cb0ef41Sopenharmony_ci}
3071cb0ef41Sopenharmony_ci
3081cb0ef41Sopenharmony_ci
3091cb0ef41Sopenharmony_ciint llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) {
3101cb0ef41Sopenharmony_ci  int err;
3111cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_header_field_complete);
3121cb0ef41Sopenharmony_ci  return err;
3131cb0ef41Sopenharmony_ci}
3141cb0ef41Sopenharmony_ci
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_ciint llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) {
3171cb0ef41Sopenharmony_ci  int err;
3181cb0ef41Sopenharmony_ci  SPAN_CALLBACK_MAYBE(s, on_header_value, p, endp - p);
3191cb0ef41Sopenharmony_ci  return err;
3201cb0ef41Sopenharmony_ci}
3211cb0ef41Sopenharmony_ci
3221cb0ef41Sopenharmony_ci
3231cb0ef41Sopenharmony_ciint llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) {
3241cb0ef41Sopenharmony_ci  int err;
3251cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_header_value_complete);
3261cb0ef41Sopenharmony_ci  return err;
3271cb0ef41Sopenharmony_ci}
3281cb0ef41Sopenharmony_ci
3291cb0ef41Sopenharmony_ci
3301cb0ef41Sopenharmony_ciint llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) {
3311cb0ef41Sopenharmony_ci  int err;
3321cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_headers_complete);
3331cb0ef41Sopenharmony_ci  return err;
3341cb0ef41Sopenharmony_ci}
3351cb0ef41Sopenharmony_ci
3361cb0ef41Sopenharmony_ci
3371cb0ef41Sopenharmony_ciint llhttp__on_message_complete(llhttp_t* s, const char* p, const char* endp) {
3381cb0ef41Sopenharmony_ci  int err;
3391cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_message_complete);
3401cb0ef41Sopenharmony_ci  return err;
3411cb0ef41Sopenharmony_ci}
3421cb0ef41Sopenharmony_ci
3431cb0ef41Sopenharmony_ci
3441cb0ef41Sopenharmony_ciint llhttp__on_body(llhttp_t* s, const char* p, const char* endp) {
3451cb0ef41Sopenharmony_ci  int err;
3461cb0ef41Sopenharmony_ci  SPAN_CALLBACK_MAYBE(s, on_body, p, endp - p);
3471cb0ef41Sopenharmony_ci  return err;
3481cb0ef41Sopenharmony_ci}
3491cb0ef41Sopenharmony_ci
3501cb0ef41Sopenharmony_ci
3511cb0ef41Sopenharmony_ciint llhttp__on_chunk_header(llhttp_t* s, const char* p, const char* endp) {
3521cb0ef41Sopenharmony_ci  int err;
3531cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_chunk_header);
3541cb0ef41Sopenharmony_ci  return err;
3551cb0ef41Sopenharmony_ci}
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ciint llhttp__on_chunk_parameters(llhttp_t* s, const char* p, const char* endp) {
3591cb0ef41Sopenharmony_ci  int err;
3601cb0ef41Sopenharmony_ci  SPAN_CALLBACK_MAYBE(s, on_chunk_parameters, p, endp - p);
3611cb0ef41Sopenharmony_ci  return err;
3621cb0ef41Sopenharmony_ci}
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ciint llhttp__on_chunk_complete(llhttp_t* s, const char* p, const char* endp) {
3661cb0ef41Sopenharmony_ci  int err;
3671cb0ef41Sopenharmony_ci  CALLBACK_MAYBE(s, on_chunk_complete);
3681cb0ef41Sopenharmony_ci  return err;
3691cb0ef41Sopenharmony_ci}
3701cb0ef41Sopenharmony_ci
3711cb0ef41Sopenharmony_ci
3721cb0ef41Sopenharmony_ci/* Private */
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci
3751cb0ef41Sopenharmony_civoid llhttp__debug(llhttp_t* s, const char* p, const char* endp,
3761cb0ef41Sopenharmony_ci                   const char* msg) {
3771cb0ef41Sopenharmony_ci  if (p == endp) {
3781cb0ef41Sopenharmony_ci    fprintf(stderr, "p=%p type=%d flags=%02x next=null debug=%s\n", s, s->type,
3791cb0ef41Sopenharmony_ci            s->flags, msg);
3801cb0ef41Sopenharmony_ci  } else {
3811cb0ef41Sopenharmony_ci    fprintf(stderr, "p=%p type=%d flags=%02x next=%02x   debug=%s\n", s,
3821cb0ef41Sopenharmony_ci            s->type, s->flags, *p, msg);
3831cb0ef41Sopenharmony_ci  }
3841cb0ef41Sopenharmony_ci}
385