You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
6.0 KiB
215 lines
6.0 KiB
14 years ago
|
/*==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/>.
|
||
|
|
||
13 years ago
|
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.
|
||
|
|
||
14 years ago
|
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/pnUtPath.cpp
|
||
|
*
|
||
|
***/
|
||
|
|
||
13 years ago
|
#include "pnUtPath.h"
|
||
|
#include "pnUtStr.h"
|
||
14 years ago
|
|
||
|
|
||
|
/****************************************************************************
|
||
|
*
|
||
|
* Exported functions
|
||
|
*
|
||
|
***/
|
||
|
|
||
|
//===========================================================================
|
||
|
void PathGetProgramDirectory (
|
||
13 years ago
|
wchar_t *dst,
|
||
14 years ago
|
unsigned dstChars
|
||
|
) {
|
||
|
ASSERT(dst);
|
||
|
ASSERT(dstChars);
|
||
|
|
||
|
PathGetProgramName(dst, dstChars);
|
||
|
PathRemoveFilename(dst, dst, dstChars);
|
||
|
}
|
||
|
|
||
|
//===========================================================================
|
||
|
void PathAddFilename (
|
||
13 years ago
|
wchar_t *dst,
|
||
|
const wchar_t src[],
|
||
|
const wchar_t fname[],
|
||
14 years ago
|
unsigned dstChars
|
||
|
) {
|
||
|
ASSERT(dst);
|
||
|
ASSERT(dstChars);
|
||
|
|
||
13 years ago
|
wchar_t temp[MAX_PATH];
|
||
14 years ago
|
if (dst == src) {
|
||
|
StrCopy(temp, src, arrsize(temp));
|
||
|
src = temp;
|
||
|
}
|
||
|
else if (dst == fname) {
|
||
|
StrCopy(temp, fname, arrsize(temp));
|
||
|
fname = temp;
|
||
|
}
|
||
|
|
||
|
PathMakePath(dst, dstChars, 0, src, fname, 0);
|
||
|
}
|
||
|
|
||
|
//===========================================================================
|
||
|
void PathRemoveFilename (
|
||
13 years ago
|
wchar_t *dst,
|
||
|
const wchar_t src[],
|
||
14 years ago
|
unsigned dstChars
|
||
|
) {
|
||
|
ASSERT(dst);
|
||
|
ASSERT(src);
|
||
|
ASSERT(dstChars);
|
||
|
|
||
13 years ago
|
wchar_t drive[MAX_DRIVE];
|
||
|
wchar_t dir[MAX_DIR];
|
||
14 years ago
|
PathSplitPath(src, drive, dir, 0, 0);
|
||
|
PathMakePath(dst, dstChars, drive, dir, 0, 0);
|
||
|
}
|
||
|
|
||
|
/*****************************************************************************
|
||
|
*
|
||
|
* Email formatting functions
|
||
|
*
|
||
|
***/
|
||
|
|
||
|
//============================================================================
|
||
|
void PathSplitEmail (
|
||
13 years ago
|
const wchar_t emailAddr[],
|
||
|
wchar_t * user,
|
||
14 years ago
|
unsigned userChars,
|
||
13 years ago
|
wchar_t * domain,
|
||
14 years ago
|
unsigned domainChars,
|
||
13 years ago
|
wchar_t * tld,
|
||
14 years ago
|
unsigned tldChars,
|
||
13 years ago
|
wchar_t * subDomains,
|
||
14 years ago
|
unsigned subDomainChars,
|
||
|
unsigned subDomainCount
|
||
|
) {
|
||
|
ASSERT(emailAddr);
|
||
|
|
||
|
#define SUB_DOMAIN(i) subDomains[(i) * subDomainChars]
|
||
|
|
||
|
// null-terminate all output parameters
|
||
|
if (userChars) {
|
||
|
ASSERT(user);
|
||
|
user[0] = 0;
|
||
|
}
|
||
|
if (domainChars) {
|
||
|
ASSERT(domain);
|
||
|
domain[0] = 0;
|
||
|
}
|
||
|
if (tldChars) {
|
||
|
ASSERT(tld);
|
||
|
tld[0] = 0;
|
||
|
}
|
||
|
if (subDomainChars || subDomainCount) {
|
||
|
ASSERT(subDomains);
|
||
|
for (unsigned i = 0; i < subDomainCount; ++i)
|
||
|
SUB_DOMAIN(i) = 0;
|
||
|
}
|
||
|
|
||
|
// bail now if email address is zero-length
|
||
|
unsigned len = StrLen(emailAddr);
|
||
|
if (!len)
|
||
|
return;
|
||
|
|
||
|
// copy email address so we can tokenize it
|
||
13 years ago
|
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1));
|
||
14 years ago
|
StrCopy(tmp, emailAddr, len + 1);
|
||
13 years ago
|
const wchar_t * work = tmp;
|
||
14 years ago
|
|
||
|
// parse user
|
||
13 years ago
|
wchar_t token[MAX_PATH];
|
||
14 years ago
|
if (!StrTokenize(&work, token, arrsize(token), L"@"))
|
||
|
return;
|
||
|
|
||
|
// copy user to output parameter
|
||
|
if (userChars)
|
||
|
StrCopy(user, token, userChars);
|
||
|
|
||
|
// skip past the '@' symbol
|
||
|
if (!*work++)
|
||
|
return;
|
||
|
|
||
|
// parse all domains
|
||
13 years ago
|
ARRAY(wchar_t *) arr;
|
||
14 years ago
|
while (StrTokenize(&work, token, arrsize(token), L".")) {
|
||
|
unsigned toklen = StrLen(token);
|
||
13 years ago
|
wchar_t * str = (wchar_t*)malloc(sizeof(wchar_t) * (toklen + 1));
|
||
14 years ago
|
StrCopy(str, token, toklen + 1);
|
||
|
arr.Add(str);
|
||
13 years ago
|
|
||
|
free(str);
|
||
14 years ago
|
}
|
||
|
|
||
|
// copy domains to output parameters
|
||
|
unsigned index = 0;
|
||
|
if (arr.Count() > 2) {
|
||
|
// all domains except for the last two are sub-domains
|
||
|
for (index = 0; index < arr.Count() - 2; ++index) {
|
||
|
if (index < subDomainCount)
|
||
|
if (subDomains)
|
||
|
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars);
|
||
|
}
|
||
|
}
|
||
|
if (arr.Count() > 1) {
|
||
|
// second to last domain is the primary domain
|
||
|
if (domain)
|
||
|
StrCopy(domain, arr[index], domainChars);
|
||
|
// last comes the top level domain
|
||
|
++index;
|
||
|
if (tld)
|
||
|
StrCopy(tld, arr[index], tldChars);
|
||
|
}
|
||
|
else if (arr.Count() == 1) {
|
||
|
// if only one domain, return it as a sub-domain
|
||
|
if (index < subDomainCount)
|
||
|
if (subDomains)
|
||
|
StrCopy(&SUB_DOMAIN(index), arr[index], subDomainChars);
|
||
|
}
|
||
13 years ago
|
|
||
|
free(tmp);
|
||
14 years ago
|
|
||
|
#undef SUB_DOMAIN
|
||
|
}
|