pazpar2  1.13.0
http.h
Go to the documentation of this file.
1 /* This file is part of Pazpar2.
2  Copyright (C) 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 #include <yaz/timing.h>
25 
26 #include "eventl.h"
27 // Generic I/O buffer
28 struct http_buf;
30 
31 typedef struct http_server *http_server_t;
33 
35 {
37  struct http_buf *iqueue;
38  struct http_buf *oqueue;
39  char version[10];
40  struct http_proxy *proxy;
41  enum
42  {
44  Http_Busy // Don't process new HTTP requests while we're busy
45  } state;
47  NMEM nmem;
48  WRBUF wrbuf;
49  yaz_timing_t yt;
52  struct http_channel *next; // for freelist
53  char addr[256]; // forwarded address
54  http_channel_observer_t observers;
56  http_server_t http_server;
57  http_sessions_t http_sessions;
58 };
59 
60 struct http_proxy // attached to iochan for proxy connection
61 {
64  struct http_buf *oqueue;
66 };
67 
69 {
70  char *name;
71  char *value;
72  struct http_header *next;
73 };
74 
76 {
77  char *name;
78  char *value;
80 };
81 
83 {
85  char http_version[20];
86  char method[20];
87  char *path;
88  char *search;
89  char *content_buf;
93 };
94 
96 {
97  char code[4];
98  char *msg;
101  char *payload;
103 };
104 
105 void http_mutex_init(struct conf_server *server);
106 void http_server_destroy(http_server_t hs);
107 
108 void http_set_proxyaddr(const char *url, struct conf_server *ser);
109 int http_init(struct conf_server *ser, const char *record_fname);
110 void http_close_server(struct conf_server *ser);
111 void http_addheader(struct http_response *r,
112  const char *name, const char *value);
113 const char *http_lookup_header(struct http_header *header,
114  const char *name);
115 struct http_header * http_header_append(struct http_channel *ch,
116  struct http_header * hp,
117  const char *name,
118  const char *value);
119 const char *http_argbyname(struct http_request *r, const char *name);
120 const char *http_headerbyname(struct http_header *r, const char *name);
122 void http_send_response(struct http_channel *c);
123 void urlencode(const char *i, char *o);
124 
125 typedef void (*http_channel_destroy_t)(void *data, struct http_channel *c,
126  void *data2);
127 
128 http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
130 void http_observer_set_data2(http_channel_observer_t obs, void *data2);
131 
132 void http_remove_observer(http_channel_observer_t obs);
133 struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
134 
135 void http_command(struct http_channel *c);
136 
137 http_sessions_t http_sessions_create(void);
138 void http_sessions_destroy(http_sessions_t hs);
139 
140 #endif
141 
142 /*
143  * Local variables:
144  * c-basic-offset: 4
145  * c-file-style: "Stroustrup"
146  * indent-tabs-mode: nil
147  * End:
148  * vim: shiftwidth=4 tabstop=8 expandtab
149  */
150 
NMEM nmem
Definition: http.h:47
struct http_buf * iqueue
Definition: http.h:37
struct http_proxy * proxy
Definition: http.h:40
void urlencode(const char *i, char *o)
Definition: http.c:266
void http_send_response(struct http_channel *c)
Definition: http.c:844
http_server_t http_server
Definition: http.h:56
struct http_channel * next
Definition: http.h:52
char * name
Definition: http.h:70
IOCHAN iochan
Definition: http.h:62
struct http_argument * next
Definition: http.h:79
struct http_channel * channel
Definition: http.h:63
char * name
Definition: http.h:77
struct http_header * next
Definition: http.h:72
char * search
Definition: http.h:88
http_channel_observer_t http_add_observer(struct http_channel *c, void *data, http_channel_destroy_t)
Definition: http.c:1427
char * content_buf
Definition: http.h:89
void(* http_channel_destroy_t)(void *data, struct http_channel *c, void *data2)
Definition: http.h:125
http_sessions_t http_sessions_create(void)
Definition: http_command.c:98
http_sessions_t http_sessions
Definition: http.h:57
struct http_header * headers
Definition: http.h:91
void http_observer_set_data2(http_channel_observer_t obs, void *data2)
Definition: http.c:1457
const char * http_lookup_header(struct http_header *header, const char *name)
Definition: http.c:119
struct http_argument * arguments
Definition: http.h:92
char * value
Definition: http.h:78
int first_response
Definition: http.h:65
const char * http_argbyname(struct http_request *r, const char *name)
Definition: http.c:292
WRBUF wrbuf
Definition: http.h:48
enum http_channel::@1 state
yaz_timing_t yt
Definition: http.h:49
struct http_channel * http_channel_observer_chan(http_channel_observer_t obs)
Definition: http.c:1452
int http_init(struct conf_server *ser, const char *record_fname)
Definition: http.c:1238
struct http_channel * channel
Definition: http.h:84
IOCHAN iochan
Definition: http.h:36
char * name
struct http_request * request
Definition: http.h:50
struct http_response * http_create_response(struct http_channel *c)
Definition: http.c:311
void http_remove_observer(http_channel_observer_t obs)
Definition: http.c:1440
struct http_channel * channel
Definition: http.h:99
void http_addheader(struct http_response *r, const char *name, const char *value)
Definition: http.c:282
struct http_buf * oqueue
Definition: http.h:38
Definition: http.c:75
struct http_sessions * http_sessions_t
Definition: http.h:32
char addr[256]
Definition: http.h:53
struct http_buf * oqueue
Definition: http.h:64
void http_server_destroy(http_server_t hs)
Definition: http.c:1476
void http_mutex_init(struct conf_server *server)
Definition: http.c:1506
char * payload
Definition: http.h:101
void http_command(struct http_channel *c)
struct http_channel_observer_s * http_channel_observer_t
Definition: http.h:29
const char * http_headerbyname(struct http_header *r, const char *name)
Definition: http.c:303
char * content_type
Definition: http.h:102
char * msg
Definition: http.h:98
Definition: eventl.h:31
struct http_header * headers
Definition: http.h:100
void http_close_server(struct conf_server *ser)
Definition: http.c:1359
struct http_response * response
Definition: http.h:51
struct http_header * http_header_append(struct http_channel *ch, struct http_header *hp, const char *name, const char *value)
Definition: http.c:702
char * path
Definition: http.h:87
http_channel_observer_t observers
Definition: http.h:54
void http_set_proxyaddr(const char *url, struct conf_server *ser)
Definition: http.c:1372
int keep_alive
Definition: http.h:46
char version[10]
Definition: http.h:39
struct conf_server * server
Definition: http.h:55
struct http_server * http_server_t
Definition: http.h:31
char * value
Definition: http.h:71
void http_sessions_destroy(http_sessions_t hs)
Definition: http_command.c:108
int content_len
Definition: http.h:90