本文整理汇总了C++中OTString::Exists方法的典型用法代码示例。如果您正苦于以下问题:C++ OTString::Exists方法的具体用法?C++ OTString::Exists怎么用?C++ OTString::Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OTString
的用法示例。
在下文中一共展示了OTString::Exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
const bool OTSettings::CheckSet_bool(const OTString & strSection, const OTString & strKey, const bool & bDefault, bool & out_bResult, bool & out_bIsNew, const OTString & strComment)
{
if (! strSection.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (! strKey.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
bool bKeyExist, bNewKeyCheck, bTempResult;
if (! Check_bool(strSection,strKey,bTempResult,bKeyExist)) return false;
if (bKeyExist)
{
// Already have a key, lets use it's value.
out_bIsNew = false;
out_bResult = bTempResult;
return true;
}
else
{
if (! Set_bool(strSection,strKey,bDefault,bNewKeyCheck,strComment)) return false;
if (bNewKeyCheck)
{
// Success
out_bIsNew = true;
out_bResult = bDefault;
return true;
}
}
// If we get here, error!
OT_ASSERT(false);
return false;
}
示例2: WriteArmoredFile
bool OTASCIIArmor::WriteArmoredFile(const OTString & foldername, const OTString & filename,
const // for "-----BEGIN OT LEDGER-----", str_type would contain "LEDGER"
std::string str_type, // There's no default, to force you to enter the right string.
bool bEscaped/*=false*/)
{
OT_ASSERT(foldername.Exists());
OT_ASSERT(filename.Exists());
// ----------------------------------
const char * szFunc = "OTASCIIArmor::WriteArmoredFile";
// ----------------------------------
OTString strOutput;
if (this->WriteArmoredString(strOutput, str_type, bEscaped) && strOutput.Exists())
{
// WRITE IT TO THE FILE
// StorePlainString will attempt to create all the folders leading up to the path
// for the output file.
//
bool bSaved = OTDB::StorePlainString(strOutput.Get(), foldername.Get(), filename.Get());
if (!bSaved)
{
OTLog::vError("%s: Failed saving to file: %s%s%s\n\n Contents:\n\n%s\n\n", szFunc,
foldername.Get(), OTLog::PathSeparator(), filename.Get(), strOutput.Get());
return false;
}
// --------------------------------------------------------------------
return true;
}
// -----------------------
return false;
}
示例3: strValue
const bool OTSettings::Set_bool(const OTString & strSection, const OTString & strKey, const bool & bValue, bool & out_bNewOrUpdate, const OTString & strComment)
{
if (! strSection.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (! strKey.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
const OTString strValue(bValue ? "true" : "false");
return Set_str(strSection,strKey,strValue,out_bNewOrUpdate,strComment);
}
示例4: Set
const bool OTPaths::Set(
OTSettings * pConfig,
const OTString & strSection,
const OTString & strKey,
const OTString & strValue,
const bool & bIsRelative,
bool & out_bIsNewOrUpdated,
const OTString & strComment
)
{
if (!strSection.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (!strKey.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
out_bIsNewOrUpdated = false;
if (NULL == pConfig) { OT_ASSERT(false); return false; }
const bool bPreLoaded(pConfig->IsLoaded());
if (!bPreLoaded) // we only need to load, if not already loaded.
{
pConfig->Reset();
if(!pConfig->Load()) { OT_ASSERT(false); return false; }
}
bool bBoolIsNew(false), bStringIsNew(false);
OTString strRelativeKey("");
strRelativeKey.Format("%s%s",strKey.Get(),OT_CONFIG_ISRELATIVE);
if(pConfig->Set_bool(strSection,strRelativeKey,bIsRelative,bBoolIsNew,strComment))
{
if(pConfig->Set_str(strSection,strKey,strValue,bStringIsNew))
{
if(bBoolIsNew && bStringIsNew) //using existing key
{
out_bIsNewOrUpdated = true;
}
if (!bPreLoaded)
{
if(!pConfig->Save()) { OT_ASSERT(false); return false; }
pConfig->Reset();
}
return true;
}
}
// if we get here, there has been a error!
OT_ASSERT(false);
pConfig->Reset();
return false;
}
示例5: SetLongValue
const bool OTSettings::Set_long(const OTString & strSection, const OTString & strKey, const long & lValue, bool & out_bNewOrUpdate, const OTString & strComment)
{
if (! strSection.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (strSection.Compare("")) { OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (! strKey.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
if (strKey.Compare("")) { OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
OTString strValue; strValue.Format("%ld",lValue);
const char * const szComment = (strComment.Exists() && !strComment.Compare("")) ? strComment.Get() : NULL;
OTString strOldValue, strNewValue;
bool bOldKeyExist, bNewKeyExist;
// Check if Old Key exists.
if(! Check_str(strSection,strKey,strOldValue,bOldKeyExist)) return false;
if (bOldKeyExist)
{
if (strValue.Compare(strOldValue))
{
out_bNewOrUpdate = false;
return true;
}
}
// Log to Output Setting Change
if (! LogChange_str(strSection,strKey,strValue)) return false;
// Set New Value
SI_Error rc = p_iniSimple -> SetLongValue(strSection.Get(),strKey.Get(),lValue,szComment,false,true);
if (0 > rc) return false;
// Check if the new value is the same as intended.
if (! Check_str(strSection,strKey,strNewValue,bNewKeyExist)) return false;
if (bNewKeyExist)
{
if (strValue.Compare(strNewValue))
{
// Success
out_bNewOrUpdate = true;
return true;
}
}
// If we get here, error!
OT_ASSERT(false);
return false;
}
示例6: Gnome_StoreSecret
// static
bool OTKeyring::Gnome_StoreSecret(const OTString& strUser,
const OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
OT_ASSERT(thePassword.getMemorySize() > 0);
OTData theData(thePassword.getMemory(), thePassword.getMemorySize());
OTASCIIArmor ascData(theData);
theData.zeroMemory(); // security reasons.
OTString strOutput;
const bool bSuccess =
ascData.Exists() &&
ascData.WriteArmoredString(strOutput, "DERIVED KEY"); // There's no
// default, to
// force you to
// enter the right
// string.
ascData.zeroMemory();
GnomeKeyringResult theResult = GNOME_KEYRING_RESULT_IO_ERROR;
if (bSuccess && strOutput.Exists()) {
theResult = gnome_keyring_store_password_sync(
GNOME_KEYRING_NETWORK_PASSWORD,
GNOME_KEYRING_DEFAULT, // GNOME_KEYRING_SESSION,
str_display.c_str(), strOutput.Get(), "user", strUser.Get(),
"protocol", "opentxs", // todo: hardcoding.
nullptr);
strOutput.zeroMemory();
bool bResult = false;
if (theResult == GNOME_KEYRING_RESULT_OK)
bResult = true;
else
otErr << "OTKeyring::Gnome_StoreSecret: "
<< "Failure in gnome_keyring_store_password_sync: "
<< gnome_keyring_result_to_message(theResult) << '\n';
return bResult;
}
otOut << "OTKeyring::Gnome_StoreSecret: No secret to store.\n";
return false;
}
示例7: Mac_StoreSecret
// static
bool OTKeyring::Mac_StoreSecret(const OTString& strUser,
const OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
OT_ASSERT(thePassword.getMemorySize() > 0);
const std::string service_name = "opentxs";
const std::string account_name = strUser.Get();
OTMacKeychain theKeychain;
void* vData =
const_cast<void*>(static_cast<const void*>(thePassword.getMemory()));
OSStatus theError = theKeychain.AddSecret(
nullptr, service_name.size(), service_name.data(), account_name.size(),
account_name.data(), thePassword.getMemorySize(),
vData, // thePassword.getMemory()
nullptr);
if (theError != noErr) {
otErr
<< "OTKeyring::Mac_StoreSecret: Error in theKeychain.AddSecret.\n";
return false;
}
return true;
}
示例8: Mac_RetrieveSecret
// static
bool OTKeyring::Mac_RetrieveSecret(const OTString& strUser,
OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
const std::string service_name = "opentxs";
const std::string account_name = strUser.Get();
uint32_t password_length = 0;
void* password_data = nullptr;
OTMacKeychain theKeychain;
OSStatus theError = theKeychain.FindSecret(
nullptr, service_name.size(), service_name.data(), account_name.size(),
account_name.data(), &password_length, // output.
&password_data, nullptr);
if (theError == noErr) {
thePassword.setMemory(password_data, password_length);
theKeychain.ItemFreeContent(nullptr, password_data);
return true;
}
else
otErr << "OTKeyring::Mac_RetrieveSecret: Error in "
"theKeychain.FindSecret.\n";
return false;
}
示例9: IOS_StoreSecret
// static
bool OTKeyring::IOS_StoreSecret(const OTString& strUser,
const OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
OT_ASSERT(thePassword.getMemorySize() > 0);
CFStringRef service_name = CFSTR("opentxs");
CFStringRef account_name = CFStringCreateWithCString(nullptr, strUser.Get(),
kCFStringEncodingUTF8);
CFDataRef vData = CFDataCreateWithBytesNoCopy(
nullptr, thePassword.getMemory_uint8(), thePassword.getMemorySize(),
kCFAllocatorNull);
const void* keys[] = {kSecClass, kSecAttrService, kSecAttrAccount,
kSecValueData};
const void* values[] = {kSecClassGenericPassword, service_name,
account_name, vData};
CFDictionaryRef item =
CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr);
OSStatus theError = SecItemAdd(item, nullptr);
CFRelease(item);
CFRelease(vData);
CFRelease(account_name);
if (theError != noErr) {
otErr << "OTKeyring::IOS_StoreSecret: Error in SecItemAdd.\n";
return false;
}
return true;
}
示例10: IOS_RetrieveSecret
// static
bool OTKeyring::IOS_RetrieveSecret(const OTString& strUser,
OTPassword& thePassword,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
CFStringRef service_name = CFSTR("opentxs");
CFStringRef account_name = CFStringCreateWithCString(nullptr, strUser.Get(),
kCFStringEncodingUTF8);
CFDataRef vData = nullptr;
const void* keys[] = {kSecClass, kSecAttrService, kSecAttrAccount,
kSecReturnData};
const void* values[] = {kSecClassGenericPassword, service_name,
account_name, kCFBooleanTrue};
CFDictionaryRef query =
CFDictionaryCreate(nullptr, keys, values, 4, nullptr, nullptr);
OSStatus theError = SecItemCopyMatching(query, (CFTypeRef*)&vData);
CFRelease(query);
CFRelease(account_name);
if (theError != noErr) {
otErr
<< "OTKeyring::IOS_RetrieveSecret: Error in SecItemCopyMatching.\n";
return false;
}
thePassword.setMemory(CFDataGetBytePtr(vData), CFDataGetLength(vData));
CFRelease(vData);
return true;
}
示例11: IOS_DeleteSecret
// static
bool OTKeyring::IOS_DeleteSecret(const OTString& strUser,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
CFStringRef service_name = CFSTR("opentxs");
CFStringRef account_name = CFStringCreateWithCString(nullptr, strUser.Get(),
kCFStringEncodingUTF8);
const void* keys[] = {kSecClass, kSecAttrService, kSecAttrAccount};
const void* values[] = {kSecClassGenericPassword, service_name,
account_name};
CFDictionaryRef query =
CFDictionaryCreate(nullptr, keys, values, 3, nullptr, nullptr);
OSStatus theError = SecItemDelete(query);
CFRelease(query);
CFRelease(account_name);
if (theError != noErr) {
otErr << "OTKeyring::IOS_RetrieveSecret: Error in SecItemDelete.\n";
return false;
}
return true;
}
示例12: strVar
const bool OTSettings::Check_str (const OTString & strSection, const OTString & strKey, OTString & out_strResult, bool & out_bKeyExist) const
{
if (! strSection.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (strSection.Compare("")) { OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strSection" ); OT_ASSERT(false); }
if (! strKey.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
if (strKey.Compare("")) { OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strKey" ); OT_ASSERT(false); }
const char * szVar = p_iniSimple -> GetValue(strSection.Get(), strKey.Get(),NULL);
OTString strVar(szVar);
if (strVar.Exists() && !strVar.Compare("")) {out_bKeyExist = true; out_strResult = strVar; }
else { out_bKeyExist = false; out_strResult = ""; }
return true;
}
示例13: KWallet_DeleteSecret
// static
bool OTKeyring::KWallet_DeleteSecret(const OTString& strUser,
const std::string& str_display)
{
OT_ASSERT(strUser.Exists());
KWallet::Wallet* pWallet = OTKeyring::OpenKWallet();
if (nullptr != pWallet) {
const QString qstrKey(strUser.Get());
bool bResult = false;
if (pWallet->removeEntry(qstrKey) == 0) // delete the entry
bResult = true;
else
otErr << "OTKeyring::KWallet_DeleteSecret: Failed trying to erase "
"secret from KWallet.\n";
return bResult;
}
otErr << "OTKeyring::KWallet_DeleteSecret: Unable to open kwallet.\n";
return false;
}
示例14: PathExists
const bool OTPaths::PathExists(const OTString & strPath)
{
if (!strPath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strPath" ); OT_ASSERT(false); }
// remove trailing backslash for stat
std::string l_strPath(strPath.Get());
l_strPath = (OTString::replace_chars(l_strPath,"\\",'/')); // all \ to /
//std::string l_strPath_stat = l_strPath;
std::string l_strPath_stat("");
// remove last / if it exists (for l_strPath_stat)
if ('/' == *l_strPath.rbegin())
l_strPath_stat = l_strPath.substr(0, l_strPath.size()-1);
else l_strPath_stat = l_strPath;
struct stat st;
memset(&st, 0, sizeof(st));
if (0 == stat(l_strPath_stat.c_str(), &st)) // good we have at-least on a node
{
if ('/' != *l_strPath.rbegin())
{
long temp_l=0;
return FileExists(strPath,temp_l);
}
else
{
return FolderExists(strPath);
}
}
return false;
}
示例15: SaveFile
const bool OTSettings::Save(const OTString & strConfigurationFileExactPath)
{
if (! strConfigurationFileExactPath.Exists()) { OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strConfigurationFileExactPath"); return false; }
SI_Error rc = p_iniSimple -> SaveFile(strConfigurationFileExactPath.Get());
if (0 > rc) return false;
else return true;
}