_cparser.pxd 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. from libc.stdint cimport int32_t, uint8_t, uint16_t, uint64_t
  2. cdef extern from "../vendor/llhttp/build/llhttp.h":
  3. struct llhttp__internal_s:
  4. int32_t _index
  5. void* _span_pos0
  6. void* _span_cb0
  7. int32_t error
  8. const char* reason
  9. const char* error_pos
  10. void* data
  11. void* _current
  12. uint64_t content_length
  13. uint8_t type
  14. uint8_t method
  15. uint8_t http_major
  16. uint8_t http_minor
  17. uint8_t header_state
  18. uint8_t lenient_flags
  19. uint8_t upgrade
  20. uint8_t finish
  21. uint16_t flags
  22. uint16_t status_code
  23. void* settings
  24. ctypedef llhttp__internal_s llhttp__internal_t
  25. ctypedef llhttp__internal_t llhttp_t
  26. ctypedef int (*llhttp_data_cb)(llhttp_t*, const char *at, size_t length) except -1
  27. ctypedef int (*llhttp_cb)(llhttp_t*) except -1
  28. struct llhttp_settings_s:
  29. llhttp_cb on_message_begin
  30. llhttp_data_cb on_url
  31. llhttp_data_cb on_status
  32. llhttp_data_cb on_header_field
  33. llhttp_data_cb on_header_value
  34. llhttp_cb on_headers_complete
  35. llhttp_data_cb on_body
  36. llhttp_cb on_message_complete
  37. llhttp_cb on_chunk_header
  38. llhttp_cb on_chunk_complete
  39. llhttp_cb on_url_complete
  40. llhttp_cb on_status_complete
  41. llhttp_cb on_header_field_complete
  42. llhttp_cb on_header_value_complete
  43. ctypedef llhttp_settings_s llhttp_settings_t
  44. enum llhttp_errno:
  45. HPE_OK,
  46. HPE_INTERNAL,
  47. HPE_STRICT,
  48. HPE_LF_EXPECTED,
  49. HPE_UNEXPECTED_CONTENT_LENGTH,
  50. HPE_CLOSED_CONNECTION,
  51. HPE_INVALID_METHOD,
  52. HPE_INVALID_URL,
  53. HPE_INVALID_CONSTANT,
  54. HPE_INVALID_VERSION,
  55. HPE_INVALID_HEADER_TOKEN,
  56. HPE_INVALID_CONTENT_LENGTH,
  57. HPE_INVALID_CHUNK_SIZE,
  58. HPE_INVALID_STATUS,
  59. HPE_INVALID_EOF_STATE,
  60. HPE_INVALID_TRANSFER_ENCODING,
  61. HPE_CB_MESSAGE_BEGIN,
  62. HPE_CB_HEADERS_COMPLETE,
  63. HPE_CB_MESSAGE_COMPLETE,
  64. HPE_CB_CHUNK_HEADER,
  65. HPE_CB_CHUNK_COMPLETE,
  66. HPE_PAUSED,
  67. HPE_PAUSED_UPGRADE,
  68. HPE_USER
  69. ctypedef llhttp_errno llhttp_errno_t
  70. enum llhttp_flags:
  71. F_CHUNKED,
  72. F_CONTENT_LENGTH
  73. enum llhttp_type:
  74. HTTP_REQUEST,
  75. HTTP_RESPONSE,
  76. HTTP_BOTH
  77. enum llhttp_method:
  78. HTTP_DELETE,
  79. HTTP_GET,
  80. HTTP_HEAD,
  81. HTTP_POST,
  82. HTTP_PUT,
  83. HTTP_CONNECT,
  84. HTTP_OPTIONS,
  85. HTTP_TRACE,
  86. HTTP_COPY,
  87. HTTP_LOCK,
  88. HTTP_MKCOL,
  89. HTTP_MOVE,
  90. HTTP_PROPFIND,
  91. HTTP_PROPPATCH,
  92. HTTP_SEARCH,
  93. HTTP_UNLOCK,
  94. HTTP_BIND,
  95. HTTP_REBIND,
  96. HTTP_UNBIND,
  97. HTTP_ACL,
  98. HTTP_REPORT,
  99. HTTP_MKACTIVITY,
  100. HTTP_CHECKOUT,
  101. HTTP_MERGE,
  102. HTTP_MSEARCH,
  103. HTTP_NOTIFY,
  104. HTTP_SUBSCRIBE,
  105. HTTP_UNSUBSCRIBE,
  106. HTTP_PATCH,
  107. HTTP_PURGE,
  108. HTTP_MKCALENDAR,
  109. HTTP_LINK,
  110. HTTP_UNLINK,
  111. HTTP_SOURCE,
  112. HTTP_PRI,
  113. HTTP_DESCRIBE,
  114. HTTP_ANNOUNCE,
  115. HTTP_SETUP,
  116. HTTP_PLAY,
  117. HTTP_PAUSE,
  118. HTTP_TEARDOWN,
  119. HTTP_GET_PARAMETER,
  120. HTTP_SET_PARAMETER,
  121. HTTP_REDIRECT,
  122. HTTP_RECORD,
  123. HTTP_FLUSH
  124. ctypedef llhttp_method llhttp_method_t;
  125. void llhttp_settings_init(llhttp_settings_t* settings)
  126. void llhttp_init(llhttp_t* parser, llhttp_type type,
  127. const llhttp_settings_t* settings)
  128. llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len)
  129. int llhttp_should_keep_alive(const llhttp_t* parser)
  130. void llhttp_resume_after_upgrade(llhttp_t* parser)
  131. llhttp_errno_t llhttp_get_errno(const llhttp_t* parser)
  132. const char* llhttp_get_error_reason(const llhttp_t* parser)
  133. const char* llhttp_get_error_pos(const llhttp_t* parser)
  134. const char* llhttp_method_name(llhttp_method_t method)
  135. void llhttp_set_lenient_headers(llhttp_t* parser, int enabled)
  136. void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled)
  137. void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled)