quark

quark web server
git clone git://git.suckless.org/quark
Log | Files | Refs | LICENSE

http.h (2072B)


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