GNU libmicrohttpd  0.9.29
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
internal.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  (C) 2007-2013 Daniel Pittman and Christian Grothoff
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 
27 #ifndef INTERNAL_H
28 #define INTERNAL_H
29 
30 #include "platform.h"
31 #include "microhttpd.h"
32 #if HTTPS_SUPPORT
33 #include <gnutls/gnutls.h>
34 #if GNUTLS_VERSION_MAJOR >= 3
35 #include <gnutls/abstract.h>
36 #endif
37 #endif
38 #if EPOLL_SUPPORT
39 #include <sys/epoll.h>
40 #endif
41 
42 
47 #define EXTRA_CHECKS MHD_NO
48 
49 #define MHD_MAX(a,b) ((a)<(b)) ? (b) : (a)
50 #define MHD_MIN(a,b) ((a)<(b)) ? (a) : (b)
51 
52 
60 #define MHD_BUF_INC_SIZE 1024
61 
62 
67 
71 extern void *mhd_panic_cls;
72 
73 #if HAVE_MESSAGES
74 
79 #define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg)
80 #else
81 
86 #define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL)
87 #endif
88 
89 
94  {
95 
101 
107 
113 
118 
123 
128  };
129 
130 
135  {
140 
145 
150 
155  };
156 
157 
164 #define MAX_NONCE_LENGTH 129
165 
166 
172 {
173 
178  unsigned long int nc;
179 
184 
185 };
186 
187 #if HAVE_MESSAGES
188 
192 void
193 MHD_DLOG (const struct MHD_Daemon *daemon,
194  const char *format, ...);
195 #endif
196 
208 size_t
209 MHD_http_unescape (void *cls,
210  struct MHD_Connection *connection,
211  char *val);
212 
213 
218 {
223 
228  char *header;
229 
233  char *value;
234 
240 
241 };
242 
243 
248 {
249 
256 
261  char *data;
262 
267  void *crc_cls;
268 
274 
280 
285  pthread_mutex_t mutex;
286 
290  uint64_t total_size;
291 
296  uint64_t data_start;
297 
301  off_t fd_off;
302 
306  size_t data_size;
307 
312 
317  unsigned int reference_count;
318 
322  int fd;
323 
324 };
325 
326 
342 {
348 
353 
358 
363 
368 
373 
378 
383 
389 
395 
401 
406 
411 
417 
422 
427 
432 
437 
442 
447 
452 
453  /*
454  * SSL/TLS connection states
455  */
456 
463 
464 };
465 
469 #define DEBUG_STATES MHD_NO
470 
471 
472 #if HAVE_MESSAGES
473 #if DEBUG_STATES
474 const char *
475 MHD_state_to_string (enum MHD_CONNECTION_STATE state);
476 #endif
477 #endif
478 
487 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
488  void *write_to, size_t max_bytes);
489 
490 
499 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
500  const void *write_to, size_t max_bytes);
501 
502 
507 {
508 
509 #if EPOLL_SUPPORT
510 
513  struct MHD_Connection *nextE;
514 
518  struct MHD_Connection *prevE;
519 #endif
520 
525 
530 
535 
540 
545 
550 
555 
560 
571  struct MemoryPool *pool;
572 
580 
585  char *method;
586 
591  char *url;
592 
597  char *version;
598 
605  char *read_buffer;
606 
612 
618  char *last;
619 
626  char *colon;
627 
632  struct sockaddr *addr;
633 
638  pthread_t pid;
639 
647 
653 
658 
663 
669 
675 
682 
688 
692  socklen_t addr_len;
693 
699 
704  unsigned int connection_timeout;
705 
712 
719 
727 
732 
736  int in_idle;
737 
738 #if EPOLL_SUPPORT
739 
742  enum MHD_EpollState epoll_state;
743 #endif
744 
749 
754 
759  unsigned int responseCode;
760 
769 
778 
785  unsigned int current_chunk_size;
786 
791  unsigned int current_chunk_offset;
792 
796  int (*read_handler) (struct MHD_Connection * connection);
797 
801  int (*write_handler) (struct MHD_Connection * connection);
802 
806  int (*idle_handler) (struct MHD_Connection * connection);
807 
812 
817 
818 #if HTTPS_SUPPORT
819 
822  gnutls_session_t tls_session;
823 
827  int protocol;
828 
832  int cipher;
833 
838  int tls_read_ready;
839 #endif
840 
845 
849  int resuming;
850 };
851 
860 typedef void * (*LogCallback)(void * cls,
861  const char * uri,
862  struct MHD_Connection *con);
863 
873 typedef size_t (*UnescapeCallback)(void *cls,
874  struct MHD_Connection *conn,
875  char *uri);
876 
877 
886 {
887 
892 
897 
902 
907 
912 
917 
922 
927 
928 #if EPOLL_SUPPORT
929 
932  struct MHD_Connection *eready_head;
933 
937  struct MHD_Connection *eready_tail;
938 #endif
939 
953 
959 
966 
972 
978 
982  void *apc_cls;
983 
989 
994 
1003 
1008 
1013 
1018 
1019 #if HAVE_MESSAGES
1020 
1024  void (*custom_error_log) (void *cls, const char *fmt, va_list va);
1025 
1029  void *custom_error_log_cls;
1030 #endif
1031 
1036 
1041 
1046 
1050  size_t pool_size;
1051 
1056 
1061 
1065  unsigned int worker_pool_size;
1066 
1070  pthread_t pid;
1071 
1075  pthread_mutex_t per_ip_connection_mutex;
1076 
1080  pthread_mutex_t cleanup_connection_mutex;
1081 
1086 
1087 #if EPOLL_SUPPORT
1088 
1091  int epoll_fd;
1092 
1097  int listen_socket_in_epoll;
1098 #endif
1099 
1106  int wpipe[2];
1107 
1112 
1113  /*
1114  * Do we need to process resuming connections?
1115  */
1117 
1121  unsigned int max_connections;
1122 
1127  unsigned int connection_timeout;
1128 
1134 
1139 
1143  uint16_t port;
1144 
1145 #if HTTPS_SUPPORT
1146 
1149  gnutls_priority_t priority_cache;
1150 
1155  gnutls_credentials_type_t cred_type;
1156 
1160  gnutls_certificate_credentials_t x509_cred;
1161 
1165  gnutls_dh_params_t dh_params;
1166 
1167 #if GNUTLS_VERSION_MAJOR >= 3
1168 
1172  gnutls_certificate_retrieve_function2 *cert_callback;
1173 #endif
1174 
1178  const char *https_mem_key;
1179 
1183  const char *https_mem_cert;
1184 
1188  const char *https_mem_trust;
1189 
1196  unsigned int num_tls_read_ready;
1197 
1198 #endif
1199 
1200 #ifdef DAUTH_SUPPORT
1201 
1205  const char *digest_auth_random;
1206 
1210  struct MHD_NonceNc *nnc;
1211 
1215  pthread_mutex_t nnc_lock;
1216 
1220  unsigned int digest_auth_rand_size;
1221 
1225  unsigned int nonce_nc_size;
1226 
1227 #endif
1228 
1229 };
1230 
1231 
1232 #if EXTRA_CHECKS
1233 #define EXTRA_CHECK(a) if (!(a)) abort();
1234 #else
1235 #define EXTRA_CHECK(a)
1236 #endif
1237 
1238 
1247 #define DLL_insert(head,tail,element) do { \
1248  (element)->next = (head); \
1249  (element)->prev = NULL; \
1250  if ((tail) == NULL) \
1251  (tail) = element; \
1252  else \
1253  (head)->prev = element; \
1254  (head) = (element); } while (0)
1255 
1256 
1266 #define DLL_remove(head,tail,element) do { \
1267  if ((element)->prev == NULL) \
1268  (head) = (element)->next; \
1269  else \
1270  (element)->prev->next = (element)->next; \
1271  if ((element)->next == NULL) \
1272  (tail) = (element)->prev; \
1273  else \
1274  (element)->next->prev = (element)->prev; \
1275  (element)->next = NULL; \
1276  (element)->prev = NULL; } while (0)
1277 
1278 
1279 
1288 #define XDLL_insert(head,tail,element) do { \
1289  (element)->nextX = (head); \
1290  (element)->prevX = NULL; \
1291  if ((tail) == NULL) \
1292  (tail) = element; \
1293  else \
1294  (head)->prevX = element; \
1295  (head) = (element); } while (0)
1296 
1297 
1307 #define XDLL_remove(head,tail,element) do { \
1308  if ((element)->prevX == NULL) \
1309  (head) = (element)->nextX; \
1310  else \
1311  (element)->prevX->nextX = (element)->nextX; \
1312  if ((element)->nextX == NULL) \
1313  (tail) = (element)->prevX; \
1314  else \
1315  (element)->nextX->prevX = (element)->prevX; \
1316  (element)->nextX = NULL; \
1317  (element)->prevX = NULL; } while (0)
1318 
1319 
1328 #define EDLL_insert(head,tail,element) do { \
1329  (element)->nextE = (head); \
1330  (element)->prevE = NULL; \
1331  if ((tail) == NULL) \
1332  (tail) = element; \
1333  else \
1334  (head)->prevE = element; \
1335  (head) = (element); } while (0)
1336 
1337 
1347 #define EDLL_remove(head,tail,element) do { \
1348  if ((element)->prevE == NULL) \
1349  (head) = (element)->nextE; \
1350  else \
1351  (element)->prevE->nextE = (element)->nextE; \
1352  if ((element)->nextE == NULL) \
1353  (tail) = (element)->prevE; \
1354  else \
1355  (element)->nextE->prevE = (element)->prevE; \
1356  (element)->nextE = NULL; \
1357  (element)->prevE = NULL; } while (0)
1358 
1359 
1367 time_t MHD_monotonic_time(void);
1368 
1369 #endif