Updated footer comment
[pazpar2-moved-to-github.git] / src / http.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2009 Index Data
3
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef HTTP_H
21 #define HTTP_H
22
23 // Generic I/O buffer
24 struct http_buf
25 {
26 #define HTTP_BUF_SIZE 4096
27     char buf[4096];
28     int offset;
29     int len;
30     struct http_buf *next;
31 };
32
33 typedef struct http_channel_observer_s *http_channel_observer_t;
34
35 struct http_channel
36 {
37     IOCHAN iochan;
38     struct http_buf *iqueue;
39     struct http_buf *oqueue;
40     char version[10];
41     struct http_proxy *proxy;
42     enum
43     {
44         Http_Idle,
45         Http_Busy      // Don't process new HTTP requests while we're busy
46     } state;
47     int keep_alive;
48     NMEM nmem;
49     WRBUF wrbuf;
50     struct http_request *request;
51     struct http_response *response;
52     struct http_channel *next; // for freelist
53     char addr[20]; // forwarded address
54     http_channel_observer_t observers;
55 };
56
57 struct http_proxy //  attached to iochan for proxy connection
58 {
59     IOCHAN iochan;
60     struct http_channel *channel;
61     struct http_buf *oqueue;
62     int first_response;
63 };
64
65 struct http_header
66 {
67     char *name;
68     char *value;
69     struct http_header *next;
70 };
71
72 struct http_argument
73 {
74     char *name;
75     char *value;
76     struct http_argument *next;
77 };
78
79 struct http_request
80 {
81     struct http_channel *channel;
82     char http_version[20];
83     char method[20];
84     char *path;
85     char *search;
86     char *content_buf;
87     int content_len;
88     struct http_header *headers;
89     struct http_argument *arguments;
90 };
91
92 struct http_response
93 {
94     char code[4];
95     char *msg;
96     struct http_channel *channel;
97     struct http_header *headers;
98     char *payload;
99     char *content_type;
100 };
101
102 void http_set_proxyaddr(char *url, char *baseurl);
103 int http_init(const char *addr);
104 void http_close_server(void);
105 void http_addheader(struct http_response *r, 
106                     const char *name, const char *value);
107 struct http_header * http_header_append(struct http_channel *ch, 
108                                         struct http_header * hp, 
109                                         const char *name, 
110                                         const char *value);
111 char *http_argbyname(struct http_request *r, char *name);
112 char *http_headerbyname(struct http_header *r, char *name);
113 struct http_response *http_create_response(struct http_channel *c);
114 void http_send_response(struct http_channel *c);
115 void urlencode(const char *i, char *o);
116
117 typedef void (*http_channel_destroy_t)(void *data, struct http_channel *c,
118                                        void *data2);
119
120 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
121                                           http_channel_destroy_t);
122 void http_observer_set_data2(http_channel_observer_t obs, void *data2);
123
124 void http_remove_observer(http_channel_observer_t obs);
125 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
126 #endif
127
128 /*
129  * Local variables:
130  * c-basic-offset: 4
131  * c-file-style: "Stroustrup"
132  * indent-tabs-mode: nil
133  * End:
134  * vim: shiftwidth=4 tabstop=8 expandtab
135  */
136