GNU libmicrohttpd  0.9.5
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 
48 #ifndef SPDY_MICROSPDY_H
49 #define SPDY_MICROSPDY_H
50 
51 #include <zlib.h>
52 #include <stdbool.h>
53 
54 /* While we generally would like users to use a configure-driven
55  build process which detects which headers are present and
56  hence works on any platform, we use "standard" includes here
57  to build out-of-the-box for beginning users on common systems.
58 
59  Once you have a proper build system and go for more exotic
60  platforms, you should define MHD_PLATFORM_H in some header that
61  you always include *before* "microhttpd.h". Then the following
62  "standard" includes won't be used (which might be a good
63  idea, especially on platforms where they do not exist). */
64 #ifndef MHD_PLATFORM_H
65 #include <unistd.h>
66 #include <stdarg.h>
67 #include <stdint.h>
68 #ifdef __MINGW32__
69 #include <ws2tcpip.h>
70 #else
71 #include <sys/time.h>
72 #include <sys/types.h>
73 #include <sys/socket.h>
74 #endif
75 #endif
76 
77 
81 #define SPDY_YES 1
82 
86 #define SPDY_NO 0
87 
93 #define SPDY_INPUT_ERROR -1
94 
98 #define SPDY_VERSION 3
99 
105 #define SPDY_MAX_SUPPORTED_FRAME_SIZE 8192
106 
110 #define SPDY_HTTP_CONTINUE 100
111 #define SPDY_HTTP_SWITCHING_PROTOCOLS 101
112 #define SPDY_HTTP_PROCESSING 102
113 
114 #define SPDY_HTTP_OK 200
115 #define SPDY_HTTP_CREATED 201
116 #define SPDY_HTTP_ACCEPTED 202
117 #define SPDY_HTTP_NON_AUTHORITATIVE_INFORMATION 203
118 #define SPDY_HTTP_NO_CONTENT 204
119 #define SPDY_HTTP_RESET_CONTENT 205
120 #define SPDY_HTTP_PARTIAL_CONTENT 206
121 #define SPDY_HTTP_MULTI_STATUS 207
122 
123 #define SPDY_HTTP_MULTIPLE_CHOICES 300
124 #define SPDY_HTTP_MOVED_PERMANENTLY 301
125 #define SPDY_HTTP_FOUND 302
126 #define SPDY_HTTP_SEE_OTHER 303
127 #define SPDY_HTTP_NOT_MODIFIED 304
128 #define SPDY_HTTP_USE_PROXY 305
129 #define SPDY_HTTP_SWITCH_PROXY 306
130 #define SPDY_HTTP_TEMPORARY_REDIRECT 307
131 
132 #define SPDY_HTTP_BAD_REQUEST 400
133 #define SPDY_HTTP_UNAUTHORIZED 401
134 #define SPDY_HTTP_PAYMENT_REQUIRED 402
135 #define SPDY_HTTP_FORBIDDEN 403
136 #define SPDY_HTTP_NOT_FOUND 404
137 #define SPDY_HTTP_METHOD_NOT_ALLOWED 405
138 #define SPDY_HTTP_METHOD_NOT_ACCEPTABLE 406
139 #define SPDY_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
140 #define SPDY_HTTP_REQUEST_TIMEOUT 408
141 #define SPDY_HTTP_CONFLICT 409
142 #define SPDY_HTTP_GONE 410
143 #define SPDY_HTTP_LENGTH_REQUIRED 411
144 #define SPDY_HTTP_PRECONDITION_FAILED 412
145 #define SPDY_HTTP_REQUEST_ENTITY_TOO_LARGE 413
146 #define SPDY_HTTP_REQUEST_URI_TOO_LONG 414
147 #define SPDY_HTTP_UNSUPPORTED_MEDIA_TYPE 415
148 #define SPDY_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 416
149 #define SPDY_HTTP_EXPECTATION_FAILED 417
150 #define SPDY_HTTP_UNPROCESSABLE_ENTITY 422
151 #define SPDY_HTTP_LOCKED 423
152 #define SPDY_HTTP_FAILED_DEPENDENCY 424
153 #define SPDY_HTTP_UNORDERED_COLLECTION 425
154 #define SPDY_HTTP_UPGRADE_REQUIRED 426
155 #define SPDY_HTTP_NO_RESPONSE 444
156 #define SPDY_HTTP_RETRY_WITH 449
157 #define SPDY_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS 450
158 #define SPDY_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS 451
159 
160 #define SPDY_HTTP_INTERNAL_SERVER_ERROR 500
161 #define SPDY_HTTP_NOT_IMPLEMENTED 501
162 #define SPDY_HTTP_BAD_GATEWAY 502
163 #define SPDY_HTTP_SERVICE_UNAVAILABLE 503
164 #define SPDY_HTTP_GATEWAY_TIMEOUT 504
165 #define SPDY_HTTP_HTTP_VERSION_NOT_SUPPORTED 505
166 #define SPDY_HTTP_VARIANT_ALSO_NEGOTIATES 506
167 #define SPDY_HTTP_INSUFFICIENT_STORAGE 507
168 #define SPDY_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
169 #define SPDY_HTTP_NOT_EXTENDED 510
170 
175 #define SPDY_HTTP_HEADER_ACCEPT "accept"
176 #define SPDY_HTTP_HEADER_ACCEPT_CHARSET "accept-charset"
177 #define SPDY_HTTP_HEADER_ACCEPT_ENCODING "accept-encoding"
178 #define SPDY_HTTP_HEADER_ACCEPT_LANGUAGE "accept-language"
179 #define SPDY_HTTP_HEADER_ACCEPT_RANGES "accept-ranges"
180 #define SPDY_HTTP_HEADER_AGE "age"
181 #define SPDY_HTTP_HEADER_ALLOW "allow"
182 #define SPDY_HTTP_HEADER_AUTHORIZATION "authorization"
183 #define SPDY_HTTP_HEADER_CACHE_CONTROL "cache-control"
184 /* Connection header is forbidden in SPDY */
185 #define SPDY_HTTP_HEADER_CONNECTION "connection"
186 #define SPDY_HTTP_HEADER_CONTENT_ENCODING "content-encoding"
187 #define SPDY_HTTP_HEADER_CONTENT_LANGUAGE "content-language"
188 #define SPDY_HTTP_HEADER_CONTENT_LENGTH "content-length"
189 #define SPDY_HTTP_HEADER_CONTENT_LOCATION "content-location"
190 #define SPDY_HTTP_HEADER_CONTENT_MD5 "content-md5"
191 #define SPDY_HTTP_HEADER_CONTENT_RANGE "content-range"
192 #define SPDY_HTTP_HEADER_CONTENT_TYPE "content-type"
193 #define SPDY_HTTP_HEADER_COOKIE "cookie"
194 #define SPDY_HTTP_HEADER_DATE "date"
195 #define SPDY_HTTP_HEADER_ETAG "etag"
196 #define SPDY_HTTP_HEADER_EXPECT "expect"
197 #define SPDY_HTTP_HEADER_EXPIRES "expires"
198 #define SPDY_HTTP_HEADER_FROM "from"
199 /* Host header is forbidden in SPDY */
200 #define SPDY_HTTP_HEADER_HOST "host"
201 #define SPDY_HTTP_HEADER_IF_MATCH "if-match"
202 #define SPDY_HTTP_HEADER_IF_MODIFIED_SINCE "if-modified-since"
203 #define SPDY_HTTP_HEADER_IF_NONE_MATCH "if-none-match"
204 #define SPDY_HTTP_HEADER_IF_RANGE "if-range"
205 #define SPDY_HTTP_HEADER_IF_UNMODIFIED_SINCE "if-unmodified-since"
206 /* Keep-Alive header is forbidden in SPDY */
207 #define SPDY_HTTP_HEADER_KEEP_ALIVE "keep-alive"
208 #define SPDY_HTTP_HEADER_LAST_MODIFIED "last-modified"
209 #define SPDY_HTTP_HEADER_LOCATION "location"
210 #define SPDY_HTTP_HEADER_MAX_FORWARDS "max-forwards"
211 #define SPDY_HTTP_HEADER_PRAGMA "pragma"
212 #define SPDY_HTTP_HEADER_PROXY_AUTHENTICATE "proxy-authenticate"
213 #define SPDY_HTTP_HEADER_PROXY_AUTHORIZATION "proxy-authorization"
214 /* Proxy-Connection header is forbidden in SPDY */
215 #define SPDY_HTTP_HEADER_PROXY_CONNECTION "proxy-connection"
216 #define SPDY_HTTP_HEADER_RANGE "range"
217 #define SPDY_HTTP_HEADER_REFERER "referer"
218 #define SPDY_HTTP_HEADER_RETRY_AFTER "retry-after"
219 #define SPDY_HTTP_HEADER_SERVER "server"
220 #define SPDY_HTTP_HEADER_SET_COOKIE "set-cookie"
221 #define SPDY_HTTP_HEADER_SET_COOKIE2 "set-cookie2"
222 #define SPDY_HTTP_HEADER_TE "te"
223 #define SPDY_HTTP_HEADER_TRAILER "trailer"
224 /* Transfer-Encoding header is forbidden in SPDY */
225 #define SPDY_HTTP_HEADER_TRANSFER_ENCODING "transfer-encoding"
226 #define SPDY_HTTP_HEADER_UPGRADE "upgrade"
227 #define SPDY_HTTP_HEADER_USER_AGENT "user-agent"
228 #define SPDY_HTTP_HEADER_VARY "vary"
229 #define SPDY_HTTP_HEADER_VIA "via"
230 #define SPDY_HTTP_HEADER_WARNING "warning"
231 #define SPDY_HTTP_HEADER_WWW_AUTHENTICATE "www-authenticate"
232 
236 #define SPDY_HTTP_VERSION_1_0 "HTTP/1.0"
237 #define SPDY_HTTP_VERSION_1_1 "HTTP/1.1"
238 
242 #define SPDY_HTTP_METHOD_CONNECT "CONNECT"
243 #define SPDY_HTTP_METHOD_DELETE "DELETE"
244 #define SPDY_HTTP_METHOD_GET "GET"
245 #define SPDY_HTTP_METHOD_HEAD "HEAD"
246 #define SPDY_HTTP_METHOD_OPTIONS "OPTIONS"
247 #define SPDY_HTTP_METHOD_POST "POST"
248 #define SPDY_HTTP_METHOD_PUT "PUT"
249 #define SPDY_HTTP_METHOD_TRACE "TRACE"
250 
255 #define SPDY_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded"
256 #define SPDY_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
257 
258 
262 struct SPDY_Daemon;
263 
264 
268 struct SPDY_Session;
269 
270 
275 struct SPDY_Request;
276 
277 
283 struct SPDY_Response;
284 
285 
290 struct SPDY_NameValue;
291 
292 
297 struct SPDY_Settings;
298 
299 
307 {
308 
313 
318 
323 };
324 
325 
335 {
336 
342 
349 
357 
363 
370 
382 };
383 
384 
390 {
395 
402 
408 };
409 
410 
416 {
417 
425 
433 
441 
449 
455 
461 
467 
473 };
474 
475 
482 
491 
500 };
501 
502 
508 {
509 
520 };
521 
522 
533 {
534 
540 };
541 
542 
549 {
550 
555 
560 
566 };
567 
577 typedef void
578 (*SPDY_PanicCallback) (void * cls,
579  const char * file,
580  unsigned int line,
581  const char * reason);
582 
583 
591 typedef void
592 (*SPDY_NewSessionCallback) (void * cls,
593  struct SPDY_Session * session);
594 
595 
608 typedef void
610  struct SPDY_Session * session,
611  int by_client);
612 
613 
623 typedef int
624 (*SPDY_NameValueIterator) (void * cls,
625  const char * name,
626  const char * const * value,
627  int num_values);
628 
629 
646 typedef void (*SPDY_NewRequestCallback) (void * cls,
647  struct SPDY_Request * request,
648  uint8_t priority,
649  const char * method,
650  const char * path,
651  const char * version,
652  const char * host,
653  const char * scheme,
654  struct SPDY_NameValue * headers);
655 
656 
671 typedef int (*SPDY_NewPOSTDataCallback) (void * cls,
672  struct SPDY_Request *request,
673  const void * buf,
674  size_t size,
675  bool more);
676 // How about passing POST encoding information
677 // here as well?
678 //TODO
679 
680 
696 typedef ssize_t (*SPDY_ResponseCallback) (void * cls,
697  void * buffer,
698  size_t max,
699  bool * more);
700 
701 
724 typedef void
726  struct SPDY_Response * response,
727  struct SPDY_Request * request,
728  enum SPDY_RESPONSE_RESULT status,
729  bool streamopened);
730 
731 
739 typedef void
740 (*SPDY_PingCallback) (void * cls,
741  struct SPDY_Session * session,
742  struct timeval * rtt);
743 
744 
756 typedef int
757 (*SPDY_SettingsIterator) (void * cls,
758  enum SPDY_SETTINGS id,
759  int32_t value,
760  uint8_t flags);
761 
762 
773 typedef void
774 (*SPDY_SettingsReceivedCallback) (struct SPDY_Session * session,
775  struct SPDY_Settings * settings,
776  uint8_t flags,
777  ...);
778 
779 
780 /* Global functions for the library */
781 
782 
796 int
797 (SPDY_init) (enum SPDY_IO_SUBSYSTEM io_subsystem, ...);
798 #define SPDY_init() SPDY_init(SPDY_IO_SUBSYSTEM_OPENSSL)
799 
800 
806 void
807 SPDY_deinit ();
808 
809 
825 void
827  void *cls);
828 
829 
830 /* Daemon functions */
831 
832 
851 struct SPDY_Daemon *
852 SPDY_start_daemon (uint16_t port,
853  const char * certfile,
854  const char * keyfile,
859  void * cls,
860  ...);
861 
862 
869 void
870 SPDY_stop_daemon (struct SPDY_Daemon *daemon);
871 
872 
895 int
896 SPDY_get_fdset (struct SPDY_Daemon * daemon,
897  fd_set * read_fd_set,
898  fd_set * write_fd_set,
899  fd_set * except_fd_set);
900 
901 
913 int
914 SPDY_get_timeout (struct SPDY_Daemon * daemon,
915  unsigned long long * timeout);
916 
917 
924 void
925 SPDY_run (struct SPDY_Daemon *daemon);
926 
927 
928 /* SPDY Session handling functions */
929 
930 
940 void
941 SPDY_close_session(struct SPDY_Session * session);
942 
943 
951 void
952 SPDY_set_cls_to_session(struct SPDY_Session * session,
953  void * cls);
954 
955 
963 void *
964 SPDY_get_cls_from_session(struct SPDY_Session * session);
965 
966 
974 socklen_t
975 SPDY_get_remote_addr(struct SPDY_Session * session,
976  struct sockaddr ** addr);
977 
978 
979 /* SPDY name/value data structure handling functions */
980 
981 
989 struct SPDY_NameValue *
991 
992 
1003 int
1004 SPDY_name_value_add (struct SPDY_NameValue * container,
1005  const char * name,
1006  const char * value);
1007 
1008 
1018 const char * const *
1019 SPDY_name_value_lookup (struct SPDY_NameValue *container,
1020  const char *name,
1021  int * num_values);
1022 
1023 
1033 int
1034 SPDY_name_value_iterate (struct SPDY_NameValue *container,
1035  SPDY_NameValueIterator iterator,
1036  void *iterator_cls);
1037 
1038 
1045 void
1046 SPDY_name_value_destroy (struct SPDY_NameValue * container);
1047 
1048 
1049 /* SPDY request handling functions */
1050 
1051 
1059 struct SPDY_Session *
1060 SPDY_get_session_for_request(const struct SPDY_Request * request);
1061 
1062 
1070 void
1071 SPDY_set_cls_to_request(struct SPDY_Request * request,
1072  void * cls);
1073 
1074 
1083 void *
1084 SPDY_get_cls_from_request(struct SPDY_Request * request);
1085 
1086 
1087 /* SPDY response handling functions */
1088 
1089 
1114 struct SPDY_Response *
1115 SPDY_build_response(int status,
1116  const char * statustext,
1117  const char * version,
1118  struct SPDY_NameValue * headers,
1119  const void * data,
1120  size_t size);
1121 
1122 
1154 struct SPDY_Response *
1156  const char * statustext,
1157  const char * version,
1158  struct SPDY_NameValue * headers,
1160  void *rcb_cls,
1161  uint32_t block_size);
1162 
1163 
1192 int
1193 SPDY_queue_response (struct SPDY_Request * request,
1194  struct SPDY_Response *response,
1195  bool closestream,
1196  bool consider_priority,
1198  void * rrcb_cls);
1199 
1200 
1212 void
1213 SPDY_destroy_response (struct SPDY_Response *response);
1214 
1215 
1216 /* SPDY settings ID/value data structure handling functions */
1217 
1218 
1226 const struct SPDY_Settings *
1228 
1229 
1243 int
1244 SPDY_settings_add (struct SPDY_Settings *container,
1245  enum SPDY_SETTINGS id,
1246  enum SPDY_FLAG_SETTINGS flags,
1247  int32_t value);
1248 
1249 
1261 int
1262 SPDY_settings_lookup (const struct SPDY_Settings * container,
1263  enum SPDY_SETTINGS id,
1264  enum SPDY_FLAG_SETTINGS * flags,
1265  int32_t * value);
1266 
1267 
1277 int
1278 SPDY_settings_iterate (const struct SPDY_Settings * container,
1279  SPDY_SettingsIterator iterator,
1280  void * iterator_cls);
1281 
1282 
1290 void
1291 SPDY_settings_destroy (struct SPDY_Settings * container);
1292 
1293 
1294 /* SPDY SETTINGS handling functions */
1295 
1296 
1312 int
1313 SPDY_send_settings (struct SPDY_Session * session,
1314  struct SPDY_Settings * settings,
1315  enum SPDY_FLAG_SETTINGS_FRAME flags,
1316  ...);
1317 
1318 
1319 /* SPDY misc functions */
1320 
1321 
1334 void
1335 SPDY_destroy_request (struct SPDY_Request * request);
1336 
1337 
1347 int
1348 SPDY_send_ping(struct SPDY_Session * session,
1349  SPDY_PingCallback rttcb,
1350  void * rttcb_cls);
1351 
1352 #endif