From a59bb9016c80c2e688e57be54e444b2a1a3a3e3f Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 24 May 2011 23:08:05 +0100 Subject: [PATCH] x google mux change to new compact channel index scheme Signed-off-by: Andy Green --- lib/extension-x-google-mux.c | 42 +++++++++++++++++++++++++++++++++--------- lib/extension-x-google-mux.h | 1 + 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/extension-x-google-mux.c b/lib/extension-x-google-mux.c index d895175..ac5c4d0 100644 --- a/lib/extension-x-google-mux.c +++ b/lib/extension-x-google-mux.c @@ -32,19 +32,33 @@ static int lws_addheader_mux_opcode(unsigned char *pb, int len) return pb - start; } -static int lws_mux_subcommand_header(int cmd, int channel, unsigned char *pb, int len) +static int +lws_mux_subcommand_header(int cmd, int channel, unsigned char *pb, int len) { unsigned char *start = pb; - *pb++ = ((channel >> 8) << 3) | cmd; - *pb++ = channel; + if (channel < 31) + *pb++ = (channel << 3) | cmd; + else { + *pb++ = (31 << 3) | cmd; + *pb++ = channel >> 8; + *pb++ = channel; + } if (len <= 253) *pb++ = len; else { - *pb++ = 254; - *pb++ = len >> 8; - *pb++ = len; + if (len <= 65535) { + *pb++ = 254; + *pb++ = len >> 8; + *pb++ = len; + } else { + *pb++ = 255; + *pb++ = len >> 24; + *pb++ = len >> 16; + *pb++ = len >> 8; + *pb++ = len; + } } return pb - start; @@ -134,15 +148,25 @@ lws_extension_x_google_mux_parser(struct libwebsocket_context *context, case LWS_EXT_XGM_STATE__MUX_BLOCK_1: muxdebug("LWS_EXT_XGM_STATE__MUX_BLOCK_1: opc=%d\n", c & 7); conn->block_subopcode = c & 7; - conn->block_subchannel = (c << 5) & ~0xff; - conn->state = LWS_EXT_XGM_STATE__MUX_BLOCK_2; + conn->block_subchannel = (c >> 3) & ~0x1f; + if (conn->block_subchannel != 31) + goto interpret; + else + conn->state = LWS_EXT_XGM_STATE__MUX_BLOCK_2; break; case LWS_EXT_XGM_STATE__MUX_BLOCK_2: + conn->block_subchannel = c << 8; + conn->state = LWS_EXT_XGM_STATE__MUX_BLOCK_3; + break; + + case LWS_EXT_XGM_STATE__MUX_BLOCK_3: conn->block_subchannel |= c; + muxdebug("LWS_EXT_XGM_STATE__MUX_BLOCK_2: subchannel=%d\n", conn->block_subchannel); - ongoing_subchannel = ongoing_subchannel; +interpret: + ongoing_subchannel = conn->block_subchannel; /* * convert the subchannel index to a child wsi diff --git a/lib/extension-x-google-mux.h b/lib/extension-x-google-mux.h index 158a2c7..95c0810 100644 --- a/lib/extension-x-google-mux.h +++ b/lib/extension-x-google-mux.h @@ -26,6 +26,7 @@ void muxdebug(const char *format, ...) enum lws_ext_x_google_mux__parser_states { LWS_EXT_XGM_STATE__MUX_BLOCK_1, LWS_EXT_XGM_STATE__MUX_BLOCK_2, + LWS_EXT_XGM_STATE__MUX_BLOCK_3, LWS_EXT_XGM_STATE__ADDCHANNEL_LEN, LWS_EXT_XGM_STATE__ADDCHANNEL_LEN16_1, LWS_EXT_XGM_STATE__ADDCHANNEL_LEN16_2, -- 2.7.4