flyson
flyso****@users*****
2006年 12月 11日 (月) 01:13:26 JST
Index: bbs2chreader/content/bbs2chreader/server/thread.js diff -u bbs2chreader/content/bbs2chreader/server/thread.js:1.1.2.6 bbs2chreader/content/bbs2chreader/server/thread.js:1.1.2.7 --- bbs2chreader/content/bbs2chreader/server/thread.js:1.1.2.6 Sun Dec 10 01:09:46 2006 +++ bbs2chreader/content/bbs2chreader/server/thread.js Mon Dec 11 01:13:26 2006 @@ -32,6 +32,9 @@ case this._bbs2chService.BOARD_TYPE_JBBS: this.thread = new b2rThreadJbbs(); break; + case this._bbs2chService.BOARD_TYPE_MACHI: + this.thread = new b2rThreadMachi(); + break; default: this.thread = null; break; @@ -56,7 +59,7 @@ var threadURLSpec = aRequestURL.path.substring(8); if(threadURLSpec == "") return null; - threadURLSpec = decodeURIComponent(threadURLSpec); + // threadURLSpec = decodeURIComponent(threadURLSpec); try{ var threadURL = this._ioService.newURI(threadURLSpec, null, null) @@ -557,6 +560,147 @@ b2rThreadJbbs.prototype.__proto__ = b2rThread2ch.prototype; +// ***** ***** ***** ***** ***** b2rThreadMachi ***** ***** ***** ***** ***** +function b2rThreadMachi(){ +} + +b2rThreadMachi.prototype = { + get optionsStart(){ + return (this.dat.queryHash["START"]) ? parseInt(this.dat.queryHash["START"]) : null; + }, + get optionsLast(){ + return (this.dat.queryHash["LAST"]) ? parseInt(this.dat.queryHash["LAST"]) : null; + }, + get optionsEnd(){ + return (this.dat.queryHash["END"]) ? parseInt(this.dat.queryHash["END"]) : null; + }, + get optionsNoFirst(){ + return (this.dat.queryHash["NOFIRST"] == "TRUE") ? true : false; + }, + + datDownload: function(){ + var datURLSpec = this.dat.datURL.spec + // ·ªGET + if(this.dat.datFile.exists() && this.dat.lineCount){ + datURLSpec += "&NOFIRST=TRUE&START=" + (this.dat.lineCount + 1); + } + var datURL = this._ioService.newURI(datURLSpec, null, null) + .QueryInterface(Components.interfaces.nsIURL); + + if(this._bbs2chService.pref.getBoolPref("fls.bbs2chreader.bypas_http_proxy")){ + // vNVðoCpXµ½ nsIHttpChannel Ìì¬ + var httpProtocolHandler = this._ioService.getProtocolHandler("http") + .QueryInterface(Components.interfaces.nsIHttpProtocolHandler); + this.httpChannel = httpProtocolHandler.newProxiedChannel(datURL, null) + .QueryInterface(Components.interfaces.nsIHttpChannel); + }else{ + this.httpChannel = this._ioService.newChannelFromURI(datURL) + .QueryInterface(Components.interfaces.nsIHttpChannel); + } + + this.httpChannel.requestMethod = "GET"; + this.httpChannel.redirectionLimit = 0; // 302 Ì_CNgðsíÈ¢ + this.httpChannel.loadFlags = this.httpChannel.LOAD_BYPASS_CACHE; + this.httpChannel.setRequestHeader("User-Agent", this._bbs2chService.userAgent, false); + + this.httpChannel.asyncOpen(this, null); + }, + + onStartRequest: function(aRequest, aContext){ + this._bInputStream = Components.classes["@mozilla.org/binaryinputstream;1"] + .createInstance(Components.interfaces.nsIBinaryInputStream); + this._htmlData = new Array(); + }, + + onDataAvailable: function (aRequest, aContext, aInputStream, aOffset, aCount){ + if(!this._opend) return; + + aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); + var httpStatus = aRequest.responseStatus; + // KvÈîñªÈ¢ÈçI¹ + if(!(httpStatus==200 || httpStatus==206)) return; + if(aCount == 0) return; + + this._bInputStream.setInputStream(aInputStream); + var availableData = this._bInputStream.readBytes(aCount); + // NULL ¶ + availableData = availableData.replace(/\x00/g, "*"); + + this._htmlData.push(availableData); + this.write(" "); + }, + + onStopRequest: function(aRequest, aContext, aStatus){ + if(!this._opend) return; + aRequest.QueryInterface(Components.interfaces.nsIHttpChannel); + var httpStatus = aRequest.responseStatus; + + + switch(httpStatus){ + case 200: // ÊíGET OK + case 206: // ·ªGET OK + break; + default: // HTTP G[ + this.write(this.converter.getFooter(httpStatus)); + this.close(); + return; + } + + var datLines = this.machiHTML2DAT(this._htmlData.join("")); + this._htmlData = null; + + if(datLines.length == 0){ // ¢XV + this.write(this.converter.getFooter("not_modified")); + this.close(); + return; + } + + for(var i=0; i<datLines.length; i++){ + this.write(this.datLineParse(datLines[i], i+1, true)); + } + + this.write(this.converter.getFooter("ok")); + this.close(); + + if(httpStatus == 200 || httpStatus == 206){ + this.dat.lineCount += datLines.length + this.datSave(datLines.join("\n")); + } + this._data = null; + }, + + machiHTML2DAT: function(aResponse){ + // bZ[Wªªñsɪ©êÄ¢éÌÅêsÉ·é + var datLines = aResponse.replace(/\n \]\<\/font\>/gm, " ]</font>"); + datLines = datLines.split("\n"); + // bZ[WÆ^CgÈOÌsðí + datLines = datLines.filter(function(aElement, aIndex, aArray){ + return (aElement.match(/^<ti|dt/)); + }); + // zñÌêÂÚÍ^Cg + var datTitle = datLines.shift().replace(/<\/?title>/g, ""); + + datLines = datLines.map(function(aElement, aIndex, aArray){ + var datLine = aElement; + var name = (datLine.match(/<b> ([^<]+) <\/b>/i)) ? RegExp.$1 : ""; + var mail = (datLine.match(/<a href="mailto:([^"]+)"><b>/i)) ? RegExp.$1 : ""; + var date = (datLine.match(/eúF ([^<]+) <font/)) ? RegExp.$1 : ""; + var message = (datLine.match(/<br><dd>/)) ? RegExp.rightContext : ""; + message = message.replace(/ <br><br>$/, ""); + var datNumber = (datLine.match(/<dt>(\d+) ¼O/)) ? parseInt(RegExp.$1) : 0; + var title = (datNumber==1) ? datTitle : ""; + return name +"<>"+ mail +"<>"+ date +"<>"+ message +"<>" + title; + }); + + return datLines; + }, + + + +}; + +b2rThreadMachi.prototype.__proto__ = b2rThread2ch.prototype; + // ***** ***** ***** ***** ***** b2rDat ***** ***** ***** ***** ***** function b2rDat(){ @@ -573,9 +717,16 @@ get datURL(){ if(!this._datURL){ - var datURLSpec = this.boardURL.resolve("dat/" + this.id + ".dat"); - this._datURL = this._ioService.newURI(datURLSpec, null, null) + if(this.type == this._bbs2chService.BOARD_TYPE_MACHI){ + var datURLSpec = this.threadURL.resolve("./read.cgi"); + datURLSpec += "?BBS=" + this.queryHash["BBS"] + "&KEY=" + this.queryHash["KEY"]; + this._datURL = this._ioService.newURI(datURLSpec, null, null) .QueryInterface(Components.interfaces.nsIURL); + }else{ + var datURLSpec = this.boardURL.resolve("dat/" + this.id + ".dat"); + this._datURL = this._ioService.newURI(datURLSpec, null, null) + .QueryInterface(Components.interfaces.nsIURL); + } } return this._datURL; }, @@ -593,8 +744,13 @@ }, get id(){ - if(!this._id) - this._id = this.threadURL.directory.match(/\/(\d{9,10})/) ? RegExp.$1 : null; + if(!this._id){ + if(this.type == this._bbs2chService.BOARD_TYPE_MACHI){ + this._id = this.queryHash["KEY"] || null; + }else{ + this._id = this.threadURL.directory.match(/\/(\d{9,10})/) ? RegExp.$1 : null; + } + } return this._id; }, @@ -619,6 +775,17 @@ return this._lastModified = aValue; }, + get queryHash(){ + if(!this._queryHash){ + this._queryHash = new Array(); + var queryArray = this.threadURL.query.split("&"); + for(var i=0; i<queryArray.length; i++){ + var query = queryArray[i].split("="); + if(query.length == 2) this._queryHash[query[0]] = query[1]; + } + } + return this._queryHash; + }, init: function(aThreadURL, aBoardURL, aType){ this._bbs2chService = Components.classes["@mozilla.org/bbs2ch-service;1"]