WIP. AutoBahn tests 6 working. Needed to check if final string is UTF-8 compliant.

This commit is contained in:
Veebs 2011-10-17 13:48:42 +11:00
parent 234952a516
commit beb56878e4

View File

@ -205,7 +205,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
} else { } else {
framePayloadLength = framePayloadLen1; framePayloadLength = framePayloadLen1;
} }
logger.debug("Frame length =" + framePayloadLength); logger.debug("Frame length =" + framePayloadLength);
checkpoint(State.MASKING_KEY); checkpoint(State.MASKING_KEY);
case MASKING_KEY: case MASKING_KEY:
@ -265,13 +265,13 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
// Check text for UTF8 correctness // Check text for UTF8 correctness
if (frameOpcode == OPCODE_TEXT || fragmentedFramesText != null) { if (frameOpcode == OPCODE_TEXT || fragmentedFramesText != null) {
// Check UTF-8 correctness for this payload
checkUTF8String(channel, framePayload.array()); checkUTF8String(channel, framePayload.array());
}
// If final frame in a fragmented message, then set // This does a second check to make sure UTF-8
// aggregated text so it can be returned // correctness for entire text message
if (fragmentedFramesText != null) {
aggregatedText = fragmentedFramesText.toString(); aggregatedText = fragmentedFramesText.toString();
fragmentedFramesText = null; fragmentedFramesText = null;
} }
} }
@ -348,13 +348,13 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
private void checkUTF8String(Channel channel, byte[] bytes) throws CorruptedFrameException { private void checkUTF8String(Channel channel, byte[] bytes) throws CorruptedFrameException {
try { try {
StringBuilder sb = new StringBuilder("UTF8 " + bytes.length + " bytes: "); StringBuilder sb = new StringBuilder("UTF8 " + bytes.length + " bytes: ");
for (byte b : bytes) { for (byte b : bytes) {
sb.append(Integer.toHexString(b)).append(" "); sb.append(Integer.toHexString(b)).append(" ");
} }
logger.debug(sb.toString()); logger.debug(sb.toString());
if (fragmentedFramesText == null) { if (fragmentedFramesText == null) {
fragmentedFramesText = new UTF8Output(bytes); fragmentedFramesText = new UTF8Output(bytes);
} else { } else {