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 #include "platform_interface.h"
33 #if HTTPS_SUPPORT
34 #include <gnutls/gnutls.h>
35 #if GNUTLS_VERSION_MAJOR >= 3
36 #include <gnutls/abstract.h>
37 #endif
38 #endif
39 #if EPOLL_SUPPORT
40 #include <sys/epoll.h>
41 #endif
42 #if HAVE_NETINET_TCP_H
43 /* for TCP_FASTOPEN */
44 #include <netinet/tcp.h>
45 #endif
46 
47 
52 #define EXTRA_CHECKS MHD_NO
53 
54 #define MHD_MAX(a,b) ((a)<(b)) ? (b) : (a)
55 #define MHD_MIN(a,b) ((a)<(b)) ? (a) : (b)
56 
57 
65 #define MHD_BUF_INC_SIZE 1024
66 
67 
72 
76 extern void *mhd_panic_cls;
77 
78 #if HAVE_MESSAGES
79 
84 #define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg)
85 #else
86 
91 #define MHD_PANIC(msg) mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL)
92 #endif
93 
94 
99  {
100 
106 
112 
118 
123 
128 
133  };
134 
135 
140  {
145 
150 
155 
160  };
161 
162 
169 #define MAX_NONCE_LENGTH 129
170 
171 
177 {
178 
183  unsigned long int nc;
184 
189 
190 };
191 
192 #if HAVE_MESSAGES
193 
197 void
198 MHD_DLOG (const struct MHD_Daemon *daemon,
199  const char *format, ...);
200 #endif
201 
213 size_t
214 MHD_http_unescape (void *cls,
215  struct MHD_Connection *connection,
216  char *val);
217 
218 
223 {
228 
233  char *header;
234 
238  char *value;
239 
245 
246 };
247 
248 
253 {
254 
261 
266  char *data;
267 
272  void *crc_cls;
273 
279 
285 
290  pthread_mutex_t mutex;
291 
295  uint64_t total_size;
296 
301  uint64_t data_start;
302 
306  off_t fd_off;
307 
311  size_t data_size;
312 
317 
322  unsigned int reference_count;
323 
327  int fd;
328 
329 };
330 
331 
347 {
353 
358 
363 
368 
373 
378 
383 
388 
394 
400 
406 
411 
416 
422 
427 
432 
437 
442 
447 
452 
457 
458  /*
459  * SSL/TLS connection states
460  */
461 
468 
469 };
470 
474 #define DEBUG_STATES MHD_NO
475 
476 
477 #if HAVE_MESSAGES
478 #if DEBUG_STATES
479 const char *
480 MHD_state_to_string (enum MHD_CONNECTION_STATE state);
481 #endif
482 #endif
483 
492 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
493  void *write_to, size_t max_bytes);
494 
495 
504 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
505  const void *write_to, size_t max_bytes);
506 
507 
512 {
513 
514 #if EPOLL_SUPPORT
515 
518  struct MHD_Connection *nextE;
519 
523  struct MHD_Connection *prevE;
524 #endif
525 
530 
535 
540 
545 
550 
555 
560 
565 
576  struct MemoryPool *pool;
577 
585 
590  char *method;
591 
596  char *url;
597 
602  char *version;
603 
610  char *read_buffer;
611 
617 
623  char *last;
624 
631  char *colon;
632 
637  struct sockaddr *addr;
638 
643  pthread_t pid;
644 
652 
658 
663 
668 
674 
680 
687 
693 
697  socklen_t addr_len;
698 
704 
709  unsigned int connection_timeout;
710 
717 
724 
732 
737 
741  int in_idle;
742 
743 #if EPOLL_SUPPORT
744 
747  enum MHD_EpollState epoll_state;
748 #endif
749 
754 
759 
764  unsigned int responseCode;
765 
774 
783 
791 
797 
801  int (*read_handler) (struct MHD_Connection * connection);
802 
806  int (*write_handler) (struct MHD_Connection * connection);
807 
811  int (*idle_handler) (struct MHD_Connection * connection);
812 
817 
822 
823 #if HTTPS_SUPPORT
824 
827  gnutls_session_t tls_session;
828 
832  int protocol;
833 
837  int cipher;
838 
843  int tls_read_ready;
844 #endif
845 
850 
854  int resuming;
855 };
856 
865 typedef void * (*LogCallback)(void * cls,
866  const char * uri,
867  struct MHD_Connection *con);
868 
878 typedef size_t (*UnescapeCallback)(void *cls,
879  struct MHD_Connection *conn,
880  char *uri);
881 
882 
891 {
892 
897 
902 
907 
912 
917 
922 
927 
932 
933 #if EPOLL_SUPPORT
934 
937  struct MHD_Connection *eready_head;
938 
942  struct MHD_Connection *eready_tail;
943 #endif
944 
958 
964 
971 
977 
983 
987  void *apc_cls;
988 
994 
999 
1008 
1013 
1018 
1023 
1024 #if HAVE_MESSAGES
1025 
1029  void (*custom_error_log) (void *cls, const char *fmt, va_list va);
1030 
1034  void *custom_error_log_cls;
1035 #endif
1036 
1041 
1046 
1051 
1055  size_t pool_size;
1056 
1061 
1066 
1070  unsigned int worker_pool_size;
1071 
1075  pthread_t pid;
1076 
1080  pthread_mutex_t per_ip_connection_mutex;
1081 
1085  pthread_mutex_t cleanup_connection_mutex;
1086 
1091 
1092 #if EPOLL_SUPPORT
1093 
1096  int epoll_fd;
1097 
1102  int listen_socket_in_epoll;
1103 #endif
1104 
1113 
1118 
1119  /*
1120  * Do we need to process resuming connections?
1121  */
1123 
1127  unsigned int max_connections;
1128 
1133  unsigned int connection_timeout;
1134 
1140 
1145 
1149  uint16_t port;
1150 
1151 #if HTTPS_SUPPORT
1152 
1155  gnutls_priority_t priority_cache;
1156 
1161  gnutls_credentials_type_t cred_type;
1162 
1166  gnutls_certificate_credentials_t x509_cred;
1167 
1171  gnutls_dh_params_t dh_params;
1172 
1173 #if GNUTLS_VERSION_MAJOR >= 3
1174 
1178  gnutls_certificate_retrieve_function2 *cert_callback;
1179 #endif
1180 
1184  const char *https_mem_key;
1185 
1189  const char *https_mem_cert;
1190 
1194  const char *https_mem_trust;
1195 
1202  unsigned int num_tls_read_ready;
1203 
1204 #endif
1205 
1206 #ifdef DAUTH_SUPPORT
1207 
1211  const char *digest_auth_random;
1212 
1216  struct MHD_NonceNc *nnc;
1217 
1221  pthread_mutex_t nnc_lock;
1222 
1226  size_t digest_auth_rand_size;
1227 
1231  unsigned int nonce_nc_size;
1232 
1233 #endif
1234 
1235 #ifdef TCP_FASTOPEN
1236 
1239  unsigned int fastopen_queue_size;
1240 #endif
1241 };
1242 
1243 
1244 #if EXTRA_CHECKS
1245 #define EXTRA_CHECK(a) if (!(a)) abort();
1246 #else
1247 #define EXTRA_CHECK(a)
1248 #endif
1249 
1250 
1259 #define DLL_insert(head,tail,element) do { \
1260  (element)->next = (head); \
1261  (element)->prev = NULL; \
1262  if ((tail) == NULL) \
1263  (tail) = element; \
1264  else \
1265  (head)->prev = element; \
1266  (head) = (element); } while (0)
1267 
1268 
1278 #define DLL_remove(head,tail,element) do { \
1279  if ((element)->prev == NULL) \
1280  (head) = (element)->next; \
1281  else \
1282  (element)->prev->next = (element)->next; \
1283  if ((element)->next == NULL) \
1284  (tail) = (element)->prev; \
1285  else \
1286  (element)->next->prev = (element)->prev; \
1287  (element)->next = NULL; \
1288  (element)->prev = NULL; } while (0)
1289 
1290 
1291 
1300 #define XDLL_insert(head,tail,element) do { \
1301  (element)->nextX = (head); \
1302  (element)->prevX = NULL; \
1303  if ((tail) == NULL) \
1304  (tail) = element; \
1305  else \
1306  (head)->prevX = element; \
1307  (head) = (element); } while (0)
1308 
1309 
1319 #define XDLL_remove(head,tail,element) do { \
1320  if ((element)->prevX == NULL) \
1321  (head) = (element)->nextX; \
1322  else \
1323  (element)->prevX->nextX = (element)->nextX; \
1324  if ((element)->nextX == NULL) \
1325  (tail) = (element)->prevX; \
1326  else \
1327  (element)->nextX->prevX = (element)->prevX; \
1328  (element)->nextX = NULL; \
1329  (element)->prevX = NULL; } while (0)
1330 
1331 
1340 #define EDLL_insert(head,tail,element) do { \
1341  (element)->nextE = (head); \
1342  (element)->prevE = NULL; \
1343  if ((tail) == NULL) \
1344  (tail) = element; \
1345  else \
1346  (head)->prevE = element; \
1347  (head) = (element); } while (0)
1348 
1349 
1359 #define EDLL_remove(head,tail,element) do { \
1360  if ((element)->prevE == NULL) \
1361  (head) = (element)->nextE; \
1362  else \
1363  (element)->prevE->nextE = (element)->nextE; \
1364  if ((element)->nextE == NULL) \
1365  (tail) = (element)->prevE; \
1366  else \
1367  (element)->nextE->prevE = (element)->prevE; \
1368  (element)->nextE = NULL; \
1369  (element)->prevE = NULL; } while (0)
1370 
1371 
1379 time_t MHD_monotonic_time(void);
1380 
1381 #endif
unsigned int per_ip_connection_limit
Definition: internal.h:1139
void * unescape_callback_cls
Definition: internal.h:1022
uint64_t total_size
Definition: internal.h:295
pthread_mutex_t per_ip_connection_mutex
Definition: internal.h:1080
ssize_t(* TransmitCallback)(struct MHD_Connection *conn, const void *write_to, size_t max_bytes)
Definition: internal.h:504
pthread_mutex_t cleanup_connection_mutex
Definition: internal.h:1085
off_t fd_off
Definition: internal.h:306
int(* write_handler)(struct MHD_Connection *connection)
Definition: internal.h:806
socklen_t addr_len
Definition: internal.h:697
int thread_joined
Definition: internal.h:736
pthread_t pid
Definition: internal.h:643
enum MHD_CONNECTION_STATE state
Definition: internal.h:753
int(* idle_handler)(struct MHD_Connection *connection)
Definition: internal.h:811
uint64_t response_write_position
Definition: internal.h:686
public interface to libmicrohttpd
enum MHD_ConnectionEventLoopInfo event_loop_info
Definition: internal.h:758
size_t current_chunk_size
Definition: internal.h:790
MHD_PanicCallback mhd_panic
Definition: daemon.c:138
size_t MHD_http_unescape(void *cls, struct MHD_Connection *connection, char *val)
Definition: internal.c:119
MHD_ContentReaderFreeCallback crfc
Definition: internal.h:284
pthread_mutex_t mutex
Definition: internal.h:290
MHD_CONNECTION_STATE
Definition: internal.h:346
char * version
Definition: internal.h:602
void(* MHD_ContentReaderFreeCallback)(void *cls)
Definition: microhttpd.h:1281
MHD_socket socket_fd
Definition: internal.h:1090
struct MHD_Response * response
Definition: internal.h:564
char * colon
Definition: internal.h:631
char * write_buffer
Definition: internal.h:616
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
Definition: microhttpd.h:1197
struct MHD_Connection * normal_timeout_tail
Definition: internal.h:963
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
Definition: internal.h:865
size_t data_size
Definition: internal.h:311
unsigned long int nc
Definition: internal.h:183
int have_chunked_upload
Definition: internal.h:782
enum MHD_ValueKind kind
Definition: internal.h:244
struct MHD_HTTP_Header * first_header
Definition: internal.h:260
MHD_AccessHandlerCallback default_handler
Definition: internal.h:896
int MHD_socket
Definition: microhttpd.h:174
size_t current_chunk_offset
Definition: internal.h:796
uint64_t remaining_upload_size
Definition: internal.h:679
unsigned int responseCode
Definition: internal.h:764
platform-specific includes for libmicrohttpd
char * value
Definition: internal.h:238
void * uri_log_callback_cls
Definition: internal.h:1012
int(* read_handler)(struct MHD_Connection *connection)
Definition: internal.h:801
struct MHD_Daemon * daemon
Definition: internal.h:549
int MHD_pipe
Definition: platform.h:160
struct MHD_Connection * manual_timeout_head
Definition: internal.h:970
struct MHD_Connection * cleanup_head
Definition: internal.h:926
int client_aware
Definition: internal.h:716
struct MHD_Connection * cleanup_tail
Definition: internal.h:931
struct MHD_Connection * prev
Definition: internal.h:534
size_t data_buffer_size
Definition: internal.h:316
size_t write_buffer_send_offset
Definition: internal.h:667
struct MHD_Daemon * worker_pool
Definition: internal.h:1045
size_t read_buffer_size
Definition: internal.h:651
void * client_context
Definition: internal.h:584
struct MHD_Connection * nextX
Definition: internal.h:539
struct MHD_Connection * manual_timeout_tail
Definition: internal.h:976
size_t continue_message_write_offset
Definition: internal.h:692
MHD_socket socket_fd
Definition: internal.h:723
char * method
Definition: internal.h:590
char nonce[MAX_NONCE_LENGTH]
Definition: internal.h:188
unsigned int worker_pool_size
Definition: internal.h:1070
LogCallback uri_log_callback
Definition: internal.h:1007
unsigned int reference_count
Definition: internal.h:322
int response_unready
Definition: internal.h:773
int(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Definition: microhttpd.h:1129
int shutdown
Definition: internal.h:1117
#define MAX_NONCE_LENGTH
Definition: internal.h:169
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
Definition: microhttpd.h:1265
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
Definition: internal.h:878
uint16_t port
Definition: internal.h:1149
char * last
Definition: internal.h:623
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
Definition: internal.h:492
struct MHD_Connection * normal_timeout_head
Definition: internal.h:957
MHD_ValueKind
Definition: microhttpd.h:872
char * read_buffer
Definition: internal.h:610
void * mhd_panic_cls
Definition: daemon.c:143
ReceiveCallback recv_cls
Definition: internal.h:816
size_t thread_stack_size
Definition: internal.h:1065
char * url
Definition: internal.h:596
size_t write_buffer_size
Definition: internal.h:662
uint64_t data_start
Definition: internal.h:301
UnescapeCallback unescape_callback
Definition: internal.h:1017
pthread_t pid
Definition: internal.h:1075
struct MHD_Connection * connections_head
Definition: internal.h:906
struct MHD_Daemon * master
Definition: internal.h:1040
size_t pool_size
Definition: internal.h:1055
char * header
Definition: internal.h:233
struct MHD_Connection * next
Definition: internal.h:529
MHD_AcceptPolicyCallback apc
Definition: internal.h:982
time_t last_activity
Definition: internal.h:703
unsigned int connection_timeout
Definition: internal.h:709
struct MemoryPool * pool
Definition: internal.h:576
MHD_pipe wpipe[2]
Definition: internal.h:1112
size_t write_buffer_append_offset
Definition: internal.h:673
int resuming
Definition: internal.h:1122
struct MHD_HTTP_Header * next
Definition: internal.h:227
MHD_RequestCompletedCallback notify_completed
Definition: internal.h:993
struct MHD_Connection * prevX
Definition: internal.h:544
enum MHD_OPTION options
Definition: internal.h:1144
void * notify_completed_cls
Definition: internal.h:998
TransmitCallback send_cls
Definition: internal.h:821
MHD_OPTION
MHD options.
Definition: microhttpd.h:582
void * apc_cls
Definition: internal.h:987
MHD_ContentReaderCallback crc
Definition: internal.h:278
void * crc_cls
Definition: internal.h:272
struct sockaddr * addr
Definition: internal.h:637
struct MHD_Connection * suspended_connections_tail
Definition: internal.h:921
MHD_ConnectionEventLoopInfo
Definition: internal.h:139
MHD_EpollState
Definition: internal.h:98
time_t MHD_monotonic_time(void)
Definition: internal.c:169
void * per_ip_connection_count
Definition: internal.h:1050
char * data
Definition: internal.h:266
int(* MHD_AccessHandlerCallback)(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
Definition: microhttpd.h:1174
size_t read_buffer_offset
Definition: internal.h:657
void * default_handler_cls
Definition: internal.h:901
unsigned int connection_timeout
Definition: internal.h:1133
struct MHD_HTTP_Header * headers_received
Definition: internal.h:554
struct MHD_Connection * connections_tail
Definition: internal.h:911
struct MHD_HTTP_Header * headers_received_tail
Definition: internal.h:559
size_t pool_increment
Definition: internal.h:1060
unsigned int max_connections
Definition: internal.h:1127
struct MHD_Connection * suspended_connections_head
Definition: internal.h:916
void(* MHD_PanicCallback)(void *cls, const char *file, unsigned int line, const char *reason)
Definition: microhttpd.h:1116