win32: enable 64-bit file lengths
authorWebsocketUser <unknown@invalid.user.github.com>
Fri, 9 Jun 2017 12:20:42 +0000 (20:20 +0800)
committerAndy Green <andy@warmcat.com>
Fri, 9 Jun 2017 12:20:42 +0000 (20:20 +0800)
https://github.com/warmcat/libwebsockets/issues/916

AG added more appveyor warning cleaning and stitched in cmake tests

14 files changed:
CMakeLists.txt
lib/client.c
lib/fops-zip.c
lib/handshake.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/lws-plat-win.c
lib/output.c
lib/private-libwebsockets.h
lib/server.c
lib/service.c
lib/ssl.c
lws_config.h.in
lwsws/main.c

index 506a7b5..6d3bdee 100644 (file)
@@ -470,6 +470,9 @@ CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
 CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
 CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
 CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG)
+CHECK_FUNCTION_EXISTS(atoll LWS_HAVE_ATOLL)
+CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64)
+CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64)
 
 if (NOT LWS_HAVE_GETIFADDRS)
        if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
@@ -1778,6 +1781,9 @@ message(" LWS_WITH_STATS = ${LWS_WITH_STATS}")
 message(" LWS_WITH_SOCKS5 = ${LWS_WITH_SOCKS5}")
 message(" LWS_HAVE_SYS_CAPABILITY_H = ${LWS_HAVE_SYS_CAPABILITY_H}")
 message(" LWS_HAVE_LIBCAP = ${LWS_HAVE_LIBCAP}")
+message(" LWS_HAVE_ATOLL = ${LWS_HAVE_ATOLL}")
+message(" LWS_HAVE__ATOI64 = ${LWS_HAVE__ATOI64}")
+message(" LWS_HAVE_STAT32I64 = ${LWS_HAVE_STAT32I64}")
 
 message("---------------------------------------------------------------------")
 
index 5a57d18..3092f3b 100755 (executable)
@@ -784,7 +784,7 @@ lws_client_interpret_server_handshake(struct lws *wsi)
 
                if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) {
                        wsi->u.http.content_length =
-                                       atoi(lws_hdr_simple_ptr(wsi,
+                                       atoll(lws_hdr_simple_ptr(wsi,
                                                WSI_TOKEN_HTTP_CONTENT_LENGTH));
                        lwsl_notice("%s: incoming content length %llu\n", __func__,
                                        (unsigned long long)wsi->u.http.content_length);
index 58cce38..45818c7 100644 (file)
@@ -535,7 +535,7 @@ lws_fops_zip_read(lws_fop_fd_t fd, lws_filepos_t *amount, uint8_t *buf,
                        *amount = 0;
                }
 
-               priv->inflate.avail_out = len;
+               priv->inflate.avail_out = (unsigned int)len;
                priv->inflate.next_out = buf;
 
 spin:
@@ -554,7 +554,7 @@ spin:
 
                        cur += ramount;
 
-                       priv->inflate.avail_in = ramount;
+                       priv->inflate.avail_in = (unsigned int)ramount;
                        priv->inflate.next_in = priv->rbuf;
                }
 
@@ -596,7 +596,7 @@ spin:
                        if (rlen > len)
                                rlen = len;
                        /* provide stuff from canned header */
-                       memcpy(buf, hd + fd->pos, rlen);
+                       memcpy(buf, hd + fd->pos, (size_t)rlen);
                        fd->pos += rlen;
                        buf += rlen;
                        len -= rlen;
@@ -636,7 +636,7 @@ spin:
                        if (rlen > len)
                                rlen = len;
 
-                       memcpy(buf, priv->u.trailer8 + cur, rlen);
+                       memcpy(buf, priv->u.trailer8 + cur, (size_t)rlen);
 
                        *amount += rlen;
                        fd->pos += rlen;
index 5f34b0e..98e75b3 100644 (file)
  */
 
 LWS_VISIBLE int
-lws_read(struct lws *wsi, unsigned char *buf, size_t len)
+lws_read(struct lws *wsi, unsigned char *buf, lws_filepos_t len)
 {
        unsigned char *last_char, *oldbuf = buf;
-       int body_chunk_len;
+       lws_filepos_t body_chunk_len;
        size_t n;
 
        lwsl_debug("%s: incoming len %d  state %d\n", __func__, (int)len, wsi->state);
@@ -113,11 +113,11 @@ lws_read(struct lws *wsi, unsigned char *buf, size_t len)
                }
                lwsl_parser("issuing %d bytes to parser\n", (int)len);
 
-               if (lws_handshake_client(wsi, &buf, len))
+               if (lws_handshake_client(wsi, &buf, (size_t)len))
                        goto bail;
 
                last_char = buf;
-               if (lws_handshake_server(wsi, &buf, len))
+               if (lws_handshake_server(wsi, &buf, (size_t)len))
                        /* Handshake indicates this session is done. */
                        goto bail;
 
@@ -190,10 +190,10 @@ http_postbody:
 #endif
                                n = wsi->protocol->callback(wsi,
                                        LWS_CALLBACK_HTTP_BODY, wsi->user_space,
-                                       buf, body_chunk_len);
+                                       buf, (size_t)body_chunk_len);
                                if (n)
                                        goto bail;
-                               n = body_chunk_len;
+                               n = (size_t)body_chunk_len;
 #ifdef LWS_WITH_CGI
                        }
 #endif
@@ -231,12 +231,12 @@ postbody_completion:
        case LWSS_ESTABLISHED:
        case LWSS_AWAITING_CLOSE_ACK:
        case LWSS_SHUTDOWN:
-               if (lws_handshake_client(wsi, &buf, len))
+               if (lws_handshake_client(wsi, &buf, (size_t)len))
                        goto bail;
                switch (wsi->mode) {
                case LWSCM_WS_SERVING:
 
-                       if (lws_interpret_incoming_packet(wsi, &buf, len) < 0) {
+                       if (lws_interpret_incoming_packet(wsi, &buf, (size_t)len) < 0) {
                                lwsl_info("interpret_incoming_packet has bailed\n");
                                goto bail;
                        }
index daa3af8..0c58dac 100755 (executable)
@@ -2244,7 +2244,7 @@ lws_snprintf(char *str, size_t size, const char *format, ...)
        n = vsnprintf(str, size, format, ap);
        va_end(ap);
 
-       if (n >= size)
+       if (n >= (int)size)
                return size;
 
        return n;
index 5e8e188..690a7f2 100644 (file)
@@ -673,9 +673,12 @@ typedef int lws_filefd_type;
 
 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
 /* ... */
-#if !defined(ssize_t)
-typedef SSIZE_T ssize_t;
+#define ssize_t SSIZE_T
 #endif
+
+#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
+#include <sys/types.h>
+#include <sys/stat.h>
 #endif
 
 #if defined(LWS_HAVE_STDINT_H)
@@ -693,8 +696,8 @@ typedef unsigned char uint8_t;
 #endif
 #endif
 
-typedef size_t lws_filepos_t;
-typedef ssize_t lws_fileofs_t;
+typedef unsigned long long lws_filepos_t;
+typedef long long lws_fileofs_t;
 typedef uint32_t lws_fop_flags_t;
 
 /** struct lws_pollargs - argument structure for all external poll related calls
@@ -4296,7 +4299,7 @@ lws_get_child(const struct lws *wsi);
  * useful when integrating with other app poll loop service code.
  */
 LWS_VISIBLE LWS_EXTERN int
-lws_read(struct lws *wsi, unsigned char *buf, size_t len);
+lws_read(struct lws *wsi, unsigned char *buf, lws_filepos_t len);
 
 /**
  * lws_set_allocator() - custom allocator support
index 2d8b8eb..9f50cda 100644 (file)
@@ -595,6 +595,7 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
        HANDLE ret;
        WCHAR buf[MAX_PATH];
        lws_fop_fd_t fop_fd;
+       LARGE_INTEGER llFileSize = {0};
 
        MultiByteToWideChar(CP_UTF8, 0, filename, -1, buf, ARRAY_SIZE(buf));
        if (((*flags) & 7) == _O_RDONLY) {
@@ -617,6 +618,9 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
        fop_fd->filesystem_priv = NULL; /* we don't use it */
        fop_fd->flags = *flags;
        fop_fd->len = GetFileSize(ret, NULL);
+       if(GetFileSizeEx(ret, &llFileSize))
+               fop_fd->len = llFileSize.QuadPart;
+
        fop_fd->pos = 0;
 
        return fop_fd;
@@ -641,7 +645,10 @@ _lws_plat_file_close(lws_fop_fd_t *fop_fd)
 LWS_VISIBLE lws_fileofs_t
 _lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
 {
-       return SetFilePointer((HANDLE)fop_fd->fd, offset, NULL, FILE_CURRENT);
+       LARGE_INTEGER l;
+
+       l.QuadPart = offset;
+       return SetFilePointerEx((HANDLE)fop_fd->fd, l, NULL, FILE_CURRENT);
 }
 
 LWS_VISIBLE int
index efb2606..c7430eb 100644 (file)
@@ -513,8 +513,8 @@ send_raw:
                             wp == LWS_WRITE_HTTP_FINAL) &&
                            wsi->u.http.content_length) {
                                wsi->u.http.content_remain -= len;
-                               lwsl_info("%s: content_remain = %lu\n", __func__,
-                                         (unsigned long)wsi->u.http.content_remain);
+                               lwsl_info("%s: content_remain = %llu\n", __func__,
+                                         (unsigned long long)wsi->u.http.content_remain);
                                if (!wsi->u.http.content_remain) {
                                        lwsl_info("%s: selecting final write mode\n", __func__);
                                        wp = LWS_WRITE_HTTP_FINAL;
@@ -679,7 +679,7 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
                        if (wsi->sending_chunked) {
                                args.p = (char *)p;
                                args.len = n;
-                               args.max_len = poss + 128;
+                               args.max_len = (unsigned int)poss + 128;
                                args.final = wsi->u.http.filepos + n ==
                                             wsi->u.http.filelen;
                                if (user_callback_handle_rxflow(
index ea6fcb5..be5a4c5 100644 (file)
@@ -134,6 +134,15 @@ char *ets_strchr(const char *s, int c);
 #include <mstcpip.h>
 #include <io.h>
 
+#if !defined(LWS_HAVE_ATOLL)
+#if defined(LWS_HAVE__ATOI64)
+#define atoll _atoi64
+#else
+#warning No atoll or _atoi64 available, using atoi
+#define atoll atoi
+#endif
+#endif
+
 #ifndef __func__
 #define __func__ __FUNCTION__
 #endif
index 3430a61..54e974a 100644 (file)
@@ -357,7 +357,11 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin,
        const struct lws_plat_file_ops *fops;
        const char *vpath;
        lws_fop_flags_t fflags = LWS_O_RDONLY;
+#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
+       struct _stat32i64 st;
+#else
        struct stat st;
+#endif
        int spin = 0;
 #endif
        char path[256], sym[512];
@@ -401,11 +405,18 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin,
                        goto bail;
                }
 #else
+#if defined(LWS_HAVE__STAT32I64)
+               if (_stat32i64(path, &st)) {
+                       lwsl_info("unable to stat %s\n", path);
+                       goto bail;
+               }
+#else
                if (stat(path, &st)) {
                        lwsl_info("unable to stat %s\n", path);
                        goto bail;
                }
 #endif
+#endif
 
                wsi->u.http.fop_fd->mod_time = (uint32_t)st.st_mtime;
                fflags |= LWS_FOP_FLAG_MOD_TIME_VALID;
index e33c6a7..6f08dee 100644 (file)
@@ -697,8 +697,8 @@ spin_chunks:
                return 0;
 
        if (wsi->u.http.content_remain &&
-           (int)wsi->u.http.content_remain < *len)
-               n = wsi->u.http.content_remain;
+           wsi->u.http.content_remain < *len)
+               n = (int)wsi->u.http.content_remain;
        else
                n = *len;
 
@@ -1152,7 +1152,7 @@ read:
                                        eff_buf.token_len = context->pt_serv_buf_size;
                                }
 
-                               if (eff_buf.token_len > context->pt_serv_buf_size)
+                               if ((unsigned int)eff_buf.token_len > context->pt_serv_buf_size)
                                        eff_buf.token_len = context->pt_serv_buf_size;
 
                                eff_buf.token_len = lws_ssl_capable_read(wsi,
index 5125430..651757f 100644 (file)
--- a/lib/ssl.c
+++ b/lib/ssl.c
@@ -40,7 +40,7 @@ int lws_alloc_vfs_file(struct lws_context *context, const char *filename, uint8_
 
        len = lws_vfs_get_length(fops_fd);
 
-       *buf = malloc(len);
+       *buf = malloc((size_t)len);
        if (!buf)
                goto bail;
 
index d7092a1..c8d5c38 100644 (file)
 #cmakedefine LWS_HAVE_SYS_CAPABILITY_H
 #cmakedefine LWS_HAVE_LIBCAP
 
+#cmakedefine LWS_HAVE_ATOLL
+#cmakedefine LWS_HAVE__ATOI64
+#cmakedefine LWS_HAVE__STAT32I64
+
 /* OpenSSL various APIs */
 
 #cmakedefine LWS_HAVE_TLS_CLIENT_METHOD
index 1af5f1b..6f36771 100644 (file)
@@ -199,8 +199,9 @@ reload_handler(int signum)
 
 int main(int argc, char **argv)
 {
-       int n = 0, m, debug_level = 7;
+       int n = 0, debug_level = 7;
 #ifndef _WIN32
+       int m;
        int status, syslog_options = LOG_PID | LOG_PERROR;
 #endif