Added basic HTTP server logic
[pazpar2-moved-to-github.git] / http.h
1 #ifndef HTTP_H
2 #define HTTP_H
3
4 struct http_channel
5 {
6     IOCHAN iochan;
7 #define IBUF_SIZE 10240
8     char ibuf[IBUF_SIZE];
9     char version[10];
10     int read;
11     char *obuf;
12     int writ;
13     NMEM nmem;
14     WRBUF wrbuf;
15 };
16
17 struct http_header
18 {
19     char *name;
20     char *value;
21     struct http_header *next;
22 };
23
24 struct http_argument
25 {
26     char *name;
27     char *value;
28     struct http_argument *next;
29 };
30
31 struct http_request
32 {
33     struct http_channel *channel;
34     char http_version[20];
35     enum
36     {
37         Method_GET,
38         Method_other
39     } method;
40     char *path;
41     struct http_header *headers;
42     struct http_argument *arguments;
43 };
44
45 struct http_response
46 {
47     char code[4];
48     char *msg;
49     struct http_channel *channel;
50     struct http_header *headers;
51     char *payload;
52 };
53
54 void http_init(int port);
55 void http_addheader(struct http_response *r, const char *name, const char *value);
56 char *argbyname(struct http_request *r, char *name);
57 char *headerbyname(struct http_request *r, char *name);
58 struct http_response *http_create_response(struct http_channel *c);
59
60 #endif