test_class.declarator: impl
test_class.modifier: private
test_class.original_string: private WebSocketHixie76 impl;
test_class.type: WebSocketHixie76
test_class.var_name: impl
test_class.file: tigase-server 7.1.0/src/test/java/tigase/server/websocket/WebSocketHixie76Test.java
test_class.identifier: WebSocketHixie76Test
test_class.superclass: extends TestCase
test_case.body: @Test
  	public void testHandshakeFail() throws NoSuchAlgorithmException, IOException {
  		final ByteBuffer tmp = ByteBuffer.allocate(2048);
  		WebSocketXMPPIOService<Object> io = new WebSocketXMPPIOService<Object>(new WebSocketProtocolIfc[]{ new WebSocketHixie76() }) {
  
  			@Override
  			protected void writeBytes(ByteBuffer data) {
  				tmp.put(data);
  			}
  
  			@Override
  			public int getLocalPort() {
  				return 80;
  			}
  
  		};		
  		Map<String,String> params = new HashMap<String,String>();
  		params.put("Sec-WebSocket-Version", "13");
  		params.put("Sec-WebSocket-Protocol", "xmpp");		
  		byte[] bytes = new byte[10];
  		bytes[0] = '\r';
  		bytes[1] = '\n';
  		Assert.assertFalse("Handshake succeeded", impl.handshake(io, params, bytes));
  	}
test_case.class_method_signature: WebSocketHixie76Test.testHandshakeFail()
test_case.full_signature: @Test public void testHandshakeFail()
test_case.identifier: testHandshakeFail
test_case.invocations: allocate put put put assertFalse handshake
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testHandshakeFail()
focal_class.declarator: log = Logger.getLogger(WebSocketHixie76.class.getCanonicalName())
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = Logger.getLogger(WebSocketHixie76.class.getCanonicalName());
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: ID = "hixie-76"
focal_class.modifier: public static final
focal_class.original_string: public static final String ID = "hixie-76";
focal_class.type: String
focal_class.var_name: ID
focal_class.declarator: RESPONSE_HEADER =
  		"HTTP/1.1 101 Switching Protocols\r\n" + "Upgrade: WebSocket\r\n" +
  		"Connection: Upgrade\r\n" + "Access-Control-Allow-Origin: *\r\n" +
  		"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n" +
  		"Access-Control-Allow-Headers: Content-Type\r\n" +
  		"Access-Control-Max-Age: 86400\r\n"
focal_class.modifier: private static final
focal_class.original_string: private static final String RESPONSE_HEADER =
  		"HTTP/1.1 101 Switching Protocols\r\n" + "Upgrade: WebSocket\r\n" +
  		"Connection: Upgrade\r\n" + "Access-Control-Allow-Origin: *\r\n" +
  		"Access-Control-Allow-Methods: GET, POST, OPTIONS\r\n" +
  		"Access-Control-Allow-Headers: Content-Type\r\n" +
  		"Access-Control-Max-Age: 86400\r\n";
focal_class.type: String
focal_class.var_name: RESPONSE_HEADER
focal_class.declarator: HOST_KEY		= "Host"
focal_class.modifier: private static final
focal_class.original_string: private static final String HOST_KEY		= "Host";
focal_class.type: String
focal_class.var_name: HOST_KEY
focal_class.declarator: ORIGIN_KEY		= "Origin"
focal_class.modifier: private static final
focal_class.original_string: private static final String ORIGIN_KEY		= "Origin";
focal_class.type: String
focal_class.var_name: ORIGIN_KEY
focal_class.declarator: WS_KEY1_KEY		= "Sec-WebSocket-Key1"
focal_class.modifier: private static final
focal_class.original_string: private static final String WS_KEY1_KEY		= "Sec-WebSocket-Key1";
focal_class.type: String
focal_class.var_name: WS_KEY1_KEY
focal_class.declarator: WS_KEY2_KEY		= "Sec-WebSocket-Key2"
focal_class.modifier: private static final
focal_class.original_string: private static final String WS_KEY2_KEY		= "Sec-WebSocket-Key2";
focal_class.type: String
focal_class.var_name: WS_KEY2_KEY
focal_class.declarator: WS_ORIGIN_KEY	= "Sec-WebSocket-Origin"
focal_class.modifier: private static final
focal_class.original_string: private static final String WS_ORIGIN_KEY	= "Sec-WebSocket-Origin";
focal_class.type: String
focal_class.var_name: WS_ORIGIN_KEY
focal_class.declarator: WS_LOCATION_KEY	= "Sec-WebSocket-Location"
focal_class.modifier: private static final
focal_class.original_string: private static final String WS_LOCATION_KEY	= "Sec-WebSocket-Location";
focal_class.type: String
focal_class.var_name: WS_LOCATION_KEY
focal_class.declarator: FRAME_HEADER = new byte[] { (byte) 0x00 }
focal_class.modifier: private static final
focal_class.original_string: private static final byte[] FRAME_HEADER = new byte[] { (byte) 0x00 };
focal_class.type: byte[]
focal_class.var_name: FRAME_HEADER
focal_class.declarator: FRAME_FOOTER = new byte[] { (byte) 0xFF }
focal_class.modifier: private static final
focal_class.original_string: private static final byte[] FRAME_FOOTER = new byte[] { (byte) 0xFF };
focal_class.type: byte[]
focal_class.var_name: FRAME_FOOTER
focal_class.file: tigase-server 7.1.0/src/main/java/tigase/server/websocket/WebSocketHixie76.java
focal_class.identifier: WebSocketHixie76
focal_class.interfaces: implements WebSocketProtocolIfc
focal_class.class_method_signature: WebSocketHixie76.getId()
focal_class.full_signature: @Override public String getId()
focal_class.identifier: getId
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getId()
focal_class.class_method_signature: WebSocketHixie76.handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_class.full_signature: @Override public boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_class.identifier: handshake
focal_class.modifiers: @Override public
focal_class.parameters: (WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_class.return: boolean
focal_class.signature: boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_class.class_method_signature: WebSocketHixie76.decodeFrame(WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.full_signature: @Override public ByteBuffer decodeFrame(WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.identifier: decodeFrame
focal_class.modifiers: @Override public
focal_class.parameters: (WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.return: ByteBuffer
focal_class.signature: ByteBuffer decodeFrame(WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.class_method_signature: WebSocketHixie76.encodeFrameAndWrite(WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.full_signature: @Override public void encodeFrameAndWrite(WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.identifier: encodeFrameAndWrite
focal_class.modifiers: @Override public
focal_class.parameters: (WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.return: void
focal_class.signature: void encodeFrameAndWrite(WebSocketXMPPIOService service, ByteBuffer buf)
focal_class.class_method_signature: WebSocketHixie76.closeConnection(WebSocketXMPPIOService service)
focal_class.full_signature: @Override public void closeConnection(WebSocketXMPPIOService service)
focal_class.identifier: closeConnection
focal_class.modifiers: @Override public
focal_class.parameters: (WebSocketXMPPIOService service)
focal_class.return: void
focal_class.signature: void closeConnection(WebSocketXMPPIOService service)
focal_class.class_method_signature: WebSocketHixie76.uintToBytes(byte[] arr, int offset, long val)
focal_class.full_signature: private void uintToBytes(byte[] arr, int offset, long val)
focal_class.identifier: uintToBytes
focal_class.modifiers: private
focal_class.parameters: (byte[] arr, int offset, long val)
focal_class.return: void
focal_class.signature: void uintToBytes(byte[] arr, int offset, long val)
focal_class.class_method_signature: WebSocketHixie76.decodeHyxie76SecKey(String data)
focal_class.full_signature: private Long decodeHyxie76SecKey(String data)
focal_class.identifier: decodeHyxie76SecKey
focal_class.modifiers: private
focal_class.parameters: (String data)
focal_class.return: Long
focal_class.signature: Long decodeHyxie76SecKey(String data)
focal_method.body: @Override
  	public boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf) throws NoSuchAlgorithmException, IOException {
  		if (headers.containsKey(WS_VERSION_KEY)) {
  			return false;
  		}	
  
  		byte[] secBufArr = new byte[16];
  		Long secKey1 = decodeHyxie76SecKey(headers.get(WS_KEY1_KEY));
  		Long secKey2 = decodeHyxie76SecKey(headers.get(WS_KEY2_KEY));
  		if (log.isLoggable(Level.FINEST)) {
  			log.log(Level.FINEST, "WS-KEY1 = {0}", secKey1);
  			log.log(Level.FINEST, "WS-KEY2 = {0}", secKey2);
  		}
  		uintToBytes(secBufArr, 0, secKey1);
  		uintToBytes(secBufArr, 4, secKey2);
  		if (buf[buf.length - 9] != '\n') {
  			throw new IOException("buf[len-9] != \\n!!");
  		}
  		for (int j = 8; j > 0; j--) {
  			secBufArr[8 + 8 - j] = buf[buf.length - j];
  		}
  
  		MessageDigest md = MessageDigest.getInstance("MD5");
  		byte[] resp = md.digest(secBufArr);
  
  		StringBuilder response = new StringBuilder(RESPONSE_HEADER.length() * 2);
  		response.append(RESPONSE_HEADER);
  
  		response.append("Content-Length: ").append(resp.length).append("\r\n");
  		response.append(WS_PROTOCOL_KEY).append(": ");
  		if (headers.get(WS_PROTOCOL_KEY).contains("xmpp-framing")) {
  			response.append("xmpp-framing");
  		} else {
  			response.append("xmpp");
  		}
  		response.append("\r\n");		
  		if (headers.containsKey(ORIGIN_KEY)) {
  			response.append(WS_ORIGIN_KEY).append(": ").append(headers.get(ORIGIN_KEY)).append("\r\n");
  		}
  
  		boolean ssl = SocketType.ssl == ((SocketType) service.getSessionData().get("socket"));
  		int localPort = service.getLocalPort();
  		String location = (ssl ? "wss://" : "ws://")
  				+ headers.get(HOST_KEY) + (((ssl && localPort == 443) || (!ssl && localPort == 80) || headers.get(HOST_KEY).contains(":")) ? "" : (":" + localPort)) + "/";
  		response.append(WS_LOCATION_KEY).append(": ").append(location).append("\r\n");
  
  		response.append("\r\n");
  
  		if (log.isLoggable(Level.FINEST)) {
  			log.log(Level.FINEST, "sending response = \n{0}", response.toString());
  		}
  
  		byte[] respBytes = response.toString().getBytes();
  		ByteBuffer out = ByteBuffer.allocate(respBytes.length + 16);
  		out.put(respBytes);
  		out.put(resp);
  		out.flip();
  		service.writeBytes(out);
  
  		return true;
  	}
focal_method.class_method_signature: WebSocketHixie76.handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_method.full_signature: @Override public boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_method.identifier: handshake
focal_method.invocations: containsKey decodeHyxie76SecKey get decodeHyxie76SecKey get isLoggable log log uintToBytes uintToBytes getInstance digest length append append append append append append contains get append append append containsKey append append append append get get getSessionData getLocalPort get contains get append append append append append isLoggable log toString getBytes toString allocate put put flip writeBytes
focal_method.modifiers: @Override public
focal_method.parameters: (WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)
focal_method.return: boolean
focal_method.signature: boolean handshake(WebSocketXMPPIOService service, Map<String, String> headers, byte[] buf)