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