27 #define MHD_NO_DEPRECATION 1
30 #ifdef HAVE_SYS_IOCTL_H
31 #include <sys/ioctl.h>
33 #if defined(_WIN32) && ! defined(__CYGWIN__)
48 #if defined(MHD_W32_MUTEX_)
49 #ifndef WIN32_LEAN_AND_MEAN
50 #define WIN32_LEAN_AND_MEAN 1
76 if ( (
NULL == response) ||
81 (
NULL != strchr (header,
'\t')) ||
82 (
NULL != strchr (header,
'\r')) ||
83 (
NULL != strchr (header,
'\n')) ||
84 (
NULL != strchr (content,
'\t')) ||
85 (
NULL != strchr (content,
'\r')) ||
86 (
NULL != strchr (content,
'\n')) )
95 if (
NULL == (hdr->
value = strdup (content)))
188 if ( (
NULL == header) ||
195 if ((0 == strcmp (header,
197 (0 == strcmp (content,
239 if ((
NULL != iterator) &&
240 (
MHD_YES != iterator (iterator_cls,
299 if ( (
NULL == key) ||
346 if ((
NULL == crc) || (0 == block_size))
351 response->
data = (
void *) &response[1];
353 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
354 if (! MHD_mutex_init_ (&response->
mutex))
388 va_start (ap, flags);
420 #if !defined(_WIN32) || defined(__CYGWIN__)
423 const HANDLE fh = (HANDLE) _get_osfhandle (response->
fd);
425 const int64_t offset64 = (int64_t)(pos + response->
fd_off);
430 #if !defined(_WIN32) || defined(__CYGWIN__)
434 #if defined(HAVE_PREAD64)
435 n = pread64(response->
fd, buf, max, offset64);
436 #elif defined(HAVE_PREAD)
437 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
441 n = pread(response->
fd, buf, max, (off_t) offset64);
443 #if defined(HAVE_LSEEK64)
444 if (lseek64 (response->
fd,
446 SEEK_SET) != offset64)
449 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
450 (offset64 > (uint64_t)INT32_MAX) )
453 if (lseek (response->
fd,
455 SEEK_SET) != (off_t) offset64)
458 n = read (response->
fd,
469 if (INVALID_HANDLE_VALUE == fh)
473 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0};
474 ULARGE_INTEGER pos_uli;
475 DWORD toRead = (max >
INT32_MAX) ? INT32_MAX : (DWORD) max;
478 pos_uli.QuadPart = (uint64_t) offset64;
479 f_ol.Offset = pos_uli.LowPart;
480 f_ol.OffsetHigh = pos_uli.HighPart;
481 if (! ReadFile(fh, (
void*)buf, toRead, &resRead, &f_ol))
485 return (ssize_t) resRead;
502 (void) close (response->
fd);
506 #undef MHD_create_response_from_fd_at_offset
558 #if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64)
559 if ( (
sizeof(uint64_t) >
sizeof(off_t)) &&
561 (offset > (uint64_t)INT32_MAX) ||
562 ((size + offset) >= (uint64_t)INT32_MAX) ) )
565 if ( ((int64_t)size < 0) ||
566 ((int64_t)offset < 0) ||
567 ((int64_t)(size + offset) < 0) )
575 if (
NULL == response)
649 if ((
NULL == data) && (size > 0))
654 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
655 if (! MHD_mutex_init_ (&response->
mutex))
661 if ((must_copy) && (size > 0))
663 if (
NULL == (tmp = malloc (size)))
665 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
671 memcpy (tmp, data, size);
677 response->
crfc = &free;
738 #ifdef UPGRADE_SUPPORT
761 connection = urh->connection;
764 if (
NULL == connection)
766 daemon = connection->
daemon;
787 urh->was_closed =
true;
818 struct MHD_UpgradeResponseHandle *urh;
830 _(
"Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
835 urh =
MHD_calloc_ (1,
sizeof (
struct MHD_UpgradeResponseHandle));
838 urh->connection = connection;
844 struct MemoryPool *pool;
848 #if defined(MHD_socket_nosignal_) || !defined(MHD_socket_pair_nblk_)
853 #ifdef MHD_socket_pair_nblk_
854 if (! MHD_socket_pair_nblk_ (sv))
860 if (! MHD_socket_pair_ (sv))
867 if ( (! res1) || (! res2) )
871 _(
"Failed to make loopback sockets non-blocking.\n"));
883 #ifdef MHD_socket_nosignal_
884 res1 = MHD_socket_nosignal_(sv[0]);
885 res2 = MHD_socket_nosignal_(sv[1]);
886 if ( (! res1) || (! res2) )
890 _(
"Failed to set SO_NOSIGPIPE on loopback sockets.\n"));
910 _(
"Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
919 urh->app.socket = sv[0];
922 urh->mhd.socket = sv[1];
925 pool = connection->
pool;
927 if (avail < RESERVE_EBUF_SIZE)
931 avail = RESERVE_EBUF_SIZE;
945 urh->in_buffer_size = avail / 2;
946 urh->out_buffer_size = avail - urh->in_buffer_size;
947 urh->in_buffer = buf;
948 urh->out_buffer = &buf[urh->in_buffer_size];
955 struct epoll_event event;
959 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
960 event.data.ptr = &urh->app;
961 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
968 _(
"Call to epoll_ctl failed: %s\n"),
978 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
979 event.data.ptr = &urh->mhd;
980 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
985 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI;
986 event.data.ptr = &urh->app;
987 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
991 MHD_PANIC (
_(
"Error cleaning up while handling epoll error"));
994 _(
"Call to epoll_ctl failed: %s\n"),
1003 daemon->eready_urh_tail,
1005 urh->in_eready_list =
true;
1025 urh->clean_ready =
true;
1028 urh->clean_ready =
true;
1030 connection->urh = urh;
1037 response->upgrade_handler (response->upgrade_handler_cls,
1042 #ifdef HTTPS_SUPPORT
1044 connection->
socket_fd : urh->app.socket,
1084 void *upgrade_handler_cls)
1088 if (
NULL == upgrade_handler)
1091 if (
NULL == response)
1093 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1094 if (! MHD_mutex_init_ (&response->
mutex))
1100 response->upgrade_handler = upgrade_handler;
1101 response->upgrade_handler_cls = upgrade_handler_cls;
1131 if (
NULL == response)
1133 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1138 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1143 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1169 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
1173 #if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
int(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
Header for platform missing functions.
additional automatic macros for MHD_config.h
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_callback(uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
bool MHD_check_response_header_token_ci(const struct MHD_Response *response, const char *key, const char *token, size_t token_len)
enum MHD_CONNECTION_STATE state
_MHD_EXTERN int MHD_add_response_header(struct MHD_Response *response, const char *header, const char *content)
MHD_mutex_lock_chk_ & daemon
#define MHD_FD_BLOCK_SIZE
#define MHD_mutex_unlock_chk_(pmutex)
size_t MHD_pool_get_free(struct MemoryPool *pool)
MHD_ContentReaderFreeCallback crfc
Methods for managing connections.
#define MHD_mutex_destroy_chk_(pmutex)
void * MHD_calloc_(size_t nelem, size_t elsize)
void(* MHD_ContentReaderFreeCallback)(void *cls)
#define EDLL_insert(head, tail, element)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd64(uint64_t size, int fd)
struct MHD_Connection * prev
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
int MHD_str_equal_caseless_(const char *str1, const char *str2)
Methods for managing response objects.
struct MHD_Daemon * daemon
int MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
Header for platform-independent inter-thread communication.
#define DLL_insert(head, tail, element)
void MHD_increment_response_rc(struct MHD_Response *response)
struct MHD_HTTP_Header * first_header
#define MHD_socket_last_strerr_()
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
#define MHD_INVALID_SOCKET
internal shared structures
_MHD_EXTERN int MHD_add_response_footer(struct MHD_Response *response, const char *footer, const char *content)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd_at_offset64(uint64_t size, int fd, uint64_t offset)
#define MHD_socket_close_chk_(fd)
unsigned int reference_count
_MHD_EXTERN void MHD_destroy_response(struct MHD_Response *response)
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
#define MHD_CONTENT_READER_END_OF_STREAM
struct MHD_Response * MHD_create_response_from_data(size_t size, void *data, int must_free, int must_copy)
Header for string manipulating helpers.
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd(size_t size, int fd)
static ssize_t file_reader(void *cls, uint64_t pos, char *buf, size_t max)
_MHD_EXTERN int MHD_upgrade_action(struct MHD_UpgradeResponseHandle *urh, enum MHD_UpgradeAction action,...)
void internal_suspend_connection_(struct MHD_Connection *connection)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer(size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
enum MHD_ResponseFlags flags
_MHD_EXTERN struct MHD_Response * MHD_create_response_for_upgrade(MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls)
#define MHD_mutex_lock_chk_(pmutex)
#define MHD_SCKT_FD_FITS_FDSET_(fd, pset)
_MHD_EXTERN int MHD_set_response_options(struct MHD_Response *response, enum MHD_ResponseFlags flags,...)
int MHD_socket_nonblocking_(MHD_socket sock)
#define MHD_CONTENT_READER_END_WITH_ERROR
MHD_ContentReaderCallback crc
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer_with_free_callback(size_t size, void *buffer, MHD_ContentReaderFreeCallback crfc)
static int add_response_entry(struct MHD_Response *response, enum MHD_ValueKind kind, const char *header, const char *content)
_MHD_EXTERN int MHD_del_response_header(struct MHD_Response *response, const char *header, const char *content)
size_t read_buffer_offset
_MHD_EXTERN const char * MHD_get_response_header(struct MHD_Response *response, const char *key)
limits values definitions
void(* MHD_UpgradeHandler)(void *cls, struct MHD_Connection *connection, void *con_cls, const char *extra_in, size_t extra_in_size, MHD_socket sock, struct MHD_UpgradeResponseHandle *urh)
struct MHD_Response * MHD_create_response_from_fd_at_offset(size_t size, int fd, off_t offset)
_MHD_EXTERN int MHD_get_response_headers(struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
_MHD_EXTERN void MHD_resume_connection(struct MHD_Connection *connection)
static void free_callback(void *cls)