[o2on-svn] [72] FIX: EUC-JPなdatに未対応

Back to archive index

o2on svn commit o2on-****@lists*****
2008年 4月 18日 (金) 14:42:26 JST


Revision: 72
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=o2on&view=rev&rev=72
Author:   electrolysis
Date:     2008-04-18 14:42:26 +0900 (Fri, 18 Apr 2008)

Log Message:
-----------
FIX: EUC-JPなdatに未対応

詳細: Be板にはEUC-JPなdatがあるため、バベルを使ってShift_JISかEUC-JPかを判別し、適切に扱うようにした

Modified Paths:
--------------
    branches/BRANCH_0043/o2on/src.o2on/O2DatIO.cpp
    branches/BRANCH_0043/o2on/src.o2on/O2DatIO.h
    branches/BRANCH_0043/o2on/src.o2on/O2DatPath.h
    branches/BRANCH_0043/o2on/src.o2on/O2Server_HTTP_Admin.h
    branches/BRANCH_0043/o2on/src.o2on/dataconv.cpp
    branches/BRANCH_0043/o2on/src.o2on/dataconv.h
    branches/BRANCH_0043/o2on/src.o2on/o2on.vcproj

Modified: branches/BRANCH_0043/o2on/src.o2on/O2DatIO.cpp
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/O2DatIO.cpp	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/O2DatIO.cpp	2008-04-18 05:42:26 UTC (rev 72)
@@ -285,8 +285,15 @@
 
 	uint pos_title = pos_gt+1;
 	string tmp(&p[pos_title], &p[pos_lf]);
+	
+	wstring encoding;
+	if (datpath.is_be())
+		sjis_or_euc(tmp, encoding);
+	if (encoding.empty())
+		encoding = L"shift_jis";
+
 	wstring title;
-	ToUnicode(L"shift_jis", tmp, title);
+	ToUnicode(encoding.c_str(), tmp, title);
 
 	//ASCIIƒRƒ“ƒgƒ[ƒ‹ƒR[ƒh‚ª“ü‚Á‚Ä‚¢‚½‚ç?‚É’u‚«Š·‚¦‚é
 	//0x00 - 0x1f, 0x7f
@@ -686,7 +693,7 @@
 
 bool
 O2DatIO::
-Dat2HTML(const hashT &hash, string &out)
+Dat2HTML(const hashT &hash, string &out, string &encoding)
 {
 	char tmp[32];
 
@@ -695,6 +702,18 @@
 	if (!Load(hash, 0, dat, datpath))
 		return false;
 
+	if (datpath.is_be())
+		sjis_or_euc(dat, encoding);
+	if (encoding.empty())
+		encoding = "shift_jis";
+
+	string colon = "F";
+	string broken = "‰ó‚ê‚Ä‚éH";
+	if (encoding == "euc-jp"){
+		sjis2euc(colon);
+		sjis2euc(broken);
+	}
+
 	string url;
 	datpath.geturl(url);
 
@@ -713,7 +732,9 @@
 		if (!firstres && token.size() == 5) {
 			out += "<html>\r\n";
 			out += "<head>\r\n";
-			out += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=shift_jis\">\r\n";
+			out += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=";
+			out += encoding;
+			out += "\">\r\n";
 			out += "<title>";
 			out += token[4];
 			out += "</title>\r\n";
@@ -731,7 +752,7 @@
 		}
 
 		out += "<dt>";
-		sprintf_s(tmp, 32, "%d F", n);
+		sprintf_s(tmp, 32, "%d %s", n, colon.c_str());
 		out += tmp;
 
 		if (token.size() >= 4) {
@@ -747,7 +768,7 @@
 				out += token[0];
 				out += "</b></a>";
 			}
-			out += "F";
+			out += colon;
 			out += token[2];
 
 			out += "<dd>";
@@ -755,7 +776,7 @@
 			out += "<br><br>\r\n";
 		}
 		else {
-			out += "‰ó‚ê‚Ä‚éH";
+			out += broken;
 			out += "<dd>";
 			out += line;
 			out += "<br><br>\r\n";

Modified: branches/BRANCH_0043/o2on/src.o2on/O2DatIO.h
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/O2DatIO.h	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/O2DatIO.h	2008-04-18 05:42:26 UTC (rev 72)
@@ -71,7 +71,7 @@
 
 	uint64 Put(O2DatPath &datpath, const char *dat, uint64 len, uint64 startpos);
 	bool ExportToXML(const wchar_t *domain, const wchar_t *bbsname, string &out);
-	bool Dat2HTML(const hashT &hash, string &out);
+	bool Dat2HTML(const hashT &hash, string &out, string &encoding);
 
 	size_t GetLocalFileKeys(O2KeyList &keylist, time_t publish_tt, size_t limit);
 

Modified: branches/BRANCH_0043/o2on/src.o2on/O2DatPath.h
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/O2DatPath.h	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/O2DatPath.h	2008-04-18 05:42:26 UTC (rev 72)
@@ -318,7 +318,12 @@
 		title = titleW;
 	}
 
+	bool is_be(void) const
+	{
+		return bbsnameA == "be";
+	}
 
+
 private:
 	bool check(const char *dom, const char *bbs, const char *dat)
 	{

Modified: branches/BRANCH_0043/o2on/src.o2on/O2Server_HTTP_Admin.h
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/O2Server_HTTP_Admin.h	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/O2Server_HTTP_Admin.h	2008-04-18 05:42:26 UTC (rev 72)
@@ -1114,12 +1114,13 @@
 	{
 		hashT hash;
 		string html;
+		string encoding;
 
 
 		strmap::iterator it = hdr->queries.find("hash");
 		if (it != hdr->queries.end()) {
 			hash.assign(it->second.c_str(), it->second.size());
-			DatIO->Dat2HTML(hash, html);
+			DatIO->Dat2HTML(hash, html, encoding);
 		}
 
 		if (html.empty())
@@ -1129,7 +1130,7 @@
 		HTTPHeader header(HTTPHEADERTYPE_RESPONSE);
 		header.status = 200;
 		AddResponseHeaderFields(header, Profile);
-		AddContentFields(header, html.size(), "text/html", "shift_jis");
+		AddContentFields(header, html.size(), "text/html", encoding.c_str());
 
 		ss->Lock();
 		header.Make(ss->sbuff);

Modified: branches/BRANCH_0043/o2on/src.o2on/dataconv.cpp
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/dataconv.cpp	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/dataconv.cpp	2008-04-18 05:42:26 UTC (rev 72)
@@ -20,6 +20,7 @@
 #include <sstream>
 #include <boost/regex.hpp>
 #include <cassert>
+#include <babel.h>
 
 const char *hex 	= "0123456789abcdef";
 const wchar_t *whex = L"0123456789abcdef";
@@ -770,6 +771,44 @@
 }
 
 // ---------------------------------------------------------------------------
+//	sjis_or_euc 
+//	sjis2euc
+// ---------------------------------------------------------------------------
+
+bool sjis_or_euc(const string &in, string &encoding)
+{
+	babel::init_babel();
+	switch (babel::analyze_base_encoding(in)) {
+		case babel::base_encoding::sjis:
+			encoding = "shift_jis";
+			return true;
+		case babel::base_encoding::euc:
+			encoding = "euc-jp";
+			return true;
+	}
+	return false;
+}
+bool sjis_or_euc(const string &in, wstring &encoding)
+{
+	babel::init_babel();
+	switch (babel::analyze_base_encoding(in)) {
+		case babel::base_encoding::sjis:
+			encoding = L"shift_jis";
+			return true;
+		case babel::base_encoding::euc:
+			encoding = L"euc-jp";
+			return true;
+	}
+	return false;
+}
+void sjis2euc(string &inout)
+{
+	babel::init_babel();
+	inout = babel::sjis_to_euc(inout);
+}
+
+
+// ---------------------------------------------------------------------------
 //	convertGTLT 
 //	
 // ---------------------------------------------------------------------------

Modified: branches/BRANCH_0043/o2on/src.o2on/dataconv.h
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/dataconv.h	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/dataconv.h	2008-04-18 05:42:26 UTC (rev 72)
@@ -72,6 +72,10 @@
 void unicode2ascii(const wchar_t *w, size_t len, string &a);
 void unicode2ascii(const wstring &w, string &a);
 
+extern bool sjis_or_euc(const string &in, string &encoding);
+extern bool sjis_or_euc(const string &in, wstring &encoding);
+extern void sjis2euc(string &inout);
+
 void convertGTLT(const string &in, string &out);
 void convertGTLT(const wstring &in, wstring &out);
 

Modified: branches/BRANCH_0043/o2on/src.o2on/o2on.vcproj
===================================================================
--- branches/BRANCH_0043/o2on/src.o2on/o2on.vcproj	2008-04-06 15:02:33 UTC (rev 71)
+++ branches/BRANCH_0043/o2on/src.o2on/o2on.vcproj	2008-04-18 05:42:26 UTC (rev 72)
@@ -60,7 +60,7 @@
 				FavorSizeOrSpeed="1"
 				OmitFramePointers="true"
 				WholeProgramOptimization="true"
-				AdditionalIncludeDirectories="..\..\sqlite;..\..\zlib"
+				AdditionalIncludeDirectories="..\..\sqlite;..\..\zlib;..\..\babel"
 				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;PROJ_SAX2;XML_LIBRARY"
 				StringPooling="false"
 				RuntimeLibrary="0"
@@ -3427,6 +3427,14 @@
 				>
 			</File>
 		</Filter>
+		<Filter
+			Name="babel"
+			>
+			<File
+				RelativePath="..\..\babel\babel.cpp"
+				>
+			</File>
+		</Filter>
 	</Files>
 	<Globals>
 	</Globals>




o2on-svn メーリングリストの案内
Back to archive index