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