aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/response.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/response.c')
-rw-r--r--src/microhttpd/response.c65
1 files changed, 52 insertions, 13 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index ca729765..aa79196d 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -16,7 +16,6 @@
16 License along with this library; if not, write to the Free Software 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 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/ 18*/
19
20/** 19/**
21 * @file response.c 20 * @file response.c
22 * @brief Methods for managing response objects 21 * @brief Methods for managing response objects
@@ -34,6 +33,7 @@
34#include "connection.h" 33#include "connection.h"
35#include "memorypool.h" 34#include "memorypool.h"
36 35
36#include <sys/ioctl.h>
37 37
38#if defined(_WIN32) && defined(MHD_W32_MUTEX_) 38#if defined(_WIN32) && defined(MHD_W32_MUTEX_)
39#ifndef WIN32_LEAN_AND_MEAN 39#ifndef WIN32_LEAN_AND_MEAN
@@ -202,7 +202,9 @@ MHD_get_response_headers (struct MHD_Response *response,
202 numHeaders++; 202 numHeaders++;
203 if ((NULL != iterator) && 203 if ((NULL != iterator) &&
204 (MHD_YES != iterator (iterator_cls, 204 (MHD_YES != iterator (iterator_cls,
205 pos->kind, pos->header, pos->value))) 205 pos->kind,
206 pos->header,
207 pos->value)))
206 break; 208 break;
207 } 209 }
208 return numHeaders; 210 return numHeaders;
@@ -337,16 +339,23 @@ file_reader (void *cls,
337 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */ 339 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */
338 340
339#if defined(HAVE_LSEEK64) 341#if defined(HAVE_LSEEK64)
340 if (lseek64 (response->fd, offset64, SEEK_SET) != offset64) 342 if (lseek64 (response->fd,
343 offset64,
344 SEEK_SET) != offset64)
341 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */ 345 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */
342#elif defined(HAVE___LSEEKI64) 346#elif defined(HAVE___LSEEKI64)
343 if (_lseeki64 (response->fd, offset64, SEEK_SET) != offset64) 347 if (_lseeki64 (response->fd,
348 offset64,
349 SEEK_SET) != offset64)
344 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */ 350 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */
345#else /* !HAVE___LSEEKI64 */ 351#else /* !HAVE___LSEEKI64 */
346 if (sizeof(off_t) < sizeof(uint64_t) && offset64 > (uint64_t)INT32_MAX) 352 if ( (sizeof(off_t) < sizeof (uint64_t)) &&
353 (offset64 > (uint64_t)INT32_MAX) )
347 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */ 354 return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is not possible */
348 355
349 if (lseek (response->fd, (off_t)offset64, SEEK_SET) != (off_t)offset64) 356 if (lseek (response->fd,
357 (off_t) offset64,
358 SEEK_SET) != (off_t) offset64)
350 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */ 359 return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required position */
351#endif 360#endif
352 361
@@ -354,12 +363,16 @@ file_reader (void *cls,
354 if (max > SSIZE_MAX) 363 if (max > SSIZE_MAX)
355 max = SSIZE_MAX; 364 max = SSIZE_MAX;
356 365
357 n = read (response->fd, buf, max); 366 n = read (response->fd,
367 buf,
368 max);
358#else /* _WIN32 */ 369#else /* _WIN32 */
359 if (max > INT32_MAX) 370 if (max > INT32_MAX)
360 max = INT32_MAX; 371 max = INT32_MAX;
361 372
362 n = read (response->fd, buf, (unsigned int)max); 373 n = read (response->fd,
374 buf,
375 (unsigned int)max);
363#endif /* _WIN32 */ 376#endif /* _WIN32 */
364 377
365 if (0 == n) 378 if (0 == n)
@@ -438,8 +451,10 @@ MHD_create_response_from_fd_at_offset64 (uint64_t size,
438 struct MHD_Response *response; 451 struct MHD_Response *response;
439 452
440#if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64) 453#if !defined(HAVE___LSEEKI64) && !defined(HAVE_LSEEK64)
441 if (sizeof(uint64_t) > sizeof(off_t) && 454 if ( (sizeof(uint64_t) > sizeof(off_t)) &&
442 (size > (uint64_t)INT32_MAX || offset > (uint64_t)INT32_MAX || (size + offset) >= (uint64_t)INT32_MAX)) 455 ( (size > (uint64_t)INT32_MAX) ||
456 (offset > (uint64_t)INT32_MAX) ||
457 ((size + offset) >= (uint64_t)INT32_MAX) ) )
443 return NULL; 458 return NULL;
444#endif 459#endif
445 if ( ((int64_t)size < 0) || 460 if ( ((int64_t)size < 0) ||
@@ -530,7 +545,9 @@ MHD_create_response_from_data (size_t size,
530 return NULL; 545 return NULL;
531 if (NULL == (response = malloc (sizeof (struct MHD_Response)))) 546 if (NULL == (response = malloc (sizeof (struct MHD_Response))))
532 return NULL; 547 return NULL;
533 memset (response, 0, sizeof (struct MHD_Response)); 548 memset (response,
549 0,
550 sizeof (struct MHD_Response));
534 response->fd = -1; 551 response->fd = -1;
535 if (! MHD_mutex_init_ (&response->mutex)) 552 if (! MHD_mutex_init_ (&response->mutex))
536 { 553 {
@@ -675,8 +692,30 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
675 /* FIXME: not implemented */ 692 /* FIXME: not implemented */
676 return MHD_NO; 693 return MHD_NO;
677 case MHD_UPGRADE_ACTION_FLUSH: 694 case MHD_UPGRADE_ACTION_FLUSH:
678 /* FIXME: not implemented */ 695#if HTTPS_SUPPORT
679 return MHD_NO; 696 if (0 != (daemon->options & MHD_USE_SSL))
697 {
698 int avail;
699
700 /* First, check that our pipe is empty, to be sure we do
701 have it all in the buffer. */
702 if ( (0 ==
703#if WINDOWS
704 ioctlsocket
705#else
706 ioctl
707#endif
708 (urh->mhd.socket,
709 FIONREAD,
710 &avail)) &&
711 (0 != avail) )
712 return MHD_NO;
713 /* then, refuse 'flush' unless our buffer is empty */
714 if (0 != urh->out_buffer_off)
715 return MHD_NO;
716 }
717#endif
718 return MHD_YES;
680 default: 719 default:
681 /* we don't understand this one */ 720 /* we don't understand this one */
682 return MHD_NO; 721 return MHD_NO;