]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
minor fixes in ws.c
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 18 Sep 2013 00:12:23 +0000 (05:12 +0500)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 18 Sep 2013 00:13:46 +0000 (05:13 +0500)
libs/sofia-sip/.update
libs/sofia-sip/libsofia-sip-ua/tport/ws.c

index 76ab95f85f15b28bbd35c75a76a75212bf1a57e6..874992669be80a712f8cf88073f8349800f0457c 100644 (file)
@@ -1 +1 @@
-Tue Sep 17 06:24:17 CDT 2013
+Wed Sep 18 05:12:10 CDT 2013
index 6039aea82604bc822b29fb173c75b4a11afb3b39..7ee756c729c0388d310f5ac795f0de6356bd3895 100644 (file)
@@ -242,7 +242,7 @@ int ws_handshake(wsh_t *wsh)
                }
        }
 
-       if (bytes > sizeof(wsh->buffer)) {
+       if (bytes > sizeof(wsh->buffer) -1) {
                goto err;
        }
 
@@ -273,12 +273,16 @@ int ws_handshake(wsh_t *wsh)
        sha1_digest(output, input);
        b64encode((unsigned char *)output, SHA1_HASH_SIZE, (unsigned char *)b64, sizeof(b64));
 
+       if (*proto) {
+               snprintf(proto, sizeof(proto), "Sec-WebSocket-Protocol: %s\r\n", proto);
+       }
+
        snprintf(respond, sizeof(respond), 
                         "HTTP/1.1 101 Switching Protocols\r\n"
                         "Upgrade: websocket\r\n"
                         "Connection: Upgrade\r\n"
                         "Sec-WebSocket-Accept: %s\r\n"
-                        "Sec-WebSocket-Protocol: %s\r\n\r\n",
+                        "%s\r\n",
                         b64,
                         proto);
 
@@ -319,7 +323,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
 #endif
                } while (r == -1 && SSL_get_error(wsh->ssl, r) == SSL_ERROR_WANT_READ && x < 100);
 
-               return r;
+               goto end;
        }
 
        do {
@@ -336,6 +340,12 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
                r = -1;
        }
 
+ end:
+
+       if (r > 0) {
+               *((char *)data + r) = '\0';
+       }
+
        return r;
 }
 
@@ -530,7 +540,7 @@ ssize_t ws_close(wsh_t *wsh, int16_t reason)
 
        restore_socket(wsh->sock);
 
-       if (wsh->close_sock) {
+       if (wsh->close_sock && wsh->sock != ws_sock_invalid) {
                close(wsh->sock);
        }
 
@@ -559,7 +569,11 @@ ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data)
                return ws_close(wsh, WS_PROTO_ERR);
        }
 
-       if ((wsh->datalen = ws_raw_read(wsh, wsh->buffer, 9)) < need) {
+       if ((wsh->datalen = ws_raw_read(wsh, wsh->buffer, 9)) < 0) {
+               return ws_close(wsh, WS_PROTO_ERR);
+       }
+       
+       if (wsh->datalen < need) {
                if ((wsh->datalen += ws_raw_read(wsh, wsh->buffer + wsh->datalen, 9 - wsh->datalen)) < need) {
                        /* too small - protocol err */
                        return ws_close(wsh, WS_PROTO_ERR);