• R/O
  • SSH
  • HTTPS

webserver: コミット


コミットメタ情報

リビジョン71 (tree)
日時2011-08-31 14:50:39
作者horitaku

ログメッセージ

ソースのクリーンナップ

変更サマリ

差分

--- branch/Basic 0.2x/src/servercore/http/HttpServer.java (revision 70)
+++ branch/Basic 0.2x/src/servercore/http/HttpServer.java (revision 71)
@@ -4,7 +4,6 @@
44 import servercore.statics.StaticsMeothds;
55 import servercore.tcp.TcpServer;
66 import extension.file.LogWriter;
7-import startup_action.StartTest;
87
98 public class HttpServer extends Thread implements StaticValues{
109
@@ -86,9 +85,6 @@
8685 LogWriter log = new LogWriter(httpServerLogPath);
8786 TcpServer server = new TcpServer();
8887 try {
89- StartTest starttest = new StartTest();
90- //starttest.start();
91-
9288 TcpServer.setPortNum(recvPort);
9389 server.start();
9490 System.out.println("server started");
--- branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 70)
+++ branch/Basic 0.2x/src/servercore/job/JobWorker.java (revision 71)
@@ -248,125 +248,7 @@
248248 String editedDate = sdf.format(new Date(milliSecound));
249249 return editedDate;
250250 }
251- private void websocketHandShake(HttpRequest req, OutputStream ops, InputStream ips) {
252- String host = req.getHeader().get("Host");
253- StringBuffer sb = new StringBuffer();
254- try {
255- String path = req.getRowPath();
256- String key1 = req.getHeader().get("Sec-WebSocket-Key1");
257- String key2 = req.getHeader().get("Sec-WebSocket-Key2");
258- String origin = req.getHeader().get("Origin");
259- String res_ws = "ws://" + host + path;
260- byte[] webSocketsByte = new byte[128];
261- int readBytes = ips.read(webSocketsByte);
262- byte[] body_code = new byte[readBytes];
263- System.arraycopy(webSocketsByte, 0, body_code, 0,readBytes);
264- System.out.println(body_code);
265- long key1_num = chooseNum(key1);
266- long key2_num = chooseNum(key2);
267- int key1_s = chooseSpace(key1);
268- int key2_s = chooseSpace(key2);
269- long key1_w = key1_num / key1_s;
270- long key2_w = key2_num / key2_s;
271- byte[] key_head = bigendiean(key1_w, key2_w);
272- byte[] byte_keys = new byte[16];
273- System.arraycopy(key_head, 0, byte_keys, 0, 8);
274- System.arraycopy(body_code, 0, byte_keys, 8, 8);
275251
276- MessageDigest md = MessageDigest.getInstance("MD5");
277- md.update(byte_keys);
278- byte[] hash = md.digest();
279-
280- sb.append("HTTP/1.1 101 WebSocket Protocol Handshake\r\n");
281- sb.append("Upgrade: WebSocket\r\n");
282- sb.append("Connection: Upgrade\r\n");
283- sb.append("Sec-WebSocket-Location: " + res_ws + "\r\n");
284- sb.append("Sec-WebSocket-Origin: http://" + host + "\r\n");
285- sb.append("\r\n");
286- ops.write(sb.toString().getBytes());
287- ops.write(hash);
288-
289- byte[] recv = new byte[128];
290- int rescByte = ips.read(recv);
291- String str = new String(recv, 0, rescByte);
292- ops.write(0x00);
293- ops.write("abcdefg".getBytes());
294- ops.write(0xff);
295-
296- } catch (IOException e) {
297- e.printStackTrace();
298- } catch (NoSuchAlgorithmException e) {
299- e.printStackTrace();
300- }
301-
302- }
303- public byte[] getChalengeKey(byte[] header) {
304- byte[] ret = null;
305- try {
306- for(int i = 0;i < header.length;i++) {
307- if(header[i] == '\r' && header[i + 1] == '\n') {
308- if(header[i + 2] == '\r' && header[i + 3] == '\n') {
309- int lastAt = header.length - (i + 4);
310- ret = new byte[lastAt];
311- System.arraycopy(header, i + 4, ret, 0, lastAt);
312- break;
313- }
314- }
315- }
316- } catch(Exception e) {
317- e.printStackTrace();
318- }
319- return ret;
320- }
321- public long chooseNum(String str) {
322- String code = "";
323- for(int i = 0;i < str.length();i++) {
324- try {
325- int num = Integer.parseInt("" + str.charAt(i));
326- code += num;
327- } catch(Exception e) {}
328- }
329- long ret = 0;
330- try {
331- ret = Long.parseLong(code);
332- } catch(Exception e) {}
333- return ret;
334- }
335- public int chooseSpace(String str) {
336- int ret = 0;
337- for(int i =0;i < str.length();i++) {
338- if(str.charAt(i) == ' ') {
339- ret++;
340- }
341- }
342- return ret;
343- }
344- public byte[] bigendiean(long key1_w, long key2_w) {
345- long lon1 = key1_w;
346- long lon2 = key2_w;
347- byte[] bytes = new byte[8];
348- int[] ints = new int[8];
349- ints[3] = (int)(lon1 % 256);
350- lon1 /= 256;
351- ints[2] = (int)(lon1 % 256);
352- lon1 /= 256;
353- ints[1] = (int)(lon1 % 256);
354- lon1 /= 256;
355- ints[0] = (int)lon1;
356-
357- ints[7] = (int)(lon2 % 256);
358- lon2 /= 256;
359- ints[6] = (int)(lon2 % 256);
360- lon2 /= 256;
361- ints[5] = (int)(lon2 % 256);
362- lon2 /= 256;
363- ints[4] = (int)lon2;
364-
365- for(int i = 0;i < 8;i++) {
366- bytes[i] = (byte)ints[i];
367- }
368- return bytes;
369- }
370252 public boolean useEncodingOK(String accept_encoding, String encode_algo) {
371253 if(accept_encoding == null || encode_algo == null || "".equals(encode_algo)) {
372254 return false;
旧リポジトリブラウザで表示