[Bbs2ch-cvs 170] CVS update: bbs2chreader/content/bbs2chreader/server

Back to archive index

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")){
+				// ƒvƒƒNƒV‚ðƒoƒCƒpƒX‚µ‚½ 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 “™‚̃Šƒ_ƒCƒŒƒNƒg‚ð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;
+			// •K—v‚ȏî•ñ‚ª‚È‚¢‚È‚ç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){ // –¢XV
+			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){
+	        // ƒƒbƒZ[ƒW•”•ª‚ª“ñs‚É•ª‚©‚ê‚Ä‚¢‚é‚̂ňês‚É‚·‚é
+	    var datLines = aResponse.replace(/\n \]\<\/font\>/gm, " ]</font>");
+	    datLines = datLines.split("\n");
+	        // ƒƒbƒZ[ƒW‚ƃ^ƒCƒgƒ‹ˆÈŠO‚̍s‚ðíœ
+	    datLines = datLines.filter(function(aElement, aIndex, aArray){
+	        return (aElement.match(/^<ti|dt/));
+	    });
+	        // ”z—ñ‚̈ê‚–ڂ̓^ƒCƒgƒ‹
+	    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"]


bbs2ch-cvs メーリングリストの案内
Back to archive index