GNU libmicrohttpd  0.9.5
internal.h
Go to the documentation of this file.
1 /*
2  This file is part of libmicrohttpd
3  (C) 2007, 2008, 2009, 2010, 2011, 2012 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 #endif
35 
40 #define EXTRA_CHECKS MHD_NO
41 
42 #define MHD_MAX(a,b) ((a)<(b)) ? (b) : (a)
43 #define MHD_MIN(a,b) ((a)<(b)) ? (a) : (b)
44 
45 
51 #define MHD_BUF_INC_SIZE 2048
52 
57 
61 extern void *mhd_panic_cls;
62 
63 #if HAVE_MESSAGES
64 
69 #define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg)
70 #else
71 
76 #define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL)
77 #endif
78 
84  {
89 
94 
99  };
100 
101 
105 struct MHD_Pollfd
106 {
110  int fd;
111 
116 };
117 
118 
125 #define MAX_NONCE_LENGTH 129
126 
127 
132 struct MHD_NonceNc
133 {
134 
139  unsigned long int nc;
140 
145 
146 };
147 
148 #if HAVE_MESSAGES
149 
153 void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...);
154 
155 #endif
156 
167 size_t MHD_http_unescape (void *cls,
168  struct MHD_Connection *connection,
169  char *val);
170 
175 {
180 
185  char *header;
186 
190  char *value;
191 
197 
198 };
199 
200 
205 {
206 
213 
218  char *data;
219 
224  void *crc_cls;
225 
231 
237 
242  pthread_mutex_t mutex;
243 
247  uint64_t total_size;
248 
253  uint64_t data_start;
254 
258  off_t fd_off;
259 
263  size_t data_size;
264 
269 
274  unsigned int reference_count;
275 
279  int fd;
280 
281 };
282 
283 
299 {
305 
310 
315 
320 
325 
330 
335 
340 
346 
352 
358 
363 
368 
374 
379 
384 
389 
394 
399 
404 
409 
410  /*
411  * SSL/TLS connection states
412  */
413 
420 
421 };
422 
426 #define DEBUG_STATES MHD_NO
427 
428 
429 #if HAVE_MESSAGES
430 #if DEBUG_STATES
431 const char *
432 MHD_state_to_string (enum MHD_CONNECTION_STATE state);
433 #endif
434 #endif
435 
444 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
445  void *write_to, size_t max_bytes);
446 
447 
456 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
457  const void *write_to, size_t max_bytes);
458 
459 
464 {
465 
470 
475 
480 
485 
490 
495 
506  struct MemoryPool *pool;
507 
515 
520  char *method;
521 
526  char *url;
527 
532  char *version;
533 
540  char *read_buffer;
541 
547 
553  char *last;
554 
561  char *colon;
562 
567  struct sockaddr *addr;
568 
573  pthread_t pid;
574 
582 
588 
593 
598 
604 
610 
617 
623 
627  socklen_t addr_len;
628 
634 
639  unsigned int connection_timeout;
640 
647 
654 
663 
668 
673 
678  unsigned int responseCode;
679 
688 
697 
704  unsigned int current_chunk_size;
705 
710  unsigned int current_chunk_offset;
711 
715  int (*read_handler) (struct MHD_Connection * connection);
716 
720  int (*write_handler) (struct MHD_Connection * connection);
721 
725  int (*idle_handler) (struct MHD_Connection * connection);
726 
731 
736 
737 #if HTTPS_SUPPORT
738 
741  gnutls_session_t tls_session;
742 
746  int protocol;
747 
751  int cipher;
752 
753 #endif
754 };
755 
763 typedef void * (*LogCallback)(void * cls, const char * uri);
764 
774 typedef size_t (*UnescapeCallback)(void *cls,
775  struct MHD_Connection *conn,
776  char *uri);
777 
778 
783 {
784 
789 
794 
799 
804 
809 
814 
821 
825  void *apc_cls;
826 
832 
837 
846 
851 
856 
861 
862 #if HAVE_MESSAGES
863 
867  void (*custom_error_log) (void *cls, const char *fmt, va_list va);
868 
872  void *custom_error_log_cls;
873 #endif
874 
879 
884 
889 
893  size_t pool_size;
894 
899 
903  unsigned int worker_pool_size;
904 
908  pthread_t pid;
909 
913  pthread_mutex_t per_ip_connection_mutex;
914 
918  pthread_mutex_t cleanup_connection_mutex;
919 
924 
930  int wpipe[2];
931 
935  int shutdown;
936 
940  unsigned int max_connections;
941 
946  unsigned int connection_timeout;
947 
953 
958 
962  uint16_t port;
963 
964 #if HTTPS_SUPPORT
965 
968  gnutls_priority_t priority_cache;
969 
974  gnutls_credentials_type_t cred_type;
975 
979  gnutls_certificate_credentials_t x509_cred;
980 
984  gnutls_dh_params_t dh_params;
985 
989  const char *https_mem_key;
990 
994  const char *https_mem_cert;
995 
999  const char *https_mem_trust;
1000 
1001 #endif
1002 
1003 #ifdef DAUTH_SUPPORT
1004 
1008  const char *digest_auth_random;
1009 
1013  struct MHD_NonceNc *nnc;
1014 
1018  pthread_mutex_t nnc_lock;
1019 
1023  unsigned int digest_auth_rand_size;
1024 
1028  unsigned int nonce_nc_size;
1029 
1030 #endif
1031 
1032 };
1033 
1034 
1035 #if EXTRA_CHECKS
1036 #define EXTRA_CHECK(a) if (!(a)) abort();
1037 #else
1038 #define EXTRA_CHECK(a)
1039 #endif
1040 
1041 
1050 #define DLL_insert(head,tail,element) do { \
1051  (element)->next = (head); \
1052  (element)->prev = NULL; \
1053  if ((tail) == NULL) \
1054  (tail) = element; \
1055  else \
1056  (head)->prev = element; \
1057  (head) = (element); } while (0)
1058 
1059 
1069 #define DLL_remove(head,tail,element) do { \
1070  if ((element)->prev == NULL) \
1071  (head) = (element)->next; \
1072  else \
1073  (element)->prev->next = (element)->next; \
1074  if ((element)->next == NULL) \
1075  (tail) = (element)->prev; \
1076  else \
1077  (element)->next->prev = (element)->prev; \
1078  (element)->next = NULL; \
1079  (element)->prev = NULL; } while (0)
1080 
1081 
1087 time_t MHD_monotonic_time(void);
1088 
1089 #endif