26 #define MHD_NO_DEPRECATION 1 29 #ifdef HAVE_SYS_IOCTL_H 30 #include <sys/ioctl.h> 42 #if defined(_WIN32) && defined(MHD_W32_MUTEX_) 43 #ifndef WIN32_LEAN_AND_MEAN 44 #define WIN32_LEAN_AND_MEAN 1 70 if ( (
NULL == response) ||
73 (0 == strlen (header)) ||
74 (0 == strlen (content)) ||
75 (
NULL != strchr (header,
'\t')) ||
76 (
NULL != strchr (header,
'\r')) ||
77 (
NULL != strchr (header,
'\n')) ||
78 (
NULL != strchr (content,
'\t')) ||
79 (
NULL != strchr (content,
'\r')) ||
80 (
NULL != strchr (content,
'\n')) )
89 if (
NULL == (hdr->
value = strdup (content)))
161 if ( (
NULL == header) ||
168 if ((0 == strcmp (header,
170 (0 == strcmp (content,
210 if ((
NULL != iterator) &&
211 (
MHD_YES != iterator (iterator_cls,
238 if (0 == strcmp (key,
270 if ((
NULL == crc) || (0 == block_size))
272 if (
NULL == (response = malloc (
sizeof (
struct MHD_Response) + block_size)))
278 response->
data = (
void *) &response[1];
280 if (! MHD_mutex_init_ (&response->
mutex))
313 va_start (ap, flags);
346 const int64_t offset64 = (int64_t)(pos + response->
fd_off);
351 #if defined(HAVE_LSEEK64) 352 if (lseek64 (response->
fd,
354 SEEK_SET) != offset64)
356 #elif defined(HAVE___LSEEKI64) 357 if (_lseeki64 (response->
fd,
359 SEEK_SET) != offset64)
362 if ( (
sizeof(off_t) <
sizeof (uint64_t)) &&
366 if (lseek (response->
fd,
368 SEEK_SET) != (off_t) offset64)
376 n = read (response->
fd,
383 n = read (response->
fd,
407 (void) close (response->
fd);
411 #undef MHD_create_response_from_fd_at_offset 463 #if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64) 464 if ( (
sizeof(uint64_t) >
sizeof(off_t)) &&
466 (offset > (uint64_t)INT32_MAX) ||
467 ((size + offset) >= (uint64_t)INT32_MAX) ) )
470 if ( ((int64_t)size < 0) ||
471 ((int64_t)offset < 0) ||
472 ((int64_t)(size + offset) < 0) )
480 if (
NULL == response)
554 if ((
NULL == data) && (size > 0))
562 if (! MHD_mutex_init_ (&response->
mutex))
567 if ((must_copy) && (size > 0))
569 if (
NULL == (tmp = malloc (size)))
575 memcpy (tmp, data, size);
580 response->
crfc = must_free ? &free :
NULL;
663 MHD_DLOG (connection->
daemon,
664 _(
"Processing thread terminating. Closing connection\n"));
721 _(
"Invalid response for upgrade: application failed to set the 'Upgrade' header!\n"));
738 struct MemoryPool *pool;
743 #ifdef MHD_socket_pair_nblk_ 744 if (! MHD_socket_pair_nblk_ (sv))
750 if (! MHD_socket_pair_ (sv))
760 _(
"Failed to make loopback sockets non-blocking: %s\n"),
771 _(
"Socketpair descriptor larger than FD_SETSIZE: %d > %d\n"),
780 urh->app.socket = sv[0];
783 urh->mhd.socket = sv[1];
786 pool = connection->
pool;
807 urh->in_buffer_size = avail;
808 urh->out_buffer_size = avail;
809 urh->in_buffer = buf;
810 urh->out_buffer = &buf[avail];
825 struct epoll_event event;
829 event.events = EPOLLIN | EPOLLOUT;
830 event.data.ptr = &urh->app;
831 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
838 _(
"Call to epoll_ctl failed: %s\n"),
848 event.events = EPOLLIN | EPOLLOUT;
849 event.data.ptr = &urh->mhd;
850 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
855 event.events = EPOLLIN | EPOLLOUT;
856 event.data.ptr = &urh->app;
857 if (0 != epoll_ctl (daemon->epoll_upgrade_fd,
861 MHD_PANIC (
_(
"Error cleaning up while handling epoll error"));
864 _(
"Call to epoll_ctl failed: %s\n"),
886 connection->
urh = urh;
893 connection->
urh = urh;
902 connection->
urh = urh;
957 if (
NULL == upgrade_handler)
960 if (
NULL == response)
963 if (! MHD_mutex_init_ (&response->
mutex))
998 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,...)
void MHD_cleanup_upgraded_connection_(struct MHD_Connection *connection)
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
struct MHD_UpgradeResponseHandle * urh
_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)
void MHD_connection_close_(struct MHD_Connection *connection, enum MHD_RequestTerminationCode termination_code)
struct MHD_Response * response
_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd64(uint64_t size, int fd)
#define RESERVE_EBUF_SIZE
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)
Methods for managing response objects.
struct MHD_Daemon * daemon
int(* idle_handler)(struct MHD_Connection *connection)
#define MHD_mutex_unlock_chk_(pmutex)
Header for platform-independent inter-thread communication.
_MHD_EXTERN struct MHD_Response * MHD_create_response_for_upgrade(MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls)
#define MHD_socket_close_chk_(fd)
MHD_UpgradeHandler upgrade_handler
#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)
_MHD_EXTERN void MHD_suspend_connection(struct MHD_Connection *connection)
struct MHD_Connection * connection
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)
internal shared structures
size_t MHD_pool_get_free(struct MemoryPool *pool)
#define MHD_socket_last_strerr_()
_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
#define MHD_SCKT_FD_FITS_FDSET_(fd, pset)
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)
#define MHD_CONTENT_READER_END_WITH_ERROR
MHD_ContentReaderCallback crc
_MHD_EXTERN int MHD_upgrade_action(struct MHD_UpgradeResponseHandle *urh, enum MHD_UpgradeAction action,...)
int MHD_response_execute_upgrade_(struct MHD_Response *response, struct MHD_Connection *connection)
_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)
void * upgrade_handler_cls
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)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...