More detailed logging of HTTP requests
[pazpar2-moved-to-github.git] / src / http.h
1 #ifndef HTTP_H
2 #define HTTP_H
3
4 // Generic I/O buffer
5 struct http_buf
6 {
7 #define HTTP_BUF_SIZE 4096
8     char buf[4096];
9     int offset;
10     int len;
11     struct http_buf *next;
12 };
13
14 struct http_channel
15 {
16     IOCHAN iochan;
17     struct http_buf *iqueue;
18     struct http_buf *oqueue;
19     char version[10];
20     struct http_proxy *proxy;
21     enum
22     {
23         Http_Idle,
24         Http_Busy      // Don't process new HTTP requests while we're busy
25     } state;
26     NMEM nmem;
27     WRBUF wrbuf;
28     struct http_request *request;
29     struct http_response *response;
30     struct http_channel *next; // for freelist
31 };
32
33 struct http_proxy //  attached to iochan for proxy connection
34 {
35     IOCHAN iochan;
36     struct http_channel *channel;
37     struct http_buf *oqueue;
38 };
39
40 struct http_header
41 {
42     char *name;
43     char *value;
44     struct http_header *next;
45 };
46
47 struct http_argument
48 {
49     char *name;
50     char *value;
51     struct http_argument *next;
52 };
53
54 struct http_request
55 {
56     struct http_channel *channel;
57     char http_version[20];
58     char method[20];
59     char *path;
60     char *search;
61     struct http_header *headers;
62     struct http_argument *arguments;
63 };
64
65 struct http_response
66 {
67     char code[4];
68     char *msg;
69     struct http_channel *channel;
70     struct http_header *headers;
71     char *payload;
72 };
73
74 void http_set_proxyaddr(char *url);
75 void http_init(const char *addr);
76 void http_addheader(struct http_response *r, const char *name, const char *value);
77 char *http_argbyname(struct http_request *r, char *name);
78 char *http_headerbyname(struct http_request *r, char *name);
79 struct http_response *http_create_response(struct http_channel *c);
80 void http_send_response(struct http_channel *c);
81
82 /*
83  * Local variables:
84  * c-basic-offset: 4
85  * indent-tabs-mode: nil
86  * End:
87  * vim: shiftwidth=4 tabstop=8 expandtab
88  */
89 #endif