Work on bug #1192: block=1, session_watch problems. The http_channel
[pazpar2-moved-to-github.git] / src / http.h
1 /* $Id: http.h,v 1.9 2007-06-15 19:35:17 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #ifndef HTTP_H
23 #define HTTP_H
24
25 // Generic I/O buffer
26 struct http_buf
27 {
28 #define HTTP_BUF_SIZE 4096
29     char buf[4096];
30     int offset;
31     int len;
32     struct http_buf *next;
33 };
34
35 typedef struct http_channel_observer_s *http_channel_observer_t;
36
37 struct http_channel
38 {
39     IOCHAN iochan;
40     struct http_buf *iqueue;
41     struct http_buf *oqueue;
42     char version[10];
43     struct http_proxy *proxy;
44     enum
45     {
46         Http_Idle,
47         Http_Busy      // Don't process new HTTP requests while we're busy
48     } state;
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 };
57
58 struct http_proxy //  attached to iochan for proxy connection
59 {
60     IOCHAN iochan;
61     struct http_channel *channel;
62     struct http_buf *oqueue;
63     int first_response;
64 };
65
66 struct http_header
67 {
68     char *name;
69     char *value;
70     struct http_header *next;
71 };
72
73 struct http_argument
74 {
75     char *name;
76     char *value;
77     struct http_argument *next;
78 };
79
80 struct http_request
81 {
82     struct http_channel *channel;
83     char http_version[20];
84     char method[20];
85     char *path;
86     char *search;
87     struct http_header *headers;
88     struct http_argument *arguments;
89 };
90
91 struct http_response
92 {
93     char code[4];
94     char *msg;
95     struct http_channel *channel;
96     struct http_header *headers;
97     char *payload;
98 };
99
100 void http_set_proxyaddr(char *url, char *baseurl);
101 void http_init(const char *addr);
102 void http_addheader(struct http_response *r, 
103                     const char *name, const char *value);
104 struct http_header * http_header_append(struct http_channel *ch, 
105                                         struct http_header * hp, 
106                                         const char *name, 
107                                         const char *value);
108 char *http_argbyname(struct http_request *r, char *name);
109 char *http_headerbyname(struct http_header *r, char *name);
110 struct http_response *http_create_response(struct http_channel *c);
111 void http_send_response(struct http_channel *c);
112 void urlencode(const char *i, char *o);
113
114 typedef void (*http_channel_destroy_t)(void *data, struct http_channel *c);
115
116 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
117                                           http_channel_destroy_t);
118
119 void http_remove_observer(http_channel_observer_t obs);
120 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
121 #endif
122
123 /*
124  * Local variables:
125  * c-basic-offset: 4
126  * indent-tabs-mode: nil
127  * End:
128  * vim: shiftwidth=4 tabstop=8 expandtab
129  */