1 |
#ifndef FREEHTTPD_RESPONSE_H |
2 |
#define FREEHTTPD_RESPONSE_H |
3 |
|
4 |
#include <stdint.h> |
5 |
#include <stdio.h> |
6 |
|
7 |
#include "request.h" |
8 |
|
9 |
typedef enum freehttpd_status |
10 |
{ |
11 |
FREEHTTPD_STATUS_OK = 200, |
12 |
FREEHTTPD_STATUS_BAD_REQUEST = 400, |
13 |
FREEHTTPD_STATUS_FORBIDDEN = 403, |
14 |
FREEHTTPD_STATUS_NOT_FOUND = 404, |
15 |
FREEHTTPD_STATUS_METHOD_NOT_ALLOWED = 405, |
16 |
FREEHTTPD_STATUS_INTERNAL_SERVER_ERROR = 500, |
17 |
FREEHTTPD_STATUS_NOT_IMPLEMENTED = 501, |
18 |
} freehttpd_status_t; |
19 |
|
20 |
typedef struct freehttpd_status_info |
21 |
{ |
22 |
freehttpd_status_t code; |
23 |
const char *text; |
24 |
size_t status_text_length; |
25 |
} freehttpd_status_info_t; |
26 |
|
27 |
typedef struct freehttpd_response |
28 |
{ |
29 |
char *version; |
30 |
size_t version_length; |
31 |
freehttpd_status_info_t status; |
32 |
freehttpd_header_t *headers; |
33 |
size_t headers_length; |
34 |
FILE *stream; |
35 |
uint8_t *buffer; |
36 |
size_t buffer_length; |
37 |
} freehttpd_response_t; |
38 |
|
39 |
freehttpd_response_t *freehttpd_response_init (FILE *stream, |
40 |
const char *version, |
41 |
size_t version_len, |
42 |
freehttpd_status_t status); |
43 |
const char *freehttpd_response_status_text (freehttpd_status_t status); |
44 |
void freehttpd_response_set_status (freehttpd_response_t *response, |
45 |
freehttpd_status_t status); |
46 |
ecode_t freehttpd_response_head_send (const freehttpd_response_t *response); |
47 |
freehttpd_header_t * |
48 |
freehttpd_response_add_header (freehttpd_response_t *response, const char *name, |
49 |
size_t name_len, const char *value_fmt, ...); |
50 |
void freehttpd_response_free (freehttpd_response_t *response); |
51 |
void freehttpd_response_add_default_headers (freehttpd_response_t *response); |
52 |
ecode_t freehttpd_response_printf (freehttpd_response_t *response, |
53 |
const char *format, ...); |
54 |
ecode_t freehttpd_response_bprintf (freehttpd_response_t *response, |
55 |
const char *format, ...); |
56 |
ecode_t freehttpd_response_flush (freehttpd_response_t *response); |
57 |
ecode_t freehttpd_response_begin_body (freehttpd_response_t *response); |
58 |
ecode_t freehttpd_response_begin_end (freehttpd_response_t *response); |
59 |
size_t freehttpd_response_write (freehttpd_response_t *response, |
60 |
const void *data, size_t size, size_t n); |
61 |
const char *freehttpd_response_status_description (freehttpd_status_t status); |
62 |
|
63 |
#endif /* FREEHTTPD_RESPONSE_H */ |