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) ||
84 (
NULL != strchr (content,
'\t')) ||
85 (
NULL != strchr (content,
'\r')) ||
86 (
NULL != strchr (content,
'\n')) )
95 if (
NULL == (hdr->
value = strdup (content)))
176 (0 == strcmp (content,
218 if ((
NULL != iterator) &&
219 (
MHD_YES != iterator (iterator_cls,
277 if ( (
NULL == key) ||
324 if ((
NULL ==
crc) || (0 == block_size))
329 response->
data = (
void *) &response[1];
331 if (! MHD_mutex_init_ (&response->
mutex))
364 va_start (ap,
flags);
396 #if !defined(_WIN32) || defined(__CYGWIN__) 399 const HANDLE fh = (HANDLE) _get_osfhandle (response->
fd);
401 const int64_t offset64 = (int64_t)(pos + response->
fd_off);
406 #if !defined(_WIN32) || defined(__CYGWIN__) 410 #if defined(HAVE_PREAD64) 411 n = pread64(response->
fd, buf, max, offset64);
412 #elif defined(HAVE_PREAD) 413 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
417 n = pread(response->
fd, buf, max, (off_t) offset64);
419 #if defined(HAVE_LSEEK64) 420 if (lseek64 (response->
fd,
422 SEEK_SET) != offset64)
425 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
429 if (lseek (response->
fd,
431 SEEK_SET) != (off_t) offset64)
434 n = read (response->
fd,
445 if (INVALID_HANDLE_VALUE == fh)
449 OVERLAPPED f_ol = {0, 0, {{0, 0}}, 0};
450 ULARGE_INTEGER pos_uli;
454 pos_uli.QuadPart = (uint64_t) offset64;
455 f_ol.Offset = pos_uli.LowPart;
456 f_ol.OffsetHigh = pos_uli.HighPart;
457 if (! ReadFile(fh, (
void*)buf, toRead, &resRead, &f_ol))
461 return (ssize_t) resRead;
478 (void) close (response->
fd);
482 #undef MHD_create_response_from_fd_at_offset 534 #if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64) 535 if ( (
sizeof(uint64_t) >
sizeof(off_t)) &&
541 if ( ((int64_t)size < 0) ||
543 ((int64_t)(size +
offset) < 0) )
551 if (
NULL == response)
630 if (! MHD_mutex_init_ (&response->
mutex))
637 if (
NULL == (tmp = malloc (size)))
643 memcpy (tmp,
data, size);
649 response->
crfc = &free;
682 #ifdef UPGRADE_SUPPORT 705 connection = urh->connection;
708 if (
NULL == connection)
710 daemon = connection->
daemon;
731 urh->was_closed =
true;
762 struct MHD_UpgradeResponseHandle *urh;
774 _(
"Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
779 urh =
MHD_calloc_ (1,
sizeof (
struct MHD_UpgradeResponseHandle));
782 urh->connection = connection;
788 struct MemoryPool *pool;
792 #if defined(MHD_socket_nosignal_) || !defined(MHD_socket_pair_nblk_) 797 #ifdef MHD_socket_pair_nblk_ 798 if (! MHD_socket_pair_nblk_ (sv))
804 if (! MHD_socket_pair_ (sv))
811 if ( (! res1) || (! res2) )
815 _(
"Failed to make loopback sockets non-blocking.\n"));
827 #ifdef MHD_socket_nosignal_ 828 res1 = MHD_socket_nosignal_(sv[0]);
829 res2 = MHD_socket_nosignal_(sv[1]);
830 if ( (! res1) || (! res2) )
834 _(
"Failed to set SO_NOSIGPIPE on loopback sockets.\n"));
854 _(
"Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
863 urh->app.socket = sv[0];
866 urh->mhd.socket = sv[1];
869 pool = connection->
pool;
871 if (avail < RESERVE_EBUF_SIZE)
875 avail = RESERVE_EBUF_SIZE;
889 urh->in_buffer_size = avail / 2;
890 urh->out_buffer_size = avail - urh->in_buffer_size;
891 urh->in_buffer = buf;
892 urh->out_buffer = &buf[urh->in_buffer_size];
899 struct epoll_event event;
903 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
904 event.data.ptr = &urh->app;
905 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
912 _(
"Call to epoll_ctl failed: %s\n"),
922 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET;
923 event.data.ptr = &urh->mhd;
924 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
929 event.events = EPOLLIN | EPOLLOUT | EPOLLPRI;
930 event.data.ptr = &urh->app;
931 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
935 MHD_PANIC (
_(
"Error cleaning up while handling epoll error"));
938 _(
"Call to epoll_ctl failed: %s\n"),
947 daemon->eready_urh_tail,
949 urh->in_eready_list =
true;
969 urh->clean_ready =
true;
972 urh->clean_ready =
true;
974 connection->urh = urh;
981 response->upgrade_handler (response->upgrade_handler_cls,
1028 void *upgrade_handler_cls)
1032 if (
NULL == upgrade_handler)
1035 if (
NULL == response)
1037 if (! MHD_mutex_init_ (&response->
mutex))
1042 response->upgrade_handler = upgrade_handler;
1043 response->upgrade_handler_cls = upgrade_handler_cls;
1073 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
_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)
static void free_callback(void *cls)
#define DLL_insert(head, tail, element)
enum MHD_CONNECTION_STATE state
_MHD_EXTERN int MHD_add_response_header(struct MHD_Response *response, const char *header, const char *content)
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)
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd64(uint64_t size, int fd)
Header for platform missing functions.
struct MHD_HTTP_Header * first_header
void * MHD_pool_allocate(struct MemoryPool *pool, size_t size, int from_end)
#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)
Header for platform-independent inter-thread communication.
#define MHD_socket_close_chk_(fd)
#define MHD_INVALID_SOCKET
_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)
ssize_t(* MHD_ContentReaderCallback)(void *cls, uint64_t pos, char *buf, size_t max)
unsigned int reference_count
_MHD_EXTERN 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
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd(size_t size, int fd)
_MHD_EXTERN int MHD_upgrade_action(struct MHD_UpgradeResponseHandle *urh, enum MHD_UpgradeAction action,...)
bool MHD_check_response_header_token_ci(const struct MHD_Response *response, const char *key, const char *token, size_t token_len)
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_()
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)
static int add_response_entry(struct MHD_Response *response, enum MHD_ValueKind kind, const char *header, const char *content)
enum MHD_ResponseFlags flags
_MHD_EXTERN struct MHD_Response * MHD_create_response_for_upgrade(MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls)
Header for string manipulating helpers.
#define MHD_SCKT_FD_FITS_FDSET_(fd, pset)
bool MHD_str_has_token_caseless_(const char *str, const char *const token, size_t token_len)
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)
int MHD_str_equal_caseless_(const char *str1, const char *str2)
#define MHD_CONTENT_READER_END_WITH_ERROR
MHD_ContentReaderCallback crc
_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)
struct MHD_Response * MHD_create_response_from_fd_at_offset(size_t size, int fd, off_t offset)
#define MHD_mutex_lock_chk_(pmutex)
_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)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...