gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35897 - in libmicrohttpd/src: include microhttpd


From: gnunet
Subject: [GNUnet-SVN] r35897 - in libmicrohttpd/src: include microhttpd
Date: Tue, 9 Jun 2015 21:33:57 +0200

Author: Karlson2k
Date: 2015-06-09 21:33:57 +0200 (Tue, 09 Jun 2015)
New Revision: 35897

Modified:
   libmicrohttpd/src/include/microhttpd.h
   libmicrohttpd/src/microhttpd/internal.h
   libmicrohttpd/src/microhttpd/response.c
Log:
Add MHD_create_response_from_fd64() and 
MHD_create_response_from_fd_at_offset64() functions,
check lseek() results when reading file, check whether desired file offset fits 
off_t

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2015-06-09 09:55:11 UTC (rev 
35896)
+++ libmicrohttpd/src/include/microhttpd.h      2015-06-09 19:33:57 UTC (rev 
35897)
@@ -2076,11 +2076,9 @@
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @ingroup response
  */
-/* NOTE: this should be 'uint64_t' instead of 'size_t', but changing
-   this would break API compatibility. */
 _MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_fd (size_t size,
-                            int fd);
+                               int fd);
 
 
 /**
@@ -2087,6 +2085,24 @@
  * Create a response object.  The response object can be extended with
  * header information and then be used any number of times.
  *
+ * @param size size of the data portion of the response;
+ *        sizes larger than 2 GiB may be not supported by OS or
+ *        MHD build
+ * @param fd file descriptor referring to a file on disk with the
+ *        data; will be closed when response is destroyed;
+ *        fd should be in 'blocking' mode
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_fd64 (uint64_t size,
+                               int fd);
+
+
+/**
+ * Create a response object.  The response object can be extended with
+ * header information and then be used any number of times.
+ *
  * @param size size of the data portion of the response
  * @param fd file descriptor referring to a file on disk with the
  *        data; will be closed when response is destroyed;
@@ -2099,14 +2115,35 @@
  * @return NULL on error (i.e. invalid arguments, out of memory)
  * @ingroup response
  */
-/* NOTE: this should be 'uint64_t' instead of 'size_t', but changing
-   this would break API compatibility. */
+_MHD_DEPR_FUNC("Function MHD_create_response_from_fd_at_offset() is 
deprecated, use MHD_create_response_from_fd_at_offset64()") \
 _MHD_EXTERN struct MHD_Response *
 MHD_create_response_from_fd_at_offset (size_t size,
-                                      int fd,
-                                      off_t offset);
+                                       int fd,
+                                       off_t offset);
 
 
+/**
+ * Create a response object.  The response object can be extended with
+ * header information and then be used any number of times.
+ *
+ * @param size size of the data portion of the response;
+ *        sizes larger than 2 GiB may be not supported by OS or
+ *        MHD build
+ * @param fd file descriptor referring to a file on disk with the
+ *        data; will be closed when response is destroyed;
+ *        fd should be in 'blocking' mode
+ * @param offset offset to start reading from in the file;
+ *        reading file beyond 2 GiB may be not supported by OS or
+ *        MHD build
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_fd_at_offset64 (uint64_t size,
+                                         int fd,
+                                         uint64_t offset);
+
+
 #if 0
 /**
  * Enumeration for actions MHD should perform on the underlying socket

Modified: libmicrohttpd/src/microhttpd/internal.h
===================================================================
--- libmicrohttpd/src/microhttpd/internal.h     2015-06-09 09:55:11 UTC (rev 
35896)
+++ libmicrohttpd/src/microhttpd/internal.h     2015-06-09 19:33:57 UTC (rev 
35897)
@@ -295,7 +295,7 @@
   /**
    * Offset to start reading from when using @e fd.
    */
-  off_t fd_off;
+  uint64_t fd_off;
 
   /**
    * Number of bytes ready in @e data (buffer may be larger

Modified: libmicrohttpd/src/microhttpd/response.c
===================================================================
--- libmicrohttpd/src/microhttpd/response.c     2015-06-09 09:55:11 UTC (rev 
35896)
+++ libmicrohttpd/src/microhttpd/response.c     2015-06-09 19:33:57 UTC (rev 
35897)
@@ -28,6 +28,7 @@
 
 #include "internal.h"
 #include "response.h"
+#include <limits.h>
 
 #if defined(_WIN32) && defined(MHD_W32_MUTEX_)
 #ifndef WIN32_LEAN_AND_MEAN
@@ -304,6 +305,10 @@
 }
 
 
+#ifndef INT32_MAX
+#define INT32_MAX ((int32_t)0x7FFFFFFF)
+#endif /* !INT32_MAX */
+
 /**
  * Given a file descriptor, read data from the file
  * to generate the response.
@@ -319,8 +324,17 @@
 {
   struct MHD_Response *response = cls;
   ssize_t n;
+  const int64_t offset64 = (int64_t)(pos + response->fd_off);
 
-  (void) lseek (response->fd, pos + response->fd_off, SEEK_SET);
+  if (offset64 < 0)
+    return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is 
not possible */
+
+  if (sizeof(off_t) < sizeof(uint64_t) && offset64 > (uint64_t)INT32_MAX)
+    return MHD_CONTENT_READER_END_WITH_ERROR; /* seek to required position is 
not possible */
+
+  if (lseek (response->fd, (off_t)offset64, SEEK_SET) != (off_t)offset64)
+    return MHD_CONTENT_READER_END_WITH_ERROR; /* can't seek to required 
position */
+
   n = read (response->fd, buf, max);
   if (0 == n)
     return MHD_CONTENT_READER_END_OF_STREAM;
@@ -367,6 +381,31 @@
                                       int fd,
                                       off_t offset)
 {
+  return MHD_create_response_from_fd_at_offset64 (size, fd, offset);
+}
+
+
+/**
+ * Create a response object.  The response object can be extended with
+ * header information and then be used any number of times.
+ *
+ * @param size size of the data portion of the response;
+ *        sizes larger than 2 GiB may be not supported by OS or
+ *        MHD build
+ * @param fd file descriptor referring to a file on disk with the
+ *        data; will be closed when response is destroyed;
+ *        fd should be in 'blocking' mode
+ * @param offset offset to start reading from in the file;
+ *        reading file beyond 2 GiB may be not supported by OS or
+ *        MHD build
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_fd_at_offset64 (uint64_t size,
+                                         int fd,
+                                         uint64_t offset)
+{
   struct MHD_Response *response;
 
   response = MHD_create_response_from_callback (size,
@@ -396,7 +435,7 @@
 MHD_create_response_from_fd (size_t size,
                             int fd)
 {
-  return MHD_create_response_from_fd_at_offset (size, fd, 0);
+  return MHD_create_response_from_fd_at_offset64 (size, fd, 0);
 }
 
 
@@ -404,6 +443,27 @@
  * Create a response object.  The response object can be extended with
  * header information and then be used any number of times.
  *
+ * @param size size of the data portion of the response;
+ *        sizes larger than 2 GiB may be not supported by OS or
+ *        MHD build
+ * @param fd file descriptor referring to a file on disk with the
+ *        data; will be closed when response is destroyed;
+ *        fd should be in 'blocking' mode
+ * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @ingroup response
+ */
+_MHD_EXTERN struct MHD_Response *
+MHD_create_response_from_fd64(uint64_t size,
+                              int fd)
+{
+  return MHD_create_response_from_fd_at_offset64 (size, fd, 0);
+}
+
+
+/**
+ * Create a response object.  The response object can be extended with
+ * header information and then be used any number of times.
+ *
  * @param size size of the @a data portion of the response
  * @param data the data itself
  * @param must_free libmicrohttpd should free data when done




reply via email to

[Prev in Thread] Current Thread [Next in Thread]