• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión0be998724ab378203f0039ba905f6095782ab769 (tree)
Tiempo2012-03-27 00:09:18
Autorqwerty2501 <qwerty2501@user...>
Commiterqwerty2501

Log Message

cookie取得処理完全実装

Cambiar Resumen

Diferencia incremental

Binary files a/nlite.suo and b/nlite.suo differ
--- a/nlite_common/bugreport.cpp
+++ b/nlite_common/bugreport.cpp
@@ -2,41 +2,64 @@
22 #include "appinfo.h"
33 #include "function.h"
44 #include "bugreport.h"
5-
5+#include "commanage.h"
66
77 #include "namespace_start.h"
88
99
10-Bool BugTransfer::Report(BugTransfer &bug){
10+Bool BugTransfer::Report()const{
1111
1212 Bool rslt = false;
13- CWinHttpClient httpClient;
13+
1414 NString userId;
1515 GetnliteUserId(userId);
1616 nstringstream bugmessage;
1717
1818 bugmessage << _T("version=") << CApplicationInfo::getProductVersion() << _T("&");
1919 bugmessage << _T("nliteUserId=") << userId << _T("&");
20- bugmessage << _T("summary=") << bug.summary << _T("&");
21- bugmessage << _T("function=") << bug.function << _T("&");
22- bugmessage << _T("sourcefile=") << bug.sourcefile << _T("&");
23- bugmessage << _T("line=") << bug.line << _T("&");
24- bugmessage << _T("windowsErrorCode=") << bug.windowsErrorCode << _T("&");
25- bugmessage << _T("windowsErrorMessage=") << bug.windowsErrorMessage << _T("&");
20+ bugmessage << _T("summary=") << summary << _T("&");
21+ bugmessage << _T("function=") << function << _T("&");
22+ bugmessage << _T("sourcefile=") << sourcefile << _T("&");
23+ bugmessage << _T("line=") << line << _T("&");
24+ bugmessage << _T("windowsErrorCode=") << windowsErrorCode << _T("&");
25+ bugmessage << _T("windowsErrorMessage=") << windowsErrorMessage << _T("&");
2626 bugmessage << _T("osVersion=") << GetWindowsVersion();
2727
2828
2929 nregex reg(_T("[\r|\n]"));
3030 NString message(std::regex_replace(bugmessage.str(),reg,NString(_T(""))));
3131
32- //MString mmessage;
33- //ToUTF8(mmessage,message);
32+ CWinHttpClient httpClient;
3433 httpClient->Open(_T("POST"),_T("http://nlite.sourceforge.jp/cgi-bin/bugreport.rb"));
3534 httpClient->SetRequestHeader(_T("Content-Type"),_T("application/x-www-form-urlencoded"));
3635 httpClient->Send(message.c_str());
37- std::wcout << message << std::endl;
3836 return rslt;
3937 }
4038
4139
40+CBugReporter::CBugReporter(){
41+
42+
43+}
44+
45+CBugReporter::~CBugReporter(){
46+
47+ this->m_threadgroup.join_all();
48+
49+}
50+
51+Void CBugReporter::Report(const BugTransfer& bug){
52+
53+
54+
55+
56+ m_threadgroup.create_thread([
57+ bug](Void) -> Bool {
58+ CComManage commanage;
59+ return bug.Report();
60+ });
61+
62+ return;
63+}
64+
4265 #include "namespace_end.h"
\ No newline at end of file
--- a/nlite_common/bugreport.h
+++ b/nlite_common/bugreport.h
@@ -1,9 +1,13 @@
11 #pragma once
2-
2+#include <boost\thread.hpp>
33 #include "define.h"
44 #include "http.h"
55 #include "windowsAPI.h"
6+#include "singleton.h"
7+
8+
69 #include "namespace_start.h"
10+
711 struct BugTransfer{
812 NString summary;
913 NString line;
@@ -15,7 +19,28 @@ struct BugTransfer{
1519
1620
1721 public:
18- static Bool Report(BugTransfer &bug);
22+ Bool Report()const;
23+
24+};
25+
26+
27+
28+class CBugReporter:public SingletonT<CBugReporter>{
29+
30+private:
31+ boost::thread_group m_threadgroup;
32+
33+
34+public:
35+ CBugReporter();
36+
37+ ~CBugReporter();
38+
39+
40+
41+public:
42+ Void Report(const BugTransfer& bug);
43+
1944
2045 };
2146
--- /dev/null
+++ b/nlite_common/commanage.h
@@ -0,0 +1,24 @@
1+#pragma once
2+
3+#include <Windows.h>
4+#include "namespace_start.h"
5+
6+
7+class CComManage{
8+
9+public:
10+
11+ CComManage(){
12+ ::CoInitialize(nullptr);
13+ }
14+
15+ ~CComManage(){
16+
17+ ::CoUninitialize();
18+ }
19+
20+
21+};
22+
23+
24+#include "namespace_end.h"
\ No newline at end of file
--- a/nlite_common/http.cpp
+++ b/nlite_common/http.cpp
@@ -1,9 +1,11 @@
11 #include "stdafx.h"
22 #include "http.h"
33
4-
4+#include "namespace_start.h"
55 CWinHttpClient::CWinHttpClient(){
66
77 this->CreateInstance(WinHttp::CLSID_WinHttpRequest);
88
9-}
\ No newline at end of file
9+}
10+
11+#include "namespace_end.h"
\ No newline at end of file
--- a/nlite_common/http.h
+++ b/nlite_common/http.h
@@ -1,9 +1,12 @@
11 #pragma once
22 #import "winhttp.dll" named_guids
33
4+
5+#include "namespace_start.h"
46 class CWinHttpClient:public WinHttp::IWinHttpRequestPtr{
57
68 public:
79 CWinHttpClient();
810
9-};
\ No newline at end of file
11+};
12+#include "namespace_end.h"
\ No newline at end of file
--- a/nlite_common/nexception.cpp
+++ b/nlite_common/nexception.cpp
@@ -73,7 +73,9 @@ Bool Exception:: Report(){
7373 bug.line = boost::lexical_cast<NString>(getLineNo());
7474 bug.windowsErrorCode = boost::lexical_cast<NString>(osErrorCode);
7575 GetWindowsErrorMessage(bug.windowsErrorMessage,osErrorCode);
76- BugTransfer::Report(bug);
76+
77+ auto &reporter = CBugReporter::GetInstance();
78+ reporter.Report(bug);
7779
7880
7981 return false;
--- a/nlite_common/nlite_common.vcxproj
+++ b/nlite_common/nlite_common.vcxproj
@@ -104,6 +104,7 @@
104104 <ItemGroup>
105105 <ClInclude Include="appinfo.h" />
106106 <ClInclude Include="bugreport.h" />
107+ <ClInclude Include="commanage.h" />
107108 <ClInclude Include="define.h" />
108109 <ClInclude Include="function.h" />
109110 <ClInclude Include="http.h" />
@@ -111,6 +112,7 @@
111112 <ClInclude Include="namespace_start.h" />
112113 <ClInclude Include="nexception.h" />
113114 <ClInclude Include="raii.h" />
115+ <ClInclude Include="singleton.h" />
114116 <ClInclude Include="stdafx.h" />
115117 <ClInclude Include="targetver.h" />
116118 <ClInclude Include="unit_test.h" />
--- a/nlite_common/nlite_common.vcxproj.filters
+++ b/nlite_common/nlite_common.vcxproj.filters
@@ -60,6 +60,12 @@
6060 <ClInclude Include="raii.h">
6161 <Filter>ヘッダー ファイル</Filter>
6262 </ClInclude>
63+ <ClInclude Include="singleton.h">
64+ <Filter>ヘッダー ファイル</Filter>
65+ </ClInclude>
66+ <ClInclude Include="commanage.h">
67+ <Filter>ヘッダー ファイル</Filter>
68+ </ClInclude>
6369 </ItemGroup>
6470 <ItemGroup>
6571 <ClCompile Include="stdafx.cpp">
--- /dev/null
+++ b/nlite_common/singleton.h
@@ -0,0 +1,21 @@
1+#pragma once
2+
3+
4+#include "namespace_start.h"
5+template<typename T>
6+class SingletonT{
7+
8+protected:
9+ SingletonT(){}
10+
11+public:
12+ static T &GetInstance(){
13+
14+ static T target;
15+
16+
17+ return target;
18+ }
19+
20+};
21+#include "namespace_end.h"
\ No newline at end of file
--- a/nlite_common/stdafx.h
+++ b/nlite_common/stdafx.h
@@ -22,6 +22,7 @@
2222 #include <strsafe.h>
2323 #include <regex>
2424 #include <array>
25+#include <boost\thread.hpp>
2526 #include <boost\test\unit_test.hpp>
2627 #include <boost\lexical_cast.hpp>
2728 #include <boost\utility.hpp>
--- a/nlite_common/unit_test.cpp
+++ b/nlite_common/unit_test.cpp
@@ -14,15 +14,6 @@ Void UnitTest(){
1414 std::wcout << GetWindowsVersion() << std::endl;
1515
1616
17- try{
18-
19- throw Exception(_T("testerror"),__LINE__,_T(__FILE__),_T(__FUNCTION__));
20-
21- } catch(Exception &e){
22- e.Report();
23-
24-
25- }
2617
2718 /*
2819 BOOST_CHECK(GetWindowsVersion().length() > 0);
@@ -45,7 +36,20 @@ Void UnitTest(){
4536 BOOST_CHECK(FAILED(result.m_hResult));
4637
4738 */
48-
39+
40+ /*
41+ for(int i = 0;i < 10;i++){
42+ try{
43+
44+ throw Exception(_T("testerror"),__LINE__,_T(__FILE__),_T(__FUNCTION__));
45+
46+ } catch(Exception &e){
47+ e.Report();
48+
49+
50+ }
51+ }
52+ */
4953 }
5054
5155
--- a/nlite_cookie/cookieGetResult.cpp
+++ b/nlite_cookie/cookieGetResult.cpp
@@ -1,6 +1,8 @@
11 #include "stdafx.h"
2+#include <nlite_common\bugreport.h>
23 #include "cookieGetResult.h"
3-
4+#include "cookiemaster.h"
5+#include <nlite_common\windowsAPI.h>
46
57 #include "namespace_start.h"
68
@@ -11,6 +13,62 @@ CCookieGetResult::CCookieGetResult(browsertype::BrowserType bt):
1113
1214 {}
1315
16+Void CCookieGetResult::Report(){
17+
18+ BugTransfer bug;
19+
20+ bug.function = _T("cookieGetFunction");
21+ bug.line = _T("0");
22+ bug.sourcefile = _T("cookieGetFile");
23+ nstringstream ns;
24+ NString btstr = CCookieMaster::BrowserTypeToString(this->browserType);
25+ NString rcstr = CCookieMaster::ResultCodeToString(this->resultCode);
26+ ns << _T("BT:") << btstr << _T(",RC:") << rcstr << _T(",");
27+ bug.windowsErrorCode = _T("");
28+ bug.windowsErrorMessage =_T("");
29+ switch(this->resultCode){
30+
31+
32+ case resultcode::ERR_SQLITE:
33+
34+ ns << _T("sqliteerr:") << this->GetExtendCode().sqliteResult;
35+
36+ break;
37+
38+ case resultcode::ERR_IEAPI:
39+
40+ ns << _T("IEnomalerr:");
41+ goto winerr;
42+
43+ case resultcode::ERR_IEAPI_SEC:
44+
45+ ns << _T("IESecerr:");
46+ goto winerr;
47+
48+winerr:
49+ {
50+ NString winerrStr;
51+
52+ bug.windowsErrorCode = boost::lexical_cast<NString>(this->GetExtendCode().hResult);
53+ GetWindowsErrorMessage(winerrStr,this->GetExtendCode().hResult);
54+ bug.windowsErrorMessage = winerrStr;
55+ }
56+ break;
57+
58+ case resultcode::OK:
59+ case resultcode::UNDEFINED:
60+
61+ break;
62+
63+
64+ }
65+ bug.summary = ns.str();
66+
67+ auto &reporter = CBugReporter::GetInstance();
68+ reporter.Report(bug);
69+
70+
71+}
1472
1573
1674 Void CCookieGetResult::SetFindFlag(Bool findFlag){
--- a/nlite_cookie/cookieGetResult.h
+++ b/nlite_cookie/cookieGetResult.h
@@ -52,6 +52,12 @@ public:
5252 ///
5353 CCookieGetResult(browsertype::BrowserType bt);
5454
55+
56+ ///
57+ ///報告関数
58+ ///
59+ Void Report();
60+
5561 };
5662
5763 static_assert(sizeof(CCookieGetResult) <= 8,"CCookieGetResult size error");
--- a/nlite_cookie/cookieGetter.h
+++ b/nlite_cookie/cookieGetter.h
@@ -25,6 +25,14 @@ public:
2525 return resultList;
2626 }
2727
28+ ~CCookieGetterT(){
29+
30+ for each(CCookieGetResult rslt in resultList){
31+
32+ rslt.Report();
33+ }
34+
35+ }
2836
2937 Bool GetCookie(const NString &domein,const NString &name,CCookie &cookie){
3038
@@ -46,14 +54,9 @@ protected:
4654 return false;
4755
4856 }
49- /*
50- CCookieGetResult ForceSearch(const Byte* data,UInt dataSize,const NString &domein,const NString &name,CCookie &cookie){
5157
52- throw Exception(_T("ForceSearchが実装されていません"),__LINE__,_T(__FILE__),_T(__FUNCTION__));
58+
5359
54- return CCookieGetResult(browsertype::UNDEFINED);
55- }
56- */
5760
5861 };
5962
--- /dev/null
+++ b/nlite_cookie/cookiemaster.cpp
@@ -0,0 +1,114 @@
1+#include "stdafx.h"
2+#include <nlite_common\nexception.h>
3+#include "iecookiegetter.h"
4+#include "firefoxcookiegetter.h"
5+#include "iecomponentcookiegetter.h"
6+#include "chromecookiegetter.h"
7+#include "safaricookiegetter.h"
8+#include "operacookiegetter.h"
9+#include "cookiemaster.h"
10+
11+
12+
13+#include "namespace_start.h"
14+
15+
16+
17+Bool CCookieMaster::GetCookie(browsertype::BrowserType bt,const NString &domein,const NString &name,CCookie &cookie){
18+
19+ Bool result = false;
20+ switch(bt){
21+
22+ case browsertype::IE:
23+ {
24+ CIECookieGetter iecookie;
25+ result = iecookie.GetCookie(domein,name,cookie);
26+
27+ }
28+ break;
29+ case browsertype::FIREFOX:
30+ {
31+ CFireFoxCookieGetter firefoxcookie;
32+ result = firefoxcookie.GetCookie(domein,name,cookie);
33+
34+ }
35+ break;
36+ case browsertype::CHROME:
37+ {
38+ CChromeCookieGetter chromecookie;
39+ result = chromecookie.GetCookie(domein,name,cookie);
40+
41+ }
42+ break;
43+ case browsertype::SAFARI:
44+ {
45+ CSafariCookieGetter safaricookie;
46+ result = safaricookie.GetCookie(domein,name,cookie);
47+
48+ }
49+ break;
50+
51+ case browsertype::OPERA:
52+ {
53+ COperaCookieGetter operacookie;
54+ result = operacookie.GetCookie(domein,name,cookie);
55+
56+ }
57+ break;
58+ case browsertype::IECOMPONENT:
59+ {
60+ CIEComponentGetter iecomcookie;
61+ result = iecomcookie.GetCookie(domein,name,cookie);
62+ }
63+ break;
64+ case browsertype::UNDEFINED:
65+ {
66+
67+ THROW_EXCEPTION(Exception,_T("クッキー取得に指定されたブラウザの種類が未定義です"));
68+
69+ }
70+ break;
71+ default:
72+ {
73+ THROW_EXCEPTION(Exception,_T("クッキー取得に指定されたブラウザの種類が不明な値です"));
74+
75+
76+ }
77+ break;
78+ }
79+
80+ return result;
81+}
82+
83+
84+const NChar *CCookieMaster::BrowserTypeToString(browsertype::BrowserType bt){
85+
86+ switch(bt){
87+ case browsertype::IE: return _T("IE");
88+ case browsertype::FIREFOX:return _T("FireFox");
89+ case browsertype::CHROME:return _T("Chrome");
90+ case browsertype::SAFARI:return _T("Safari");
91+ case browsertype::OPERA:return _T("Opera");
92+ case browsertype::IECOMPONENT:return _T("IEComponent");
93+ case browsertype::UNDEFINED:return _T("UnDefined");
94+
95+ default:return _T("UnKnown");
96+
97+ }
98+
99+}
100+
101+const NChar *CCookieMaster::ResultCodeToString(resultcode::ResultCode rc){
102+ switch(rc){
103+ case resultcode::OK:return _T("OK");
104+ case resultcode::ERR_SQLITE:return _T("Err_Sqlite");
105+ case resultcode::ERR_IEAPI:return _T("Err_IE");
106+ case resultcode::ERR_IEAPI_SEC:return _T("Err_IESec");
107+ case resultcode::UNDEFINED :return _T("Undefined");
108+
109+ default:return _T("UnKnown");
110+ }
111+}
112+
113+
114+#include "namespace_end.h"
\ No newline at end of file
--- /dev/null
+++ b/nlite_cookie/cookiemaster.h
@@ -0,0 +1,27 @@
1+#pragma once
2+
3+#include <nlite_common\singleton.h>
4+#include "define.h"
5+#include "cookie.h"
6+
7+#include "namespace_start.h"
8+
9+
10+
11+class CCookieMaster:public SingletonT<CCookieMaster>{
12+
13+
14+public:
15+ Bool GetCookie(browsertype::BrowserType bt,const NString &domein,const NString &name,CCookie &cookie);
16+
17+
18+ static const NChar *BrowserTypeToString(browsertype::BrowserType bt);
19+
20+ static const NChar *ResultCodeToString(resultcode::ResultCode rc);
21+
22+};
23+
24+
25+
26+
27+#include "namespace_end.h"
\ No newline at end of file
--- a/nlite_cookie/ieapicookiegetter.h
+++ b/nlite_cookie/ieapicookiegetter.h
@@ -55,6 +55,7 @@ protected:
5555 val = std::regex_replace(val,reg,NString(_T("")));
5656 cookie.SetCookieValue(val);
5757 result.SetFindFlag(true);
58+ result.SetResultCode(resultcode::OK);
5859 } else {
5960
6061
--- a/nlite_cookie/iecomponentcookiegetter.cpp
+++ b/nlite_cookie/iecomponentcookiegetter.cpp
@@ -9,7 +9,7 @@ Bool CIEComponentGetter::GetCookieInternal(const NString &domein,const NString &
99
1010 CCookieGetResult result = this->GetCookieIEAPI(domein,name,cookie,false);
1111
12- if(result.GetResultCode() != resultcode::OK){
12+ if(result.GetResultCode() != resultcode::OK || (!result.IsFound())){
1313
1414 resultList.push_back(result);
1515 CCookieGetResult forceresult = CIEComponentGetter::ForceSearchFiles(this->normalDirectry,domein,name,cookie,CIEComponentGetter::Fancta);
--- a/nlite_cookie/iecookiegetter.cpp
+++ b/nlite_cookie/iecookiegetter.cpp
@@ -16,7 +16,7 @@ Bool CIECookieGetter::GetCookieInternal(const NString &domein,const NString &nam
1616 Bool secFlag = IEIsSecurityMode();
1717 CCookieGetResult result = this->GetCookieIEAPI(domein,name,cookie,secFlag);
1818
19- if(result.GetResultCode() != resultcode::OK){
19+ if(result.GetResultCode() != resultcode::OK || (!result.IsFound())){
2020
2121 resultList.push_back(result);
2222 CCookieGetResult forceresult = CIECookieGetter::ForceSearchFiles(secFlag ? this->securityCookiedir : this->normalDirectry,domein,name,cookie,CIECookieGetter::Fancta);
--- a/nlite_cookie/nlite_cookie.vcxproj
+++ b/nlite_cookie/nlite_cookie.vcxproj
@@ -103,6 +103,7 @@
103103 </ItemGroup>
104104 <ItemGroup>
105105 <ClInclude Include="chromecookiegetter.h" />
106+ <ClInclude Include="cookiemaster.h" />
106107 <ClInclude Include="iecomponentcookiegetter.h" />
107108 <ClInclude Include="cookie.h" />
108109 <ClInclude Include="cookieGetResult.h" />
@@ -126,6 +127,7 @@
126127 <ClCompile Include="chromecookiegetter.cpp" />
127128 <ClCompile Include="cookie.cpp" />
128129 <ClCompile Include="cookieGetResult.cpp" />
130+ <ClCompile Include="cookiemaster.cpp" />
129131 <ClCompile Include="firefoxcookiegetter.cpp" />
130132 <ClCompile Include="iecomponentcookiegetter.cpp" />
131133 <ClCompile Include="iecookiegetter.cpp" />
--- a/nlite_cookie/nlite_cookie.vcxproj.filters
+++ b/nlite_cookie/nlite_cookie.vcxproj.filters
@@ -75,6 +75,9 @@
7575 <ClInclude Include="safaricookiegetter.h">
7676 <Filter>ヘッダー ファイル</Filter>
7777 </ClInclude>
78+ <ClInclude Include="cookiemaster.h">
79+ <Filter>ヘッダー ファイル</Filter>
80+ </ClInclude>
7881 </ItemGroup>
7982 <ItemGroup>
8083 <ClCompile Include="stdafx.cpp">
@@ -107,5 +110,8 @@
107110 <ClCompile Include="safaricookiegetter.cpp">
108111 <Filter>ソース ファイル</Filter>
109112 </ClCompile>
113+ <ClCompile Include="cookiemaster.cpp">
114+ <Filter>ソース ファイル</Filter>
115+ </ClCompile>
110116 </ItemGroup>
111117 </Project>
\ No newline at end of file
--- a/nlite_cookie/stdafx.h
+++ b/nlite_cookie/stdafx.h
@@ -18,4 +18,5 @@
1818 #include <boost\test\unit_test.hpp>
1919 #include <boost/format.hpp>
2020 #include <boost\lexical_cast.hpp>
21+#include <boost\thread.hpp>
2122 #include <atlfile.h>
--- a/nlite_cookie/unit_test.cpp
+++ b/nlite_cookie/unit_test.cpp
@@ -10,6 +10,7 @@
1010 #include "operacookiegetter.h"
1111 #include "iecookiegetter.h"
1212 #include "cookieGetter.h"
13+#include "cookiemaster.h"
1314 #include "unit_test.h"
1415
1516
@@ -22,6 +23,27 @@
2223
2324 class TestGetter:public CCookieGetterT<TestGetter>{};
2425
26+
27+static Void CookieManageTest(browsertype::BrowserType bt){
28+
29+ CCookie cookie;
30+ NString domein = _T("nicovideo.jp");
31+ NString name = _T("user_session");
32+ MString cookieval;
33+ NString browsertypestr = CCookieMaster::BrowserTypeToString(bt);
34+ MString browsertypestrm;
35+ ToSJIS(browsertypestrm,browsertypestr);
36+ auto &cookiemaster = CCookieMaster::GetInstance();
37+ Bool result = false;
38+ result = cookiemaster.GetCookie(bt,domein,name,cookie);
39+ ToSJIS(cookieval,cookie.GetCookieValue());
40+
41+ std::cout <<"browsertype:" << browsertypestrm << "result:" << result << "cookie:" << cookieval << std::endl;
42+
43+ BOOST_CHECK_MESSAGE(result,"cookieが取れませんでした");
44+
45+}
46+
2547 Void UnitTest(){
2648
2749 CCookieGetResult cookieResult(browsertype::UNDEFINED);
@@ -269,6 +291,13 @@ Void UnitTest(){
269291 }
270292
271293 }
294+
295+ CookieManageTest(browsertype::IE);
296+ CookieManageTest(browsertype::FIREFOX);
297+ CookieManageTest(browsertype::CHROME);
298+ CookieManageTest(browsertype::IECOMPONENT);
299+ CookieManageTest(browsertype::OPERA);
300+ CookieManageTest(browsertype::SAFARI);
272301 return;
273302
274303 }
--- a/nlite_test/nlite_test.cpp
+++ b/nlite_test/nlite_test.cpp
@@ -9,7 +9,7 @@
99
1010 #define BOOST_TEST_MODULE SimpleTest
1111
12-//#include "commontest.h"
12+#include "commontest.h"
1313 #include "cookietest.h"
1414
1515