session.[ch] replaces logic.c, pazpar2.h
[pazpar2-moved-to-github.git] / src / http.h
1 /* This file is part of Pazpar2.
2    Copyright (C) 2006-2010 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 <yaz/wrbuf.h>
24
25 #include "eventl.h"
26 // Generic I/O buffer
27 struct http_buf;
28 typedef struct http_channel_observer_s *http_channel_observer_t;
29
30 typedef struct http_server *http_server_t;
31 typedef struct http_sessions *http_sessions_t;
32
33 struct http_channel
34 {
35     IOCHAN iochan;
36     struct http_buf *iqueue;
37     struct http_buf *oqueue;
38     char version[10];
39     struct http_proxy *proxy;
40     enum
41     {
42         Http_Idle,
43         Http_Busy      // Don't process new HTTP requests while we're busy
44     } state;
45     int keep_alive;
46     NMEM nmem;
47     WRBUF wrbuf;
48     struct http_request *request;
49     struct http_response *response;
50     struct http_channel *next; // for freelist
51     char addr[20]; // forwarded address
52     http_channel_observer_t observers;
53     struct conf_server *server;
54     http_server_t http_server;
55     http_sessions_t http_sessions;
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     char *content_type;
101 };
102
103 void http_mutex_init(struct conf_server *server);
104 void http_server_destroy(http_server_t hs);
105
106 void http_set_proxyaddr(const char *url, struct conf_server *ser);
107 int http_init(const char *addr, struct conf_server *ser);
108 void http_close_server(struct conf_server *ser);
109 void http_addheader(struct http_response *r, 
110                     const char *name, const char *value);
111 const char *http_lookup_header(struct http_header *header,
112                                const char *name);
113 struct http_header * http_header_append(struct http_channel *ch, 
114                                         struct http_header * hp, 
115                                         const char *name, 
116                                         const char *value);
117 const char *http_argbyname(struct http_request *r, const char *name);
118 const char *http_headerbyname(struct http_header *r, const char *name);
119 struct http_response *http_create_response(struct http_channel *c);
120 void http_send_response(struct http_channel *c);
121 void urlencode(const char *i, char *o);
122
123 typedef void (*http_channel_destroy_t)(void *data, struct http_channel *c,
124                                        void *data2);
125
126 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
127                                           http_channel_destroy_t);
128 void http_observer_set_data2(http_channel_observer_t obs, void *data2);
129
130 void http_remove_observer(http_channel_observer_t obs);
131 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
132
133 void http_command(struct http_channel *c);
134
135 http_sessions_t http_sessions_create(void);
136 void http_sessions_destroy(http_sessions_t hs);
137
138 #endif
139
140 /*
141  * Local variables:
142  * c-basic-offset: 4
143  * c-file-style: "Stroustrup"
144  * indent-tabs-mode: nil
145  * End:
146  * vim: shiftwidth=4 tabstop=8 expandtab
147  */
148