llhttp_url.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef INCLUDE_LLHTTP_URL_H_
  2. #define INCLUDE_LLHTTP_URL_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. // copy code from http_parser
  9. /* Compile with -DLLHTTP_STRICT_MODE=0 to make less checks, but run
  10. * faster
  11. */
  12. #ifndef LLHTTP_STRICT_MODE
  13. # define LLHTTP_STRICT_MODE 1
  14. #endif
  15. enum http_parser_url_fields
  16. { UF_SCHEMA = 0
  17. , UF_HOST = 1
  18. , UF_PORT = 2
  19. , UF_PATH = 3
  20. , UF_QUERY = 4
  21. , UF_FRAGMENT = 5
  22. , UF_USERINFO = 6
  23. , UF_MAX = 7
  24. };
  25. /* Result structure for http_parser_parse_url().
  26. *
  27. * Callers should index into field_data[] with UF_* values iff field_set
  28. * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
  29. * because we probably have padding left over), we convert any port to
  30. * a uint16_t.
  31. */
  32. struct http_parser_url {
  33. uint16_t field_set; /* Bitmask of (1 << UF_*) values */
  34. uint16_t port; /* Converted UF_PORT string */
  35. struct {
  36. uint16_t off; /* Offset into buffer in which field starts */
  37. uint16_t len; /* Length of run in buffer */
  38. } field_data[UF_MAX];
  39. };
  40. /* Initialize all http_parser_url members to 0 */
  41. void http_parser_url_init(struct http_parser_url *u);
  42. /* Parse a URL; return nonzero on failure */
  43. int http_parser_parse_url(const char *buf, size_t buflen,
  44. int is_connect, struct http_parser_url *u);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif // INCLUDE_LLHTTP_URL_H_