From ee0848ce30ce2cddd3701e54e6112a62135ff320 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 3 Jan 2015 00:58:23 -0500 Subject: [PATCH] Clean up string spin-washing in the Vault API --- .../pfConsole/pfConsoleCommandsNet.cpp | 6 +- .../Plasma/FeatureLib/pfPython/pyAgeVault.cpp | 17 ++---- .../Plasma/FeatureLib/pfPython/pyAgeVault.h | 4 +- .../Plasma/FeatureLib/pfPython/pyVault.cpp | 9 +-- Sources/Plasma/FeatureLib/pfPython/pyVault.h | 2 +- .../plNetClient/plNetLinkingMgr.cpp | 10 +--- .../plNetGameLib/Private/plNglAuth.cpp | 59 +++++++++---------- .../plNetGameLib/Private/plNglAuth.h | 8 +-- .../PubUtilLib/plVault/plVaultClientApi.cpp | 52 ++++++---------- .../PubUtilLib/plVault/plVaultClientApi.h | 14 ++--- 10 files changed, 69 insertions(+), 112 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp index 7f9ec74d..295240db 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommandsNet.cpp @@ -789,11 +789,7 @@ PF_CONSOLE_CMD( Net_Vault, "string stationName, string mtSpawnPt", "Register an MT Station with your Nexus" ) { - wchar_t wName[MAX_PATH]; - wchar_t wObj[MAX_PATH]; - StrToUnicode(wName, params[0], arrsize(wName)); - StrToUnicode(wObj, params[1], arrsize(wObj)); - VaultRegisterMTStationAndWait ( wName, wObj ); + VaultRegisterMTStationAndWait((char*)params[0], (char*)params[1]); PrintString("Registered MT Station."); } diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp b/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp index 0420fa28..4de0ff1f 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp @@ -173,27 +173,18 @@ plUUID pyAgeVault::GetAgeGuid( void ) /////////////// // Chronicle -PyObject* pyAgeVault::FindChronicleEntry( const char * entryName ) +PyObject* pyAgeVault::FindChronicleEntry( const plString& entryName ) { - wchar_t wEntryName[kMaxVaultNodeStringLength]; - StrToUnicode(wEntryName, entryName, arrsize(wEntryName)); - - if (hsRef rvn = VaultFindAgeChronicleEntry(wEntryName)) + if (hsRef rvn = VaultFindAgeChronicleEntry(entryName)) return pyVaultChronicleNode::New(rvn); // just return a None object PYTHON_RETURN_NONE; } -void pyAgeVault::AddChronicleEntry( const char * name, uint32_t type, const char * value ) +void pyAgeVault::AddChronicleEntry( const plString& name, uint32_t type, const plString& value ) { - wchar_t * wEntryName = StrDupToUnicode(name); - wchar_t * wEntryValue = StrDupToUnicode(value); - - VaultAddAgeChronicleEntry(wEntryName, type, wEntryValue); - - free(wEntryName); - free(wEntryValue); + VaultAddAgeChronicleEntry(name, type, value); } // AGE DEVICES. AKA IMAGERS, WHATEVER. diff --git a/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.h b/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.h index bce1cdc4..ebc6ef2f 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyAgeVault.h @@ -92,8 +92,8 @@ public: PyObject* GetSubAgesFolder( void ); // returns pyVaultFolderNode PyObject* GetChronicleFolder( void ); // returns pyVaultFolderNode // Age chronicle (not the player chronicle!) - PyObject* FindChronicleEntry( const char * entryName ); // returns pyVaultChronicleNode - void AddChronicleEntry( const char * name, uint32_t type, const char * value ); + PyObject* FindChronicleEntry( const plString& entryName ); // returns pyVaultChronicleNode + void AddChronicleEntry( const plString& name, uint32_t type, const plString& value ); // Players who have published to devices in this age PyObject* GetPeopleIKnowAboutFolder( void ); // returns pyVaultPlayerInfoListNode // PERSONAL AGE SPECIFIC diff --git a/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp b/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp index 2606bbd3..77738fd5 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/pyVault.cpp @@ -489,15 +489,10 @@ bool pyVault::AmAgeCzar( const pyAgeInfoStruct * ageInfo ) return VaultAmCzarOfAge(ageInstId); } -void pyVault::RegisterMTStation( const char * stationName, const char * backLinkSpawnPtObjName ) +void pyVault::RegisterMTStation( const plString& stationName, const plString& backLinkSpawnPtObjName ) { - wchar_t wStationName[256]; - wchar_t wSpawnPt[256]; - StrToUnicode(wStationName, stationName, arrsize(wStationName)); - StrToUnicode(wSpawnPt, backLinkSpawnPtObjName, arrsize(wSpawnPt)); - // Note: This doesn't actually block (~Hoikas) - VaultRegisterMTStationAndWait( wStationName, wSpawnPt); + VaultRegisterMTStationAndWait(stationName, backLinkSpawnPtObjName); } void pyVault::RegisterOwnedAge( const pyAgeLinkStruct & link ) diff --git a/Sources/Plasma/FeatureLib/pfPython/pyVault.h b/Sources/Plasma/FeatureLib/pfPython/pyVault.h index e243d7a1..fe6d808c 100644 --- a/Sources/Plasma/FeatureLib/pfPython/pyVault.h +++ b/Sources/Plasma/FeatureLib/pfPython/pyVault.h @@ -160,7 +160,7 @@ public: void RegisterVisitAge( const pyAgeLinkStruct & link ); void UnRegisterVisitAge( const char * guid ); // Register a nexus station - void RegisterMTStation( const char * stationName, const char * mtSpawnPt ); + void RegisterMTStation( const plString& stationName, const plString& mtSpawnPt ); /////////////// // Invite player to visit an age. diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp index b71efbf7..5557ccbc 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp @@ -1069,14 +1069,10 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void) case plNetCommon::LinkingRules::kChildAgeBook: { plAgeLinkStruct childLink; - wchar_t parentAgeName[MAX_PATH]; - if (link->HasParentAgeFilename()) - StrToUnicode(parentAgeName, link->GetParentAgeFilename(), arrsize(parentAgeName)); - switch(VaultAgeFindOrCreateChildAgeLink( - (link->HasParentAgeFilename() ? parentAgeName : nil), - info, - &childLink)) + link->GetParentAgeFilename(), + info, + &childLink)) { case static_cast(hsFail): success = kLinkFailed; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 3b732146..a5ed26bd 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -686,10 +686,10 @@ struct VaultInitAgeTrans : NetAuthTrans { plUUID m_ageInstId; plUUID m_parentAgeInstId; - wchar_t * m_ageFilename; - wchar_t * m_ageInstName; - wchar_t * m_ageUserName; - wchar_t * m_ageDesc; + plString m_ageFilename; + plString m_ageInstName; + plString m_ageUserName; + plString m_ageDesc; unsigned m_ageSequenceNumber; unsigned m_ageLanguage; @@ -701,10 +701,10 @@ struct VaultInitAgeTrans : NetAuthTrans { void * param, // optional const plUUID& ageInstId, // optional. is used in match const plUUID& parentAgeInstId, // optional. is used in match - const wchar_t ageFilename[], // optional. is used in match - const wchar_t ageInstName[], // optional. not used in match - const wchar_t ageUserName[], // optional. not used in match - const wchar_t ageDesc[], // optional. not used in match + const plString ageFilename, // optional. is used in match + const plString ageInstName, // optional. not used in match + const plString ageUserName, // optional. not used in match + const plString ageDesc, // optional. not used in match unsigned ageSequenceNumber, // optional. not used in match unsigned ageLanguage // optional. not used in match ); @@ -3815,10 +3815,10 @@ VaultInitAgeTrans::VaultInitAgeTrans ( void * param, // optional const plUUID& ageInstId, // optional. is used in match const plUUID& parentAgeInstId, // optional. is used in match - const wchar_t ageFilename[], // optional. is used in match - const wchar_t ageInstName[], // optional. not used in match - const wchar_t ageUserName[], // optional. not used in match - const wchar_t ageDesc[], // optional. not used in match + const plString ageFilename, // optional. is used in match + const plString ageInstName, // optional. not used in match + const plString ageUserName, // optional. not used in match + const plString ageDesc, // optional. not used in match unsigned ageSequenceNumber, // optional. not used in match unsigned ageLanguage // optional. not used in match ) : NetAuthTrans(kVaultInitAgeTrans) @@ -3826,10 +3826,6 @@ VaultInitAgeTrans::VaultInitAgeTrans ( , m_param(param) , m_ageInstId(ageInstId) , m_parentAgeInstId(parentAgeInstId) -, m_ageFilename(StrDup(ageFilename ? ageFilename : L"")) -, m_ageInstName(StrDup(ageInstName ? ageInstName : L"")) -, m_ageUserName(StrDup(ageUserName ? ageUserName : L"")) -, m_ageDesc(StrDup(ageDesc ? ageDesc : L"")) , m_ageSequenceNumber(ageSequenceNumber) , m_ageLanguage(ageLanguage) , m_ageId(0) @@ -3839,10 +3835,6 @@ VaultInitAgeTrans::VaultInitAgeTrans ( //============================================================================ VaultInitAgeTrans::~VaultInitAgeTrans () { - free(m_ageFilename); - free(m_ageInstName); - free(m_ageUserName); - free(m_ageDesc); } //============================================================================ @@ -3850,19 +3842,24 @@ bool VaultInitAgeTrans::Send () { if (!AcquireConn()) return false; + plStringBuffer ageFilename = m_ageFilename.ToUtf16(); + plStringBuffer ageInstName = m_ageInstName.ToUtf16(); + plStringBuffer ageUserName = m_ageUserName.ToUtf16(); + plStringBuffer ageDesc = m_ageDesc.ToUtf16(); + const uintptr_t msg[] = { kCli2Auth_VaultInitAgeRequest, m_transId, (uintptr_t) &m_ageInstId, (uintptr_t) &m_parentAgeInstId, - (uintptr_t) m_ageFilename, - (uintptr_t) m_ageInstName, - (uintptr_t) m_ageUserName, - (uintptr_t) m_ageDesc, - m_ageSequenceNumber, - m_ageLanguage, + (uintptr_t) ageFilename.GetData(), + (uintptr_t) ageInstName.GetData(), + (uintptr_t) ageUserName.GetData(), + (uintptr_t) ageDesc.GetData(), + m_ageSequenceNumber, + m_ageLanguage, }; - + m_conn->Send(msg, arrsize(msg)); return true; @@ -5736,10 +5733,10 @@ void NetCliAuthVaultSendNode ( void NetCliAuthVaultInitAge ( const plUUID& ageInstId, // optional. is used in match const plUUID& parentAgeInstId, // optional. is used in match - const wchar_t ageFilename[], // optional. is used in match - const wchar_t ageInstName[], // optional. not used in match - const wchar_t ageUserName[], // optional. not used in match - const wchar_t ageDesc[], // optional. not used in match + const plString& ageFilename, // optional. is used in match + const plString& ageInstName, // optional. not used in match + const plString& ageUserName, // optional. not used in match + const plString& ageDesc, // optional. not used in match unsigned ageSequenceNumber, // optional. not used in match unsigned ageLanguage, // optional. not used in match FNetCliAuthAgeInitCallback callback, // optional diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index 9a4b25b0..9763412d 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -521,10 +521,10 @@ typedef void (*FNetCliAuthAgeInitCallback) ( void NetCliAuthVaultInitAge ( const plUUID& ageInstId, // optional. is used in match const plUUID& parentAgeInstId, // optional. is used in match - const wchar_t ageFilename[], // optional. is used in match - const wchar_t ageInstName[], // optional. not used in match - const wchar_t ageUserName[], // optional. not used in match - const wchar_t ageDesc[], // optional. not used in match + const plString& ageFilename, // optional. is used in match + const plString& ageInstName, // optional. not used in match + const plString& ageUserName, // optional. not used in match + const plString& ageDesc, // optional. not used in match unsigned ageSequenceNumber, // optional. not used in match unsigned ageLanguage, // optional. not used in match FNetCliAuthAgeInitCallback callback, // optional diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp index 86ae798c..021639c0 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp @@ -2074,23 +2074,13 @@ void VaultInitAge ( ) { VaultAgeInitTrans * trans = new VaultAgeInitTrans(callback, state, param); - wchar_t ageFilename[MAX_PATH]; - wchar_t ageInstName[MAX_PATH]; - wchar_t ageUserName[MAX_PATH]; - wchar_t ageDesc[1024]; - - StrToUnicode(ageFilename, info->GetAgeFilename(), arrsize(ageFilename)); - StrToUnicode(ageInstName, info->GetAgeInstanceName(), arrsize(ageInstName)); - StrToUnicode(ageUserName, info->GetAgeUserDefinedName(), arrsize(ageUserName)); - StrToUnicode(ageDesc, info->GetAgeDescription(), arrsize(ageDesc)); - NetCliAuthVaultInitAge( *info->GetAgeInstanceGuid(), parentAgeInstId, - ageFilename, - ageInstName, - ageUserName, - ageDesc, + info->GetAgeFilename(), + info->GetAgeInstanceName(), + info->GetAgeUserDefinedName(), + info->GetAgeDescription(), info->GetAgeSequenceNumber(), info->GetAgeLanguage(), VaultAgeInitTrans::AgeInitCallback, @@ -3440,17 +3430,14 @@ bool VaultAmCzarOfAge (const plUUID& ageInstId) { //============================================================================ bool VaultRegisterMTStationAndWait ( - const wchar_t stationName[], - const wchar_t linkBackSpawnPtObjName[] + const plString& stationName, + const plString& linkBackSpawnPtObjName ) { plAgeInfoStruct info; info.SetAgeFilename(kCityAgeFilename); if (hsRef rvn = VaultGetOwnedAgeLink(&info)) { - char title[MAX_PATH], spawnPt[MAX_PATH]; - StrToAnsi(title, stationName, arrsize(title)); - StrToAnsi(spawnPt, linkBackSpawnPtObjName, arrsize(spawnPt)); VaultAgeLinkNode link(rvn); - link.AddSpawnPoint(plSpawnPointInfo(title, spawnPt)); + link.AddSpawnPoint({ stationName, linkBackSpawnPtObjName }); return true; } return false; @@ -3669,16 +3656,16 @@ hsRef VaultFindAgeSubAgeLink (const plAgeInfoStruct * info) { } //============================================================================ -hsRef VaultFindAgeChronicleEntry (const wchar_t entryName[], int entryType) { +hsRef VaultFindAgeChronicleEntry (const plString& entryName, int entryType) { hsAssert(false, "eric, implement me"); return nil; } //============================================================================ void VaultAddAgeChronicleEntry ( - const wchar_t entryName[], - int entryType, - const wchar_t entryValue[] + const plString& entryName, + int entryType, + const plString& entryValue ) { hsAssert(false, "eric, implement me"); } @@ -4258,7 +4245,7 @@ static void _AddChildNodeCallback ( //============================================================================ bool VaultAgeFindOrCreateChildAgeLinkAndWait ( - const wchar_t parentAgeName[], + const plString& parentAgeName, const plAgeInfoStruct * info, plAgeLinkStruct * link ) { @@ -4270,15 +4257,12 @@ bool VaultAgeFindOrCreateChildAgeLinkAndWait ( { // Get id of child ages folder hsRef rvnAgeInfo; - if (parentAgeName) { - char ansi[MAX_PATH]; - StrToAnsi(ansi, parentAgeName, arrsize(ansi)); + if (!parentAgeName.IsEmpty()) { plAgeInfoStruct pinfo; - pinfo.SetAgeFilename(ansi); + pinfo.SetAgeFilename(parentAgeName); if (hsRef rvnAgeLink = VaultGetOwnedAgeLink(&pinfo)) rvnAgeInfo = rvnAgeLink->GetChildNode(plVault::kNodeType_AgeInfo, 1); - } - else { + } else { rvnAgeInfo = VaultGetAgeInfoNode(); } @@ -4519,17 +4503,15 @@ namespace _VaultCreateChildAge { }; // namespace _VaultCreateAge uint8_t VaultAgeFindOrCreateChildAgeLink( - const wchar_t parentAgeName[], + const plString& parentAgeName, const plAgeInfoStruct* info, plAgeLinkStruct* link) { using namespace _VaultCreateChildAge; // First, try to find an already existing ChildAge - char name[MAX_PATH]; - StrToAnsi(name, parentAgeName, arrsize(name)); plAgeInfoStruct search; - search.SetAgeFilename(name); + search.SetAgeFilename(parentAgeName); hsRef rvnParentInfo; if (hsRef rvnParentLink = VaultGetOwnedAgeLink(&search)) diff --git a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h index a76991ed..380b0b31 100644 --- a/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h +++ b/Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h @@ -375,8 +375,8 @@ bool VaultAmCzarOfCurrentAge (); bool VaultAmOwnerOfAge (const plUUID& ageInstId); bool VaultAmCzarOfAge (const plUUID& ageInstId); bool VaultRegisterMTStationAndWait ( - const wchar_t stationName[], - const wchar_t linkBackSpawnPtObjName[] + const plString& stationName, + const plString& linkBackSpawnPtObjName ); void VaultProcessPlayerInbox (); @@ -402,12 +402,12 @@ hsRef VaultGetAgePublicAgesFolder(); hsRef VaultAgeGetBookshelfFolder(); hsRef VaultFindAgeSubAgeLink(const plAgeInfoStruct * info); hsRef VaultFindAgeChildAgeLink(const plAgeInfoStruct * info); -hsRef VaultFindAgeChronicleEntry(const wchar_t entryName[], int entryType = -1); +hsRef VaultFindAgeChronicleEntry(const plString& entryName, int entryType = -1); // if entry of same name and type already exists, value is updated void VaultAddAgeChronicleEntry ( - const wchar_t entryName[], + const plString& entryName, int entryType, - const wchar_t entryValue[] + const plString& entryValue ); hsRef VaultAgeAddDeviceAndWait(const plString& deviceName); // blocks until completion void VaultAgeRemoveDevice (const plString& deviceName); @@ -434,11 +434,11 @@ bool VaultAgeFindOrCreateSubAgeLinkAndWait ( ); bool VaultAgeFindOrCreateSubAgeLink(const plAgeInfoStruct* info, plAgeLinkStruct* link, const plUUID& arentUuid); bool VaultAgeFindOrCreateChildAgeLinkAndWait ( - const wchar_t parentAgeName[], // nil --> current age, non-nil --> owned age by given name + const plString& parentAgeName, // nil --> current age, non-nil --> owned age by given name const plAgeInfoStruct * info, plAgeLinkStruct * link ); -uint8_t VaultAgeFindOrCreateChildAgeLink(const wchar_t parentAgeName[], const plAgeInfoStruct* info, plAgeLinkStruct* link); +uint8_t VaultAgeFindOrCreateChildAgeLink(const plString& parentAgeName, const plAgeInfoStruct* info, plAgeLinkStruct* link);