Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.0 KiB

  1. /* See LICENSE file for copyright and license details. */
  2. #ifndef HTTP_H
  3. #define HTTP_H
  4. #include <limits.h>
  5. #include <sys/socket.h>
  6. #include "config.h"
  7. #include "server.h"
  8. #include "util.h"
  9. enum req_field {
  10. REQ_HOST,
  11. REQ_RANGE,
  12. REQ_IF_MODIFIED_SINCE,
  13. NUM_REQ_FIELDS,
  14. };
  15. extern const char *req_field_str[];
  16. enum req_method {
  17. M_GET,
  18. M_HEAD,
  19. NUM_REQ_METHODS,
  20. };
  21. extern const char *req_method_str[];
  22. struct request {
  23. enum req_method method;
  24. char path[PATH_MAX];
  25. char query[FIELD_MAX];
  26. char fragment[FIELD_MAX];
  27. char field[NUM_REQ_FIELDS][FIELD_MAX];
  28. };
  29. enum status {
  30. S_OK = 200,
  31. S_PARTIAL_CONTENT = 206,
  32. S_MOVED_PERMANENTLY = 301,
  33. S_NOT_MODIFIED = 304,
  34. S_BAD_REQUEST = 400,
  35. S_FORBIDDEN = 403,
  36. S_NOT_FOUND = 404,
  37. S_METHOD_NOT_ALLOWED = 405,
  38. S_REQUEST_TIMEOUT = 408,
  39. S_RANGE_NOT_SATISFIABLE = 416,
  40. S_REQUEST_TOO_LARGE = 431,
  41. S_INTERNAL_SERVER_ERROR = 500,
  42. S_VERSION_NOT_SUPPORTED = 505,
  43. };
  44. extern const char *status_str[];
  45. enum res_field {
  46. RES_ACCEPT_RANGES,
  47. RES_ALLOW,
  48. RES_LOCATION,
  49. RES_LAST_MODIFIED,
  50. RES_CONTENT_LENGTH,
  51. RES_CONTENT_RANGE,
  52. RES_CONTENT_TYPE,
  53. NUM_RES_FIELDS,
  54. };
  55. extern const char *res_field_str[];
  56. enum res_type {
  57. RESTYPE_DIRLISTING,
  58. RESTYPE_ERROR,
  59. RESTYPE_FILE,
  60. NUM_RES_TYPES,
  61. };
  62. struct response {
  63. enum res_type type;
  64. enum status status;
  65. char field[NUM_RES_FIELDS][FIELD_MAX];
  66. char path[PATH_MAX];
  67. char internal_path[PATH_MAX];
  68. struct vhost *vhost;
  69. struct {
  70. size_t lower;
  71. size_t upper;
  72. } file;
  73. };
  74. enum status http_prepare_header_buf(const struct response *, struct buffer *);
  75. enum status http_send_buf(int, struct buffer *);
  76. enum status http_recv_header(int, struct buffer *, int *);
  77. enum status http_parse_header(const char *, struct request *);
  78. void http_prepare_response(const struct request *, struct response *,
  79. const struct server *);
  80. void http_prepare_error_response(const struct request *,
  81. struct response *, enum status);
  82. #endif /* HTTP_H */