GNU libmicrohttpd  0.9.29
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
microspdy.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrospdy
3  Copyright (C) 2012, 2013 Christian Grothoff
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
57 #ifndef SPDY_MICROSPDY_H
58 #define SPDY_MICROSPDY_H
59 
60 #include <zlib.h>
61 #include <stdbool.h>
62 
63 /* While we generally would like users to use a configure-driven
64  build process which detects which headers are present and
65  hence works on any platform, we use "standard" includes here
66  to build out-of-the-box for beginning users on common systems.
67 
68  Once you have a proper build system and go for more exotic
69  platforms, you should define MHD_PLATFORM_H in some header that
70  you always include *before* "microhttpd.h". Then the following
71  "standard" includes won't be used (which might be a good
72  idea, especially on platforms where they do not exist). */
73 #ifndef MHD_PLATFORM_H
74 #include <unistd.h>
75 #include <stdarg.h>
76 #include <stdint.h>
77 #ifdef __MINGW32__
78 #include <ws2tcpip.h>
79 #else
80 #include <sys/time.h>
81 #include <sys/types.h>
82 #include <sys/socket.h>
83 #endif
84 #endif
85 
86 
90 #define SPDY_YES 1
91 
95 #define SPDY_NO 0
96 
102 #define SPDY_INPUT_ERROR -1
103 
107 #define SPDY_VERSION 3
108 
114 #define SPDY_MAX_SUPPORTED_FRAME_SIZE 8192
115 
119 #define SPDY_HTTP_CONTINUE 100
120 #define SPDY_HTTP_SWITCHING_PROTOCOLS 101
121 #define SPDY_HTTP_PROCESSING 102
122 
123 #define SPDY_HTTP_OK 200
124 #define SPDY_HTTP_CREATED 201
125 #define SPDY_HTTP_ACCEPTED 202
126 #define SPDY_HTTP_NON_AUTHORITATIVE_INFORMATION 203
127 #define SPDY_HTTP_NO_CONTENT 204
128 #define SPDY_HTTP_RESET_CONTENT 205
129 #define SPDY_HTTP_PARTIAL_CONTENT 206
130 #define SPDY_HTTP_MULTI_STATUS 207
131 
132 #define SPDY_HTTP_MULTIPLE_CHOICES 300
133 #define SPDY_HTTP_MOVED_PERMANENTLY 301
134 #define SPDY_HTTP_FOUND 302
135 #define SPDY_HTTP_SEE_OTHER 303
136 #define SPDY_HTTP_NOT_MODIFIED 304
137 #define SPDY_HTTP_USE_PROXY 305
138 #define SPDY_HTTP_SWITCH_PROXY 306
139 #define SPDY_HTTP_TEMPORARY_REDIRECT 307
140 
141 #define SPDY_HTTP_BAD_REQUEST 400
142 #define SPDY_HTTP_UNAUTHORIZED 401
143 #define SPDY_HTTP_PAYMENT_REQUIRED 402
144 #define SPDY_HTTP_FORBIDDEN 403
145 #define SPDY_HTTP_NOT_FOUND 404
146 #define SPDY_HTTP_METHOD_NOT_ALLOWED 405
147 #define SPDY_HTTP_METHOD_NOT_ACCEPTABLE 406
148 #define SPDY_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
149 #define SPDY_HTTP_REQUEST_TIMEOUT 408
150 #define SPDY_HTTP_CONFLICT 409
151 #define SPDY_HTTP_GONE 410
152 #define SPDY_HTTP_LENGTH_REQUIRED 411
153 #define SPDY_HTTP_PRECONDITION_FAILED 412
154 #define SPDY_HTTP_REQUEST_ENTITY_TOO_LARGE 413
155 #define SPDY_HTTP_REQUEST_URI_TOO_LONG 414
156 #define SPDY_HTTP_UNSUPPORTED_MEDIA_TYPE 415
157 #define SPDY_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 416
158 #define SPDY_HTTP_EXPECTATION_FAILED 417
159 #define SPDY_HTTP_UNPROCESSABLE_ENTITY 422
160 #define SPDY_HTTP_LOCKED 423
161 #define SPDY_HTTP_FAILED_DEPENDENCY 424
162 #define SPDY_HTTP_UNORDERED_COLLECTION 425
163 #define SPDY_HTTP_UPGRADE_REQUIRED 426
164 #define SPDY_HTTP_NO_RESPONSE 444
165 #define SPDY_HTTP_RETRY_WITH 449
166 #define SPDY_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS 450
167 #define SPDY_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS 451
168 
169 #define SPDY_HTTP_INTERNAL_SERVER_ERROR 500
170 #define SPDY_HTTP_NOT_IMPLEMENTED 501
171 #define SPDY_HTTP_BAD_GATEWAY 502
172 #define SPDY_HTTP_SERVICE_UNAVAILABLE 503
173 #define SPDY_HTTP_GATEWAY_TIMEOUT 504
174 #define SPDY_HTTP_HTTP_VERSION_NOT_SUPPORTED 505
175 #define SPDY_HTTP_VARIANT_ALSO_NEGOTIATES 506
176 #define SPDY_HTTP_INSUFFICIENT_STORAGE 507
177 #define SPDY_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
178 #define SPDY_HTTP_NOT_EXTENDED 510
179 
184 #define SPDY_HTTP_HEADER_ACCEPT "accept"
185 #define SPDY_HTTP_HEADER_ACCEPT_CHARSET "accept-charset"
186 #define SPDY_HTTP_HEADER_ACCEPT_ENCODING "accept-encoding"
187 #define SPDY_HTTP_HEADER_ACCEPT_LANGUAGE "accept-language"
188 #define SPDY_HTTP_HEADER_ACCEPT_RANGES "accept-ranges"
189 #define SPDY_HTTP_HEADER_AGE "age"
190 #define SPDY_HTTP_HEADER_ALLOW "allow"
191 #define SPDY_HTTP_HEADER_AUTHORIZATION "authorization"
192 #define SPDY_HTTP_HEADER_CACHE_CONTROL "cache-control"
193 /* Connection header is forbidden in SPDY */
194 #define SPDY_HTTP_HEADER_CONNECTION "connection"
195 #define SPDY_HTTP_HEADER_CONTENT_ENCODING "content-encoding"
196 #define SPDY_HTTP_HEADER_CONTENT_LANGUAGE "content-language"
197 #define SPDY_HTTP_HEADER_CONTENT_LENGTH "content-length"
198 #define SPDY_HTTP_HEADER_CONTENT_LOCATION "content-location"
199 #define SPDY_HTTP_HEADER_CONTENT_MD5 "content-md5"
200 #define SPDY_HTTP_HEADER_CONTENT_RANGE "content-range"
201 #define SPDY_HTTP_HEADER_CONTENT_TYPE "content-type"
202 #define SPDY_HTTP_HEADER_COOKIE "cookie"
203 #define SPDY_HTTP_HEADER_DATE "date"
204 #define SPDY_HTTP_HEADER_ETAG "etag"
205 #define SPDY_HTTP_HEADER_EXPECT "expect"
206 #define SPDY_HTTP_HEADER_EXPIRES "expires"
207 #define SPDY_HTTP_HEADER_FROM "from"
208 /* Host header is forbidden in SPDY */
209 #define SPDY_HTTP_HEADER_HOST "host"
210 #define SPDY_HTTP_HEADER_IF_MATCH "if-match"
211 #define SPDY_HTTP_HEADER_IF_MODIFIED_SINCE "if-modified-since"
212 #define SPDY_HTTP_HEADER_IF_NONE_MATCH "if-none-match"
213 #define SPDY_HTTP_HEADER_IF_RANGE "if-range"
214 #define SPDY_HTTP_HEADER_IF_UNMODIFIED_SINCE "if-unmodified-since"
215 /* Keep-Alive header is forbidden in SPDY */
216 #define SPDY_HTTP_HEADER_KEEP_ALIVE "keep-alive"
217 #define SPDY_HTTP_HEADER_LAST_MODIFIED "last-modified"
218 #define SPDY_HTTP_HEADER_LOCATION "location"
219 #define SPDY_HTTP_HEADER_MAX_FORWARDS "max-forwards"
220 #define SPDY_HTTP_HEADER_PRAGMA "pragma"
221 #define SPDY_HTTP_HEADER_PROXY_AUTHENTICATE "proxy-authenticate"
222 #define SPDY_HTTP_HEADER_PROXY_AUTHORIZATION "proxy-authorization"
223 /* Proxy-Connection header is forbidden in SPDY */
224 #define SPDY_HTTP_HEADER_PROXY_CONNECTION "proxy-connection"
225 #define SPDY_HTTP_HEADER_RANGE "range"
226 #define SPDY_HTTP_HEADER_REFERER "referer"
227 #define SPDY_HTTP_HEADER_RETRY_AFTER "retry-after"
228 #define SPDY_HTTP_HEADER_SERVER "server"
229 #define SPDY_HTTP_HEADER_SET_COOKIE "set-cookie"
230 #define SPDY_HTTP_HEADER_SET_COOKIE2 "set-cookie2"
231 #define SPDY_HTTP_HEADER_TE "te"
232 #define SPDY_HTTP_HEADER_TRAILER "trailer"
233 /* Transfer-Encoding header is forbidden in SPDY */
234 #define SPDY_HTTP_HEADER_TRANSFER_ENCODING "transfer-encoding"
235 #define SPDY_HTTP_HEADER_UPGRADE "upgrade"
236 #define SPDY_HTTP_HEADER_USER_AGENT "user-agent"
237 #define SPDY_HTTP_HEADER_VARY "vary"
238 #define SPDY_HTTP_HEADER_VIA "via"
239 #define SPDY_HTTP_HEADER_WARNING "warning"
240 #define SPDY_HTTP_HEADER_WWW_AUTHENTICATE "www-authenticate"
241 
245 #define SPDY_HTTP_VERSION_1_0 "HTTP/1.0"
246 #define SPDY_HTTP_VERSION_1_1 "HTTP/1.1"
247 
251 #define SPDY_HTTP_METHOD_CONNECT "CONNECT"
252 #define SPDY_HTTP_METHOD_DELETE "DELETE"
253 #define SPDY_HTTP_METHOD_GET "GET"
254 #define SPDY_HTTP_METHOD_HEAD "HEAD"
255 #define SPDY_HTTP_METHOD_OPTIONS "OPTIONS"
256 #define SPDY_HTTP_METHOD_POST "POST"
257 #define SPDY_HTTP_METHOD_PUT "PUT"
258 #define SPDY_HTTP_METHOD_TRACE "TRACE"
259 
264 #define SPDY_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded"
265 #define SPDY_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
266 
267 
271 struct SPDY_Daemon;
272 
273 
277 struct SPDY_Session;
278 
279 
284 struct SPDY_Request;
285 
286 
292 struct SPDY_Response;
293 
294 
299 struct SPDY_NameValue;
300 
301 
306 struct SPDY_Settings;
307 
308 
316 {
317 
322 
327 
332 };
333 
334 
344 {
345 
351 
358 
366 
372 
379 
391 };
392 
393 
399 {
404 
411 
417 };
418 
419 
425 {
426 
434 
442 
450 
458 
464 
470 
476 
482 };
483 
484 
491 
500 
509 };
510 
511 
517 {
518 
529 };
530 
531 
542 {
543 
549 };
550 
551 
558 {
559 
564 
569 
575 };
576 
586 typedef void
587 (*SPDY_PanicCallback) (void * cls,
588  const char * file,
589  unsigned int line,
590  const char * reason);
591 
592 
600 typedef void
601 (*SPDY_NewSessionCallback) (void * cls,
602  struct SPDY_Session * session);
603 
604 
617 typedef void
619  struct SPDY_Session * session,
620  int by_client);
621 
622 
632 typedef int
633 (*SPDY_NameValueIterator) (void * cls,
634  const char * name,
635  const char * const * value,
636  int num_values);
637 
638 
664 typedef void (*SPDY_NewRequestCallback) (void * cls,
665  struct SPDY_Request * request,
666  uint8_t priority,
667  const char * method,
668  const char * path,
669  const char * version,
670  const char * host,
671  const char * scheme,
672  struct SPDY_NameValue * headers,
673  bool more);
674 
675 
691 typedef int
692 (*SPDY_NewDataCallback) (void * cls,
693  struct SPDY_Request *request,
694  const void * buf,
695  size_t size,
696  bool more);
697 // How about passing POST encoding information
698 // here as well?
699 //TODO
700 
701 
717 typedef ssize_t (*SPDY_ResponseCallback) (void * cls,
718  void * buffer,
719  size_t max,
720  bool * more);
721 
722 
745 typedef void
747  struct SPDY_Response * response,
748  struct SPDY_Request * request,
749  enum SPDY_RESPONSE_RESULT status,
750  bool streamopened);
751 
752 
760 typedef void
761 (*SPDY_PingCallback) (void * cls,
762  struct SPDY_Session * session,
763  struct timeval * rtt);
764 
765 
777 typedef int
778 (*SPDY_SettingsIterator) (void * cls,
779  enum SPDY_SETTINGS id,
780  int32_t value,
781  uint8_t flags);
782 
783 
794 typedef void
796  struct SPDY_Settings * settings,
797  uint8_t flags,
798  ...);
799 
800 
801 /* Global functions for the library */
802 
803 
817 int
818 (SPDY_init) (enum SPDY_IO_SUBSYSTEM io_subsystem, ...);
819 #define SPDY_init() SPDY_init(SPDY_IO_SUBSYSTEM_OPENSSL)
820 
821 
827 void
828 SPDY_deinit ();
829 
830 
846 void
848  void *cls);
849 
850 
851 /* Daemon functions */
852 
853 
872 struct SPDY_Daemon *
873 SPDY_start_daemon (uint16_t port,
874  const char * certfile,
875  const char * keyfile,
879  SPDY_NewDataCallback npdcb,
880  void * cls,
881  ...);
882 
883 
890 void
891 SPDY_stop_daemon (struct SPDY_Daemon *daemon);
892 
893 
916 int
917 SPDY_get_fdset (struct SPDY_Daemon * daemon,
918  fd_set * read_fd_set,
919  fd_set * write_fd_set,
920  fd_set * except_fd_set);
921 
922 
934 int
935 SPDY_get_timeout (struct SPDY_Daemon * daemon,
936  unsigned long long * timeout);
937 
938 
945 void
946 SPDY_run (struct SPDY_Daemon *daemon);
947 
948 
949 /* SPDY Session handling functions */
950 
951 
961 void
962 SPDY_close_session(struct SPDY_Session * session);
963 
964 
972 void
973 SPDY_set_cls_to_session(struct SPDY_Session * session,
974  void * cls);
975 
976 
984 void *
985 SPDY_get_cls_from_session(struct SPDY_Session * session);
986 
987 
995 socklen_t
996 SPDY_get_remote_addr(struct SPDY_Session * session,
997  struct sockaddr ** addr);
998 
999 
1000 /* SPDY name/value data structure handling functions */
1001 
1002 
1010 struct SPDY_NameValue *
1012 
1013 
1024 int
1025 SPDY_name_value_add (struct SPDY_NameValue * container,
1026  const char * name,
1027  const char * value);
1028 
1029 
1039 const char * const *
1040 SPDY_name_value_lookup (struct SPDY_NameValue *container,
1041  const char *name,
1042  int * num_values);
1043 
1044 
1054 int
1055 SPDY_name_value_iterate (struct SPDY_NameValue *container,
1056  SPDY_NameValueIterator iterator,
1057  void *iterator_cls);
1058 
1059 
1066 void
1067 SPDY_name_value_destroy (struct SPDY_NameValue * container);
1068 
1069 
1070 /* SPDY request handling functions */
1071 
1072 
1080 struct SPDY_Session *
1081 SPDY_get_session_for_request(const struct SPDY_Request * request);
1082 
1083 
1091 void
1092 SPDY_set_cls_to_request(struct SPDY_Request * request,
1093  void * cls);
1094 
1095 
1104 void *
1105 SPDY_get_cls_from_request(struct SPDY_Request * request);
1106 
1107 
1108 /* SPDY response handling functions */
1109 
1110 
1135 struct SPDY_Response *
1136 SPDY_build_response(int status,
1137  const char * statustext,
1138  const char * version,
1139  struct SPDY_NameValue * headers,
1140  const void * data,
1141  size_t size);
1142 
1143 
1175 struct SPDY_Response *
1177  const char * statustext,
1178  const char * version,
1179  struct SPDY_NameValue * headers,
1181  void *rcb_cls,
1182  uint32_t block_size);
1183 
1184 
1213 int
1214 SPDY_queue_response (struct SPDY_Request * request,
1215  struct SPDY_Response *response,
1216  bool closestream,
1217  bool consider_priority,
1219  void * rrcb_cls);
1220 
1221 
1233 void
1234 SPDY_destroy_response (struct SPDY_Response *response);
1235 
1236 
1237 /* SPDY settings ID/value data structure handling functions */
1238 
1239 
1247 const struct SPDY_Settings *
1249 
1250 
1264 int
1265 SPDY_settings_add (struct SPDY_Settings *container,
1266  enum SPDY_SETTINGS id,
1267  enum SPDY_FLAG_SETTINGS flags,
1268  int32_t value);
1269 
1270 
1282 int
1283 SPDY_settings_lookup (const struct SPDY_Settings * container,
1284  enum SPDY_SETTINGS id,
1285  enum SPDY_FLAG_SETTINGS * flags,
1286  int32_t * value);
1287 
1288 
1298 int
1299 SPDY_settings_iterate (const struct SPDY_Settings * container,
1300  SPDY_SettingsIterator iterator,
1301  void * iterator_cls);
1302 
1303 
1311 void
1312 SPDY_settings_destroy (struct SPDY_Settings * container);
1313 
1314 
1315 /* SPDY SETTINGS handling functions */
1316 
1317 
1333 int
1334 SPDY_send_settings (struct SPDY_Session * session,
1335  struct SPDY_Settings * settings,
1336  enum SPDY_FLAG_SETTINGS_FRAME flags,
1337  ...);
1338 
1339 
1340 /* SPDY misc functions */
1341 
1342 
1355 void
1356 SPDY_destroy_request (struct SPDY_Request * request);
1357 
1358 
1368 int
1369 SPDY_send_ping(struct SPDY_Session * session,
1370  SPDY_PingCallback rttcb,
1371  void * rttcb_cls);
1372 
1373 #endif