mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-05 12:41:38 +00:00
minor fixes in ws.c
This commit is contained in:
parent
1d992ea9ea
commit
f1d0357e92
@ -1 +1 @@
|
|||||||
Tue Sep 17 06:24:17 CDT 2013
|
Wed Sep 18 05:12:10 CDT 2013
|
||||||
|
@ -242,7 +242,7 @@ int ws_handshake(wsh_t *wsh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes > sizeof(wsh->buffer)) {
|
if (bytes > sizeof(wsh->buffer) -1) {
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,12 +273,16 @@ int ws_handshake(wsh_t *wsh)
|
|||||||
sha1_digest(output, input);
|
sha1_digest(output, input);
|
||||||
b64encode((unsigned char *)output, SHA1_HASH_SIZE, (unsigned char *)b64, sizeof(b64));
|
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),
|
snprintf(respond, sizeof(respond),
|
||||||
"HTTP/1.1 101 Switching Protocols\r\n"
|
"HTTP/1.1 101 Switching Protocols\r\n"
|
||||||
"Upgrade: websocket\r\n"
|
"Upgrade: websocket\r\n"
|
||||||
"Connection: Upgrade\r\n"
|
"Connection: Upgrade\r\n"
|
||||||
"Sec-WebSocket-Accept: %s\r\n"
|
"Sec-WebSocket-Accept: %s\r\n"
|
||||||
"Sec-WebSocket-Protocol: %s\r\n\r\n",
|
"%s\r\n",
|
||||||
b64,
|
b64,
|
||||||
proto);
|
proto);
|
||||||
|
|
||||||
@ -319,7 +323,7 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
|
|||||||
#endif
|
#endif
|
||||||
} while (r == -1 && SSL_get_error(wsh->ssl, r) == SSL_ERROR_WANT_READ && x < 100);
|
} while (r == -1 && SSL_get_error(wsh->ssl, r) == SSL_ERROR_WANT_READ && x < 100);
|
||||||
|
|
||||||
return r;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -336,6 +340,12 @@ ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes)
|
|||||||
r = -1;
|
r = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
|
||||||
|
if (r > 0) {
|
||||||
|
*((char *)data + r) = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,7 +540,7 @@ ssize_t ws_close(wsh_t *wsh, int16_t reason)
|
|||||||
|
|
||||||
restore_socket(wsh->sock);
|
restore_socket(wsh->sock);
|
||||||
|
|
||||||
if (wsh->close_sock) {
|
if (wsh->close_sock && wsh->sock != ws_sock_invalid) {
|
||||||
close(wsh->sock);
|
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);
|
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) {
|
if ((wsh->datalen += ws_raw_read(wsh, wsh->buffer + wsh->datalen, 9 - wsh->datalen)) < need) {
|
||||||
/* too small - protocol err */
|
/* too small - protocol err */
|
||||||
return ws_close(wsh, WS_PROTO_ERR);
|
return ws_close(wsh, WS_PROTO_ERR);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user