Fixed bug #1659: Honor LF in HTTP headers.
[pazpar2-moved-to-github.git] / src / http.h
1 /* $Id: http.h,v 1.11 2007-09-26 08:53:53 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     int keep_alive;
50     NMEM nmem;
51     WRBUF wrbuf;
52     struct http_request *request;
53     struct http_response *response;
54     struct http_channel *next; // for freelist
55     char addr[20]; // forwarded address
56     http_channel_observer_t observers;
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 };
102
103 void http_set_proxyaddr(char *url, char *baseurl);
104 void http_init(const char *addr);
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
119 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
120                                           http_channel_destroy_t);
121
122 void http_remove_observer(http_channel_observer_t obs);
123 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
124 #endif
125
126 /*
127  * Local variables:
128  * c-basic-offset: 4
129  * indent-tabs-mode: nil
130  * End:
131  * vim: shiftwidth=4 tabstop=8 expandtab
132  */