27 #define MHD_NO_DEPRECATION 1 30 #ifdef HAVE_SYS_IOCTL_H 31 #include <sys/ioctl.h> 47 #if defined(_WIN32) && defined(MHD_W32_MUTEX_) 48 #ifndef WIN32_LEAN_AND_MEAN 49 #define WIN32_LEAN_AND_MEAN 1 75 if ( (
NULL == response) ||
80 (
NULL != strchr (header,
'\t')) ||
81 (
NULL != strchr (header,
'\r')) ||
82 (
NULL != strchr (header,
'\n')) ||
83 (
NULL != strchr (content,
'\t')) ||
84 (
NULL != strchr (content,
'\r')) ||
85 (
NULL != strchr (content,
'\n')) )
94 if (
NULL == (hdr->
value = strdup (content)))
166 if ( (
NULL == header) ||
173 if ((0 == strcmp (header,
175 (0 == strcmp (content,
215 if ((
NULL != iterator) &&
216 (
MHD_YES != iterator (iterator_cls,
243 if (0 == strcmp (key,
275 if ((
NULL == crc) || (0 == block_size))
280 response->
data = (
void *) &response[1];
282 if (! MHD_mutex_init_ (&response->
mutex))
306 enum MHD_ResponseFlags
flags,
311 enum MHD_ResponseOptions ro;
315 va_start (ap, flags);
316 while (MHD_RO_END != (ro = va_arg (ap,
enum MHD_ResponseOptions)))
350 const HANDLE fh = (HANDLE) _get_osfhandle (response->
fd);
352 const int64_t offset64 = (int64_t)(pos + response->
fd_off);
361 #if defined(HAVE_PREAD64) 362 n = pread64(response->
fd, buf, max, offset64);
363 #elif defined(HAVE_PREAD) 364 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
368 n = pread(response->
fd, buf, max, (off_t) offset64);
370 #if defined(HAVE_LSEEK64) 371 if (lseek64 (response->
fd,
373 SEEK_SET) != offset64)
376 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
377 (offset64 > (uint64_t)INT32_MAX) )
380 if (lseek (response->
fd,
382 SEEK_SET) != (off_t) offset64)
385 n = read (response->
fd,
396 if (INVALID_HANDLE_VALUE == fh)
400 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0};
401 ULARGE_INTEGER pos_uli;
402 DWORD toRead = (max >
INT32_MAX) ? INT32_MAX : (DWORD) max;
405 pos_uli.QuadPart = (uint64_t) offset64;
406 f_ol.Offset = pos_uli.LowPart;
407 f_ol.OffsetHigh = pos_uli.HighPart;
408 if (! ReadFile(fh, (
void*)buf, toRead, &resRead, &f_ol))
412 return (ssize_t) resRead;
429 (void) close (response->
fd);
433 #undef MHD_create_response_from_fd_at_offset 485 #if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64) 486 if ( (
sizeof(uint64_t) >
sizeof(off_t)) &&
488 (offset > (uint64_t)INT32_MAX) ||
489 ((size + offset) >= (uint64_t)INT32_MAX) ) )
492 if ( ((int64_t)size < 0) ||
493 ((int64_t)offset < 0) ||
494 ((int64_t)(size + offset) < 0) )
502 if (
NULL == response)
505 response->
fd_off = offset;
576 if ((
NULL == data) && (size > 0))
581 if (! MHD_mutex_init_ (&response->
mutex))
586 if ((must_copy) && (size > 0))
588 if (
NULL == (tmp = malloc (size)))
594 memcpy (tmp, data, size);
600 response->
crfc = &free;
624 enum MHD_ResponseMemoryMode mode)
628 mode == MHD_RESPMEM_MUST_FREE,
629 mode == MHD_RESPMEM_MUST_COPY);
633 #ifdef UPGRADE_SUPPORT 647 MHD_upgrade_action (
struct MHD_UpgradeResponseHandle *urh,
648 enum MHD_UpgradeAction action,
656 connection = urh->connection;
659 if (
NULL == connection)
661 daemon = connection->
daemon;
667 case MHD_UPGRADE_ACTION_CLOSE:
682 urh->was_closed =
true;
713 struct MHD_UpgradeResponseHandle *urh;
725 _(
"Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
730 urh =
MHD_calloc_ (1,
sizeof (
struct MHD_UpgradeResponseHandle));
733 urh->connection = connection;
739 struct MemoryPool *pool;
743 #if defined(MHD_socket_nosignal_) || !defined(MHD_socket_pair_nblk_) 748 #ifdef MHD_socket_pair_nblk_ 749 if (! MHD_socket_pair_nblk_ (sv))
755 if (! MHD_socket_pair_ (sv))
762 if ( (! res1) || (! res2) )
766 _(
"Failed to make loopback sockets non-blocking.\n"));
778 #ifdef MHD_socket_nosignal_ 779 res1 = MHD_socket_nosignal_(sv[0]);
780 res2 = MHD_socket_nosignal_(sv[1]);
781 if ( (! res1) || (! res2) )
785 _(
"Failed to set SO_NOSIGPIPE on loopback sockets.\n"));
805 _(
"Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
814 urh->app.socket = sv[0];
817 urh->mhd.socket = sv[1];
820 pool = connection->
pool;
822 if (avail < RESERVE_EBUF_SIZE)
826 avail = RESERVE_EBUF_SIZE;
840 urh->in_buffer_size = avail / 2;
841 urh->out_buffer_size = avail - urh->in_buffer_size;
842 urh->in_buffer = buf;
843 urh->out_buffer = &buf[urh->in_buffer_size];
850 struct epoll_event event;
854 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
855 event.data.ptr = &urh->app;
856 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
863 _(
"Call to epoll_ctl failed: %s\n"),
873 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
874 event.data.ptr = &urh->mhd;
875 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
880 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI;
881 event.data.ptr = &urh->app;
882 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
886 MHD_PANIC (
_(
"Error cleaning up while handling epoll error"));
889 _(
"Call to epoll_ctl failed: %s\n"),
898 daemon->eready_urh_tail,
900 urh->in_eready_list =
true;
920 urh->clean_ready =
true;
923 urh->clean_ready =
true;
925 connection->urh = urh;
932 response->upgrade_handler (response->upgrade_handler_cls,
978 MHD_create_response_for_upgrade (MHD_UpgradeHandler upgrade_handler,
979 void *upgrade_handler_cls)
983 if (
NULL == upgrade_handler)
986 if (
NULL == response)
988 if (! MHD_mutex_init_ (&response->
mutex))
993 response->upgrade_handler = upgrade_handler;
994 response->upgrade_handler_cls = upgrade_handler_cls;
1024 if (
NULL == response)
int(* MHD_KeyValueIterator)(void *cls, enum MHD_ValueKind kind, const char *key, const char *value)
int MHD_socket_nonblocking_(MHD_socket sock)
int MHD_set_response_options(struct MHD_Response *response, enum MHD_ResponseFlags flags,...)
additional automatic macros for MHD_config.h
static void free_callback(void *cls)
#define DLL_insert(head, tail, element)
enum MHD_CONNECTION_STATE state
int MHD_add_response_header(struct MHD_Response *response, const char *header, const char *content)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd64(uint64_t size, int fd)
MHD_ContentReaderFreeCallback crfc
Methods for managing connections.
void(* MHD_ContentReaderFreeCallback)(void *cls)
static ssize_t file_reader(void *cls, uint64_t pos, char *buf, size_t max)
const char * MHD_get_response_header(struct MHD_Response *response, const char *key)
Header for platform missing functions.
struct MHD_HTTP_Header * first_header
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
void MHD_suspend_connection(struct MHD_Connection *connection)
#define MHD_mutex_destroy_chk_(pmutex)
#define EDLL_insert(head, tail, element)
Methods for managing response objects.
int MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
struct MHD_Daemon * daemon
#define MHD_mutex_unlock_chk_(pmutex)
struct MHD_Response * MHD_create_response_from_callback(uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
Header for platform-independent inter-thread communication.
struct MHD_Response * MHD_create_response_from_buffer(size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
#define MHD_socket_close_chk_(fd)
#define MHD_INVALID_SOCKET
int MHD_add_response_footer(struct MHD_Response *response, const char *footer, const char *content)
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
unsigned int reference_count
void MHD_destroy_response(struct MHD_Response *response)
void MHD_increment_response_rc(struct MHD_Response *response)
#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)
limits values definitions
internal shared structures
void * MHD_calloc_(size_t nelem, size_t elsize)
size_t MHD_pool_get_free(struct MemoryPool *pool)
#define MHD_socket_last_strerr_()
static int add_response_entry(struct MHD_Response *response, enum MHD_ValueKind kind, const char *header, const char *content)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd_at_offset64(uint64_t size, int fd, uint64_t offset)
enum MHD_ResponseFlags flags
#define MHD_SCKT_FD_FITS_FDSET_(fd, pset)
#define MHD_CONTENT_READER_END_WITH_ERROR
MHD_ContentReaderCallback crc
void MHD_resume_connection(struct MHD_Connection *connection)
int MHD_del_response_header(struct MHD_Response *response, const char *header, const char *content)
size_t read_buffer_offset
struct MHD_Response * MHD_create_response_from_fd(size_t size, int fd)
struct MHD_Response * MHD_create_response_from_fd_at_offset(size_t size, int fd, off_t offset)
#define MHD_mutex_lock_chk_(pmutex)
int MHD_get_response_headers(struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...