1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Get rid of pnUtW32Addr and make IP strings char*s.

IP addresses don't need to be unicode.
pnUtAddr is still around until we replace all NetAddress uses with
plNetAddress (they are typedef'ed to each other right now).
This commit is contained in:
Darryl Pogue
2012-03-26 21:27:55 -07:00
parent 06a561fc85
commit 3ea3473d13
27 changed files with 166 additions and 329 deletions

View File

@ -213,7 +213,7 @@ FAsyncNotifySocketProc AsyncSocketFindNotifyProc (
void AsyncSocketConnect (
AsyncCancelId * cancelId,
const NetAddress & netAddr,
const plNetAddress& netAddr,
FAsyncNotifySocketProc notifyProc,
void * param = nil,
const void * sendData = nil,
@ -275,11 +275,11 @@ void AsyncSocketSetBacklogAlloc (
// for connections with hard-coded behavior, set the notifyProc here (e.g. for use
// protocols like SNMP on port 25)
unsigned AsyncSocketStartListening (
const NetAddress & listenAddr,
const plNetAddress& listenAddr,
FAsyncNotifySocketProc notifyProc = nil
);
void AsyncSocketStopListening (
const NetAddress & listenAddr,
const plNetAddress& listenAddr,
FAsyncNotifySocketProc notifyProc = nil
);
@ -297,15 +297,15 @@ void AsyncSocketEnableNagling (
typedef void (* FAsyncLookupProc) (
void * param,
const wchar_t name[],
const char name[],
unsigned addrCount,
const NetAddress addrs[]
const plNetAddress addrs[]
);
void AsyncAddressLookupName (
AsyncCancelId * cancelId,
FAsyncLookupProc lookupProc,
const wchar_t name[],
const char name[],
unsigned port,
void * param
);
@ -313,7 +313,7 @@ void AsyncAddressLookupName (
void AsyncAddressLookupAddr (
AsyncCancelId * cancelId,
FAsyncLookupProc lookupProc,
const NetAddress & address,
const plNetAddress& address,
void * param
);

View File

@ -540,13 +540,13 @@ static SOCKET ListenSocket (NetAddress * listenAddr) {
);
*/
NetAddressNode node = listenAddr->GetHost();
unsigned port = listenAddr->GetPort();
uint32_t node = listenAddr->GetHost();
uint16_t port = listenAddr->GetPort();
// bind socket to port
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons((uint16_t)port);
addr.sin_port = htons(port);
addr.sin_addr.S_un.S_addr = node;
memset(addr.sin_zero, 0, sizeof(addr.sin_zero));
if (bind(s, (sockaddr *) &addr, sizeof(addr))) {

View File

@ -69,7 +69,7 @@ struct Lookup {
FAsyncLookupProc lookupProc;
unsigned port;
void * param;
wchar_t name[kMaxLookupName];
char name[kMaxLookupName];
char buffer[MAXGETHOSTSTRUCT];
};
@ -122,7 +122,7 @@ static void LookupProcess (Lookup * lookup, unsigned error) {
}
if (host.h_name && host.h_name[0])
StrToUnicode(lookup->name, host.h_name, arrsize(lookup->name));
strncpy(lookup->name, host.h_name, arrsize(lookup->name));
if (lookup->lookupProc)
lookup->lookupProc(lookup->param, lookup->name, count, addrs);
@ -271,7 +271,7 @@ void DnsDestroy (unsigned exitThreadWaitMs) {
void AsyncAddressLookupName (
AsyncCancelId * cancelId, // out
FAsyncLookupProc lookupProc,
const wchar_t name[],
const char* name,
unsigned port,
void * param
) {
@ -282,9 +282,8 @@ void AsyncAddressLookupName (
PerfAddCounter(kAsyncPerfNameLookupAttemptsTotal, 1);
// Get name/port
char ansiName[kMaxLookupName];
StrToAnsi(ansiName, name, arrsize(ansiName));
if (char * portStr = StrChr(ansiName, ':')) {
char* ansiName = strdup(name);
if (char* portStr = StrChr(ansiName, ':')) {
if (unsigned newPort = StrToUnsigned(portStr + 1, nil, 10))
port = newPort;
*portStr = 0;
@ -295,7 +294,7 @@ void AsyncAddressLookupName (
lookup->lookupProc = lookupProc;
lookup->port = port;
lookup->param = param;
StrCopy(lookup->name, name, arrsize(lookup->name));
strncpy(lookup->name, name, arrsize(lookup->name));
s_critsect.Enter();
{
@ -312,7 +311,7 @@ void AsyncAddressLookupName (
lookup->cancelHandle = WSAAsyncGetHostByName(
s_lookupWindow,
WM_LOOKUP_FOUND_HOST,
ansiName,
name,
&lookup->buffer[0],
sizeof(lookup->buffer)
);
@ -342,7 +341,7 @@ void AsyncAddressLookupAddr (
lookup->param = param;
plString str = address.GetHostString();
wcsncpy(lookup->name, (const wchar_t*)str.ToUtf16().GetData(), 127);
strncpy(lookup->name, str.c_str(), arrsize(lookup->name));
s_critsect.Enter();
{

View File

@ -53,26 +53,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*
***/
static wchar_t s_authAddrConsole[64] = {0};
static const wchar_t * s_authAddrs[] = {
static char s_authAddrConsole[64] = {0};
static const char* s_authAddrs[] = {
s_authAddrConsole
};
static wchar_t s_fileAddrConsole[64] = {0};
static const wchar_t * s_fileAddrs[] = {
static char s_fileAddrConsole[64] = {0};
static const char* s_fileAddrs[] = {
s_fileAddrConsole
};
static wchar_t s_csrAddrConsole[64] = {0};
static const wchar_t * s_csrAddrs[] = {
static char s_csrAddrConsole[64] = {0};
static const char* s_csrAddrs[] = {
s_csrAddrConsole
};
static wchar_t s_gateKeeperAddrConsole[64] = {0};
static const wchar_t * s_gateKeeperAddrs[] = {
static char s_gateKeeperAddrConsole[64] = {0};
static const char* s_gateKeeperAddrs[] = {
s_gateKeeperAddrConsole
};
@ -86,97 +86,97 @@ static const wchar_t * s_gateKeeperAddrs[] = {
//============================================================================
// Auth
//============================================================================
unsigned GetAuthSrvHostnames (const wchar_t *** addrs) {
unsigned GetAuthSrvHostnames (const char*** addrs) {
*addrs = s_authAddrs;
return arrsize(s_authAddrs);
}
//============================================================================
void SetAuthSrvHostname (const wchar_t addr[]) {
void SetAuthSrvHostname (const char addr[]) {
wcsncpy(s_authAddrConsole, addr, arrsize(s_authAddrConsole));
strncpy(s_authAddrConsole, addr, arrsize(s_authAddrConsole));
}
//============================================================================
// File
//============================================================================
unsigned GetFileSrvHostnames (const wchar_t *** addrs) {
unsigned GetFileSrvHostnames (const char*** addrs) {
*addrs = s_fileAddrs;
return arrsize(s_fileAddrs);
}
//============================================================================
void SetFileSrvHostname (const wchar_t addr[]) {
void SetFileSrvHostname (const char addr[]) {
wcsncpy(s_fileAddrConsole, addr, arrsize(s_fileAddrConsole));
strncpy(s_fileAddrConsole, addr, arrsize(s_fileAddrConsole));
}
//============================================================================
// Csr
//============================================================================
unsigned GetCsrSrvHostnames (const wchar_t *** addrs) {
unsigned GetCsrSrvHostnames (const char*** addrs) {
*addrs = s_csrAddrs;
return arrsize(s_csrAddrs);
}
//============================================================================
void SetCsrSrvHostname (const wchar_t addr[]) {
void SetCsrSrvHostname (const char addr[]) {
wcsncpy(s_csrAddrConsole, addr, arrsize(s_csrAddrConsole));
strncpy(s_csrAddrConsole, addr, arrsize(s_csrAddrConsole));
}
//============================================================================
// GateKeeper
//============================================================================
unsigned GetGateKeeperSrvHostnames (const wchar_t *** addrs) {
unsigned GetGateKeeperSrvHostnames (const char*** addrs) {
*addrs = s_gateKeeperAddrs;
return arrsize(s_gateKeeperAddrs);
}
//============================================================================
void SetGateKeeperSrvHostname (const wchar_t addr[]) {
wcsncpy(s_gateKeeperAddrConsole, addr, arrsize(s_gateKeeperAddrConsole));
void SetGateKeeperSrvHostname (const char addr[]) {
strncpy(s_gateKeeperAddrConsole, addr, arrsize(s_gateKeeperAddrConsole));
}
//============================================================================
// User-visible Server
//============================================================================
static wchar_t s_serverStatusUrl[256] = {0};
static wchar_t s_serverSignupUrl[256] = {0};
static wchar_t s_serverName[256] = {0};
static char s_serverStatusUrl[256] = {0};
static char s_serverSignupUrl[256] = {0};
static char s_serverName[256] = {0};
//============================================================================
const wchar_t *GetServerStatusUrl () {
const char* GetServerStatusUrl () {
return s_serverStatusUrl;
}
//============================================================================
void SetServerStatusUrl (const wchar_t url[]) {
wcsncpy(s_serverStatusUrl, url, arrsize(s_serverStatusUrl));
void SetServerStatusUrl (const char url[]) {
strncpy(s_serverStatusUrl, url, arrsize(s_serverStatusUrl));
}
//============================================================================
const wchar_t *GetServerSignupUrl () {
const char* GetServerSignupUrl () {
return s_serverSignupUrl;
}
//============================================================================
void SetServerSignupUrl (const wchar_t url[]) {
wcsncpy(s_serverSignupUrl, url, arrsize(s_serverSignupUrl));
void SetServerSignupUrl (const char url[]) {
strncpy(s_serverSignupUrl, url, arrsize(s_serverSignupUrl));
}
//============================================================================
const wchar_t *GetServerDisplayName () {
const char* GetServerDisplayName () {
return s_serverName;
}
//============================================================================
void SetServerDisplayName (const wchar_t name[]) {
wcsncpy(s_serverName, name, arrsize(s_serverName));
void SetServerDisplayName (const char name[]) {
strncpy(s_serverName, name, arrsize(s_serverName));
}

View File

@ -84,25 +84,25 @@ enum ESrvType {
*
***/
unsigned GetAuthSrvHostnames (const wchar_t *** addrs); // returns addrCount
void SetAuthSrvHostname (const wchar_t addr[]);
unsigned GetAuthSrvHostnames (const char*** addrs); // returns addrCount
void SetAuthSrvHostname (const char addr[]);
unsigned GetFileSrvHostnames (const wchar_t *** addrs); // returns addrCount
void SetFileSrvHostname (const wchar_t addr[]);
unsigned GetFileSrvHostnames (const char*** addrs); // returns addrCount
void SetFileSrvHostname (const char addr[]);
unsigned GetCsrSrvHostnames (const wchar_t *** addrs); // returns addrCount
void SetCsrSrvHostname (const wchar_t addr[]);
unsigned GetCsrSrvHostnames (const char*** addrs); // returns addrCount
void SetCsrSrvHostname (const char addr[]);
unsigned GetGateKeeperSrvHostnames (const wchar_t *** addrs); // returns addrCount
void SetGateKeeperSrvHostname (const wchar_t addr[]);
unsigned GetGateKeeperSrvHostnames (const char*** addrs); // returns addrCount
void SetGateKeeperSrvHostname (const char addr[]);
const wchar_t *GetServerStatusUrl ();
void SetServerStatusUrl (const wchar_t url[]);
const char *GetServerStatusUrl ();
void SetServerStatusUrl (const char url[]);
const wchar_t *GetServerSignupUrl ();
void SetServerSignupUrl (const wchar_t url[]);
const char *GetServerSignupUrl ();
void SetServerSignupUrl (const char url[]);
const wchar_t *GetServerDisplayName ();
void SetServerDisplayName (const wchar_t name[]);
const char *GetServerDisplayName ();
void SetServerDisplayName (const char name[]);
#endif // pnNbSrvs_inc

View File

@ -677,8 +677,8 @@ struct Auth2Cli_AccountExistsReply {
// ServerAddr
extern const NetMsg kNetMsg_Auth2Cli_ServerAddr;
struct Auth2Cli_ServerAddr {
uint32_t messageId;
NetAddressNode srvAddr;
uint32_t messageId;
uint32_t srvAddr;
Uuid token;
};
@ -713,13 +713,13 @@ struct Auth2Cli_AcctLoginReply {
// AgeReply
extern const NetMsg kNetMsg_Auth2Cli_AgeReply;
struct Auth2Cli_AgeReply {
uint32_t messageId;
uint32_t transId;
ENetError result;
uint32_t ageMcpId;
Uuid ageInstId;
uint32_t ageVaultId;
NetAddressNode gameSrvNode;
uint32_t messageId;
uint32_t transId;
ENetError result;
uint32_t ageMcpId;
Uuid ageInstId;
uint32_t ageVaultId;
uint32_t gameSrvNode;
};
// AcctCreateReply

View File

@ -191,9 +191,9 @@ struct Srv2Mcp_KickPlayer : SrvMsgHeader {
***/
struct Mcp2Srv_AgeJoinReply : SrvMsgHeader {
uint32_t ageMcpId;
Uuid ageUuid;
NetAddressNode gameSrvNode;
uint32_t ageMcpId;
Uuid ageUuid;
uint32_t gameSrvNode;
};
struct Mcp2Srv_AgeSpawnRequest : SrvMsgHeader {

View File

@ -410,7 +410,7 @@ static void Connect(const plNetAddress& addr, ConnectParam * cp) {
//============================================================================
static void AsyncLookupCallback (
void * param,
const wchar_t name[],
const char name[],
unsigned addrCount,
const plNetAddress addrs[]
) {
@ -568,7 +568,7 @@ void SimpleNetDestroyChannel (unsigned channelId) {
//============================================================================
void SimpleNetStartConnecting (
unsigned channelId,
const wchar_t addr[],
const char addr[],
FSimpleNetOnConnect onConnect,
void * param
) {
@ -593,7 +593,7 @@ void SimpleNetStartConnecting (
ASSERT(cp->channel);
// Do we need to lookup the address?
const wchar_t * name = addr;
const char* name = addr;
while (unsigned ch = *name) {
++name;
if (!(isdigit(ch) || ch == L'.' || ch == L':')) {
@ -610,8 +610,7 @@ void SimpleNetStartConnecting (
}
}
if (!name[0]) {
plString saddr = _TEMP_CONVERT_FROM_WCHAR_T(addr);
plNetAddress netAddr(saddr.c_str(), kNetDefaultSimpleNetPort);
plNetAddress netAddr(addr, kNetDefaultSimpleNetPort);
Connect(netAddr, cp);
}
}

View File

@ -39,7 +39,6 @@ set(pnUtils_SOURCES
if(WIN32)
set(pnUtils_WIN32
Win32/pnUtW32Addr.cpp
Win32/pnUtW32Misc.cpp
Win32/pnUtW32Path.cpp
Win32/pnUtW32Str.cpp

View File

@ -1,117 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/Win32/pnUtW32Addr.cpp
*
***/
#include "../pnUtils.h"
/*****************************************************************************
*
* Internal functions
*
***/
//===========================================================================
static NetAddressNode NodeFromString (const wchar_t * string[]) {
// skip leading whitespace
const wchar_t * str = *string;
while (iswspace(*str))
++str;
// This function handles partial ip addresses (61.33)
// as well as full dotted quads. The address can be
// terminated by whitespace or ':' as well as '\0'
uint8_t data[4];
* (uint32_t *) data = 0;
for (unsigned i = sizeof(data); i--; ) {
if (!iswdigit(*str))
return (unsigned)-1;
unsigned value = StrToUnsigned(str, &str, 10);
if (value >= 256)
return (unsigned)-1;
data[i] = (uint8_t) value;
if (!*str || (*str == ':') || iswspace(*str))
break;
static const wchar_t s_separator[] = L"\0...";
if (*str++ != s_separator[i])
return (unsigned)-1;
}
*string = str;
return * (NetAddressNode *) &data[0];
}
/*****************************************************************************
*
* Exports
*
***/
//===========================================================================
bool NetAddressFromString (NetAddress * addr, const wchar_t str[], uint16_t defaultPort) {
ASSERT(addr);
ASSERT(str);
for (;;) {
NetAddressNode node = NodeFromString(&str);
if (node == (unsigned)-1)
break;
if (*str == L':')
defaultPort = StrToUnsigned(str + 1, nil, 10);
addr->SetPort((uint16_t)defaultPort);
addr->SetHostLE(node);
return true;
}
// address already zeroed
return false;
}

View File

@ -50,36 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h"
/*****************************************************************************
*
* Types and constants
*
***/
/*struct NetAddress {
uint8_t data[24];
};
typedef unsigned NetAddressNode;*/
#include "pnNetCommon/plNetAddress.h"
typedef plNetAddress NetAddress;
typedef uint32_t NetAddressNode;
/*****************************************************************************
*
* Functions
*
***/
// 'str' must be in the form of a dotted IP address (IPv4 or IPv6)
// - names which require DNS lookup will cause the function to return false
bool NetAddressFromString (
NetAddress * addr,
const wchar_t str[],
uint16_t defaultPort
);
#endif