Revisión | 455139b3ba32caef11606da1ad2539ca3bb54d17 (tree) |
---|---|
Tiempo | 2012-03-30 01:40:45 |
Autor | qwerty2501 <qwerty2501@user...> |
Commiter | qwerty2501 |
ニコ生api実装途中
@@ -30,9 +30,9 @@ Bool BugTransfer::Report()const{ | ||
30 | 30 | NString message(std::regex_replace(bugmessage.str(),reg,NString(_T("")))); |
31 | 31 | |
32 | 32 | CWinHttpClient httpClient; |
33 | - httpClient->Open(_T("POST"),_T("http://nlite.sourceforge.jp/cgi-bin/bugreport.rb")); | |
34 | - httpClient->SetRequestHeader(_T("Content-Type"),_T("application/x-www-form-urlencoded")); | |
35 | - httpClient->Send(message.c_str()); | |
33 | + httpClient.Open(_T("POST"),_T("http://nlite.sourceforge.jp/cgi-bin/bugreport.rb")); | |
34 | + httpClient.SetRequestHeader(_T("Content-Type"),_T("application/x-www-form-urlencoded")); | |
35 | + httpClient.Send(message.c_str()); | |
36 | 36 | return rslt; |
37 | 37 | } |
38 | 38 |
@@ -1,11 +1,55 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | +#include "define.h" | |
2 | 3 | #include "http.h" |
3 | 4 | |
4 | 5 | #include "namespace_start.h" |
5 | 6 | CWinHttpClient::CWinHttpClient(){ |
6 | 7 | |
7 | - this->CreateInstance(WinHttp::CLSID_WinHttpRequest); | |
8 | + m_ptr.CreateInstance(WinHttp::CLSID_WinHttpRequest); | |
8 | 9 | |
9 | 10 | } |
10 | 11 | |
12 | +CHResult CWinHttpClient::Open(const NString &method,const NString &url,const _variant_t &async){ | |
13 | + | |
14 | + return m_ptr->Open(method.c_str(),url.c_str(),async); | |
15 | + | |
16 | +} | |
17 | + | |
18 | + | |
19 | +CHResult CWinHttpClient::get_Response(IStream **ppStream){ | |
20 | + CComVariant var; | |
21 | + CHResult result = m_ptr->get_ResponseStream(&var); | |
22 | + | |
23 | + | |
24 | + if(result.IsSucceded()&& (VT_UNKNOWN == V_VT(&var) || VT_STREAM == V_VT(&var))){ | |
25 | + | |
26 | + result = V_UNKNOWN(&var)->QueryInterface(IID_IStream,reinterpret_cast<Void**>(ppStream)); | |
27 | + | |
28 | + | |
29 | + } | |
30 | + | |
31 | + return result; | |
32 | +} | |
33 | + | |
34 | +CHResult CWinHttpClient::SetRequestHeader(const NString &headerName,const NString &headerBody){ | |
35 | + | |
36 | + return m_ptr->SetRequestHeader(headerName.c_str(),headerBody.c_str()); | |
37 | +} | |
38 | + | |
39 | +CHResult CWinHttpClient::SetRequestHeader(const cookie::CCookie &val){ | |
40 | + | |
41 | + nstringstream ss; | |
42 | + | |
43 | + ss << val.GetName(); | |
44 | + ss << _T("="); | |
45 | + ss << val.GetCookieValue(); | |
46 | + | |
47 | + return m_ptr->SetRequestHeader(_T("Cookie"),ss.str().c_str()); | |
48 | + | |
49 | +} | |
50 | + | |
51 | +CHResult CWinHttpClient::Send(const _variant_t &value){ | |
52 | + | |
53 | + return m_ptr->Send(value); | |
54 | +} | |
11 | 55 | #include "namespace_end.h" |
\ No newline at end of file |
@@ -1,12 +1,77 @@ | ||
1 | 1 | #pragma once |
2 | +#include "commanage.h" | |
3 | +#include "windowsAPI.h" | |
4 | +#include "xmlReader.h" | |
5 | +#include <nlite_cookie\cookie.h> | |
2 | 6 | #import "winhttp.dll" named_guids |
3 | 7 | |
4 | 8 | |
5 | 9 | #include "namespace_start.h" |
6 | -class CWinHttpClient:public WinHttp::IWinHttpRequestPtr{ | |
7 | - | |
10 | +class CWinHttpClient { | |
11 | +private: | |
12 | + CComManage m_com; | |
13 | + WinHttp::IWinHttpRequestPtr m_ptr; | |
8 | 14 | public: |
15 | + | |
16 | + /// | |
17 | + ///URLオープン | |
18 | + /// | |
19 | + CHResult Open(const NString &method,const NString &url,const _variant_t &async = vtMissing); | |
20 | + | |
21 | + | |
22 | + /// | |
23 | + ///レスポンスからIStreamを取得 | |
24 | + /// | |
25 | + CHResult get_Response(IStream **ppStream); | |
26 | + | |
27 | + /// | |
28 | + ///ヘッダセット | |
29 | + /// | |
30 | + CHResult SetRequestHeader(const NString &headerName,const NString &headerBody); | |
31 | + | |
32 | + CHResult SetRequestHeader(const cookie::CCookie &val); | |
33 | + | |
34 | + /// | |
35 | + ///データ送信 | |
36 | + /// | |
37 | + CHResult Send(const _variant_t &value = vtMissing); | |
38 | + | |
9 | 39 | CWinHttpClient(); |
10 | 40 | |
41 | + | |
42 | + | |
43 | + // | |
44 | + //テンプレート関数 | |
45 | + // | |
46 | + template<typename F> | |
47 | + CHResult get_ResponseXml(F func){ | |
48 | + | |
49 | + CComPtr<IStream> pStream; | |
50 | + CHResult result = this->get_Response(&pStream); | |
51 | + | |
52 | + if(result.IsSucceded()){ | |
53 | + | |
54 | + CXmlReader xmlReader; | |
55 | + | |
56 | + result = xmlReader.Create(); | |
57 | + | |
58 | + if(result.IsSucceded()){ | |
59 | + | |
60 | + result = xmlReader.SetInput(pStream); | |
61 | + | |
62 | + if(result.IsSucceded()){ | |
63 | + | |
64 | + result = func(xmlReader); | |
65 | + } | |
66 | + } | |
67 | + | |
68 | + } | |
69 | + | |
70 | + | |
71 | + return result; | |
72 | + } | |
73 | + | |
74 | + | |
75 | + | |
11 | 76 | }; |
12 | 77 | #include "namespace_end.h" |
\ No newline at end of file |
@@ -0,0 +1,10 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | + | |
4 | +#define ASSERT(e) assert(e) | |
5 | + | |
6 | +#ifdef NDEBUG | |
7 | +#define VERIFY(expression) expression | |
8 | +#else // #ifdef NDEBUG | |
9 | +#define VERIFY(expression) assert( 0 != (expression) ) | |
10 | +#endif // #ifdef NDEBUG | |
\ No newline at end of file |
@@ -108,6 +108,7 @@ | ||
108 | 108 | <ClInclude Include="define.h" /> |
109 | 109 | <ClInclude Include="function.h" /> |
110 | 110 | <ClInclude Include="http.h" /> |
111 | + <ClInclude Include="macro.h" /> | |
111 | 112 | <ClInclude Include="namespace_end.h" /> |
112 | 113 | <ClInclude Include="namespace_start.h" /> |
113 | 114 | <ClInclude Include="nexception.h" /> |
@@ -118,6 +119,8 @@ | ||
118 | 119 | <ClInclude Include="unit_test.h" /> |
119 | 120 | <ClInclude Include="use_namespace.h" /> |
120 | 121 | <ClInclude Include="windowsAPI.h" /> |
122 | + <ClInclude Include="winhttphandle.h" /> | |
123 | + <ClInclude Include="xmlReader.h" /> | |
121 | 124 | </ItemGroup> |
122 | 125 | <ItemGroup> |
123 | 126 | <ClCompile Include="appInfo.cpp" /> |
@@ -133,6 +136,8 @@ | ||
133 | 136 | </ClCompile> |
134 | 137 | <ClCompile Include="unit_test.cpp" /> |
135 | 138 | <ClCompile Include="windowsAPI.cpp" /> |
139 | + <ClCompile Include="winhttphandle.cpp" /> | |
140 | + <ClCompile Include="xmlreader.cpp" /> | |
136 | 141 | </ItemGroup> |
137 | 142 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
138 | 143 | <ImportGroup Label="ExtensionTargets"> |
@@ -66,6 +66,15 @@ | ||
66 | 66 | <ClInclude Include="commanage.h"> |
67 | 67 | <Filter>ヘッダー ファイル</Filter> |
68 | 68 | </ClInclude> |
69 | + <ClInclude Include="macro.h"> | |
70 | + <Filter>ヘッダー ファイル</Filter> | |
71 | + </ClInclude> | |
72 | + <ClInclude Include="winhttphandle.h"> | |
73 | + <Filter>ヘッダー ファイル</Filter> | |
74 | + </ClInclude> | |
75 | + <ClInclude Include="xmlReader.h"> | |
76 | + <Filter>ヘッダー ファイル</Filter> | |
77 | + </ClInclude> | |
69 | 78 | </ItemGroup> |
70 | 79 | <ItemGroup> |
71 | 80 | <ClCompile Include="stdafx.cpp"> |
@@ -95,5 +104,11 @@ | ||
95 | 104 | <ClCompile Include="function.cpp"> |
96 | 105 | <Filter>ソース ファイル</Filter> |
97 | 106 | </ClCompile> |
107 | + <ClCompile Include="winhttphandle.cpp"> | |
108 | + <Filter>ソース ファイル</Filter> | |
109 | + </ClCompile> | |
110 | + <ClCompile Include="xmlreader.cpp"> | |
111 | + <Filter>ソース ファイル</Filter> | |
112 | + </ClCompile> | |
98 | 113 | </ItemGroup> |
99 | 114 | </Project> |
\ No newline at end of file |
@@ -14,7 +14,7 @@ | ||
14 | 14 | #include <Shlobj.h> |
15 | 15 | #include <Shlwapi.h> |
16 | 16 | #include <Iphlpapi.h> |
17 | -// TODO: プログラムに必要な追加ヘッダーをここで参照してください。 | |
17 | + | |
18 | 18 | #include <iostream> |
19 | 19 | #include <string> |
20 | 20 | #include <tchar.h> |
@@ -26,4 +26,7 @@ | ||
26 | 26 | #include <boost\test\unit_test.hpp> |
27 | 27 | #include <boost\lexical_cast.hpp> |
28 | 28 | #include <boost\utility.hpp> |
29 | -#include <stdexcept> | |
\ No newline at end of file | ||
29 | +#include <stdexcept> | |
30 | +#include <atlmem.h> | |
31 | +#include <atlbase.h> | |
32 | +#include <xmllite.h> | |
\ No newline at end of file |
@@ -270,22 +270,27 @@ HRESULT CHResult::operator=(HRESULT hResult){ | ||
270 | 270 | |
271 | 271 | } |
272 | 272 | |
273 | -CHResult::operator HRESULT(){ | |
273 | +CHResult::operator HRESULT()const{ | |
274 | 274 | |
275 | 275 | return this->m_hResult; |
276 | 276 | } |
277 | 277 | |
278 | -Bool CHResult::IsS_OK(){ | |
278 | +Bool CHResult::IsS_OK()const{ | |
279 | 279 | |
280 | 280 | return m_hResult == S_OK; |
281 | 281 | |
282 | 282 | } |
283 | 283 | |
284 | -Bool CHResult::IsSucceded(){ | |
284 | +Bool CHResult::IsSucceded()const{ | |
285 | 285 | |
286 | 286 | return SUCCEEDED(m_hResult); |
287 | 287 | } |
288 | 288 | |
289 | +Bool CHResult::IsFailed()const{ | |
290 | + | |
291 | + return FAILED(m_hResult); | |
292 | +} | |
293 | + | |
289 | 294 | |
290 | 295 | Bool operator==(const CHResult &result,HRESULT hResult){ |
291 | 296 |
@@ -383,7 +388,7 @@ Void GetWindowsErrorMessage(NString &buf,DWORD lastErrorCode){ | ||
383 | 388 | NString rslt; |
384 | 389 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lastErrorCode,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf,0,(va_list*)NULL); |
385 | 390 | |
386 | - buf = lpMsgBuf; | |
391 | + buf = lpMsgBuf != nullptr ? lpMsgBuf: _T(""); | |
387 | 392 | LocalFree(lpMsgBuf); |
388 | 393 | |
389 | 394 | return; |
@@ -1,6 +1,7 @@ | ||
1 | 1 | #pragma once |
2 | 2 | |
3 | 3 | #include <Windows.h> |
4 | + | |
4 | 5 | #include "unit_test.h" |
5 | 6 | #include "define.h" |
6 | 7 | #include "raii.h" |
@@ -26,11 +27,13 @@ public: | ||
26 | 27 | |
27 | 28 | HRESULT operator=(HRESULT hResult); |
28 | 29 | |
29 | - operator HRESULT(); | |
30 | + operator HRESULT()const; | |
31 | + | |
32 | + Bool IsS_OK()const; | |
30 | 33 | |
31 | - Bool IsS_OK(); | |
34 | + Bool IsSucceded()const; | |
32 | 35 | |
33 | - Bool IsSucceded(); | |
36 | + Bool IsFailed()const; | |
34 | 37 | |
35 | 38 | |
36 | 39 |
@@ -0,0 +1,112 @@ | ||
1 | + | |
2 | +#include "stdafx.h" | |
3 | +#include "winhttphandle.h" | |
4 | +#include "macro.h" | |
5 | + | |
6 | + | |
7 | +/* | |
8 | +#include "namespace_start.h" | |
9 | + | |
10 | + | |
11 | +// | |
12 | +//ハンドル管理 | |
13 | +// | |
14 | +WinHttpHandle::WinHttpHandle() : | |
15 | + m_handle(0) | |
16 | + {} | |
17 | + | |
18 | +WinHttpHandle::~WinHttpHandle() | |
19 | + { | |
20 | + Close(); | |
21 | + } | |
22 | + | |
23 | + | |
24 | + Bool WinHttpHandle::Attach(HINTERNET handle) | |
25 | + { | |
26 | + ASSERT(0 == m_handle); | |
27 | + m_handle = handle; | |
28 | + return 0 != m_handle; | |
29 | + } | |
30 | + | |
31 | + HINTERNET WinHttpHandle::Detach() | |
32 | + { | |
33 | + HANDLE handle = m_handle; | |
34 | + m_handle = 0; | |
35 | + return handle; | |
36 | + } | |
37 | + | |
38 | + Void WinHttpHandle::Close() | |
39 | + { | |
40 | + if (0 != m_handle) | |
41 | + { | |
42 | + VERIFY(::WinHttpCloseHandle(m_handle)); | |
43 | + m_handle = 0; | |
44 | + } | |
45 | + } | |
46 | + | |
47 | + | |
48 | + CHResult WinHttpHandle::SetOption(DWORD option,const Void* value,DWORD length) | |
49 | + { | |
50 | + if (!::WinHttpSetOption(m_handle, | |
51 | + option, | |
52 | + const_cast<void*>(value), | |
53 | + length)) | |
54 | + { | |
55 | + return HRESULT_FROM_WIN32(::GetLastError()); | |
56 | + } | |
57 | + | |
58 | + return S_OK; | |
59 | + } | |
60 | + | |
61 | + CHResult WinHttpHandle::QueryOption(DWORD option,Void* value,DWORD& length) const | |
62 | + { | |
63 | + if (!::WinHttpQueryOption(m_handle, | |
64 | + option, | |
65 | + value, | |
66 | + &length)) | |
67 | + { | |
68 | + return HRESULT_FROM_WIN32(::GetLastError()); | |
69 | + } | |
70 | + | |
71 | + return S_OK; | |
72 | + } | |
73 | + | |
74 | + | |
75 | +// | |
76 | +//セッション管理 | |
77 | +// | |
78 | +CHResult WinHttpSession::Initialize() | |
79 | +{ | |
80 | + if (!Attach(::WinHttpOpen(0, // no agent string | |
81 | + WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, | |
82 | + WINHTTP_NO_PROXY_NAME, | |
83 | + WINHTTP_NO_PROXY_BYPASS, | |
84 | + WINHTTP_FLAG_ASYNC))) | |
85 | + { | |
86 | + return HRESULT_FROM_WIN32(::GetLastError()); | |
87 | + } | |
88 | + | |
89 | + return S_OK; | |
90 | +} | |
91 | + | |
92 | +// | |
93 | +//接続管理 | |
94 | +// | |
95 | +CHResult WinHttpConnection::Initialize(PCWSTR serverName,INTERNET_PORT portNumber,const WinHttpSession& session) | |
96 | + { | |
97 | + if (!Attach(::WinHttpConnect(session.m_handle, | |
98 | + serverName, | |
99 | + portNumber, | |
100 | + 0))) // reserved | |
101 | + { | |
102 | + return HRESULT_FROM_WIN32(::GetLastError()); | |
103 | + } | |
104 | + | |
105 | + return S_OK; | |
106 | + } | |
107 | + | |
108 | + | |
109 | + | |
110 | + | |
111 | +#include "namespace_end.h" | |
112 | + */ | |
\ No newline at end of file |
@@ -0,0 +1,117 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +/* | |
4 | +#include <winhttp.h> | |
5 | +#include <atlmem.h> | |
6 | +#include <boost\noncopyable.hpp> | |
7 | +#include "define.h" | |
8 | +#include "windowsAPI.h" | |
9 | + | |
10 | + | |
11 | +#include "namespace_start.h" | |
12 | + | |
13 | + | |
14 | + | |
15 | +/// | |
16 | +///ハンドル管理 | |
17 | +/// | |
18 | +class WinHttpHandle:public boost::noncopyable | |
19 | +{ | |
20 | +public: | |
21 | + WinHttpHandle(); | |
22 | + | |
23 | + ~WinHttpHandle(); | |
24 | + | |
25 | + Bool Attach(HINTERNET handle); | |
26 | + | |
27 | + HINTERNET Detach(); | |
28 | + | |
29 | + Void Close(); | |
30 | + | |
31 | + CHResult SetOption(DWORD option,const Void* value,DWORD length); | |
32 | + | |
33 | + CHResult QueryOption(DWORD option,Void* value,DWORD& length) const; | |
34 | + | |
35 | + | |
36 | + | |
37 | + HINTERNET m_handle; | |
38 | +}; | |
39 | + | |
40 | + | |
41 | +/// | |
42 | +///セッション管理 | |
43 | +/// | |
44 | +class WinHttpSession : public WinHttpHandle | |
45 | +{ | |
46 | +public: | |
47 | + CHResult Initialize(); | |
48 | + | |
49 | +}; | |
50 | + | |
51 | + | |
52 | +class WinHttpConnection : public WinHttpHandle | |
53 | +{ | |
54 | +public: | |
55 | + CHResult Initialize(PCWSTR serverName,INTERNET_PORT portNumber,const WinHttpSession& session); | |
56 | + | |
57 | +}; | |
58 | + | |
59 | + | |
60 | +//template <typename T> | |
61 | +class WinHttpRequest : public WinHttpHandle | |
62 | +{ | |
63 | +public: | |
64 | + CHResult Initialize(PCWSTR path, | |
65 | + __in_opt PCWSTR verb, | |
66 | + const WinHttpConnection& connection) | |
67 | + { | |
68 | + m_buffer.Allocate(8 * 1024); | |
69 | + | |
70 | + WinHttpOpenRequest(connection.m_handle,verb, | |
71 | + // Call WinHttpOpenRequest and WinHttpSetStatusCallback. | |
72 | + } | |
73 | + | |
74 | + CHResult SendRequest(__in_opt PCWSTR headers, | |
75 | + DWORD headersLength, | |
76 | + __in_opt const void* optional, | |
77 | + DWORD optionalLength, | |
78 | + DWORD totalLength) | |
79 | + { | |
80 | + T* pT = static_cast<T*>(this); | |
81 | + | |
82 | + // Call WinHttpSendRequest with pT as the context value. | |
83 | + } | |
84 | + | |
85 | +protected: | |
86 | + static void CALLBACK Callback(HINTERNET handle, | |
87 | + DWORD_PTR context, | |
88 | + DWORD code, | |
89 | + void* info, | |
90 | + DWORD length) | |
91 | + { | |
92 | + if (0 != context) | |
93 | + { | |
94 | + T* pT = reinterpret_cast<T*>(context); | |
95 | + | |
96 | + HRESULT result = pT->OnCallback(code, | |
97 | + info, | |
98 | + length); | |
99 | + | |
100 | + if (FAILED(result)) | |
101 | + { | |
102 | + pT->OnResponseComplete(result); | |
103 | + } | |
104 | + } | |
105 | + } | |
106 | + | |
107 | + CHResult OnCallback(DWORD code, | |
108 | + const void* info, | |
109 | + DWORD length) | |
110 | + { | |
111 | + // Handle notifications here. | |
112 | + } | |
113 | + | |
114 | + CGlobalHeap m_buffer; | |
115 | +}; | |
116 | +#include "namespace_end.h" | |
117 | +*/ | |
\ No newline at end of file |
@@ -0,0 +1,40 @@ | ||
1 | +#include "stdafx.h" | |
2 | +#include "xmlReader.h" | |
3 | + | |
4 | +#include "namespace_start.h" | |
5 | + | |
6 | + | |
7 | +CHResult CXmlReader::Create(REFIID riid,IMalloc *pMalloc){ | |
8 | + | |
9 | + return CreateXmlReader(riid,reinterpret_cast<Void**>(&m_xmlReader),pMalloc); | |
10 | + | |
11 | +} | |
12 | + | |
13 | + | |
14 | +CHResult CXmlReader::SetInput(IStream *pStream){ | |
15 | + | |
16 | + return m_xmlReader->SetInput(pStream); | |
17 | +} | |
18 | + | |
19 | + | |
20 | +CHResult CXmlReader::Read(XmlNodeType *pXmlNodeType){ | |
21 | + | |
22 | + | |
23 | + return m_xmlReader->Read(pXmlNodeType); | |
24 | +} | |
25 | + | |
26 | +CHResult CXmlReader::GetLocalName(const NChar **ppLocalName,UInt *pLocalNameLen){ | |
27 | + | |
28 | + return m_xmlReader->GetLocalName(ppLocalName,pLocalNameLen); | |
29 | +} | |
30 | + | |
31 | +CHResult CXmlReader::GetValue(const NChar **ppValue,UInt *pValueLen = nullptr){ | |
32 | + | |
33 | + return m_xmlReader->GetValue(ppValue,pValueLen); | |
34 | +} | |
35 | +CHResult CXmlReader::MoveToFirstAttribute(){ | |
36 | + | |
37 | + return m_xmlReader->MoveToFirstAttribute(); | |
38 | +} | |
39 | + | |
40 | +#include "namespace_end.h" | |
\ No newline at end of file |
@@ -0,0 +1,33 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +#include <atlbase.h> | |
4 | +#include <xmllite.h> | |
5 | +#include "windowsAPI.h" | |
6 | + | |
7 | +#include "namespace_start.h" | |
8 | + | |
9 | + | |
10 | +class CXmlReader{ | |
11 | + | |
12 | +private: | |
13 | + CComPtr<IXmlReader> m_xmlReader; | |
14 | + | |
15 | +public: | |
16 | + CHResult Create(REFIID riid = __uuidof(IXmlReader),IMalloc *pMalloc = nullptr); | |
17 | + | |
18 | + CHResult SetInput(IStream *pStream); | |
19 | + | |
20 | + CHResult Read(XmlNodeType *pXmlNodeType); | |
21 | + | |
22 | + | |
23 | + CHResult GetLocalName(const NChar **ppLocalName,UInt *pLocalNameLen = nullptr); | |
24 | + | |
25 | + CHResult GetValue(const NChar **ppValue,UInt *pValueLen = nullptr); | |
26 | + | |
27 | + CHResult MoveToFirstAttribute(); | |
28 | + | |
29 | +}; | |
30 | + | |
31 | + | |
32 | + | |
33 | +#include "namespace_end.h" | |
\ No newline at end of file |
@@ -1,5 +1,6 @@ | ||
1 | 1 | #pragma once |
2 | 2 | |
3 | +#include <deque> | |
3 | 4 | |
4 | 5 | #include <nlite_common\define.h> |
5 | 6 |
@@ -37,4 +38,10 @@ public: | ||
37 | 38 | |
38 | 39 | }; |
39 | 40 | |
41 | + | |
42 | +/// | |
43 | +///クッキーリスト定義 | |
44 | +/// | |
45 | +typedef std::deque<CCookie> CookieList; | |
46 | + | |
40 | 47 | #include "namespace_end.h" |
\ No newline at end of file |
@@ -51,7 +51,9 @@ winerr: | ||
51 | 51 | |
52 | 52 | bug.windowsErrorCode = boost::lexical_cast<NString>(this->GetExtendCode().hResult); |
53 | 53 | GetWindowsErrorMessage(winerrStr,this->GetExtendCode().hResult); |
54 | - bug.windowsErrorMessage = winerrStr; | |
54 | + if(!winerrStr.empty()){ | |
55 | + bug.windowsErrorMessage = winerrStr; | |
56 | + } | |
55 | 57 | } |
56 | 58 | break; |
57 | 59 |
@@ -20,3 +20,4 @@ | ||
20 | 20 | #include <boost\lexical_cast.hpp> |
21 | 21 | #include <boost\thread.hpp> |
22 | 22 | #include <atlfile.h> |
23 | +#include <deque> | |
\ No newline at end of file |
@@ -299,12 +299,11 @@ Void UnitTest(){ | ||
299 | 299 | CookieManageTest(browsertype::OPERA); |
300 | 300 | CookieManageTest(browsertype::SAFARI); |
301 | 301 | |
302 | - | |
303 | 302 | /* |
304 | 303 | CCookieGetResult rslt(browsertype::UNDEFINED); |
305 | 304 | |
306 | - rslt.SetResultCode(resultcode::ERR_SQLITE); | |
307 | - rslt.SetSQLiteResult(-1); | |
305 | + rslt.SetResultCode(resultcode::ERR_IEAPI_SEC); | |
306 | + rslt.SetHResult(-1); | |
308 | 307 | rslt.Report(); |
309 | 308 | */ |
310 | 309 | return; |
@@ -0,0 +1,21 @@ | ||
1 | +#include "stdafx.h" | |
2 | +#include "define.h" | |
3 | +#include "auth.h" | |
4 | + | |
5 | +#include "namespace_start.h" | |
6 | + | |
7 | +Void CAuth::SetUserSession(cookie::CCookie &val){ | |
8 | + | |
9 | + this->user_session = val; | |
10 | +} | |
11 | + | |
12 | +const cookie::CCookie &CAuth::GetUserSession()const{ | |
13 | + | |
14 | + return this->user_session; | |
15 | +} | |
16 | + | |
17 | + | |
18 | + | |
19 | + | |
20 | + | |
21 | +#include "namespace_end.h" | |
\ No newline at end of file |
@@ -0,0 +1,26 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +#include <nlite_cookie\cookie.h> | |
4 | +#include "define.h" | |
5 | + | |
6 | +#include "namespace_start.h" | |
7 | + | |
8 | + | |
9 | +/// | |
10 | +///ニコニコ動画認証クラス | |
11 | +/// | |
12 | +class CAuth{ | |
13 | + | |
14 | +private: | |
15 | + cookie::CCookie user_session; | |
16 | + | |
17 | +public: | |
18 | + Void SetUserSession(cookie::CCookie &val); | |
19 | + | |
20 | + const cookie::CCookie &GetUserSession()const; | |
21 | + | |
22 | +}; | |
23 | + | |
24 | + | |
25 | + | |
26 | +#include "namespace_end.h" | |
\ No newline at end of file |
@@ -0,0 +1,4 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | + | |
4 | +#include <nlite_common\define.h> | |
\ No newline at end of file |
@@ -0,0 +1,2 @@ | ||
1 | +#include <nlite_common\namespace_end.h> | |
2 | +} | |
\ No newline at end of file |
@@ -0,0 +1,2 @@ | ||
1 | +#include <nlite_common\namespace_start.h> | |
2 | +namespace nicoapi{ | |
\ No newline at end of file |
@@ -102,15 +102,22 @@ | ||
102 | 102 | <None Include="ReadMe.txt" /> |
103 | 103 | </ItemGroup> |
104 | 104 | <ItemGroup> |
105 | + <ClInclude Include="auth.h" /> | |
106 | + <ClInclude Include="define.h" /> | |
107 | + <ClInclude Include="namespace_end.h" /> | |
108 | + <ClInclude Include="namespace_start.h" /> | |
105 | 109 | <ClInclude Include="stdafx.h" /> |
106 | 110 | <ClInclude Include="targetver.h" /> |
111 | + <ClInclude Include="unit_test.h" /> | |
107 | 112 | </ItemGroup> |
108 | 113 | <ItemGroup> |
114 | + <ClCompile Include="auth.cpp" /> | |
109 | 115 | <ClCompile Include="stdafx.cpp"> |
110 | 116 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> |
111 | 117 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UnitTest|Win32'">Create</PrecompiledHeader> |
112 | 118 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> |
113 | 119 | </ClCompile> |
120 | + <ClCompile Include="unit_test.cpp" /> | |
114 | 121 | </ItemGroup> |
115 | 122 | <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
116 | 123 | <ImportGroup Label="ExtensionTargets"> |
@@ -24,10 +24,31 @@ | ||
24 | 24 | <ClInclude Include="targetver.h"> |
25 | 25 | <Filter>ヘッダー ファイル</Filter> |
26 | 26 | </ClInclude> |
27 | + <ClInclude Include="namespace_start.h"> | |
28 | + <Filter>ヘッダー ファイル</Filter> | |
29 | + </ClInclude> | |
30 | + <ClInclude Include="namespace_end.h"> | |
31 | + <Filter>ヘッダー ファイル</Filter> | |
32 | + </ClInclude> | |
33 | + <ClInclude Include="unit_test.h"> | |
34 | + <Filter>ヘッダー ファイル</Filter> | |
35 | + </ClInclude> | |
36 | + <ClInclude Include="define.h"> | |
37 | + <Filter>ヘッダー ファイル</Filter> | |
38 | + </ClInclude> | |
39 | + <ClInclude Include="auth.h"> | |
40 | + <Filter>ヘッダー ファイル</Filter> | |
41 | + </ClInclude> | |
27 | 42 | </ItemGroup> |
28 | 43 | <ItemGroup> |
29 | 44 | <ClCompile Include="stdafx.cpp"> |
30 | 45 | <Filter>ソース ファイル</Filter> |
31 | 46 | </ClCompile> |
47 | + <ClCompile Include="unit_test.cpp"> | |
48 | + <Filter>ソース ファイル</Filter> | |
49 | + </ClCompile> | |
50 | + <ClCompile Include="auth.cpp"> | |
51 | + <Filter>ソース ファイル</Filter> | |
52 | + </ClCompile> | |
32 | 53 | </ItemGroup> |
33 | 54 | </Project> |
\ No newline at end of file |
@@ -0,0 +1,12 @@ | ||
1 | +#include "stdafx.h" | |
2 | +#include "define.h" | |
3 | +#include "unit_test.h" | |
4 | + | |
5 | +#include "namespace_start.h" | |
6 | +Void UnitTest(){ | |
7 | + | |
8 | + | |
9 | + | |
10 | + | |
11 | +} | |
12 | +#include "namespace_end.h" | |
\ No newline at end of file |
@@ -0,0 +1,5 @@ | ||
1 | +#include "namespace_start.h" | |
2 | + | |
3 | +#include <nlite_test\unit_test.h> | |
4 | + | |
5 | +#include "namespace_end.h" | |
\ No newline at end of file |
@@ -0,0 +1,33 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | + | |
4 | + | |
5 | +#include <boost\test\unit_test.hpp> | |
6 | +#include <nlite_nicoapi\unit_test.h> | |
7 | + | |
8 | + | |
9 | + | |
10 | + | |
11 | + | |
12 | +BOOST_AUTO_TEST_SUITE(nicoapi_test_suite) | |
13 | + | |
14 | + BOOST_AUTO_TEST_CASE(init_nlite_test_cookie){ | |
15 | + | |
16 | + | |
17 | + | |
18 | + } | |
19 | + | |
20 | + BOOST_AUTO_TEST_CASE(unit_test_nicoapi){ | |
21 | + | |
22 | + | |
23 | + nicoapi::UnitTest(); | |
24 | + | |
25 | + } | |
26 | + | |
27 | + | |
28 | + BOOST_AUTO_TEST_CASE(finalize_test_nicoapi){ | |
29 | + | |
30 | + | |
31 | + } | |
32 | + | |
33 | +BOOST_AUTO_TEST_SUITE_END() | |
\ No newline at end of file |
@@ -9,6 +9,7 @@ | ||
9 | 9 | |
10 | 10 | #define BOOST_TEST_MODULE SimpleTest |
11 | 11 | |
12 | +#include "nicoapitest.h" | |
12 | 13 | #include "commontest.h" |
13 | 14 | #include "cookietest.h" |
14 | 15 |
@@ -21,7 +22,6 @@ BOOST_AUTO_TEST_SUITE(end_test_suite) | ||
21 | 22 | |
22 | 23 | |
23 | 24 | |
24 | - | |
25 | 25 | std::string s; |
26 | 26 | |
27 | 27 | do{ |
@@ -37,3 +37,4 @@ BOOST_AUTO_TEST_SUITE_END() | ||
37 | 37 | |
38 | 38 | #pragma comment(lib,"nlite_common.lib") |
39 | 39 | #pragma comment(lib,"nlite_cookie.lib") |
40 | +#pragma comment(lib,"nlite_nicoapi.lib") | |
\ No newline at end of file |
@@ -115,6 +115,7 @@ | ||
115 | 115 | <ItemGroup> |
116 | 116 | <ClInclude Include="commontest.h" /> |
117 | 117 | <ClInclude Include="cookietest.h" /> |
118 | + <ClInclude Include="nicoapitest.h" /> | |
118 | 119 | <ClInclude Include="stdafx.h" /> |
119 | 120 | <ClInclude Include="targetver.h" /> |
120 | 121 | <ClInclude Include="unit_test.h" /> |
@@ -39,6 +39,9 @@ | ||
39 | 39 | <ClInclude Include="cookietest.h"> |
40 | 40 | <Filter>ヘッダー ファイル</Filter> |
41 | 41 | </ClInclude> |
42 | + <ClInclude Include="nicoapitest.h"> | |
43 | + <Filter>ヘッダー ファイル</Filter> | |
44 | + </ClInclude> | |
42 | 45 | </ItemGroup> |
43 | 46 | <ItemGroup> |
44 | 47 | <ClCompile Include="stdafx.cpp"> |