HTTP free buffers handled by http_server_t
[pazpar2-moved-to-github.git] / src / http.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2010 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 #include "eventl.h"
24 // Generic I/O buffer
25 struct http_buf;
26 typedef struct http_channel_observer_s *http_channel_observer_t;
27
28 typedef struct http_server *http_server_t;
29
30 struct http_channel
31 {
32     IOCHAN iochan;
33     struct http_buf *iqueue;
34     struct http_buf *oqueue;
35     char version[10];
36     struct http_proxy *proxy;
37     enum
38     {
39         Http_Idle,
40         Http_Busy      // Don't process new HTTP requests while we're busy
41     } state;
42     int keep_alive;
43     NMEM nmem;
44     WRBUF wrbuf;
45     struct http_request *request;
46     struct http_response *response;
47     struct http_channel *next; // for freelist
48     char addr[20]; // forwarded address
49     http_channel_observer_t observers;
50     struct conf_server *server;
51     http_server_t http_server;
52 };
53
54 struct http_proxy //  attached to iochan for proxy connection
55 {
56     IOCHAN iochan;
57     struct http_channel *channel;
58     struct http_buf *oqueue;
59     int first_response;
60 };
61
62 struct http_header
63 {
64     char *name;
65     char *value;
66     struct http_header *next;
67 };
68
69 struct http_argument
70 {
71     char *name;
72     char *value;
73     struct http_argument *next;
74 };
75
76 struct http_request
77 {
78     struct http_channel *channel;
79     char http_version[20];
80     char method[20];
81     char *path;
82     char *search;
83     char *content_buf;
84     int content_len;
85     struct http_header *headers;
86     struct http_argument *arguments;
87 };
88
89 struct http_response
90 {
91     char code[4];
92     char *msg;
93     struct http_channel *channel;
94     struct http_header *headers;
95     char *payload;
96     char *content_type;
97 };
98
99 void http_mutex_init(struct conf_server *server);
100 void http_server_destroy(http_server_t hs);
101
102 void http_set_proxyaddr(const char *url, struct conf_server *ser);
103 int http_init(const char *addr, struct conf_server *ser);
104 void http_close_server(struct conf_server *ser);
105 void http_addheader(struct http_response *r, 
106                     const char *name, const char *value);
107 const char *http_lookup_header(struct http_header *header,
108                                const char *name);
109 struct http_header * http_header_append(struct http_channel *ch, 
110                                         struct http_header * hp, 
111                                         const char *name, 
112                                         const char *value);
113 const char *http_argbyname(struct http_request *r, const char *name);
114 const char *http_headerbyname(struct http_header *r, const char *name);
115 struct http_response *http_create_response(struct http_channel *c);
116 void http_send_response(struct http_channel *c);
117 void urlencode(const char *i, char *o);
118
119 typedef void (*http_channel_destroy_t)(void *data, struct http_channel *c,
120                                        void *data2);
121
122 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
123                                           http_channel_destroy_t);
124 void http_observer_set_data2(http_channel_observer_t obs, void *data2);
125
126 void http_remove_observer(http_channel_observer_t obs);
127 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
128
129 void http_command(struct http_channel *c);
130
131 #endif
132
133 /*
134  * Local variables:
135  * c-basic-offset: 4
136  * c-file-style: "Stroustrup"
137  * indent-tabs-mode: nil
138  * End:
139  * vim: shiftwidth=4 tabstop=8 expandtab
140  */
141