[asterisk-commits] file: branch file/websocket r368031 - /team/file/websocket/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed May 30 14:19:38 CDT 2012
Author: file
Date: Wed May 30 14:19:34 2012
New Revision: 368031
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=368031
Log:
More tweaking based on feedback.
Modified:
team/file/websocket/res/res_http_websocket.c
Modified: team/file/websocket/res/res_http_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/file/websocket/res/res_http_websocket.c?view=diff&rev=368031&r1=368030&r2=368031
==============================================================================
--- team/file/websocket/res/res_http_websocket.c (original)
+++ team/file/websocket/res/res_http_websocket.c Wed May 30 14:19:34 2012
@@ -306,12 +306,15 @@
}
}
+ /* Assume no extended length and no masking at the beginning */
*payload_len = buf[1] & 0x7f;
+ *payload = &buf[2];
/* Determine if extended length is being used */
if (*payload_len == 126) {
/* Use the next 2 bytes to get a uint16_t */
expected += 2;
+ *payload += 2;
if (frame_size < expected) {
ast_websocket_close(session, 1009);
@@ -319,16 +322,10 @@
}
*payload_len = ntohs(get_unaligned_uint16(&buf[2]));
-
- if (mask_present) {
- mask = &buf[4];
- *payload = &buf[8];
- } else {
- *payload = &buf[4];
- }
} else if (*payload_len == 127) {
/* Use the next 8 bytes to get a uint64_t */
expected += 8;
+ *payload += 8;
if (frame_size < expected) {
ast_websocket_close(session, 1009);
@@ -336,20 +333,12 @@
}
*payload_len = ntohl(get_unaligned_uint64(&buf[2]));
-
- if (mask_present) {
- mask = &buf[10];
- *payload = &buf[12];
- } else {
- *payload = &buf[10];
- }
- } else if (*payload_len) {
- if (mask_present) {
- mask = &buf[2];
- *payload = &buf[6];
- } else {
- *payload = &buf[6];
- }
+ }
+
+ /* If masking is present the payload currently points to the mask, so move it over 4 bytes to the actual payload */
+ if (mask_present) {
+ mask = *payload;
+ *payload += 4;
}
/* Determine how much payload we need to read in as we may have already read some in */
@@ -538,7 +527,6 @@
/* Version 13 defined in specification http://tools.ietf.org/html/rfc6455 */
char combined[strlen(key) + strlen(WEBSOCKET_GUID) + 1], base64[64];
uint8_t sha[20];
- struct ast_str *response = ast_str_alloca(256);
if (!(session = ao2_alloc(sizeof(*session), session_destroy_fn))) {
ast_log(LOG_WARNING, "WebSocket connection from '%s' could not be accepted",
@@ -553,16 +541,14 @@
ast_sha1_hash_uint(sha, combined);
ast_base64encode(base64, (const unsigned char*)sha, 20, sizeof(base64));
- ast_str_set(&response, 0, "HTTP/1.1 101 Switching Protocols\r\n"
- "Upgrade: %s\r\n"
- "Connection: Upgrade\r\n"
- "Sec-WebSocket-Accept: %s\r\n"
- "Sec-WebSocket-Protocol: %s\r\n\r\n",
- upgrade,
- base64,
- protocol);
-
- fprintf(ser->f, "%s", ast_str_buffer(response));
+ fprintf(ser->f, "HTTP/1.1 101 Switching Protocols\r\n"
+ "Upgrade: %s\r\n"
+ "Connection: Upgrade\r\n"
+ "Sec-WebSocket-Accept: %s\r\n"
+ "Sec-WebSocket-Protocol: %s\r\n\r\n",
+ upgrade,
+ base64,
+ protocol);
} else {
/* Specification defined in http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-75 or completely unknown */
More information about the asterisk-commits
mailing list