From 0be9e98aaeeeeb1a9a7b75f6d1633297029e0a10 Mon Sep 17 00:00:00 2001 From: WebsocketUser Date: Fri, 9 Jun 2017 20:20:42 +0800 Subject: [PATCH] win32: enable 64-bit file lengths https://github.com/warmcat/libwebsockets/issues/916 AG added more appveyor warning cleaning and stitched in cmake tests --- CMakeLists.txt | 6 ++++++ lib/client.c | 2 +- lib/fops-zip.c | 8 ++++---- lib/handshake.c | 16 ++++++++-------- lib/libwebsockets.c | 2 +- lib/libwebsockets.h | 13 ++++++++----- lib/lws-plat-win.c | 9 ++++++++- lib/output.c | 6 +++--- lib/private-libwebsockets.h | 9 +++++++++ lib/server.c | 11 +++++++++++ lib/service.c | 6 +++--- lib/ssl.c | 2 +- lws_config.h.in | 4 ++++ lwsws/main.c | 3 ++- 14 files changed, 69 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 506a7b5..6d3bdee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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("---------------------------------------------------------------------") diff --git a/lib/client.c b/lib/client.c index 5a57d18..3092f3b 100755 --- a/lib/client.c +++ b/lib/client.c @@ -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); diff --git a/lib/fops-zip.c b/lib/fops-zip.c index 58cce38..45818c7 100644 --- a/lib/fops-zip.c +++ b/lib/fops-zip.c @@ -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; diff --git a/lib/handshake.c b/lib/handshake.c index 5f34b0e..98e75b3 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -60,10 +60,10 @@ */ 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; } diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index daa3af8..0c58dac 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -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; diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 5e8e188..690a7f2 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -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 +#include #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 diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index 2d8b8eb..9f50cda 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -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 diff --git a/lib/output.c b/lib/output.c index efb2606..c7430eb 100644 --- a/lib/output.c +++ b/lib/output.c @@ -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( diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index ea6fcb5..be5a4c5 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -134,6 +134,15 @@ char *ets_strchr(const char *s, int c); #include #include +#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 diff --git a/lib/server.c b/lib/server.c index 3430a61..54e974a 100644 --- a/lib/server.c +++ b/lib/server.c @@ -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; diff --git a/lib/service.c b/lib/service.c index e33c6a7..6f08dee 100644 --- a/lib/service.c +++ b/lib/service.c @@ -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, diff --git a/lib/ssl.c b/lib/ssl.c index 5125430..651757f 100644 --- 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; diff --git a/lws_config.h.in b/lws_config.h.in index d7092a1..c8d5c38 100644 --- a/lws_config.h.in +++ b/lws_config.h.in @@ -139,6 +139,10 @@ #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 diff --git a/lwsws/main.c b/lwsws/main.c index 1af5f1b..6f36771 100644 --- a/lwsws/main.c +++ b/lwsws/main.c @@ -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 -- 2.7.4