Use U8String/U16String/WString instead of UTF8String/UTF16String/WideString

This commit is contained in:
hyzboy 2024-12-24 22:40:20 +08:00
parent 1cfe60d239
commit 87cd2e4f4f
12 changed files with 43 additions and 43 deletions

View File

@ -2,7 +2,7 @@
#define HGL_NETWORK_SOCKET_MANAGE_INCLUDE #define HGL_NETWORK_SOCKET_MANAGE_INCLUDE
#include<hgl/type/Map.h> #include<hgl/type/Map.h>
#include<hgl/type/SortedSets.h> #include<hgl/type/SortedSet.h>
#include<hgl/network/SocketEvent.h> #include<hgl/network/SocketEvent.h>
#include<hgl/network/TCPAccept.h> #include<hgl/network/TCPAccept.h>
namespace hgl namespace hgl
@ -31,7 +31,7 @@ namespace hgl
sock_send_list, sock_send_list,
sock_error_list; sock_error_list;
SortedSets<TCPAccept *> error_sets; SortedSet<TCPAccept *> error_sets;
protected: protected:
@ -43,7 +43,7 @@ namespace hgl
public: public:
const SortedSets<TCPAccept *> &GetErrorSocketSet(){return error_sets;} ///<获取错误SOCKET合集 const SortedSet<TCPAccept *> &GetErrorSocketSet(){return error_sets;} ///<获取错误SOCKET合集
public: public:

View File

@ -46,7 +46,7 @@ namespace hgl
/** /**
* firefox用户代理字符串 * firefox用户代理字符串
*/ */
UTF8String FirefoxUserAgent(FirefoxUserAgentConfig &cfg); U8String FirefoxUserAgent(FirefoxUserAgentConfig &cfg);
}//namespace webapi }//namespace webapi
}//namespace hgl }//namespace hgl
#endif//HGL_WEBAPI_BROWSER_AGENT_STRING_INCLUDE #endif//HGL_WEBAPI_BROWSER_AGENT_STRING_INCLUDE

View File

@ -6,8 +6,8 @@ namespace hgl
{ {
namespace network namespace network
{ {
bool GetWebSocketInfo(UTF8String &sec_websocket_key,UTF8String &sec_websocket_protocol,uint &sec_websocket_version,const u8char *data,const uint size); bool GetWebSocketInfo(U8String &sec_websocket_key,U8String &sec_websocket_protocol,uint &sec_websocket_version,const u8char *data,const uint size);
void MakeWebSocketAccept(UTF8String &result,const UTF8String &sec_websocket_key,const UTF8String &sec_websocket_protocol); void MakeWebSocketAccept(U8String &result,const U8String &sec_websocket_key,const U8String &sec_websocket_protocol);
}//namespace network }//namespace network
}//namespace hgl }//namespace hgl
#endif//HGL_NETWORK_WEBSOCKET_INCLUDE #endif//HGL_NETWORK_WEBSOCKET_INCLUDE

View File

@ -49,7 +49,7 @@ namespace hgl
* @param version WebSocket版本 * @param version WebSocket版本
* @return * @return
*/ */
virtual bool OnHandshake(UTF8String &accept_protocol,const UTF8String &protocol,uint version) virtual bool OnHandshake(U8String &accept_protocol,const U8String &protocol,uint version)
{ {
accept_protocol=protocol; //原样接收,如有需求请自行重载此函数处理 accept_protocol=protocol; //原样接收,如有需求请自行重载此函数处理
return(true); return(true);
@ -72,7 +72,7 @@ namespace hgl
bool SendBinary(void *,uint32,bool=true); bool SendBinary(void *,uint32,bool=true);
bool SendText(void *,uint32,bool=true); bool SendText(void *,uint32,bool=true);
bool SendText(const UTF8String &str) bool SendText(const U8String &str)
{ {
return SendText(str.c_str(),str.Length()); return SendText(str.c_str(),str.Length());
} }

View File

@ -67,7 +67,7 @@ namespace hgl
addr->ToString(ipstr,IP_STR_MAX_SIZE); addr->ToString(ipstr,IP_STR_MAX_SIZE);
LOG_INFO(U8_TEXT("AcceptServer Accept IP:")+UTF8String((u8char *)ipstr)+U8_TEXT(" ,sock:")+UTF8String::numberOf(new_sock)); LOG_INFO(U8_TEXT("AcceptServer Accept IP:")+U8String((u8char *)ipstr)+U8_TEXT(" ,sock:")+U8String::numberOf(new_sock));
return(new_sock); return(new_sock);
} }

View File

@ -66,7 +66,7 @@ namespace hgl
RETURN_ERROR(-3); RETURN_ERROR(-3);
} }
LOG_INFO(U8_TEXT("Create ")+UTF8String((u8char *)(addr->GetProtocolName()))+U8_TEXT(" Socket OK: ")+UTF8String::numberOf(s)); LOG_INFO(U8_TEXT("Create ")+U8String((u8char *)(addr->GetProtocolName()))+U8_TEXT(" Socket OK: ")+U8String::numberOf(s));
return s; return s;
} }
@ -92,7 +92,7 @@ namespace hgl
ThisAddress=nullptr; ThisAddress=nullptr;
ThisSocket=-1; ThisSocket=-1;
// LOG_INFO(u8"Socket Count ++: "+UTF8String(++socket_count)); // LOG_INFO(u8"Socket Count ++: "+U8String(++socket_count));
} }
Socket::Socket(int sock,const IPAddress *addr) Socket::Socket(int sock,const IPAddress *addr)
@ -109,7 +109,7 @@ namespace hgl
{ {
CloseSocket(); CloseSocket();
// LOG_INFO(u8"Socket Count --: "+UTF8String(--socket_count)); // LOG_INFO(u8"Socket Count --: "+U8String(--socket_count));
} }
bool Socket::InitSocket(const IPAddress *addr) bool Socket::InitSocket(const IPAddress *addr)

View File

@ -81,12 +81,12 @@ namespace hgl
SAFE_CLEAR(ipstr); SAFE_CLEAR(ipstr);
ipstr=ThisAddress->CreateString(); ipstr=ThisAddress->CreateString();
LOG_HINT(U8_TEXT("Don't Connect to TCPServer ")+UTF8String((u8char *)ipstr)); LOG_HINT(U8_TEXT("Don't Connect to TCPServer ")+U8String((u8char *)ipstr));
this->CloseSocket(); this->CloseSocket();
return(false); return(false);
} }
// LOG_INFO(u"connect "+u8_to_u16(host)+u':'+UTF16String(port)+u" ok,socket:"+UTF16String(ThisSocket)); // LOG_INFO(u"connect "+u8_to_u16(host)+u':'+U16String(port)+u" ok,socket:"+U16String(ThisSocket));
SetBlock(true,TimeOut); //阻塞模式 SetBlock(true,TimeOut); //阻塞模式

View File

@ -67,7 +67,7 @@ namespace hgl
// //
// if((ThisSocket=socket(family,SOCK_DGRAM,IPPROTO_UDP))<0) // if((ThisSocket=socket(family,SOCK_DGRAM,IPPROTO_UDP))<0)
// { // {
// LOG_ERROR(U16_TEXT("创建Socket失败errno:")+UTF16String(GetLastSocketError())); // LOG_ERROR(U16_TEXT("创建Socket失败errno:")+U16String(GetLastSocketError()));
// RETURN_FALSE; // RETURN_FALSE;
// } // }
// //

View File

@ -13,7 +13,7 @@ namespace hgl
* @param size * @param size
* @return * @return
*/ */
bool GetWebSocketInfo(UTF8String &sec_websocket_key,UTF8String &sec_websocket_protocol,uint &sec_websocket_version,const u8char *data,const uint size) bool GetWebSocketInfo(U8String &sec_websocket_key,U8String &sec_websocket_protocol,uint &sec_websocket_version,const u8char *data,const uint size)
{ {
constexpr u8char SEC_WEBSOCKET_KEY[]=U8_TEXT("Sec-WebSocket-Key: "); constexpr u8char SEC_WEBSOCKET_KEY[]=U8_TEXT("Sec-WebSocket-Key: ");
constexpr uint SEC_WEBSOCKET_KEY_SIZE=sizeof(SEC_WEBSOCKET_KEY)-1; //sizeof的带\0所以要-1 constexpr uint SEC_WEBSOCKET_KEY_SIZE=sizeof(SEC_WEBSOCKET_KEY)-1; //sizeof的带\0所以要-1
@ -38,7 +38,7 @@ namespace hgl
end=key; end=key;
while(*end!='\r')++end; while(*end!='\r')++end;
sec_websocket_key=UTF8String(key,end-key); sec_websocket_key=U8String(key,end-key);
} }
{ {
@ -75,9 +75,9 @@ namespace hgl
// * 生成WebSocket回复头 // * 生成WebSocket回复头
// * @param result 回复头存放字符串 // * @param result 回复头存放字符串
// */ // */
//void MakeWebSocketAccept(UTF8String &result,const UTF8String &sec_websocket_key,const UTF8String &sec_websocket_protocol) //void MakeWebSocketAccept(U8String &result,const U8String &sec_websocket_key,const U8String &sec_websocket_protocol)
//{ //{
// const UTF8String key_mask=sec_websocket_key+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; // const U8String key_mask=sec_websocket_key+"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
// util::HashCodeSHA1 hc; // util::HashCodeSHA1 hc;
@ -87,7 +87,7 @@ namespace hgl
// base64_encode(&mos,hc.code,hc.size()); // base64_encode(&mos,hc.code,hc.size());
// const UTF8String sec_websocket_accept((char *)mos.GetData(),mos.GetSize()); // const U8String sec_websocket_accept((char *)mos.GetData(),mos.GetSize());
// result="HTTP/1.1 101 Switching Protocols\r\n" // result="HTTP/1.1 101 Switching Protocols\r\n"
// "Upgrade: websocket\r\n" // "Upgrade: websocket\r\n"

View File

@ -53,16 +53,16 @@ namespace hgl
end+=HTTP_HEADER_END_SIZE; end+=HTTP_HEADER_END_SIZE;
total=end-ws_header.data(); total=end-ws_header.data();
UTF8String key; U8String key;
UTF8String ws_protocol; U8String ws_protocol;
uint ws_version; uint ws_version;
UTF8String ws_accept_protocol; U8String ws_accept_protocol;
if(GetWebSocketInfo(key,ws_protocol,ws_version,ws_header.data(),total)) if(GetWebSocketInfo(key,ws_protocol,ws_version,ws_header.data(),total))
if(OnHandshake(ws_accept_protocol,ws_protocol,ws_version)) if(OnHandshake(ws_accept_protocol,ws_protocol,ws_version))
{ {
UTF8String ws_return; U8String ws_return;
MakeWebSocketAccept(ws_return,key,ws_accept_protocol); MakeWebSocketAccept(ws_return,key,ws_accept_protocol);
@ -235,7 +235,7 @@ namespace hgl
DataToLowerHexStr(data_out_str.data(),(uint8 *)pack,msg_length,u8char(',')); DataToLowerHexStr(data_out_str.data(),(uint8 *)pack,msg_length,u8char(','));
LOG_INFO(U8_TEXT("WebSocket[")+UTF8String::numberOf(ThisSocket)+U8_TEXT("] Recv binary [")+UTF8String::numberOf(msg_length)+U8_TEXT("]: ")+UTF8String(data_out_str.data())); LOG_INFO(U8_TEXT("WebSocket[")+U8String::numberOf(ThisSocket)+U8_TEXT("] Recv binary [")+U8String::numberOf(msg_length)+U8_TEXT("]: ")+U8String(data_out_str.data()));
#endif//_DEBUG #endif//_DEBUG
OnBinary(pack,msg_length,msg_fin); OnBinary(pack,msg_length,msg_fin);
@ -338,7 +338,7 @@ namespace hgl
DataToLowerHexStr(data_out_str.data(),(uint8 *)data,size,u8char(',')); DataToLowerHexStr(data_out_str.data(),(uint8 *)data,size,u8char(','));
LOG_INFO(U8_TEXT("WebSocket[")+UTF8String::numberOf(ThisSocket)+U8_TEXT("] Send binary [")+UTF8String::numberOf(size)+U8_TEXT("]: ")+UTF8String(data_out_str.data())); LOG_INFO(U8_TEXT("WebSocket[")+U8String::numberOf(ThisSocket)+U8_TEXT("] Send binary [")+U8String::numberOf(size)+U8_TEXT("]: ")+U8String(data_out_str.data()));
#endif//_DEBUG #endif//_DEBUG
return SendFrame(0x2,data,size,fin)>0; return SendFrame(0x2,data,size,fin)>0;

View File

@ -4,9 +4,9 @@ namespace hgl
{ {
namespace webapi namespace webapi
{ {
UTF8String FirefoxUserAgent(FirefoxUserAgentConfig &cfg) U8String FirefoxUserAgent(FirefoxUserAgentConfig &cfg)
{ {
UTF8String agent=U8_TEXT("Mozilla/5.0 "); U8String agent=U8_TEXT("Mozilla/5.0 ");
if(cfg.os>=OS_WindowsX86 if(cfg.os>=OS_WindowsX86
&&cfg.os<=OS_LinuxX86_64) &&cfg.os<=OS_LinuxX86_64)
@ -14,14 +14,14 @@ namespace hgl
if(cfg.os>=OS_WindowsX86 if(cfg.os>=OS_WindowsX86
&&cfg.os<=OS_WindowsWOW64) &&cfg.os<=OS_WindowsWOW64)
{ {
agent+=U8_TEXT("(Windows NT ")+UTF8String::numberOf(cfg.os_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.os_ver.minor)+U8_TEXT("; "); agent+=U8_TEXT("(Windows NT ")+U8String::numberOf(cfg.os_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.os_ver.minor)+U8_TEXT("; ");
if(cfg.os==OS_WindowsAMD64)agent+=U8_TEXT("Win64; x64; ");else if(cfg.os==OS_WindowsAMD64)agent+=U8_TEXT("Win64; x64; ");else
if(cfg.os==OS_WindowsWOW64)agent+=U8_TEXT("WOW64; "); if(cfg.os==OS_WindowsWOW64)agent+=U8_TEXT("WOW64; ");
} }
else else
if(cfg.os==OS_macOS) if(cfg.os==OS_macOS)
agent+=U8_TEXT("(Macintosh; Intel Mac OS X ")+UTF8String::numberOf(cfg.os_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.os_ver.minor)+U8_TEXT("; "); agent+=U8_TEXT("(Macintosh; Intel Mac OS X ")+U8String::numberOf(cfg.os_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.os_ver.minor)+U8_TEXT("; ");
else else
if(cfg.os==OS_Linuxi686) if(cfg.os==OS_Linuxi686)
agent+=U8_TEXT("(X11; Linux i686; "); agent+=U8_TEXT("(X11; Linux i686; ");
@ -29,8 +29,8 @@ namespace hgl
if(cfg.os==OS_LinuxX86_64) if(cfg.os==OS_LinuxX86_64)
agent+=U8_TEXT("(X11; Linux x86_64; "); agent+=U8_TEXT("(X11; Linux x86_64; ");
agent+=U8_TEXT("rv:")+UTF8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.ff_ver.minor)+U8_TEXT(") Gecko/")+UTF8String::numberOf(cfg.gecko_version)+U8_TEXT(" Firefox/") agent+=U8_TEXT("rv:")+U8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.ff_ver.minor)+U8_TEXT(") Gecko/")+U8String::numberOf(cfg.gecko_version)+U8_TEXT(" Firefox/")
+UTF8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.ff_ver.minor); +U8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.ff_ver.minor);
} }
else else
if(cfg.os>=OS_iPod if(cfg.os>=OS_iPod
@ -40,26 +40,26 @@ namespace hgl
if(cfg.os==OS_iPad) agent+=U8_TEXT("(iPad; ");else if(cfg.os==OS_iPad) agent+=U8_TEXT("(iPad; ");else
agent+=U8_TEXT("(iPhone; "); agent+=U8_TEXT("(iPhone; ");
agent+= U8_TEXT("CPU iPhone OS ")+UTF8String::numberOf(cfg.os_ver.major)+U8_TEXT("_")+UTF8String::numberOf(cfg.os_ver.minor)+U8_TEXT(" like Mac OS X) ")+ agent+= U8_TEXT("CPU iPhone OS ")+U8String::numberOf(cfg.os_ver.major)+U8_TEXT("_")+U8String::numberOf(cfg.os_ver.minor)+U8_TEXT(" like Mac OS X) ")+
U8_TEXT("AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4"); U8_TEXT("AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4");
} }
else else
if(cfg.os>=OS_AndroidPhone if(cfg.os>=OS_AndroidPhone
&&cfg.os<=OS_AndroidTV) &&cfg.os<=OS_AndroidTV)
{ {
agent+=U8_TEXT("(Android ")+UTF8String::numberOf(cfg.os_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.os_ver.minor)+U8_TEXT("; "); agent+=U8_TEXT("(Android ")+U8String::numberOf(cfg.os_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.os_ver.minor)+U8_TEXT("; ");
if(cfg.os==OS_AndroidPhone )agent+=U8_TEXT("Mobile; "); if(cfg.os==OS_AndroidPhone )agent+=U8_TEXT("Mobile; ");
if(cfg.os==OS_AndroidTablet )agent+=U8_TEXT("Tablet; "); if(cfg.os==OS_AndroidTablet )agent+=U8_TEXT("Tablet; ");
if(cfg.os==OS_AndroidTV )agent+=U8_TEXT("TV; "); if(cfg.os==OS_AndroidTV )agent+=U8_TEXT("TV; ");
agent+=U8_TEXT("rv:")+UTF8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.ff_ver.minor)+U8_TEXT(") Gecko/") agent+=U8_TEXT("rv:")+U8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.ff_ver.minor)+U8_TEXT(") Gecko/")
+UTF8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.ff_ver.minor)+U8_TEXT(" Firefox/") +U8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.ff_ver.minor)+U8_TEXT(" Firefox/")
+UTF8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.ff_ver.minor); +U8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.ff_ver.minor);
} }
else else
{ {
agent+=U8_TEXT("Firefox/")+UTF8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+UTF8String::numberOf(cfg.ff_ver.minor); agent+=U8_TEXT("Firefox/")+U8String::numberOf(cfg.ff_ver.major)+U8_TEXT(".")+U8String::numberOf(cfg.ff_ver.minor);
} }
return agent; return agent;

View File

@ -192,7 +192,7 @@ namespace hgl
FW_ERROR_CODE ret = FW_NOERROR; FW_ERROR_CODE ret = FW_NOERROR;
HRESULT hr; HRESULT hr;
// BSTR bstrFWProcessImageFileName = NULL; // BSTR bstrFWProcessImageFileName = NULL;
UTF16String bstrFWProcessImageFileName; U16String bstrFWProcessImageFileName;
VARIANT_BOOL bFWEnabled; VARIANT_BOOL bFWEnabled;
INetFwAuthorizedApplication* pFWApp = NULL; INetFwAuthorizedApplication* pFWApp = NULL;
INetFwAuthorizedApplications* pFWApps = NULL; INetFwAuthorizedApplications* pFWApps = NULL;
@ -260,9 +260,9 @@ namespace hgl
HRESULT hr; HRESULT hr;
bool bAppEnable; bool bAppEnable;
//BSTR bstrProcessImageFileName = NULL; //BSTR bstrProcessImageFileName = NULL;
UTF16String bstrProcessImageFileName; U16String bstrProcessImageFileName;
//BSTR bstrRegisterName = NULL; //BSTR bstrRegisterName = NULL;
UTF16String bstrRegisterName; U16String bstrRegisterName;
INetFwAuthorizedApplication* pFWApp = NULL; INetFwAuthorizedApplication* pFWApp = NULL;
INetFwAuthorizedApplications* pFWApps = NULL; INetFwAuthorizedApplications* pFWApps = NULL;
@ -347,7 +347,7 @@ namespace hgl
HRESULT hr; HRESULT hr;
bool bAppEnable; bool bAppEnable;
//BSTR bstrProcessImageFileName = NULL; //BSTR bstrProcessImageFileName = NULL;
UTF16String bstrProcessImageFileName; U16String bstrProcessImageFileName;
INetFwAuthorizedApplications* pFWApps = NULL; INetFwAuthorizedApplications* pFWApps = NULL;
try try
@ -456,7 +456,7 @@ namespace hgl
INetFwOpenPort* pFWOpenPort = NULL; INetFwOpenPort* pFWOpenPort = NULL;
INetFwOpenPorts* pFWOpenPorts = NULL; INetFwOpenPorts* pFWOpenPorts = NULL;
//BSTR bstrRegisterName = NULL; //BSTR bstrRegisterName = NULL;
UTF16String bstrRegisterName; U16String bstrRegisterName;
HRESULT hr; HRESULT hr;
try try