clean reduce windows build warnings
authorAndy Green <andy.green@linaro.org>
Sun, 6 Dec 2015 00:00:03 +0000 (08:00 +0800)
committerAndy Green <andy.green@linaro.org>
Sun, 6 Dec 2015 00:00:03 +0000 (08:00 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/handshake.c
lib/lws-plat-win.c
lib/output.c
lib/private-libwebsockets.h
lib/server.c
lib/service.c
lib/sha-1.c
lib/ssl.c

index 67eb41b..2446a75 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * libwebsockets - small server side websockets and web server implementation
  *
- * Copyright (C) 2010-2013 Andy Green <andy@warmcat.com>
+ * Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -49,6 +49,7 @@
 #ifndef min
 #define min(a, b) ((a) < (b) ? (a) : (b))
 #endif
+
 /*
  * We have to take care about parsing because the headers may be split
  * into multiple fragments.  They may contain unknown headers with arbitrary
  */
 
 LWS_VISIBLE int
-lws_read(struct lws_context *context,
-        struct lws *wsi, unsigned char *buf, size_t len)
+lws_read(struct lws_context *context, struct lws *wsi, unsigned char *buf,
+        size_t len)
 {
-       size_t n;
-       int body_chunk_len;
        unsigned char *last_char;
+       int body_chunk_len;
+       size_t n;
 
        switch (wsi->state) {
 #ifdef LWS_USE_HTTP2
index 5176f1c..d1a3694 100644 (file)
@@ -36,7 +36,7 @@ time_t time(time_t *t)
 /* file descriptor hash management */
 
 struct lws *
-wsi_from_fd(struct lws_context *context, int fd)
+wsi_from_fd(struct lws_context *context, lws_sockfd_type fd)
 {
        int h = LWS_FD_HASH(fd);
        int n = 0;
@@ -64,7 +64,7 @@ insert_wsi(struct lws_context *context, struct lws *wsi)
 }
 
 int
-delete_from_fd(struct lws_context *context, int fd)
+delete_from_fd(struct lws_context *context, lws_sockfd_type fd)
 {
        int h = LWS_FD_HASH(fd);
        int n = 0;
@@ -198,7 +198,7 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
                return -1;
        }
 
-       pfd->revents = networkevents.lNetworkEvents;
+       pfd->revents = (short)networkevents.lNetworkEvents;
 
        if (pfd->revents & LWS_POLLOUT) {
                wsi = wsi_from_fd(context, pfd->fd);
@@ -210,7 +210,7 @@ lws_plat_service(struct lws_context *context, int timeout_ms)
 }
 
 LWS_VISIBLE int
-lws_plat_set_socket_options(struct lws_context *context, int fd)
+lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd)
 {
        int optval = 1;
        int optlen = sizeof(optval);
@@ -349,7 +349,7 @@ interface_to_sa(struct lws_context *context,
        if (address == INADDR_NONE)
                return -1;
 
-       addr->sin_addr.s_addr = address;
+       addr->sin_addr.s_addr = (unsigned long)address;
 
        return 0;
 }
index 213a4ec..9985e79 100644 (file)
@@ -338,8 +338,8 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
                        if (wsi->u.ws.close_reason) {
                                /* reason codes count as data bytes */
                                buf -= 2;
-                               buf[0] = wsi->u.ws.close_reason >> 8;
-                               buf[1] = wsi->u.ws.close_reason;
+                               buf[0] = (unsigned char)(wsi->u.ws.close_reason >> 8);
+                               buf[1] = (unsigned char)wsi->u.ws.close_reason;
                                len += 2;
                        }
                        break;
@@ -360,14 +360,14 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
                if (len < 126) {
                        pre += 2;
                        buf[-pre] = n;
-                       buf[-pre + 1] = len | is_masked_bit;
+                       buf[-pre + 1] = (unsigned char)(len | is_masked_bit);
                } else {
                        if (len < 65536) {
                                pre += 4;
                                buf[-pre] = n;
                                buf[-pre + 1] = 126 | is_masked_bit;
-                               buf[-pre + 2] = len >> 8;
-                               buf[-pre + 3] = len;
+                               buf[-pre + 2] = (unsigned char)(len >> 8);
+                               buf[-pre + 3] = (unsigned char)len;
                        } else {
                                pre += 10;
                                buf[-pre] = n;
@@ -383,10 +383,10 @@ LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf,
                                        buf[-pre + 4] = 0;
                                        buf[-pre + 5] = 0;
 #endif
-                               buf[-pre + 6] = len >> 24;
-                               buf[-pre + 7] = len >> 16;
-                               buf[-pre + 8] = len >> 8;
-                               buf[-pre + 9] = len;
+                               buf[-pre + 6] = (unsigned char)(len >> 24);
+                               buf[-pre + 7] = (unsigned char)(len >> 16);
+                               buf[-pre + 8] = (unsigned char)(len >> 8);
+                               buf[-pre + 9] = (unsigned char)len;
                        }
                }
                break;
index 203377a..0e67aa2 100644 (file)
@@ -628,7 +628,7 @@ struct lws_fragments {
  */
 
 struct allocated_headers {
-       unsigned short next_frag_index;
+       unsigned char next_frag_index;
        unsigned short pos;
        unsigned char frag_index[WSI_TOKEN_COUNT];
        struct lws_fragments frags[WSI_TOKEN_COUNT * 2];
index d8d3846..2473cb5 100644 (file)
 int lws_context_init_server(struct lws_context_creation_info *info,
                            struct lws_context *context)
 {
-       lws_sockfd_type sockfd;
-#if LWS_POSIX
-       int n;
-       struct sockaddr_in sin;
-       socklen_t len = sizeof(sin);
 #ifdef LWS_USE_IPV6
        struct sockaddr_in6 serv_addr6;
 #endif
+#if LWS_POSIX
        struct sockaddr_in serv_addr4;
+       socklen_t len = sizeof(struct sockaddr);
+       struct sockaddr_in sin;
        struct sockaddr *v;
-       int opt = 1;
+       int n, opt = 1;
 #endif
+       lws_sockfd_type sockfd;
        struct lws *wsi;
 
        /* set up our external listening socket we serve on */
@@ -57,7 +56,6 @@ int lws_context_init_server(struct lws_context_creation_info *info,
        sockfd = mbed3_create_tcp_stream_socket();
        if (!lws_sockfd_valid(sockfd)) {
 #endif
-
                lwsl_err("ERROR opening socket\n");
                return 1;
        }
@@ -67,7 +65,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
         * allow us to restart even if old sockets in TIME_WAIT
         */
        if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
-                                     (const void *)&opt, sizeof(opt)) < 0) {
+                      (const void *)&opt, sizeof(opt)) < 0) {
                compatible_close(sockfd);
                return 1;
        }
@@ -187,18 +185,18 @@ _lws_rx_flow_control(struct lws *wsi)
        return 0;
 }
 
-int lws_http_action(struct lws_context *context,
-                   struct lws *wsi)
+int lws_http_action(struct lws_context *context, struct lws *wsi)
 {
-       char *uri_ptr = NULL;
-       int uri_len = 0;
-       enum http_version request_version;
        enum http_connection_type connection_type;
-       int http_version_len;
+       enum http_version request_version;
        char content_length_str[32];
+       unsigned int n, count = 0;
        char http_version_str[10];
        char http_conn_str[20];
-       unsigned int n, count = 0;
+       int http_version_len;
+       char *uri_ptr = NULL;
+       int uri_len = 0;
+
        static const unsigned char methods[] = {
                WSI_TOKEN_GET_URI,
                WSI_TOKEN_POST_URI,
@@ -293,11 +291,9 @@ int lws_http_action(struct lws_context *context,
        }
        wsi->u.http.connection_type = connection_type;
 
-       n = 0;
-       if (wsi->protocol->callback)
-               n = wsi->protocol->callback(context, wsi,
-                                       LWS_CALLBACK_FILTER_HTTP_CONNECTION,
-                                            wsi->user_space, uri_ptr, uri_len);
+       n = wsi->protocol->callback(context, wsi,
+                                   LWS_CALLBACK_FILTER_HTTP_CONNECTION,
+                                   wsi->user_space, uri_ptr, uri_len);
 
        if (!n) {
                /*
@@ -305,11 +301,9 @@ int lws_http_action(struct lws_context *context,
                 * put a timeout on it having arrived
                 */
                lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
-                                                             AWAITING_TIMEOUT);
+                               AWAITING_TIMEOUT);
 
-               if (wsi->protocol->callback)
-                       n = wsi->protocol->callback(context, wsi,
-                           LWS_CALLBACK_HTTP,
+               n = wsi->protocol->callback(context, wsi, LWS_CALLBACK_HTTP,
                            wsi->user_space, uri_ptr, uri_len);
        }
 
@@ -343,15 +337,14 @@ bail_nuke_ah:
 }
 
 
-int lws_handshake_server(struct lws_context *context,
-               struct lws *wsi, unsigned char **buf, size_t len)
+int lws_handshake_server(struct lws_context *context, struct lws *wsi,
+                        unsigned char **buf, size_t len)
 {
        struct allocated_headers *ah;
-       int protocol_len;
+       int protocol_len, n, hit;
        char protocol_list[128];
        char protocol_name[32];
        char *p;
-       int n, hit;
 
        /* LWS_CONNMODE_WS_SERVING */
 
@@ -389,7 +382,7 @@ int lws_handshake_server(struct lws_context *context,
                }
 
                if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
-                                                               "websocket"))
+                               "websocket"))
                        goto upgrade_ws;
 #ifdef LWS_USE_HTTP2
                if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
@@ -410,7 +403,8 @@ upgrade_h2c:
 
                p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP2_SETTINGS);
                /* convert the peer's HTTP-Settings */
-               n = lws_b64_decode_string(p, protocol_list, sizeof(protocol_list));
+               n = lws_b64_decode_string(p, protocol_list,
+                                         sizeof(protocol_list));
                if (n < 0) {
                        lwsl_parser("HTTP2_SETTINGS too long\n");
                        return 1;
@@ -430,7 +424,8 @@ upgrade_h2c:
                
                /* HTTP2 union */
                
-               lws_http2_interpret_settings_payload(&wsi->u.http2.peer_settings, (unsigned char *)protocol_list, n);
+               lws_http2_interpret_settings_payload(&wsi->u.http2.peer_settings,
+                               (unsigned char *)protocol_list, n);
 
                strcpy(protocol_list,
                       "HTTP/1.1 101 Switching Protocols\x0d\x0a"
@@ -579,7 +574,8 @@ upgrade_ws:
                }
                lwsl_info("Allocating RX buffer %d\n", n);
 #if LWS_POSIX
-               if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&n, sizeof n)) {
+               if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF,
+                              (const char *)&n, sizeof n)) {
                        lwsl_warn("Failed to set SNDBUF to %d", n);
                        return 1;
                }
@@ -708,8 +704,8 @@ int lws_server_socket_service(struct lws_context *context,
                if (wsi->truncated_send_len) {
                        if (pollfd->revents & LWS_POLLOUT)
                                if (lws_issue_raw(wsi, wsi->truncated_send_malloc +
-                                       wsi->truncated_send_offset,
-                                                       wsi->truncated_send_len) < 0) {
+                                                      wsi->truncated_send_offset,
+                                                 wsi->truncated_send_len) < 0) {
                                        goto fail;
                                }
                        /*
@@ -743,13 +739,17 @@ int lws_server_socket_service(struct lws_context *context,
                        /* just ignore incoming if waiting for close */
                        if (wsi->state != WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
                        
-                               /* hm this may want to send (via HTTP callback for example) */
+                               /*
+                                * hm this may want to send
+                                * (via HTTP callback for example)
+                                */
                                n = lws_read(context, wsi,
                                             context->service_buffer, len);
                                if (n < 0) /* we closed wsi */
                                        return 1;
 
-                               /* hum he may have used up the writability above */
+                               /* hum he may have used up the
+                                * writability above */
                                break;
                        }
                }
@@ -798,12 +798,13 @@ try_pollout:
                clilen = sizeof(cli_addr);
                lws_latency_pre(context, wsi);
                accept_fd  = accept(pollfd->fd, (struct sockaddr *)&cli_addr,
-                                                                      &clilen);
+                                   &clilen);
                lws_latency(context, wsi,
                        "unencrypted accept LWS_CONNMODE_SERVER_LISTENER",
                                                     accept_fd, accept_fd >= 0);
                if (accept_fd < 0) {
-                       if (LWS_ERRNO == LWS_EAGAIN || LWS_ERRNO == LWS_EWOULDBLOCK) {
+                       if (LWS_ERRNO == LWS_EAGAIN ||
+                           LWS_ERRNO == LWS_EWOULDBLOCK) {
                                lwsl_debug("accept asks to try again\n");
                                break;
                        }
@@ -906,28 +907,35 @@ LWS_VISIBLE int lws_serve_http_file(struct lws_context *context,
                                    const char *other_headers,
                                    int other_headers_len)
 {
-       unsigned char *response = context->service_buffer + LWS_SEND_BUFFER_PRE_PADDING;
+       unsigned char *response = context->service_buffer +
+                                 LWS_SEND_BUFFER_PRE_PADDING;
        unsigned char *p = response;
        unsigned char *end = p + sizeof(context->service_buffer) -
-                                       LWS_SEND_BUFFER_PRE_PADDING;
+                            LWS_SEND_BUFFER_PRE_PADDING;
        int ret = 0;
 
        wsi->u.http.fd = lws_plat_open_file(file, &wsi->u.http.filelen);
 
        if (wsi->u.http.fd == LWS_INVALID_FILE) {
                lwsl_err("Unable to open '%s'\n", file);
-               lws_return_http_status(context, wsi,
-                                               HTTP_STATUS_NOT_FOUND, NULL);
+               lws_return_http_status(context, wsi, HTTP_STATUS_NOT_FOUND,
+                                      NULL);
                return -1;
        }
 
        if (lws_add_http_header_status(context, wsi, 200, &p, end))
                return -1;
-       if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_SERVER, (unsigned char *)"libwebsockets", 13, &p, end))
+       if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_SERVER,
+                                        (unsigned char *)"libwebsockets", 13,
+                                        &p, end))
                return -1;
-       if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_CONTENT_TYPE, (unsigned char *)content_type, strlen(content_type), &p, end))
+       if (lws_add_http_header_by_token(context, wsi,
+                                        WSI_TOKEN_HTTP_CONTENT_TYPE,
+                                        (unsigned char *)content_type,
+                                        strlen(content_type), &p, end))
                return -1;
-       if (lws_add_http_header_content_length(context, wsi, wsi->u.http.filelen, &p, end))
+       if (lws_add_http_header_content_length(context, wsi,
+                                              wsi->u.http.filelen, &p, end))
                return -1;
 
        if (other_headers) {
@@ -954,7 +962,8 @@ LWS_VISIBLE int lws_serve_http_file(struct lws_context *context,
 }
 
 
-int lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf, size_t len)
+int lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf,
+                                 size_t len)
 {
        size_t n = 0;
        int m;
index 4b4b8a6..7c4ad54 100644 (file)
@@ -401,7 +401,8 @@ lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
                        if (!wsi)
                                continue;
 
-                       if (lws_service_timeout_check(context, wsi, now))
+                       if (lws_service_timeout_check(context, wsi,
+                                                     (unsigned int)now))
                                /* he did time out... */
                                if (mfd == our_fd)
                                        /* it was the guy we came to service! */
index 3dd9d3f..1c5f69a 100644 (file)
@@ -212,14 +212,14 @@ sha1_pad(struct sha1_ctxt *ctxt)
        padlen = 64 - padstart;
        if (padlen < 8) {
                bzero(&ctxt->m.b8[padstart], padlen);
-               COUNT += padlen;
+               COUNT += (unsigned char)padlen;
                COUNT %= 64;
                sha1_step(ctxt);
                padstart = COUNT % 64;  /* should be 0 */
                padlen = 64 - padstart; /* should be 64 */
        }
        bzero(&ctxt->m.b8[padstart], padlen - 8);
-       COUNT += (padlen - 8);
+       COUNT += ((unsigned char)padlen - 8);
        COUNT %= 64;
 #if BYTE_ORDER == BIG_ENDIAN
        PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
@@ -250,7 +250,7 @@ sha1_loop(struct sha1_ctxt *ctxt, const unsigned char *input, size_t len)
 
                copysiz = (gaplen < len - off) ? gaplen : len - off;
                memcpy(&ctxt->m.b8[gapstart], &input[off], copysiz);
-               COUNT += copysiz;
+               COUNT += (unsigned char)copysiz;
                COUNT %= 64;
                ctxt->c.b64[0] += copysiz * 8;
                if (COUNT % 64 == 0)
index f3a9ee5..2cb5d86 100644 (file)
--- a/lib/ssl.c
+++ b/lib/ssl.c
@@ -530,7 +530,7 @@ lws_ssl_close(struct lws *wsi)
 
 LWS_VISIBLE int
 lws_server_socket_service_ssl(struct lws_context *context, struct lws **pwsi,
-                             struct lws *new_wsi, int accept_fd,
+                             struct lws *new_wsi, lws_sockfd_type accept_fd,
                              struct lws_pollfd *pollfd)
 {
        struct lws *wsi = *pwsi;