@@ -260,8 +260,7 @@ public void run() {
260260 * http://github.com/gimite/web-socket-js
261261 *
262262 * @return An XML String that comforms to Flash's security policy. You MUST
263- * not need to include the null char at the end, it is appended
264- * automatically.
263+ * not include the null char at the end, it is appended automatically.
265264 */
266265 protected String getFlashSecurityPolicy () {
267266 return "<cross-domain-policy><allow-access-from domain=\" *\" to-ports=\" "
@@ -282,7 +281,7 @@ protected String getFlashSecurityPolicy() {
282281 * @throws IOException When socket related I/O errors occur.
283282 * @throws NoSuchAlgorithmException
284283 */
285- public boolean onHandshakeRecieved (WebSocket conn , String handshake ,byte [] key3 ) throws IOException , NoSuchAlgorithmException {
284+ public boolean onHandshakeRecieved (WebSocket conn , String handshake , byte [] key3 ) throws IOException , NoSuchAlgorithmException {
286285
287286 // If a Flash client requested the Policy File...
288287 if (FLASH_POLICY_REQUEST .equals (handshake )) {
@@ -319,11 +318,11 @@ public boolean onHandshakeRecieved(WebSocket conn, String handshake,byte[] key3)
319318 if (prop == null || !prop .equals ("Upgrade" )) {
320319 isWebSocketRequest = false ;
321320 }
322- String key1 = p .getProperty ("Sec-WebSocket-Key1" );
323- String key2 = p .getProperty ("Sec-WebSocket-Key2" );
324- String headerPrefix = "" ;
325- byte [] responseChallenge = null ;
326- switch (this .draft ){
321+ String key1 = p .getProperty ("Sec-WebSocket-Key1" );
322+ String key2 = p .getProperty ("Sec-WebSocket-Key2" );
323+ String headerPrefix = "" ;
324+ byte [] responseChallenge = null ;
325+ switch (this .draft ) {
327326 case DRAFT75 :
328327 if (key1 != null || key2 != null || key3 != null ) {
329328 isWebSocketRequest = false ;
@@ -337,28 +336,28 @@ public boolean onHandshakeRecieved(WebSocket conn, String handshake,byte[] key3)
337336 }
338337 if (isWebSocketRequest ) {
339338 if (key1 != null && key2 != null && key3 != null ) {
340- headerPrefix = "Sec-" ;
341- byte [] part1 = this .getPart (key1 );
342- byte [] part2 = this .getPart (key2 );
343- byte [] challenge = new byte [16 ];
344- challenge [0 ]= part1 [0 ];
345- challenge [1 ]= part1 [1 ];
346- challenge [2 ]= part1 [2 ];
347- challenge [3 ]= part1 [3 ];
348- challenge [4 ]= part2 [0 ];
349- challenge [5 ]= part2 [1 ];
350- challenge [6 ]= part2 [2 ];
351- challenge [7 ]= part2 [3 ];
352- challenge [8 ]= key3 [0 ];
353- challenge [9 ]= key3 [1 ];
354- challenge [10 ]= key3 [2 ];
355- challenge [11 ]= key3 [3 ];
356- challenge [12 ]= key3 [4 ];
357- challenge [13 ]= key3 [5 ];
358- challenge [14 ]= key3 [6 ];
359- challenge [15 ]= key3 [7 ];
360- MessageDigest md5 = MessageDigest .getInstance ("MD5" );
361- responseChallenge = md5 .digest (challenge );
339+ headerPrefix = "Sec-" ;
340+ byte [] part1 = this .getPart (key1 );
341+ byte [] part2 = this .getPart (key2 );
342+ byte [] challenge = new byte [16 ];
343+ challenge [0 ] = part1 [0 ];
344+ challenge [1 ] = part1 [1 ];
345+ challenge [2 ] = part1 [2 ];
346+ challenge [3 ] = part1 [3 ];
347+ challenge [4 ] = part2 [0 ];
348+ challenge [5 ] = part2 [1 ];
349+ challenge [6 ] = part2 [2 ];
350+ challenge [7 ] = part2 [3 ];
351+ challenge [8 ] = key3 [0 ];
352+ challenge [9 ] = key3 [1 ];
353+ challenge [10 ] = key3 [2 ];
354+ challenge [11 ] = key3 [3 ];
355+ challenge [12 ] = key3 [4 ];
356+ challenge [13 ] = key3 [5 ];
357+ challenge [14 ] = key3 [6 ];
358+ challenge [15 ] = key3 [7 ];
359+ MessageDigest md5 = MessageDigest .getInstance ("MD5" );
360+ responseChallenge = md5 .digest (challenge );
362361 }
363362
364363 String responseHandshake = "HTTP/1.1 101 Web Socket Protocol Handshake\r \n " +
@@ -397,25 +396,25 @@ public void onOpen(WebSocket conn) {
397396 onClientOpen (conn );
398397 }
399398 }
400-
399+
401400 public void onClose (WebSocket conn ) {
402401 if (this .connections .remove (conn )) {
403402 onClientClose (conn );
404403 }
405404 }
406405
407- private byte [] getPart (String key ){
408- long keyNumber = Long .parseLong (key .replaceAll ("[^0-9]" ,"" ));
409- long keySpace = key .split ("\u0020 " ).length - 1 ;
410- long part = new Long (keyNumber / keySpace );
411- byte [] bytes = new byte [4 ];
412- bytes [ 0 ] = (byte )( part >> 24 );
413- bytes [ 1 ] = (byte )( (part << 8 ) >> 24 );
414- bytes [ 2 ] = (byte )( (part << 16 ) >> 24 );
415- bytes [ 3 ] = (byte )( (part << 24 ) >> 24 );
416- return bytes ;
406+ private byte [] getPart (String key ) {
407+ long keyNumber = Long .parseLong (key .replaceAll ("[^0-9]" ,"" ));
408+ long keySpace = key .split ("\u0020 " ).length - 1 ;
409+ long part = new Long (keyNumber / keySpace );
410+ return new byte [] {
411+ (byte )( part >> 24 ),
412+ (byte )( (part << 8 ) >> 24 ),
413+ (byte )( (part << 16 ) >> 24 ),
414+ (byte )( (part << 24 ) >> 24 )
415+ } ;
417416 }
418-
417+
419418 // ABTRACT METHODS /////////////////////////////////////////////////////////
420419 public abstract void onClientOpen (WebSocket conn );
421420 public abstract void onClientClose (WebSocket conn );
0 commit comments