Pazpar2 honors POST requests and proxy's them too if proxy is enabled.
[pazpar2-moved-to-github.git] / src / http.h
1 /* $Id: http.h,v 1.10 2007-09-23 15:39:24 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     char *content_buf;
88     int content_len;
89     struct http_header *headers;
90     struct http_argument *arguments;
91 };
92
93 struct http_response
94 {
95     char code[4];
96     char *msg;
97     struct http_channel *channel;
98     struct http_header *headers;
99     char *payload;
100 };
101
102 void http_set_proxyaddr(char *url, char *baseurl);
103 void http_init(const char *addr);
104 void http_addheader(struct http_response *r, 
105                     const char *name, const char *value);
106 struct http_header * http_header_append(struct http_channel *ch, 
107                                         struct http_header * hp, 
108                                         const char *name, 
109                                         const char *value);
110 char *http_argbyname(struct http_request *r, char *name);
111 char *http_headerbyname(struct http_header *r, char *name);
112 struct http_response *http_create_response(struct http_channel *c);
113 void http_send_response(struct http_channel *c);
114 void urlencode(const char *i, char *o);
115
116 typedef void (*http_channel_destroy_t)(void *data, struct http_channel *c);
117
118 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
119                                           http_channel_destroy_t);
120
121 void http_remove_observer(http_channel_observer_t obs);
122 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
123 #endif
124
125 /*
126  * Local variables:
127  * c-basic-offset: 4
128  * indent-tabs-mode: nil
129  * End:
130  * vim: shiftwidth=4 tabstop=8 expandtab
131  */