GNU libmicrohttpd  0.9.5
microhttpd.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  (C) 2006, 2007, 2008, 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
72 #ifndef MHD_MICROHTTPD_H
73 #define MHD_MICROHTTPD_H
74 
75 #ifdef __cplusplus
76 extern "C"
77 {
78 #if 0 /* keep Emacsens' auto-indent happy */
79 }
80 #endif
81 #endif
82 
83 /* While we generally would like users to use a configure-driven
84  build process which detects which headers are present and
85  hence works on any platform, we use "standard" includes here
86  to build out-of-the-box for beginning users on common systems.
87 
88  Once you have a proper build system and go for more exotic
89  platforms, you should define MHD_PLATFORM_H in some header that
90  you always include *before* "microhttpd.h". Then the following
91  "standard" includes won't be used (which might be a good
92  idea, especially on platforms where they do not exist). */
93 #ifndef MHD_PLATFORM_H
94 #include <unistd.h>
95 #include <stdarg.h>
96 #include <stdint.h>
97 #ifdef __MINGW32__
98 #include <ws2tcpip.h>
99 #else
100 #include <sys/time.h>
101 #include <sys/types.h>
102 #include <sys/socket.h>
103 #endif
104 #endif
105 
109 #define MHD_VERSION 0x00090700
110 
114 #define MHD_YES 1
115 
119 #define MHD_NO 0
120 
124 #define MHD_INVALID_NONCE -1
125 
130 #ifdef UINT64_MAX
131 #define MHD_SIZE_UNKNOWN UINT64_MAX
132 #else
133 #define MHD_SIZE_UNKNOWN ((uint64_t) -1LL)
134 #endif
135 
136 #ifdef SIZE_MAX
137 #define MHD_CONTENT_READER_END_OF_STREAM SIZE_MAX
138 #define MHD_CONTENT_READER_END_WITH_ERROR (SIZE_MAX - 1)
139 #else
140 #define MHD_CONTENT_READER_END_OF_STREAM ((size_t) -1LL)
141 #define MHD_CONTENT_READER_END_WITH_ERROR (((size_t) -1LL) - 1)
142 #endif
143 
149 #ifndef MHD_LONG_LONG
150 #define MHD_LONG_LONG long long
151 #endif
152 #ifndef MHD_LONG_LONG_PRINTF
153 
157 #define MHD_LONG_LONG_PRINTF "ll"
158 #endif
159 
160 
164 #define MHD_HTTP_CONTINUE 100
165 #define MHD_HTTP_SWITCHING_PROTOCOLS 101
166 #define MHD_HTTP_PROCESSING 102
167 
168 #define MHD_HTTP_OK 200
169 #define MHD_HTTP_CREATED 201
170 #define MHD_HTTP_ACCEPTED 202
171 #define MHD_HTTP_NON_AUTHORITATIVE_INFORMATION 203
172 #define MHD_HTTP_NO_CONTENT 204
173 #define MHD_HTTP_RESET_CONTENT 205
174 #define MHD_HTTP_PARTIAL_CONTENT 206
175 #define MHD_HTTP_MULTI_STATUS 207
176 
177 #define MHD_HTTP_MULTIPLE_CHOICES 300
178 #define MHD_HTTP_MOVED_PERMANENTLY 301
179 #define MHD_HTTP_FOUND 302
180 #define MHD_HTTP_SEE_OTHER 303
181 #define MHD_HTTP_NOT_MODIFIED 304
182 #define MHD_HTTP_USE_PROXY 305
183 #define MHD_HTTP_SWITCH_PROXY 306
184 #define MHD_HTTP_TEMPORARY_REDIRECT 307
185 
186 #define MHD_HTTP_BAD_REQUEST 400
187 #define MHD_HTTP_UNAUTHORIZED 401
188 #define MHD_HTTP_PAYMENT_REQUIRED 402
189 #define MHD_HTTP_FORBIDDEN 403
190 #define MHD_HTTP_NOT_FOUND 404
191 #define MHD_HTTP_METHOD_NOT_ALLOWED 405
192 #define MHD_HTTP_METHOD_NOT_ACCEPTABLE 406
193 #define MHD_HTTP_PROXY_AUTHENTICATION_REQUIRED 407
194 #define MHD_HTTP_REQUEST_TIMEOUT 408
195 #define MHD_HTTP_CONFLICT 409
196 #define MHD_HTTP_GONE 410
197 #define MHD_HTTP_LENGTH_REQUIRED 411
198 #define MHD_HTTP_PRECONDITION_FAILED 412
199 #define MHD_HTTP_REQUEST_ENTITY_TOO_LARGE 413
200 #define MHD_HTTP_REQUEST_URI_TOO_LONG 414
201 #define MHD_HTTP_UNSUPPORTED_MEDIA_TYPE 415
202 #define MHD_HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 416
203 #define MHD_HTTP_EXPECTATION_FAILED 417
204 #define MHD_HTTP_UNPROCESSABLE_ENTITY 422
205 #define MHD_HTTP_LOCKED 423
206 #define MHD_HTTP_FAILED_DEPENDENCY 424
207 #define MHD_HTTP_UNORDERED_COLLECTION 425
208 #define MHD_HTTP_UPGRADE_REQUIRED 426
209 #define MHD_HTTP_RETRY_WITH 449
210 
211 #define MHD_HTTP_INTERNAL_SERVER_ERROR 500
212 #define MHD_HTTP_NOT_IMPLEMENTED 501
213 #define MHD_HTTP_BAD_GATEWAY 502
214 #define MHD_HTTP_SERVICE_UNAVAILABLE 503
215 #define MHD_HTTP_GATEWAY_TIMEOUT 504
216 #define MHD_HTTP_HTTP_VERSION_NOT_SUPPORTED 505
217 #define MHD_HTTP_VARIANT_ALSO_NEGOTIATES 506
218 #define MHD_HTTP_INSUFFICIENT_STORAGE 507
219 #define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
220 #define MHD_HTTP_NOT_EXTENDED 510
221 
227 #define MHD_ICY_FLAG ((uint32_t)(1 << 31))
228 
229 /* See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html */
230 #define MHD_HTTP_HEADER_ACCEPT "Accept"
231 #define MHD_HTTP_HEADER_ACCEPT_CHARSET "Accept-Charset"
232 #define MHD_HTTP_HEADER_ACCEPT_ENCODING "Accept-Encoding"
233 #define MHD_HTTP_HEADER_ACCEPT_LANGUAGE "Accept-Language"
234 #define MHD_HTTP_HEADER_ACCEPT_RANGES "Accept-Ranges"
235 #define MHD_HTTP_HEADER_AGE "Age"
236 #define MHD_HTTP_HEADER_ALLOW "Allow"
237 #define MHD_HTTP_HEADER_AUTHORIZATION "Authorization"
238 #define MHD_HTTP_HEADER_CACHE_CONTROL "Cache-Control"
239 #define MHD_HTTP_HEADER_CONNECTION "Connection"
240 #define MHD_HTTP_HEADER_CONTENT_ENCODING "Content-Encoding"
241 #define MHD_HTTP_HEADER_CONTENT_LANGUAGE "Content-Language"
242 #define MHD_HTTP_HEADER_CONTENT_LENGTH "Content-Length"
243 #define MHD_HTTP_HEADER_CONTENT_LOCATION "Content-Location"
244 #define MHD_HTTP_HEADER_CONTENT_MD5 "Content-MD5"
245 #define MHD_HTTP_HEADER_CONTENT_RANGE "Content-Range"
246 #define MHD_HTTP_HEADER_CONTENT_TYPE "Content-Type"
247 #define MHD_HTTP_HEADER_COOKIE "Cookie"
248 #define MHD_HTTP_HEADER_DATE "Date"
249 #define MHD_HTTP_HEADER_ETAG "ETag"
250 #define MHD_HTTP_HEADER_EXPECT "Expect"
251 #define MHD_HTTP_HEADER_EXPIRES "Expires"
252 #define MHD_HTTP_HEADER_FROM "From"
253 #define MHD_HTTP_HEADER_HOST "Host"
254 #define MHD_HTTP_HEADER_IF_MATCH "If-Match"
255 #define MHD_HTTP_HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
256 #define MHD_HTTP_HEADER_IF_NONE_MATCH "If-None-Match"
257 #define MHD_HTTP_HEADER_IF_RANGE "If-Range"
258 #define MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
259 #define MHD_HTTP_HEADER_LAST_MODIFIED "Last-Modified"
260 #define MHD_HTTP_HEADER_LOCATION "Location"
261 #define MHD_HTTP_HEADER_MAX_FORWARDS "Max-Forwards"
262 #define MHD_HTTP_HEADER_PRAGMA "Pragma"
263 #define MHD_HTTP_HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
264 #define MHD_HTTP_HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
265 #define MHD_HTTP_HEADER_RANGE "Range"
266 #define MHD_HTTP_HEADER_REFERER "Referer"
267 #define MHD_HTTP_HEADER_RETRY_AFTER "Retry-After"
268 #define MHD_HTTP_HEADER_SERVER "Server"
269 #define MHD_HTTP_HEADER_SET_COOKIE "Set-Cookie"
270 #define MHD_HTTP_HEADER_SET_COOKIE2 "Set-Cookie2"
271 #define MHD_HTTP_HEADER_TE "TE"
272 #define MHD_HTTP_HEADER_TRAILER "Trailer"
273 #define MHD_HTTP_HEADER_TRANSFER_ENCODING "Transfer-Encoding"
274 #define MHD_HTTP_HEADER_UPGRADE "Upgrade"
275 #define MHD_HTTP_HEADER_USER_AGENT "User-Agent"
276 #define MHD_HTTP_HEADER_VARY "Vary"
277 #define MHD_HTTP_HEADER_VIA "Via"
278 #define MHD_HTTP_HEADER_WARNING "Warning"
279 #define MHD_HTTP_HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
280 
285 #define MHD_HTTP_VERSION_1_0 "HTTP/1.0"
286 #define MHD_HTTP_VERSION_1_1 "HTTP/1.1"
287 
291 #define MHD_HTTP_METHOD_CONNECT "CONNECT"
292 #define MHD_HTTP_METHOD_DELETE "DELETE"
293 #define MHD_HTTP_METHOD_GET "GET"
294 #define MHD_HTTP_METHOD_HEAD "HEAD"
295 #define MHD_HTTP_METHOD_OPTIONS "OPTIONS"
296 #define MHD_HTTP_METHOD_POST "POST"
297 #define MHD_HTTP_METHOD_PUT "PUT"
298 #define MHD_HTTP_METHOD_TRACE "TRACE"
299 
304 #define MHD_HTTP_POST_ENCODING_FORM_URLENCODED "application/x-www-form-urlencoded"
305 #define MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA "multipart/form-data"
306 
318 {
323 
330 
335 
340 
345 
351 
362 
369 };
370 
376 {
377 
383 
389 
395 
402 
416 
428 
435 
458 
466 
474 
481 
487 
495 
509 
519 
540 
560 
571 
578 
584 
591 };
592 
593 
598 {
604 
610  intptr_t value;
611 
616  void *ptr_value;
617 
618 };
619 
620 
626 {
627 
632 
637 
643 
653 
658 
663 };
664 
670 {
671 
676 
683 
690 
696 
697 };
698 
699 
705 {
711 
717 
725 
730 
735 
736 };
737 
743 {
751 
759 
765 };
766 
767 
768 
772 struct MHD_Daemon;
773 
780 struct MHD_Connection;
781 
785 struct MHD_Response;
786 
790 struct MHD_PostProcessor;
791 
799 typedef void (*MHD_PanicCallback) (void *cls,
800  const char *file,
801  unsigned int line,
802  const char *reason);
803 
811 typedef int
813  const struct sockaddr * addr,
814  socklen_t addrlen);
815 
851 typedef int
853  struct MHD_Connection * connection,
854  const char *url,
855  const char *method,
856  const char *version,
857  const char *upload_data,
858  size_t *upload_data_size,
859  void **con_cls);
860 
872 typedef void
874  struct MHD_Connection * connection,
875  void **con_cls,
876  enum MHD_RequestTerminationCode toe);
877 
888 typedef int
889  (*MHD_KeyValueIterator) (void *cls,
890  enum MHD_ValueKind kind,
891  const char *key, const char *value);
892 
940 typedef ssize_t
942  uint64_t pos,
943  char *buf,
944  size_t max);
945 
952 typedef void (*MHD_ContentReaderFreeCallback) (void *cls);
953 
973 typedef int
974  (*MHD_PostDataIterator) (void *cls,
975  enum MHD_ValueKind kind,
976  const char *key,
977  const char *filename,
978  const char *content_type,
979  const char *transfer_encoding,
980  const char *data, uint64_t off, size_t size);
981 
982 /* **************** Daemon handling functions ***************** */
983 
1000 struct MHD_Daemon *MHD_start_daemon_va (unsigned int options,
1001  uint16_t port,
1003  void *apc_cls,
1005  void *dh_cls, va_list ap);
1006 
1022 struct MHD_Daemon *MHD_start_daemon (unsigned int flags,
1023  uint16_t port,
1025  void *apc_cls,
1027  void *dh_cls, ...);
1028 
1034 void MHD_stop_daemon (struct MHD_Daemon *daemon);
1035 
1036 
1050 int
1051 MHD_get_fdset (struct MHD_Daemon *daemon,
1052  fd_set * read_fd_set,
1053  fd_set * write_fd_set, fd_set * except_fd_set, int *max_fd);
1054 
1067 int MHD_get_timeout (struct MHD_Daemon *daemon,
1068  unsigned MHD_LONG_LONG *timeout);
1069 
1070 
1082 int MHD_run (struct MHD_Daemon *daemon);
1083 
1084 
1085 /* **************** Connection handling functions ***************** */
1086 
1097 int
1098 MHD_get_connection_values (struct MHD_Connection *connection,
1099  enum MHD_ValueKind kind,
1100  MHD_KeyValueIterator iterator, void *iterator_cls);
1101 
1131 int
1132 MHD_set_connection_value (struct MHD_Connection *connection,
1133  enum MHD_ValueKind kind,
1134  const char *key, const char *value);
1135 
1151 void MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
1152 
1162 const char *MHD_lookup_connection_value (struct MHD_Connection *connection,
1163  enum MHD_ValueKind kind,
1164  const char *key);
1165 
1176 int
1177 MHD_queue_response (struct MHD_Connection *connection,
1178  unsigned int status_code, struct MHD_Response *response);
1179 
1180 
1181 /* **************** Response manipulation functions ***************** */
1182 
1198 struct MHD_Response *MHD_create_response_from_callback (uint64_t size,
1199  size_t block_size,
1201  crc, void *crc_cls,
1203  crfc);
1204 
1205 
1206 
1220 struct MHD_Response *MHD_create_response_from_data (size_t size,
1221  void *data,
1222  int must_free,
1223  int must_copy);
1224 
1225 
1231 
1238 
1245 
1253 
1254 };
1255 
1256 
1266 struct MHD_Response *
1267 MHD_create_response_from_buffer (size_t size,
1268  void *buffer,
1269  enum MHD_ResponseMemoryMode mode);
1270 
1271 
1281 struct MHD_Response *MHD_create_response_from_fd (size_t size,
1282  int fd);
1283 
1284 
1295  int fd,
1296  off_t offset);
1297 
1298 
1307 void MHD_destroy_response (struct MHD_Response *response);
1308 
1318 int
1319 MHD_add_response_header (struct MHD_Response *response,
1320  const char *header, const char *content);
1321 
1322 
1331 int
1332 MHD_add_response_footer (struct MHD_Response *response,
1333  const char *footer, const char *content);
1334 
1335 
1344 int
1345 MHD_del_response_header (struct MHD_Response *response,
1346  const char *header, const char *content);
1347 
1357 int
1358 MHD_get_response_headers (struct MHD_Response *response,
1359  MHD_KeyValueIterator iterator, void *iterator_cls);
1360 
1361 
1369 const char *MHD_get_response_header (struct MHD_Response *response,
1370  const char *key);
1371 
1372 
1373 /* ********************** PostProcessor functions ********************** */
1374 
1398 struct MHD_PostProcessor *MHD_create_post_processor (struct MHD_Connection
1399  *connection,
1400  size_t buffer_size,
1402  iter, void *cls);
1403 
1418 int
1419 MHD_post_process (struct MHD_PostProcessor *pp,
1420  const char *post_data, size_t post_data_len);
1421 
1431 int MHD_destroy_post_processor (struct MHD_PostProcessor *pp);
1432 
1433 
1434 /* ********************* Digest Authentication functions *************** */
1435 
1436 
1441 #define MHD_INVALID_NONCE -1
1442 
1443 
1451 char *
1452 MHD_digest_auth_get_username (struct MHD_Connection *connection);
1453 
1454 
1467 int
1468 MHD_digest_auth_check (struct MHD_Connection *connection,
1469  const char *realm,
1470  const char *username,
1471  const char *password,
1472  unsigned int nonce_timeout);
1473 
1474 
1488 int
1489 MHD_queue_auth_fail_response (struct MHD_Connection *connection,
1490  const char *realm,
1491  const char *opaque,
1492  struct MHD_Response *response,
1493  int signal_stale);
1494 
1495 
1504 char *
1506  char** password);
1507 
1515 int
1517  const char *realm,
1518  struct MHD_Response *response);
1519 
1520 /* ********************** generic query functions ********************** */
1521 
1526 {
1527 
1531  int /* enum gnutls_cipher_algorithm */ cipher_algorithm;
1532 
1536  int /* enum gnutls_protocol */ protocol;
1537 
1541  void * /* gnutls_session_t */ tls_session;
1542 
1546  void * /* gnutls_x509_crt_t */ client_cert;
1547 
1551  struct sockaddr *client_addr;
1552 };
1553 
1564  *connection,
1565  enum
1567  infoType, ...);
1568 
1569 
1574 {
1578  size_t key_size;
1579 
1584 
1589 };
1590 
1601 const union MHD_DaemonInfo *MHD_get_daemon_info (struct MHD_Daemon *daemon,
1602  enum MHD_DaemonInfoType
1603  infoType, ...);
1604 
1610 const char* MHD_get_version(void);
1611 
1612 #if 0 /* keep Emacsens' auto-indent happy */
1613 {
1614 #endif
1615 #ifdef __cplusplus
1616 }
1617 #endif
1618 
1619 #endif