aboutsummaryrefslogtreecommitdiff
path: root/src/examples/mhd2spdy_structures.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/mhd2spdy_structures.h')
-rw-r--r--src/examples/mhd2spdy_structures.h265
1 files changed, 265 insertions, 0 deletions
diff --git a/src/examples/mhd2spdy_structures.h b/src/examples/mhd2spdy_structures.h
new file mode 100644
index 00000000..175dc62e
--- /dev/null
+++ b/src/examples/mhd2spdy_structures.h
@@ -0,0 +1,265 @@
1/*
2 Copyright (C) 2013 Andrey Uzunov
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/**
19 * @file structures.h
20 * @author Andrey Uzunov
21 */
22#ifndef STRUCTURES_H
23#define STRUCTURES_H
24
25#define _GNU_SOURCE
26
27#include <unistd.h>
28#include <stdlib.h>
29#include <stdint.h>
30#include <stdbool.h>
31#include <string.h>
32#include <stdio.h>
33#include <ctype.h>
34#include <errno.h>
35#include <assert.h>
36#include <microhttpd.h>
37#include <signal.h>
38#include <poll.h>
39#include <fcntl.h>
40#include <regex.h>
41#include <sys/types.h>
42#include <sys/socket.h>
43#include <netdb.h>
44#include <netinet/in.h>
45#include <netinet/tcp.h>
46#include <openssl/ssl.h>
47#include <openssl/err.h>
48#include <spdylay/spdylay.h>
49#include <getopt.h>
50
51struct Proxy;
52
53struct SPDY_Connection {
54 SSL *ssl;
55 //SSL_CTX *ssl_ctx;
56 spdylay_session *session;
57 struct SPDY_Connection *prev;
58 struct SPDY_Connection *next;
59 struct Proxy *proxies_head;
60 struct Proxy *proxies_tail;
61 char *host;
62 /* WANT_READ if SSL connection needs more input; or WANT_WRITE if it
63 needs more output; or IO_NONE. This is necessary because SSL/TLS
64 re-negotiation is possible at any time. Spdylay API offers
65 similar functions like spdylay_session_want_read() and
66 spdylay_session_want_write() but they do not take into account
67 SSL connection. */
68 int fd;
69 int want_io;
70 uint counter;
71 uint streams_opened;
72 bool is_tls;
73};
74
75
76struct URI
77{
78 char * full_uri;
79 char * scheme;
80 char * host_and_port;
81 //char * host_and_port_for_connecting;
82 char * host;
83 char * path;
84 char * path_and_more;
85 char * query;
86 char * fragment;
87 uint16_t port;
88};
89
90struct HTTP_URI;
91
92struct Proxy
93{
94 struct MHD_Connection *http_connection;
95 struct MHD_Response *http_response;
96 struct URI *uri;
97 struct HTTP_URI *http_uri; //TODO remove me
98 struct SPDY_Connection *spdy_connection;
99 struct Proxy *next;
100 struct Proxy *prev;
101 //char *path;
102 char *url;
103 //struct SPDY_Request *request;
104 //struct SPDY_Response *response;
105 //CURL *curl_handle;
106 //struct curl_slist *curl_headers;
107 //struct SPDY_NameValue *headers;
108 char *version;
109 //char *status_msg;
110 void *http_body;
111 size_t http_body_size;
112 ssize_t length;
113 int status;
114 int id;
115 bool done;
116 bool http_active;
117 bool spdy_active;
118};
119
120struct HTTP_URI
121{
122 char * uri;
123 struct Proxy * proxy;
124};
125
126struct SPDY_Headers
127{
128 const char **nv;
129 int num;
130 int cnt;
131};
132
133struct global_options
134{
135 char *spdy2http_str;
136 struct SPDY_Connection *spdy_connection;
137 struct SPDY_Connection *spdy_connections_head;
138 struct SPDY_Connection *spdy_connections_tail;
139 int streams_opened;
140 int responses_pending;
141 regex_t uri_preg;
142 size_t global_memory;
143 SSL_CTX *ssl_ctx;
144 uint32_t total_spdy_connections;
145 uint16_t spdy_proto_version;
146 uint16_t listen_port;
147 bool verbose;
148 bool only_proxy;
149 bool spdy_data_received;
150} glob_opt;
151
152/*
153
154#define SOCK_ADDR_IN_PTR(sa) ((struct sockaddr_in *)(sa))
155#define SOCK_ADDR_IN_FAMILY(sa) SOCK_ADDR_IN_PTR(sa)->sin_family
156#define SOCK_ADDR_IN_PORT(sa) SOCK_ADDR_IN_PTR(sa)->sin_port
157#define SOCK_ADDR_IN_ADDR(sa) SOCK_ADDR_IN_PTR(sa)->sin_addr
158
159#ifdef HAS_IPV6
160
161#define SOCK_ADDR_IN6_PTR(sa) ((struct sockaddr_in6 *)(sa))
162#define SOCK_ADDR_IN6_FAMILY(sa) SOCK_ADDR_IN6_PTR(sa)->sin6_family
163#define SOCK_ADDR_IN6_PORT(sa) SOCK_ADDR_IN6_PTR(sa)->sin6_port
164#define SOCK_ADDR_IN6_ADDR(sa) SOCK_ADDR_IN6_PTR(sa)->sin6_addr
165
166#endif
167*/
168
169//forbidden headers
170#define SPDY_HTTP_HEADER_TRANSFER_ENCODING "transfer-encoding"
171#define SPDY_HTTP_HEADER_PROXY_CONNECTION "proxy-connection"
172#define SPDY_HTTP_HEADER_KEEP_ALIVE "keep-alive"
173#define SPDY_HTTP_HEADER_CONNECTION "connection"
174
175#define MAX_SPDY_CONNECTIONS 100
176
177
178/**
179 * Insert an element at the head of a DLL. Assumes that head, tail and
180 * element are structs with prev and next fields.
181 *
182 * @param head pointer to the head of the DLL (struct ? *)
183 * @param tail pointer to the tail of the DLL (struct ? *)
184 * @param element element to insert (struct ? *)
185 */
186#define DLL_insert(head,tail,element) do { \
187 (element)->next = (head); \
188 (element)->prev = NULL; \
189 if ((tail) == NULL) \
190 (tail) = element; \
191 else \
192 (head)->prev = element; \
193 (head) = (element); } while (0)
194
195
196/**
197 * Remove an element from a DLL. Assumes
198 * that head, tail and element are structs
199 * with prev and next fields.
200 *
201 * @param head pointer to the head of the DLL (struct ? *)
202 * @param tail pointer to the tail of the DLL (struct ? *)
203 * @param element element to remove (struct ? *)
204 */
205#define DLL_remove(head,tail,element) do { \
206 if ((element)->prev == NULL) \
207 (head) = (element)->next; \
208 else \
209 (element)->prev->next = (element)->next; \
210 if ((element)->next == NULL) \
211 (tail) = (element)->prev; \
212 else \
213 (element)->next->prev = (element)->prev; \
214 (element)->next = NULL; \
215 (element)->prev = NULL; } while (0)
216
217
218#define PRINT_INFO(msg) do{\
219 if(glob_opt.verbose){\
220 printf("%i:%s\n", __LINE__, msg);\
221 fflush(stdout);\
222 }\
223 }\
224 while(0)
225
226
227#define PRINT_INFO2(fmt, ...) do{\
228 if(glob_opt.verbose){\
229 printf("%i\n", __LINE__);\
230 printf(fmt,##__VA_ARGS__);\
231 printf("\n");\
232 fflush(stdout);\
233 }\
234 }\
235 while(0)
236
237
238#define DIE(msg) do{\
239 printf("FATAL ERROR (line %i): %s\n", __LINE__, msg);\
240 fflush(stdout);\
241 exit(EXIT_FAILURE);\
242 }\
243 while(0)
244
245
246
247
248void
249free_uri(struct URI * uri);
250
251int
252init_parse_uri(regex_t * preg);
253
254void
255deinit_parse_uri(regex_t * preg);
256
257int
258parse_uri(regex_t * preg, char * full_uri, struct URI ** uri);
259
260void
261free_proxy(struct Proxy *proxy);
262
263void *au_malloc(size_t size);
264
265#endif