svnno****@sourc*****
svnno****@sourc*****
2007年 12月 29日 (土) 22:01:24 JST
Revision: 295 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=295 Author: flyson Date: 2007-12-29 22:01:24 +0900 (Sat, 29 Dec 2007) Log Message: ----------- ãµã¼ãã¹ã¯ãªãããã¡ã¤ã³ã¹ã¬ããå´ã§å®è¡ããããã«ãã Modified Paths: -------------- trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js trunk/bbs2chreader/components/b2rServer.js -------------- next part -------------- Modified: trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js =================================================================== --- trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js 2007-12-28 16:21:17 UTC (rev 294) +++ trunk/bbs2chreader/chrome/content/bbs2chreader/server/thread.js 2007-12-29 13:01:24 UTC (rev 295) @@ -144,7 +144,7 @@ this._pref.setCharPref("extensions.bbs2chreader.thread_skin", ""); return; }else { - this.write(ex); + this.write(ex.toSource()); this.close(); return; } @@ -1294,7 +1294,7 @@ toFunction: function(aRes){ return eval( - "function(aNumber, aName, aMail, aMailName, aDate, aID, resIDColor, resIDBgColor, aBeID, aMessage){return \""+aRes + "(function(aNumber, aName, aMail, aMailName, aDate, aID, resIDColor, resIDBgColor, aBeID, aMessage){return \""+aRes .replace(/\\/g,"\\\\").replace(/\"/g,"\\\"") .replace(/(\r|\n|\t)/g,"").replace(/<!--.*?-->/g,"") .replace(/<PLAINNUMBER\/>/g, "\"+aNumber+\"") @@ -1307,7 +1307,7 @@ .replace(/<IDCOLOR\/>/g, "\"+resIDColor+\"") .replace(/<IDBACKGROUNDCOLOR\/>/g, "\"+resIDBgColor+\"") .replace(/<BEID\/>/g, "\"+aBeID+\"") - .replace(/<MESSAGE\/>/g, "\"+aMessage+\"")+"\";}" + .replace(/<MESSAGE\/>/g, "\"+aMessage+\"")+"\";})" ); }, Modified: trunk/bbs2chreader/components/b2rServer.js =================================================================== --- trunk/bbs2chreader/components/b2rServer.js 2007-12-28 16:21:17 UTC (rev 294) +++ trunk/bbs2chreader/components/b2rServer.js 2007-12-29 13:01:24 UTC (rev 295) @@ -193,7 +193,7 @@ aTransport.setTimeout(Ci.nsITransport.TIMEOUT_CONNECT, 30); aTransport.setTimeout(Ci.nsITransport.TIMEOUT_READ_WRITE, 30); - var input = aTransport.openInputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0); + var input = aTransport.openInputStream(0, 1024*8, 1024).QueryInterface(Ci.nsIAsyncInputStream); var output = XPC.createInstance("@mozilla.org/network/buffered-output-stream;1", "nsIBufferedOutputStream"); output.init(aTransport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0), 1024*16); @@ -311,7 +311,7 @@ aTransport.setTimeout(Ci.nsITransport.TIMEOUT_CONNECT, 30); aTransport.setTimeout(Ci.nsITransport.TIMEOUT_READ_WRITE, 30); - var input = aTransport.openInputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0); + var input = aTransport.openInputStream(0, 1024*8, 1024).QueryInterface(Ci.nsIAsyncInputStream); var output = XPC.createInstance("@mozilla.org/network/buffered-output-stream;1", "nsIBufferedOutputStream"); output.init(aTransport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0), 1024*16); @@ -414,38 +414,46 @@ this._requestURL = null; this._getData = new Array(); - this._parseRequestData(); - this._responseHeaders["Host"] = this.requestURL.host; - this._responseHeaders["Date"] = new Date().toUTCString(); - this._responseHeaders["Content-Type"] = "text/plain; charset=UTF-8"; - this._responseHeaders["Connection"] = "close"; - this._startScript(); + this._requestBuffer = ""; + this._input.asyncWait(this, 0, 0, this._getMainThread()); }, + _getMainThread: function(){ + if("@mozilla.org/thread-manager;1" in Components.classes){ + return Cc["@mozilla.org/thread-manager;1"].getService().mainThread; + }else{ + var eventQueueService = XPC.getService("@mozilla.org/event-queue-service;1", "nsIEventQueueService"); + return eventQueueService.getSpecialEventQueue(Ci.nsIEventQueueService.UI_THREAD_EVENT_QUEUE); + } + }, + onInputStreamReady: function(aInput){ + var available = aInput.available(); + var bInputStream = XPC.createInstance("@mozilla.org/binaryinputstream;1", "nsIBinaryInputStream"); + bInputStream.setInputStream(aInput); + this._requestBuffer += bInputStream.readBytes(available); + if((/\r\n\r\n/).test(this._requestBuffer)){ + this._parseRequestData(); + }else{ + this._input.asyncWait(this, 0, 0, this._getMainThread()); + } + }, _parseRequestData: function(){ - var inputStram = XPC.createInstance("@mozilla.org/intl/converter-input-stream;1", "nsIConverterInputStream") - .QueryInterface(Ci.nsIUnicharLineInputStream); - inputStram.init(this._input, "ISO-8859-1", 1024, 0xFFFD); - var line = {}; + var lines = this._requestBuffer.split("\r\n"); + this._requestBuffer = ""; + var headerLine = lines.shift(); - // HTTP wb_ - while (inputStram.readLine(line) && line.value.length == 0){ - // æªÌósð³·é - } - var herderLine = line.value; - // NGXgwb_ª - while (inputStram.readLine(line)){ - if(line.value == "") break; - if(line.value.match(/([^: ]+)[: ]*(.+)/i)){ + for(let [i, line] in Iterator(lines)){ + if(line == "") break; + if(line.match(/([^: ]+)[: ]*(.+)/i)){ this._requestHeaders[RegExp.$1] = RegExp.$2; } } var uri = ""; - if(herderLine.match(/(.+) (.+) (.+)/)){ + if(headerLine.match(/(.+) (.+) (.+)/)){ this._method = RegExp.$1; uri = RegExp.$2; this._httpVersion = RegExp.$3; @@ -464,6 +472,12 @@ this._getData[query[0]] = query[1]; } } + + this._responseHeaders["Host"] = this.requestURL.host; + this._responseHeaders["Date"] = new Date().toUTCString(); + this._responseHeaders["Content-Type"] = "text/plain; charset=UTF-8"; + this._responseHeaders["Connection"] = "close"; + this._startScript(); }, @@ -475,23 +489,25 @@ var mode = (this.requestURL.directory.match(/^\/([^\/]+)\//)) ? RegExp.$1 : null; if(!mode){ - this.sendErrorPage(404, "b2rServerHandler Internal"); + this.sendErrorPage(404, this.requestURL.spec); return; } var scriptURL = "chrome://bbs2chreader/content/server/%MODE%.js"; scriptURL = scriptURL.replace("%MODE%", mode); - var subScrLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Ci.mozIJSSubScriptLoader); - + var subScrLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); try{ this._scope = { script:null }; - subScrLoader.loadSubScript(scriptURL, this._scope); + try{ + subScrLoader.loadSubScript(scriptURL, this._scope); + }catch(ex){ + this.sendErrorPage(404, this.requestURL.spec); + return; + } this._scope.script.start(this); }catch(ex){ - var message = (typeof(ex) == "string") ? ex : - ex.message + "\n" + ex.fileName +" : "+ ex.lineNumber; + var message = (typeof(ex) == "string") ? ex : ex.message + "\n" + ex.fileName +" : "+ ex.lineNumber; this.sendErrorPage(500, message); } },