added HTTP headers "pazpar2-version", "pazpar2-server-host", "pazpar2-server-port...
[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     int first_response;
39 };
40
41 struct http_header
42 {
43     char *name;
44     char *value;
45     struct http_header *next;
46 };
47
48 struct http_argument
49 {
50     char *name;
51     char *value;
52     struct http_argument *next;
53 };
54
55 struct http_request
56 {
57     struct http_channel *channel;
58     char http_version[20];
59     char method[20];
60     char *path;
61     char *search;
62     struct http_header *headers;
63     struct http_argument *arguments;
64 };
65
66 struct http_response
67 {
68     char code[4];
69     char *msg;
70     struct http_channel *channel;
71     struct http_header *headers;
72     char *payload;
73 };
74
75 void http_set_proxyaddr(char *url, char *baseurl);
76 void http_init(const char *addr);
77 void http_addheader(struct http_response *r, 
78                     const char *name, const char *value);
79 struct http_header * http_header_append(struct http_channel *ch, 
80                                         struct http_header * hp, 
81                                         const char *name, 
82                                         const char *value);
83 char *http_argbyname(struct http_request *r, char *name);
84 char *http_headerbyname(struct http_header *r, char *name);
85 struct http_response *http_create_response(struct http_channel *c);
86 void http_send_response(struct http_channel *c);
87 void urlencode(const char *i, char *o);
88
89 /*
90  * Local variables:
91  * c-basic-offset: 4
92  * indent-tabs-mode: nil
93  * End:
94  * vim: shiftwidth=4 tabstop=8 expandtab
95  */
96 #endif