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
unsigned int per_ip_connection_limit
Definition: internal.h:1133
void * unescape_callback_cls
Definition: internal.h:1017
uint64_t total_size
Definition: internal.h:290
pthread_mutex_t per_ip_connection_mutex
Definition: internal.h:1075
ssize_t(* TransmitCallback)(struct MHD_Connection *conn, const void *write_to, size_t max_bytes)
Definition: internal.h:499
pthread_mutex_t cleanup_connection_mutex
Definition: internal.h:1080
void * mhd_panic_cls
Definition: daemon.c:129
off_t fd_off
Definition: internal.h:301
int(* write_handler)(struct MHD_Connection *connection)
Definition: internal.h:801
socklen_t addr_len
Definition: internal.h:692
int thread_joined
Definition: internal.h:731
pthread_t pid
Definition: internal.h:638
enum MHD_CONNECTION_STATE state
Definition: internal.h:748
int(* idle_handler)(struct MHD_Connection *connection)
Definition: internal.h:806
uint64_t response_write_position
Definition: internal.h:681
public interface to libmicrohttpd
enum MHD_ConnectionEventLoopInfo event_loop_info
Definition: internal.h:753
MHD_ContentReaderFreeCallback crfc
Definition: internal.h:279
pthread_mutex_t mutex
Definition: internal.h:285
int socket_fd
Definition: internal.h:1085
MHD_CONNECTION_STATE
Definition: internal.h:341
char * version
Definition: internal.h:597
void(* MHD_ContentReaderFreeCallback)(void *cls)
Definition: microhttpd.h:1238
struct MHD_Response * response
Definition: internal.h:559
char * colon
Definition: internal.h:626
char * write_buffer
Definition: internal.h:611
void(* MHD_RequestCompletedCallback)(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
Definition: microhttpd.h:1154
struct MHD_Connection * normal_timeout_tail
Definition: internal.h:958
void *(* LogCallback)(void *cls, const char *uri, struct MHD_Connection *con)
Definition: internal.h:860
size_t data_size
Definition: internal.h:306
unsigned long int nc
Definition: internal.h:178
int have_chunked_upload
Definition: internal.h:777
enum MHD_ValueKind kind
Definition: internal.h:239
struct MHD_HTTP_Header * first_header
Definition: internal.h:255
MHD_AccessHandlerCallback default_handler
Definition: internal.h:891
uint64_t remaining_upload_size
Definition: internal.h:674
unsigned int responseCode
Definition: internal.h:759
platform-specific includes for libmicrohttpd
char * value
Definition: internal.h:233
void * uri_log_callback_cls
Definition: internal.h:1007
unsigned int current_chunk_offset
Definition: internal.h:791
int(* read_handler)(struct MHD_Connection *connection)
Definition: internal.h:796
int wpipe[2]
Definition: internal.h:1106
struct MHD_Daemon * daemon
Definition: internal.h:544
struct MHD_Connection * manual_timeout_head
Definition: internal.h:965
struct MHD_Connection * cleanup_head
Definition: internal.h:921
int client_aware
Definition: internal.h:711
struct MHD_Connection * cleanup_tail
Definition: internal.h:926
struct MHD_Connection * prev
Definition: internal.h:529
size_t data_buffer_size
Definition: internal.h:311
size_t write_buffer_send_offset
Definition: internal.h:662
struct MHD_Daemon * worker_pool
Definition: internal.h:1040
size_t read_buffer_size
Definition: internal.h:646
void * client_context
Definition: internal.h:579
struct MHD_Connection * nextX
Definition: internal.h:534
struct MHD_Connection * manual_timeout_tail
Definition: internal.h:971
size_t continue_message_write_offset
Definition: internal.h:687
char * method
Definition: internal.h:585
char nonce[MAX_NONCE_LENGTH]
Definition: internal.h:183
unsigned int worker_pool_size
Definition: internal.h:1065
time_t MHD_monotonic_time(void)
Definition: internal.c:169
LogCallback uri_log_callback
Definition: internal.h:1002
unsigned int reference_count
Definition: internal.h:317
int response_unready
Definition: internal.h:768
int(* MHD_AcceptPolicyCallback)(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Definition: microhttpd.h:1086
int shutdown
Definition: internal.h:1111
#define MAX_NONCE_LENGTH
Definition: internal.h:164
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
Definition: microhttpd.h:1222
size_t(* UnescapeCallback)(void *cls, struct MHD_Connection *conn, char *uri)
Definition: internal.h:873
uint16_t port
Definition: internal.h:1143
char * last
Definition: internal.h:618
ssize_t(* ReceiveCallback)(struct MHD_Connection *conn, void *write_to, size_t max_bytes)
Definition: internal.h:487
struct MHD_Connection * normal_timeout_head
Definition: internal.h:952
MHD_ValueKind
Definition: microhttpd.h:829
char * read_buffer
Definition: internal.h:605
ReceiveCallback recv_cls
Definition: internal.h:811
size_t thread_stack_size
Definition: internal.h:1060
char * url
Definition: internal.h:591
size_t write_buffer_size
Definition: internal.h:657
uint64_t data_start
Definition: internal.h:296
UnescapeCallback unescape_callback
Definition: internal.h:1012
pthread_t pid
Definition: internal.h:1070
struct MHD_Connection * connections_head
Definition: internal.h:901
struct MHD_Daemon * master
Definition: internal.h:1035
size_t pool_size
Definition: internal.h:1050
char * header
Definition: internal.h:228
struct MHD_Connection * next
Definition: internal.h:524
MHD_AcceptPolicyCallback apc
Definition: internal.h:977
time_t last_activity
Definition: internal.h:698
unsigned int connection_timeout
Definition: internal.h:704
size_t MHD_http_unescape(void *cls, struct MHD_Connection *connection, char *val)
Definition: internal.c:119
struct MemoryPool * pool
Definition: internal.h:571
size_t write_buffer_append_offset
Definition: internal.h:668
int resuming
Definition: internal.h:1116
unsigned int current_chunk_size
Definition: internal.h:785
struct MHD_HTTP_Header * next
Definition: internal.h:222
MHD_RequestCompletedCallback notify_completed
Definition: internal.h:988
struct MHD_Connection * prevX
Definition: internal.h:539
enum MHD_OPTION options
Definition: internal.h:1138
void * notify_completed_cls
Definition: internal.h:993
TransmitCallback send_cls
Definition: internal.h:816
MHD_OPTION
MHD options.
Definition: microhttpd.h:548
void * apc_cls
Definition: internal.h:982
MHD_ContentReaderCallback crc
Definition: internal.h:273
void * crc_cls
Definition: internal.h:267
struct sockaddr * addr
Definition: internal.h:632
struct MHD_Connection * suspended_connections_tail
Definition: internal.h:916
MHD_PanicCallback mhd_panic
Definition: daemon.c:124
MHD_ConnectionEventLoopInfo
Definition: internal.h:134
MHD_EpollState
Definition: internal.h:93
void * per_ip_connection_count
Definition: internal.h:1045
char * data
Definition: internal.h:261
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:1131
size_t read_buffer_offset
Definition: internal.h:652
void * default_handler_cls
Definition: internal.h:896
unsigned int connection_timeout
Definition: internal.h:1127
struct MHD_HTTP_Header * headers_received
Definition: internal.h:549
struct MHD_Connection * connections_tail
Definition: internal.h:906
struct MHD_HTTP_Header * headers_received_tail
Definition: internal.h:554
size_t pool_increment
Definition: internal.h:1055
unsigned int max_connections
Definition: internal.h:1121
struct MHD_Connection * suspended_connections_head
Definition: internal.h:911
void(* MHD_PanicCallback)(void *cls, const char *file, unsigned int line, const char *reason)
Definition: microhttpd.h:1073