• R/O
  • SSH
  • HTTPS

ppregnessem: 提交


Commit MetaInfo

修订版113 (tree)
时间2010-06-28 00:28:59
作者kamoya

Log Message

NsmClientSocket tstring

更改概述

差异

--- trunk/ClientSocket/src/NsmClientSocket.cpp (revision 112)
+++ trunk/ClientSocket/src/NsmClientSocket.cpp (revision 113)
@@ -7,6 +7,8 @@
77 #include <winsock2.h>
88 #include <ws2tcpip.h>
99
10+#include "../../Common/dummy.h"
11+
1012 #include "ClientSocketConsts.h"
1113 #include "NsmClientSocket.h"
1214
@@ -21,7 +23,7 @@
2123 class AutoPtrAddrinfo
2224 {
2325 public:
24- ADDRINFO *Info;
26+ ADDRINFOT *Info;
2527
2628 AutoPtrAddrinfo()
2729 :Info()
@@ -29,7 +31,7 @@
2931
3032 ~AutoPtrAddrinfo()
3133 {
32- freeaddrinfo(Info);
34+ FreeAddrInfo(Info);
3335 }
3436 };
3537
@@ -38,9 +40,9 @@
3840 NsmClientSocket::WinsockInit::WinsockInit()
3941 {
4042 WSADATA wsa;
41- WSAStartup(WINSOCK_VERSION,&wsa);
43+ WSAStartup(WINSOCK_VERSION, &wsa);
4244
43- WNDCLASSEX wc = {0};
45+ WNDCLASSEX wc = {};
4446 wc.cbSize = sizeof(wc);
4547 wc.lpszClassName = TEXT("socket");
4648 wc.lpfnWndProc = WndProc;
@@ -57,11 +59,11 @@
5759
5860 // NsmClientSocket::FindByHandle -----------------------------------------------
5961
60- NsmClientSocket::FindByHandle::FindByHandle(const NsmClientSocket *const s)
62+ NsmClientSocket::FindByHandle::FindByHandle(const NsmClientSocket *s)
6163 :x(s)
6264 {}
6365
64- bool NsmClientSocket::FindByHandle::operator ()(const NsmClientSocketListSub &v) const
66+ bool NsmClientSocket::FindByHandle::operator()(const NsmClientSocketListSub &v) const
6567 {
6668 return v.get() == x;
6769 }
@@ -68,7 +70,7 @@
6870
6971 // NsmClientSocket -------------------------------------------------------------
7072
71- NsmClientSocket::NsmClientSocket(const NsmClientSocketInitInfo& initInfo,bool useProxy,int proxyType)
73+ NsmClientSocket::NsmClientSocket(const NsmClientSocketInitInfo &initInfo, bool useProxy, int proxyType)
7274 :InitInfo(initInfo)
7375 ,Socket(INVALID_SOCKET)
7476 ,Host()
@@ -84,9 +86,9 @@
8486
8587 Handle = CreateWindow(
8688 MAKEINTATOM(init.Atom),
87- 0,
89+ NULL,
8890 WS_OVERLAPPED,
89- 0,0,0,0,
91+ 0, 0, 0, 0,
9092 HWND_MESSAGE,
9193 NULL,
9294 NULL,
@@ -97,13 +99,13 @@
9799 {
98100 Close();
99101
100- PostMessage(Handle,WM_CLOSE,0,0);
102+ PostMessage(Handle, WM_CLOSE, 0, 0);
101103 }
102104
103- LRESULT CALLBACK NsmClientSocket::WndProc(const HWND hWnd,const UINT msg,const WPARAM wParam,const LPARAM lParam)
105+ LRESULT CALLBACK NsmClientSocket::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
104106 {
105107 const NsmClientSocket *const window = (msg != WM_CREATE) ?
106- reinterpret_cast<NsmClientSocket*>(GetWindowLongPtr(hWnd,GWLP_USERDATA))
108+ reinterpret_cast<NsmClientSocket*>(GetWindowLongPtr(hWnd, GWLP_USERDATA))
107109 : static_cast<NsmClientSocket*>(reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams);
108110
109111 if(window)
@@ -110,7 +112,7 @@
110112 switch(msg)
111113 {
112114 case WM_CREATE:
113- SetWindowLongPtr(hWnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(window));
115+ SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(window));
114116 return FALSE;
115117 case WM_WINSOCK:
116118 {
@@ -121,19 +123,19 @@
121123 {
122124 case FD_READ:
123125 if(WSAGETSELECTERROR(lParam))
124- window->DoError(SocketErrorType::Receive,WSAGetLastError());
126+ window->DoError(SocketErrorType::Receive, WSAGetLastError());
125127 else
126128 window->DoRead();
127129 return FALSE;
128130 case FD_WRITE:
129131 if(WSAGETSELECTERROR(lParam))
130- window->DoError(SocketErrorType::Send,WSAGetLastError());
132+ window->DoError(SocketErrorType::Send, WSAGetLastError());
131133 else
132134 window->DoWrite();
133135 return FALSE;
134136 case FD_CLOSE:
135137 if(WSAGETSELECTERROR(lParam))
136- window->DoError(SocketErrorType::Disconnect,WSAGetLastError());
138+ window->DoError(SocketErrorType::Disconnect, WSAGetLastError());
137139 else
138140 window->DoDisconnect();
139141 return FALSE;
@@ -151,7 +153,7 @@
151153 {
152154 if(InitInfo.lpOnConnect)
153155 InitInfo.lpOnConnect(
154- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
156+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
155157 }
156158
157159 void NsmClientSocket::DoConnecting() const
@@ -158,7 +160,7 @@
158160 {
159161 if(InitInfo.lpOnConnecting)
160162 InitInfo.lpOnConnecting(
161- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
163+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
162164 }
163165
164166 void NsmClientSocket::DoDisconnect() const
@@ -169,12 +171,12 @@
169171 __try
170172 {
171173 InitInfo.lpOnDisconnect(
172- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
174+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
173175 }
174176 __except(EXCEPTION_EXECUTE_HANDLER){}
175177 #else
176178 InitInfo.lpOnDisconnect(
177- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
179+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
178180 #endif
179181 }
180182 }
@@ -183,7 +185,7 @@
183185 {
184186 if(InitInfo.lpOnLookup)
185187 InitInfo.lpOnLookup(
186- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
188+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
187189 }
188190
189191 void NsmClientSocket::DoRead() const
@@ -190,7 +192,7 @@
190192 {
191193 if(InitInfo.lpOnRead)
192194 InitInfo.lpOnRead(
193- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
195+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
194196 }
195197
196198 void NsmClientSocket::DoWrite() const
@@ -197,7 +199,7 @@
197199 {
198200 if(InitInfo.lpOnWrite)
199201 InitInfo.lpOnWrite(
200- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data);
202+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data);
201203 }
202204
203205 void NsmClientSocket::DoError(int errtype, int errcode) const
@@ -204,7 +206,7 @@
204206 {
205207 if(InitInfo.lpOnError)
206208 InitInfo.lpOnError(
207- reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)),InitInfo.Data,errtype,errcode);
209+ reinterpret_cast<HNsmClientSocket>(const_cast<NsmClientSocket*>(this)), InitInfo.Data, errtype, errcode);
208210 }
209211
210212 //----
@@ -225,7 +227,7 @@
225227 Host = Address;
226228 }
227229
228- std::string host;
230+ tstring host;
229231 unsigned short port;
230232
231233 if(UseProxy)
@@ -248,7 +250,7 @@
248250 port = Port;
249251 }
250252
251- int err = DirectOpen(host,port);
253+ int err = DirectOpen(host, port);
252254 if(err)
253255 return err;
254256
@@ -281,45 +283,45 @@
281283 DoConnect();
282284
283285 // 非同期select
284- WSAAsyncSelect(Socket,Handle,WM_WINSOCK,FD_READ | FD_WRITE | FD_CLOSE);
286+ WSAAsyncSelect(Socket, Handle, WM_WINSOCK, FD_READ | FD_WRITE | FD_CLOSE);
285287
286288 return 0;
287289 }
288290
289- int NsmClientSocket::DirectOpen(const std::string &host,unsigned short port)
291+ int NsmClientSocket::DirectOpen(const tstring &host, unsigned short port)
290292 {
291293 // アドレスを変換する。
292- std::stringstream portStr;
294+ tstringstream portStr;
293295 portStr << port;
294296
295297 AutoPtrAddrinfo res;
296298
297- ADDRINFO hints = {0};
299+ ADDRINFOT hints = {};
298300 hints.ai_family = AF_INET;
299301 hints.ai_socktype = SOCK_STREAM;
300302
301303 DoLookup();
302304
303- int err = getaddrinfo(host.c_str(), portStr.str().c_str(), &hints, &res.Info);
305+ int err = GetAddrInfo(host.c_str(), portStr.str().c_str(), &hints, &res.Info);
304306 if(err != 0)
305307 return err;
306308
307- Socket = socket(hints.ai_family,hints.ai_socktype,hints.ai_protocol);
309+ Socket = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
308310
309311 // ソケットオープンに失敗
310312 if(Socket == INVALID_SOCKET)
311313 return 2;
312314
313- const ADDRINFO *it = res.Info;
314- for(; it != NULL; it = it->ai_next)
315+ const ADDRINFOT *it = res.Info;
316+ for(; it; it = it->ai_next)
315317 {
316318 /* connect()が成功したらloopを抜けます */
317- if(connect(Socket,it->ai_addr,static_cast<int>(it->ai_addrlen)) != SOCKET_ERROR)
319+ if(connect(Socket, it->ai_addr, static_cast<int>(it->ai_addrlen)) != SOCKET_ERROR)
318320 break;
319321 }
320322
321323 /* connectが全て失敗した場合 */
322- if(it == NULL)
324+ if(!it)
323325 {
324326 Close();
325327 return 3;
@@ -344,17 +346,18 @@
344346
345347 AutoPtrAddrinfo res;
346348
347- ADDRINFO hints = {0};
349+ ADDRINFOT hints = {};
348350 hints.ai_family = AF_INET;
349351 hints.ai_socktype = SOCK_STREAM;
350352
351353 DoLookup();
352354
353- int err = getaddrinfo(Host.c_str(), NULL, &hints, &res.Info);
355+ int err = GetAddrInfo(Host.c_str(), NULL, &hints, &res.Info);
356+
354357 if(err != 0)
355358 return err;
356359
357- Socks4Packet packet = {0};
360+ Socks4Packet packet = {};
358361 packet.Version = 4;
359362 packet.Command = 1;
360363 packet.DstPort = htons(Port);
@@ -363,7 +366,7 @@
363366 if(Send(reinterpret_cast<char*>(&packet), sizeof(packet)) == SOCKET_ERROR)
364367 return WSAGetLastError();
365368
366- char user[1] = {0};
369+ char user[1] = {};
367370
368371 if(Send(user, 1) == SOCKET_ERROR)
369372 return WSAGetLastError();
@@ -380,7 +383,7 @@
380383 int NsmClientSocket::Socks5Open() const
381384 {
382385 {
383- BYTE buff[3] = {0};
386+ BYTE buff[3] = {};
384387 buff[0] = 5;
385388 buff[1] = 1;
386389 buff[2] = 0;
@@ -400,17 +403,17 @@
400403 {
401404 AutoPtrAddrinfo res;
402405
403- ADDRINFO hints = {0};
406+ ADDRINFOT hints = {};
404407 hints.ai_family = AF_INET;
405408 hints.ai_socktype = SOCK_STREAM;
406409
407410 DoLookup();
408411
409- int err = getaddrinfo(Host.c_str(), NULL, &hints, &res.Info);
412+ int err = GetAddrInfo(Host.c_str(), NULL, &hints, &res.Info);
410413 if(err != 0)
411414 return err;
412415
413- BYTE buff[10] = {0};
416+ BYTE buff[10] = {};
414417 buff[0] = 5;
415418 buff[1] = 1;
416419 buff[2] = 0;
@@ -435,18 +438,18 @@
435438
436439 int NsmClientSocket::HttpOpen() const
437440 {
438- std::stringstream portStr;
441+ tstringstream portStr;
439442 portStr << Port;
440443
441- const std::string cmd = "CONNECT " + Host + ":" + portStr.str() + " HTTP/1.1\r\nHost: "
442- + Host + ":" + portStr.str() + "\r\nConnection: Keep-Alive\r\n" "\r\n";
444+ const std::string cmd = t2c(TEXT("CONNECT ") + Host + TEXT(":") + portStr.str() + TEXT(" HTTP/1.1\r\nHost: ")
445+ + Host + TEXT(":") + portStr.str() + TEXT("\r\nConnection: Keep-Alive\r\n") TEXT("\r\n"));
443446
444447 if(Send(cmd.c_str(), cmd.size()) == SOCKET_ERROR)
445448 return WSAGetLastError();
446449
447- char buff[1024] = {0};
450+ char buff[1024] = {};
448451
449- if(Receive(buff, sizeof(buff)-1) == SOCKET_ERROR)
452+ if(Receive(buff, sizeof(buff) - 1) == SOCKET_ERROR)
450453 return WSAGetLastError();
451454
452455 const std::string receive = buff;
@@ -462,7 +465,7 @@
462465
463466 if(n != receive.npos && n < receive.size() - receiveMinLen)
464467 {
465- std::stringstream str(receive.substr(n+9,3));
468+ std::stringstream str(receive.substr(n + 9, 3));
466469 int tmp;
467470 str >> tmp;
468471 if(!str.fail())
@@ -480,7 +483,7 @@
480483 if (Socket == INVALID_SOCKET)
481484 return 0;
482485
483- shutdown(Socket,SD_SEND);
486+ shutdown(Socket, SD_SEND);
484487
485488 closesocket(Socket);
486489
@@ -491,14 +494,14 @@
491494
492495 //----
493496
494- int NsmClientSocket::Send(const char* buf,int len) const
497+ int NsmClientSocket::Send(const char* buf, int len) const
495498 {
496- return send(Socket,buf,len,0);
499+ return send(Socket, buf, len, 0);
497500 }
498501
499- int NsmClientSocket::Receive(char* buf,int len) const
502+ int NsmClientSocket::Receive(char* buf, int len) const
500503 {
501- return recv(Socket,buf,len,0);
504+ return recv(Socket, buf, len, 0);
502505 }
503506
504507 int NsmClientSocket::ReceiveLength() const
--- trunk/ClientSocket/src/ClientSocket.cpp (revision 112)
+++ trunk/ClientSocket/src/ClientSocket.cpp (revision 113)
@@ -75,7 +75,7 @@
7575
7676 // ソケットを生成
7777 NsmClientSocketListSub soc(new NsmClientSocket(initInfo, Config.UseProxy, Config.ProxyType));
78- soc->ProxyHost = t2c(Config.ProxyHost);
78+ soc->ProxyHost = Config.ProxyHost;
7979 soc->ProxyPort = Config.ProxyPort;
8080
8181 {
@@ -223,10 +223,10 @@
223223 switch (sockInfo.nInfoKey)
224224 {
225225 case SocketInfoType::Host:
226- handle->Host = Common::NsmInfoUtility::NsmInfoToStrA(sockInfo.lpInfo);
226+ handle->Host = Common::NsmInfoUtility::NsmInfoToStr(sockInfo.lpInfo);
227227 return 1;
228228 case SocketInfoType::Address:
229- handle->Address = Common::NsmInfoUtility::NsmInfoToStrA(sockInfo.lpInfo);
229+ handle->Address = Common::NsmInfoUtility::NsmInfoToStr(sockInfo.lpInfo);
230230 return 1;
231231 case SocketInfoType::Port:
232232 handle->Port = static_cast<unsigned short>(Common::NsmInfoUtility::NsmInfoToInt(sockInfo.lpInfo));
--- trunk/ClientSocket/src/NsmClientSocket.h (revision 112)
+++ trunk/ClientSocket/src/NsmClientSocket.h (revision 113)
@@ -33,11 +33,11 @@
3333 SOCKET Socket;
3434 HWND Handle;
3535
36- static LRESULT CALLBACK WndProc(const HWND hWnd,const UINT msg,const WPARAM wParam,const LPARAM lParam);
36+ static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
3737
3838 //--
3939
40- int DirectOpen(const std::string &host,unsigned short port);
40+ int DirectOpen(const tstring &host, unsigned short port);
4141 int Socks4Open() const;
4242 int Socks5Open() const;
4343 int HttpOpen() const;
@@ -50,23 +50,23 @@
5050 void DoRead() const;
5151 void DoWrite() const;
5252
53- NsmClientSocket& operator=(const NsmClientSocket& other);
53+ NsmClientSocket& operator=(const NsmClientSocket &);
5454 public:
5555 struct FindByHandle
5656 {
5757 const NsmClientSocket *const x;
58- explicit FindByHandle(const NsmClientSocket *const s);
59- bool operator()(const NsmClientSocketListSub& v)const;
58+ explicit FindByHandle(const NsmClientSocket *s);
59+ bool operator()(const NsmClientSocketListSub &v) const;
6060 private:
61- FindByHandle& operator=(const FindByHandle& other);
61+ FindByHandle& operator=(const FindByHandle &);
6262 };
6363
6464 // メンバ変数
65- std::string Host;
66- std::string Address;
65+ tstring Host;
66+ tstring Address;
6767 unsigned short Port;
68- std::string ProxyHost;
69- std::string ProxyAddress;
68+ tstring ProxyHost;
69+ tstring ProxyAddress;
7070 unsigned short ProxyPort;
7171 const bool UseProxy;
7272 const int ProxyType;
@@ -80,8 +80,8 @@
8080
8181 void DoError(int errtype, int errcode) const;
8282
83- int Send(const char* buf,int len) const;
84- int Receive(char* buf,int len) const;
83+ int Send(const char* buf, int len) const;
84+ int Receive(char* buf, int len) const;
8585 int ReceiveLength() const;
8686 };
8787
Show on old repository browser