Modified http_create. Used a per-request nmem structure to allocate space for the
[pazpar2-moved-to-github.git] / src / http.h
1 /* $Id: http.h,v 1.8 2007-04-15 00:35:57 quinn 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 struct http_channel
36 {
37     IOCHAN iochan;
38     struct http_buf *iqueue;
39     struct http_buf *oqueue;
40     char version[10];
41     struct http_proxy *proxy;
42     enum
43     {
44         Http_Idle,
45         Http_Busy      // Don't process new HTTP requests while we're busy
46     } state;
47     NMEM nmem;
48     WRBUF wrbuf;
49     struct http_request *request;
50     struct http_response *response;
51     struct http_channel *next; // for freelist
52     char addr[20]; // forwarded address
53 };
54
55 struct http_proxy //  attached to iochan for proxy connection
56 {
57     IOCHAN iochan;
58     struct http_channel *channel;
59     struct http_buf *oqueue;
60     int first_response;
61 };
62
63 struct http_header
64 {
65     char *name;
66     char *value;
67     struct http_header *next;
68 };
69
70 struct http_argument
71 {
72     char *name;
73     char *value;
74     struct http_argument *next;
75 };
76
77 struct http_request
78 {
79     struct http_channel *channel;
80     char http_version[20];
81     char method[20];
82     char *path;
83     char *search;
84     struct http_header *headers;
85     struct http_argument *arguments;
86 };
87
88 struct http_response
89 {
90     char code[4];
91     char *msg;
92     struct http_channel *channel;
93     struct http_header *headers;
94     char *payload;
95 };
96
97 void http_set_proxyaddr(char *url, char *baseurl);
98 void http_init(const char *addr);
99 void http_addheader(struct http_response *r, 
100                     const char *name, const char *value);
101 struct http_header * http_header_append(struct http_channel *ch, 
102                                         struct http_header * hp, 
103                                         const char *name, 
104                                         const char *value);
105 char *http_argbyname(struct http_request *r, char *name);
106 char *http_headerbyname(struct http_header *r, char *name);
107 struct http_response *http_create_response(struct http_channel *c);
108 void http_send_response(struct http_channel *c);
109 void urlencode(const char *i, char *o);
110
111 /*
112  * Local variables:
113  * c-basic-offset: 4
114  * indent-tabs-mode: nil
115  * End:
116  * vim: shiftwidth=4 tabstop=8 expandtab
117  */
118 #endif