Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
int32_t OTMasterkey::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
	int32_t nReturnVal = ot_super::ProcessXMLNode(xml);
	
	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do in the case of OTAccount.
    //
	if (0 != nReturnVal)
       return nReturnVal;
	// else it was 0 (continue...)
    // --------------------------------------------------
    const OTString strNodeName(xml->getNodeName());
    // --------------------------------------------------
	if (strNodeName.Compare("masterCredential"))
	{
		m_strNymID = xml->getAttributeValue("nymID");

		m_strMasterCredID.Release();
		
		OTLog::Output(1, "Loading masterCredential...\n");
		
		nReturnVal = 1;
	}
	// ----------------------------------
	return nReturnVal;
}
Пример #4
0
int OTPayment::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
    const OTString strNodeName(xml->getNodeName());
    
	if (strNodeName.Compare("payment"))
	{	
		m_strVersion = xml->getAttributeValue("version"); 

        const OTString strPaymentType = xml->getAttributeValue("type");
        
		if (strPaymentType.Exists())
			m_Type = OTPayment::GetTypeFromString(strPaymentType);
        else
            m_Type = OTPayment::ERROR_STATE;
        
		OTLog::vOutput(4, "Loaded payment... Type: %s\n----------\n",
                       this->GetTypeString());
		
		return (OTPayment::ERROR_STATE == m_Type) ? (-1) : 1;
	}
	
	else if (strNodeName.Compare("contents")) 
	{
        OTString strContents;
		
		if (!OTContract::LoadEncodedTextField(xml, strContents) || 
            !strContents.Exists() ||
            // -------------------------------
            !this->SetPayment(strContents))
		{
			OTLog::vError("OTPayment::ProcessXMLNode: ERROR: \"contents\" field without a value, OR error setting that "
                          "value onto this object. Raw:\n\n%s\n\n", strContents.Get());
			
			return (-1); // error condition
		}
		// else success -- the value is now set on this object.
        // todo security: Make sure the type of the payment that's ACTUALLY there
        // matches the type expected (based on the m_Type that we already read, above.)
        
		return 1;
	}

	return 0;
}
Пример #5
0
bool OTIdentifier::CalculateDigestInternal(const OTData & dataInput, const OTString & strHashAlgorithm)
{
	// See if they wanted to use the SAMY hash
	if (strHashAlgorithm.Compare(DefaultHashAlgorithm)) 
	{
		return CalculateDigest(dataInput);
	}
	
	return false;	
}
Пример #6
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
//
int32_t OTSubkey::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
	int32_t nReturnVal = ot_super::ProcessXMLNode(xml);
	
	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do in the case of OTAccount.
    //
	if (0 != nReturnVal)
       return nReturnVal;
	// else it was 0 (continue...)
    // --------------------------------------------------
    const OTString strNodeName(xml->getNodeName());
    // --------------------------------------------------
	if (strNodeName.Compare("keyCredential"))
	{
		m_strNymID			= xml->getAttributeValue("nymID");
		m_strMasterCredID	= xml->getAttributeValue("masterCredentialID");
		
		OTLog::Output(1, "Loading keyCredential...\n");
		
		nReturnVal = 1;
	}
	// ----------------------------------
	else if (strNodeName.Compare("masterSigned"))
	{
		if (false == OTContract::LoadEncodedTextField(xml, m_strMasterSigned))
		{
			OTLog::vError("Error in %s line %d: failed loading expected master-signed version while loading keyCredential.\n",
                          __FILE__, __LINE__);
			return (-1); // error condition
		}
		
		nReturnVal = 1;
	}
	// ------------------
	return nReturnVal;
}
Пример #7
0
//static
OTPayment::paymentType OTPayment::GetTypeFromString(const OTString & strType)
{
#define OT_NUM_ELEM(blah) (sizeof (blah) / sizeof (*(blah)))    
    for (unsigned int i = 0; i < ( OT_NUM_ELEM(OTPayment::_TypeStrings) - 1 ); i++ )
    {
        if (strType.Compare(OTPayment::_TypeStrings[i]))
            return static_cast<OTPayment::paymentType>(i);
    }
#undef OT_NUM_ELEM
    return OTPayment::ERROR_STATE;
}
Пример #8
0
const bool	OTSettings::LogChange_str (const OTString & strSection,const OTString & strKey,const OTString & strValue)
{
	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 char * const szValue	 = (strValue.Exists()	&& !strValue.Compare("")  ) ? strValue.Get()   : "NULL";

	OTString strCategory, strOption;
	if (!OTLog::StringFill(strCategory,strSection.Get(),12)) return false;
	if (!OTLog::StringFill(strOption,strKey.Get(),30," to:")) return false;

	OTLog::vOutput(1, "Setting %s %s %s \n",strCategory.Get(),strOption.Get(),szValue);
	return true;
}
Пример #9
0
const bool	OTSettings::CheckSet_str (const OTString & strSection, const OTString & strKey, const OTString & strDefault, OTString & out_strResult, 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); }

	const char * const szDefault = (strDefault.Exists() && !strDefault.Compare("")) ? strDefault.Get() : NULL;

	OTString strTempResult;
	bool bKeyExist, bNewKeyCheck;
	if (! Check_str(strSection,strKey,strTempResult,bKeyExist)) return false;

	if (bKeyExist)
	{
		// Already have a key, lets use it's value.
		out_bIsNew = false;
		out_strResult = strTempResult;
		return true;
	}
	else
	{
		if (! Set_str(strSection,strKey,strDefault,bNewKeyCheck,strComment)) return false;

		if (NULL == szDefault) // The Default is to have no key.
		{
			// Success
			out_bIsNew = false;
			out_strResult = "";
			return true;
		}
		
		if (bNewKeyCheck)
		{
			// Success
			out_bIsNew = true;
			out_strResult = strDefault;
			return true;
		}
	}

	// If we get here, error!
	OT_ASSERT(false);
	return false;
}
Пример #10
0
const bool	OTSettings::CheckSetSection(const OTString & strSection, const OTString & strComment, bool & out_bIsNewSection)
{
	if (! strSection.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); }
	if (! strComment.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strComment"			); OT_ASSERT(false); }

	const char * const szComment = (strComment.Exists() && !strComment.Compare("")) ? strComment.Get() : NULL;

	const long lSectionSize = p_iniSimple -> GetSectionSize(strSection.Get());

	if (1 > lSectionSize)
	{
		out_bIsNewSection = true;
		SI_Error rc = p_iniSimple -> SetValue(strSection.Get(),NULL,NULL,szComment,false);
		if (0 > rc) return false;
	}
	else
	{
		out_bIsNewSection = false;
	}
	return true;
}
Пример #11
0
// this function dosn't change the "strRelativePath" so.  It will only fix the strBasePath.
const bool OTPaths::RelativeToCanonical(OTString & out_strCanonicalPath, const OTString & strBasePath, const OTString & strRelativePath)
{
	if (!strBasePath.Exists())	   { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strBasePath"	); OT_ASSERT(false); }
	if (!strRelativePath.Exists()) { OTLog::sError("%s: Null: %s passed in!\n", __FUNCTION__, "strRelativePath" ); OT_ASSERT(false); }

	OTString l_strBasePath_fix("");
	if(!FixPath(strBasePath,l_strBasePath_fix,true)) return false;

	if(strRelativePath.Compare(".")) { out_strCanonicalPath = strBasePath; return true; }  // if ".", return base path.

	std::string l_strBasePath(l_strBasePath_fix.Get()), l_strRelativePath(strRelativePath.Get());

	l_strBasePath.append(l_strRelativePath);

	OTString l_strPath(l_strBasePath), l_strCanonicalPath("");

	if(!ToReal(l_strPath,l_strCanonicalPath)) return false;

	out_strCanonicalPath = l_strCanonicalPath;

	return true;
}
OTAccount::AccountType TranslateAccountTypeStringToEnum(const OTString & strAcctType)
{
	OTAccount::AccountType theReturnVal = OTAccount::err_acct;

	if (strAcctType.Compare("simple"))
		theReturnVal = OTAccount::simple;
	else if (strAcctType.Compare("issuer"))
		theReturnVal = OTAccount::issuer;
	else if (strAcctType.Compare("basket"))
		theReturnVal = OTAccount::basket;
	else if (strAcctType.Compare("basketsub"))
		theReturnVal = OTAccount::basketsub;
	else if (strAcctType.Compare("mint"))
		theReturnVal = OTAccount::mint;
	else if (strAcctType.Compare("voucher"))
		theReturnVal = OTAccount::voucher;
	else if (strAcctType.Compare("stash"))
		theReturnVal = OTAccount::stash;
	else
		OTLog::vError("Error: Unknown account type: %s \n", strAcctType.Get());

	return theReturnVal;
}
Пример #13
0
const bool OTPaths::LoadSetScriptsFolder  // ie. PrefixFolder() + lib/opentxs/
	(
	OTSettings * pConfig, //optional
	const OTString & strScriptsFolder,	//optional
	const bool & bIsRelative			//optional
	)
{
	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	OTString strRelativeKey = "";
	strRelativeKey.Format("%s%s","scripts",OT_CONFIG_ISRELATIVE);


	// local vairables.
	bool bConfigIsRelative = false;
	OTString strConfigFolder = "";


	// lets first check what we have in the configuration:
	{
	bool bKeyIsNew = false;

	if (!pConfig->CheckSet_bool("paths",strRelativeKey,true,bConfigIsRelative,bKeyIsNew)) { return false; }
	if (!pConfig->CheckSet_str("paths","scripts",OT_SCRIPTS_DIR,strConfigFolder,bKeyIsNew)) { return false; }
	}

	// lets first test if there was a folder passed in

	if ((strScriptsFolder.Exists()) && (3 < strScriptsFolder.GetLength())) {

		// we have a folder passed in, lets now check if we need to update anything:

		if (bConfigIsRelative != bIsRelative) {

			bConfigIsRelative = bIsRelative;
			bool bNewOrUpdated = false;

			if (!pConfig->Set_bool("paths", strRelativeKey, bConfigIsRelative, bNewOrUpdated)) { return false; }

		}

		if (!strConfigFolder.Compare(strScriptsFolder)) {

			strConfigFolder = strScriptsFolder; // update folder
			bool bNewOrUpdated = false;

			if (!pConfig->Set_str( "paths", "scripts", strConfigFolder, bNewOrUpdated)) { return false; }
		}
	}


	if(bConfigIsRelative)
	{
		if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; }

		OTString strScriptPath = "";
		if(!AppendFolder(strScriptPath, PrefixFolder(), strConfigFolder)) { OT_ASSERT(false); return false; }

		m_strScriptsFolder = strScriptPath; // set
	}
	else
	{
		if(!ToReal(strConfigFolder, strConfigFolder)) { OT_ASSERT(false); return false; }
		if(!FixPath(strConfigFolder, strConfigFolder, true)) { OT_ASSERT(false); return false; }
		m_strScriptsFolder = strConfigFolder; // set
	}
		
	if (!bPreLoaded)
	{
		if(!pConfig->Save()) { OT_ASSERT(false); return false; }
		pConfig->Reset();
	}
	return true;  // success
}
Пример #14
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int32_t OTBasket::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
    const OTString strNodeName(xml->getNodeName());

	if (strNodeName.Compare("currencyBasket"))
	{		
		OTString strSubCount, strMinTrans;
		strSubCount			= xml->getAttributeValue("contractCount");
		strMinTrans			= xml->getAttributeValue("minimumTransfer"); 
		
		m_nSubCount			= atoi(strSubCount.Get());
		m_lMinimumTransfer	= atol(strMinTrans.Get()); 
		
		OTLog::Output(1, "Loading currency basket...\n");
		
		return 1;
	}
	else if (strNodeName.Compare("requestExchange"))
	{		
		OTString strTransferMultiple, strRequestAccountID, strDirection, strTemp;
		
		strTransferMultiple	= xml->getAttributeValue("transferMultiple");
		strRequestAccountID	= xml->getAttributeValue("transferAccountID");
        strDirection        = xml->getAttributeValue("direction"); 
        strTemp             = xml->getAttributeValue("closingTransactionNo");
		
        if (strTransferMultiple.Exists())
            m_nTransferMultiple	= atoi(strTransferMultiple.Get());
        if (strRequestAccountID.Exists())
            m_RequestAccountID.SetString(strRequestAccountID);
        if (strDirection.Exists())
            m_bExchangingIn = strDirection.Compare("in");
        if (strTemp.Exists())
            SetClosingNum(atol(	strTemp.Get()	));

		OTLog::vOutput(2, "Basket Transfer multiple is %d. Direction is %s. Closing number is %lld. "
                       "Target account is:\n%s\n", m_nTransferMultiple, strDirection.Get(),
                       m_lClosingTransactionNo, strRequestAccountID.Get());
		
		return 1;
	}
	else if (strNodeName.Compare("basketItem"))
	{
		BasketItem * pItem = new BasketItem;
		
		OT_ASSERT_MSG(NULL != pItem, "Error allocating memory in OTBasket::ProcessXMLNode\n");
		
        OTString strTemp;
        
		strTemp = xml->getAttributeValue("minimumTransfer");
        if (strTemp.Exists())
            pItem->lMinimumTransferAmount	= atol(	strTemp.Get()	);

        strTemp = xml->getAttributeValue("closingTransactionNo");
        if (strTemp.Exists())
            pItem->lClosingTransactionNo	= atol(	strTemp.Get()	);
        
		OTString	strSubAccountID(xml->getAttributeValue("accountID")),
					strContractID(xml->getAttributeValue("assetID"));
		pItem->SUB_ACCOUNT_ID.SetString(strSubAccountID); 
		pItem->SUB_CONTRACT_ID.SetString(strContractID);
		
		m_dequeItems.push_back(pItem);

		OTLog::Output(2, "Loaded basket item.\n");
		
		return 1;
	}
	
	return 0;	
}
Пример #15
0
bool OTIdentifier::operator!=(const OTIdentifier &s2) const
{
	const OTString ots1(*this), ots2(s2);
	return !(ots1.Compare(ots2));	
}
Пример #16
0
const bool	OTSettings::Set_str (const OTString & strSection, const OTString & strKey, const OTString & strValue, bool & out_bNewOrUpdate, const OTString & strComment)
{
	if (! strSection.Exists())		{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); return false; }
	if (strSection.Compare(""))		{ OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strSection"			); OT_ASSERT(false); return false;  }

	if (! strKey.Exists())			{ OTLog::vError("%s: Error: %s is Empty!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); return false; }
	if (strKey.Compare(""))			{ OTLog::vError("%s: Error: %s is Blank!\n", __FUNCTION__, "strKey"				); OT_ASSERT(false); return false; }

	if (NULL == p_iniSimple)		{ OTLog::vError("%s: Error: %s is a NULL!\n", __FUNCTION__, "p_iniSimple"	); OT_ASSERT(false); return false; }
	//if (NULL == this->m_strConfigurationFileExactPath)		{ OTLog::vError("%s: Error: %s is a NULL!\n", __FUNCTION__, "p_iniSimple"	); OT_ASSERT(false); return false; }

	const char * const szValue	 = (strValue.Exists()	&& !strValue.Compare("")  ) ? strValue.Get()   : NULL;
	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 -> SetValue(strSection.Get(), strKey.Get(), szValue, szComment, true);
	if (0 > rc) return false;

	if (NULL == szValue)  // We set the key's value to null, thus removing it.
	{
		if (bOldKeyExist) out_bNewOrUpdate = true;
		else out_bNewOrUpdate = false;
		
		return true;
	}

	// 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;
}
Пример #17
0
const bool OTPaths::LoadSetScriptsFolder  // ie. PrefixFolder() + lib/opentxs/
	(
	OTSettings * pConfig, //optional
	const OTString & strScriptsFolder,	//optional
	const bool & bIsRelative			//optional
	)
{
	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	OTString strRelativeKey = "";
	strRelativeKey.Format("%s%s","scripts",OT_CONFIG_ISRELATIVE);

	// local vairables.
	bool bConfigIsRelative = false;
	OTString strConfigFolder = "";

	bool bKeyIsNew = false;

	if (!pConfig->CheckSet_bool("paths",strRelativeKey,true,bConfigIsRelative,bKeyIsNew)) { return false; }
	if (!pConfig->CheckSet_str("paths","scripts",OT_SCRIPTS_DIR,strConfigFolder,bKeyIsNew)) { return false; }

	if (!strConfigFolder.Compare(strScriptsFolder))  // only if we need to.
	{
		if(strScriptsFolder.Exists() && (3 < strScriptsFolder.GetLength()))
		{
			// update the local vairables.
			bConfigIsRelative = bIsRelative;
			strConfigFolder = strScriptsFolder;

			bool bNewOrUpdated = false;

			if (!pConfig->Set_bool("paths","scripts_is_",bConfigIsRelative,bNewOrUpdated)) { return false; }
			if (!pConfig->Set_str( "paths","scripts",strConfigFolder,bNewOrUpdated)) {return false; }
		}
	}

	if(bIsRelative)
	{
		if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; }

		OTString strScriptPath = "";
		if(AppendFolder(strScriptPath,PrefixFolder(),strConfigFolder)); else { OT_ASSERT(false); return false; }

		m_strScriptsFolder = strScriptPath; // set
	}
	else
	{
		if(!ToReal(strConfigFolder,strConfigFolder)) { OT_ASSERT(false); return false; }
		if(!FixPath(strConfigFolder,strConfigFolder,true)) { OT_ASSERT(false); return false; }
		m_strScriptsFolder = strConfigFolder; // set
	}

	if (!bPreLoaded)
	{
		if(!pConfig->Save()) { OT_ASSERT(false); return false; }
		pConfig->Reset();
	}
	return true;  // success
}
Пример #18
0
const bool OTPaths::ConfirmCreateFolder(const OTString & strExactPath, bool & out_Exists, bool & out_IsNew)
{
	const bool bExists = (strExactPath.Exists() && !strExactPath.Compare(""));
	OT_ASSERT_MSG(bExists,"OTPaths::ConfirmCreateFolder: Assert failed: no strFolderName\n");

	std::string l_strExactPath(strExactPath.Get());

	if ('/' != *l_strExactPath.rbegin()) return false; // not a directory.

	// Confirm If Directory Exists Already
	out_Exists = PathExists(strExactPath);

	if (out_Exists)
	{
		out_IsNew = false;
		return true;  // Already Have Folder, lets retun true!
	}
	else 
	{
		// It dosn't exist: lets create it.

#ifdef _WIN32
		bool bCreateDirSuccess = (_mkdir(strExactPath.Get()) == 0);
#else
		bool bCreateDirSuccess = (mkdir(strExactPath.Get(), 0700) == 0);
#endif

		if (!bCreateDirSuccess) 
		{
			OTLog::vError("OTPaths::ConfirmCreateFolder: Unable To Confirm "
				"Created Directory %s.\n", strExactPath.Get());
			out_IsNew = false;
			out_Exists = false;
			return false;
		}

		// At this point if the folder still doesn't exist, nothing we can do. We
		// already tried to create the folder, and SUCCEEDED, and then STILL failed 
		// to find it (if this is still false.)

		else 
		{
			bool bCheckDirExist = PathExists(strExactPath);

			if (!bCheckDirExist) 
			{
				OTLog::vError("OTPaths::ConfirmCreateFolder: "
					"Unable To Confirm Created Directory %s.\n", 
					strExactPath.Get());
				out_IsNew = false;
				out_Exists = false;
				return false;
			}
			else
			{
				out_IsNew = true;
				out_Exists = false;
				return true;  // We have Created and checked the Folder
			}
		}
		return false; // should never happen.
	}
}
Пример #19
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int OTCheque::ProcessXMLNode(IrrXMLReader*& xml)
{	
	int nReturnVal = 0;
	
	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do below, in the case of OTAccount.
	//if (nReturnVal = OTContract::ProcessXMLNode(xml))
	//	return nReturnVal;
	
	if (!strcmp("cheque", xml->getNodeName())) 
	{
		OTString strHasRecipient;
		strHasRecipient		= xml->getAttributeValue("hasRecipient");
		if (strHasRecipient.Compare("true"))
			m_bHasRecipient = true;
		else
			m_bHasRecipient = false;
        // ---------------------------------
        OTString strHasRemitter;
        strHasRemitter		= xml->getAttributeValue("hasRemitter");
		if (strHasRemitter.Compare("true"))
			m_bHasRemitter = true;
		else
			m_bHasRemitter = false;
        // ---------------------------------
		m_strVersion		= xml->getAttributeValue("version");					
		m_lAmount			= atol(xml->getAttributeValue("amount"));
        // ---------------------------------
		SetTransactionNum( atol(xml->getAttributeValue("transactionNum")) );
        // ---------------------------------
		SetValidFrom(atol(xml->getAttributeValue("validFrom")));
		SetValidTo  (atol(xml->getAttributeValue("validTo")));
        // ---------------------------------
		OTString	strAssetTypeID     (xml->getAttributeValue("assetTypeID")),
					strServerID        (xml->getAttributeValue("serverID")),
					strSenderAcctID    (xml->getAttributeValue("senderAcctID")),
					strSenderUserID    (xml->getAttributeValue("senderUserID")),
                    strRecipientUserID (xml->getAttributeValue("recipientUserID")),
                    strRemitterUserID  (xml->getAttributeValue("remitterUserID"));
		// ---------------------
		OTIdentifier	ASSET_ID(strAssetTypeID),		 SERVER_ID(strServerID),
						SENDER_ACCT_ID(strSenderAcctID), SENDER_USER_ID(strSenderUserID);
		// ---------------------
		SetAssetID(ASSET_ID);
		SetServerID(SERVER_ID);
		SetSenderAcctID(SENDER_ACCT_ID);
		SetSenderUserID(SENDER_USER_ID);
		// ---------------------
		// Recipient ID 
		if (m_bHasRecipient)
		{
			m_RECIPIENT_USER_ID.SetString(strRecipientUserID);
		}
		else
		{
			m_RECIPIENT_USER_ID.Release();
		}
		// ---------------------
		// Remitter ID (for vouchers)
		if (m_bHasRemitter)
		{
			m_REMITTER_ID.SetString(strRemitterUserID);
		}
		else
		{
			m_REMITTER_ID.Release();
		}
		// ---------------------
		
		OTLog::vOutput(2,
                       "\n\nCheque Amount: %ld.  Transaction Number: %ld\n Valid From: %d\n Valid To: %d\n"
                       " AssetTypeID: %s\n ServerID: %s\n"
                       " senderAcctID: %s\n senderUserID: %s\n "
                       " Has Recipient? %s. If yes, UserID of Recipient: %s\n"
                       " Has Remitter? %s. If yes, UserID of Recipient: %s\n",
                       m_lAmount, m_lTransactionNum, m_VALID_FROM, m_VALID_TO,
                       strAssetTypeID.Get(), strServerID.Get(),
                       strSenderAcctID.Get(), strSenderUserID.Get(), 
                       (m_bHasRecipient ? "Yes" : "No"),
                       strRecipientUserID.Get(),
                       (m_bHasRemitter ? "Yes" : "No"),
                       strRemitterUserID.Get());
		
		nReturnVal = 1;
	}
	
	else if (!strcmp("memo", xml->getNodeName())) 
	{		
		if (false == OTContract::LoadEncodedTextField(xml, m_strMemo))
		{
			OTLog::Error("Error in OTCheque::ProcessXMLNode: memo field without value.\n");
			return (-1); // error condition
		}
		
		return 1;
	}
	
	return nReturnVal;
}
Пример #20
0
// The LoadSet Functions will update the static values.
const bool OTPaths::LoadSetPrefixFolder	// eg. /usr/local/  
	(	
	OTSettings * pConfig,	//optional
	const OTString & strPrefixFolder				//optional
	//const bool & bIsRelative (cannot be relative);
	)
{
	/*
	The prefix path is special.

	This path is tested if it is different to the
	one that would be automatically selected by this program
	(aka either compiled into, or from the registry, or the default user data directory).

	If the set path is different to what would be supplied and the ‘override path’ value is set.
	Then we will use that path.

	Otherwise, we will update the path in the configuration to link against the updated path.

	Users will need to set the ‘override path’ flag in the configuration,
	if they want to manually set the prefix path.
	*/

	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	// get default path
	OTString strDefaultPrefixPath(OT_PREFIX_PATH);

#ifdef _WIN32
	OTString strTemp;
	if (OTPaths::Win_GetInstallFolderFromRegistry(strTemp))
	{
		strDefaultPrefixPath = strTemp;
	}
#endif

	// now check the configuration to see what values we have:
	OTString strConfigPath = "";
	bool bNewPath = false;
	bool bHaveRelativePath = false; // should always be false.
	bool bPrefixPathOverride = false;
	bool bNoOverrideFlagWasSet = false;

	if(!pConfig->CheckSet_str("paths","prefix_path",strDefaultPrefixPath,strConfigPath,bNewPath)) { return false; }

	OTString strPrefixPathOverride("prefix_path_override");
	if(!pConfig->CheckSet_bool("paths",strPrefixPathOverride,false,bPrefixPathOverride,bNoOverrideFlagWasSet,"; Set this if you don't want this path to change")) {return false; }

	OTString strLocalPrefixPath = "";

	// if the caller has supplied a prefix folder, lets set that.
	if(strPrefixFolder.Exists() && (3 < strPrefixFolder.GetLength()))
	{
		if (!strConfigPath.Compare(strPrefixFolder))
		{
			// we set the new path (from this function caller)
			bool bNewOrUpdate = false;
			if(!pConfig->Set_str("paths","prefix_path",strPrefixFolder,bNewOrUpdate)) { return false; }
		}
		strLocalPrefixPath = strPrefixFolder; // set
	}
	else
	{
		// we should update the path
		if (!bPrefixPathOverride)
		{
			if (!strConfigPath.Compare(strDefaultPrefixPath))
			{
				// we set the new default path (since we have no overide set)
				bool bNewOrUpdate = false;
				if(!pConfig->Set_str("paths","prefix_path",strDefaultPrefixPath,bNewOrUpdate)) { return false; }
			}
			strLocalPrefixPath = strDefaultPrefixPath; // set
		}
		else
		{
			strLocalPrefixPath = strConfigPath; // set
		}
	}

	if (!strLocalPrefixPath.Exists()) { OT_ASSERT(false); }

	if(!ToReal(strLocalPrefixPath,strLocalPrefixPath)) { OT_ASSERT(false); return false; }
	if(!FixPath(strLocalPrefixPath,strLocalPrefixPath,true)) { OT_ASSERT(false); return false; }

	m_strPrefixFolder = strLocalPrefixPath;

	if (!bPreLoaded)
	{
		if(!pConfig->Save()) { OT_ASSERT(false); return false; }
		pConfig->Reset();
	}
	return true;
}
Пример #21
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int OTToken::ProcessXMLNode(IrrXMLReader*& xml)
{
	static int nPublicTokenCount = 0;
	static int nPrivateTokenCount = 0;
	
	int nReturnVal = 0;
	
	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do below, in the case of OTAccount.
	//if (nReturnVal = OTContract::ProcessXMLNode(xml))
	//	return nReturnVal;
	
	if (!strcmp("token", xml->getNodeName())) 
	{
		OTString strState;

		m_strVersion	= xml->getAttributeValue("version");					
		strState		= xml->getAttributeValue("state");

		m_nSeries		= atoi(xml->getAttributeValue("series"));
		m_VALID_FROM	= atol(xml->getAttributeValue("validFrom"));
		m_VALID_TO		= atol(xml->getAttributeValue("validTo"));
		
		SetDenomination(atol(xml->getAttributeValue("denomination")));

		if (strState.Compare("blankToken"))
			m_State = OTToken::blankToken;
		else if (strState.Compare("protoToken"))
			m_State = OTToken::protoToken;
		else if (strState.Compare("signedToken"))
			m_State = OTToken::signedToken;
		else if (strState.Compare("spendableToken"))
			m_State = OTToken::spendableToken;
		else if (strState.Compare("verifiedToken"))
			m_State = OTToken::verifiedToken;
		else
			m_State = OTToken::errorToken;
		
        if (m_State == OTToken::spendableToken)
            m_strContractType.Set("CASH");

		OTString	strAssetTypeID(xml->getAttributeValue("assetTypeID")),
					strServerID(xml->getAttributeValue("serverID"));
		
		m_AssetTypeID.SetString(strAssetTypeID);
		m_ServerID.SetString(strServerID);

		OTLog::vOutput(4,
				//	"\n===> Loading XML for token into memory structures..."
				"\n\nToken State: %s\n Denomination: %ld\n"
				" AssetTypeID: %s\nServerID: %s\n", 
				strState.Get(), GetDenomination(), strAssetTypeID.Get(), strServerID.Get());
		
		nReturnVal = 1;
	}
	
	else if (!strcmp("tokenID", xml->getNodeName())) 
	{		
		if (false == LoadEncodedTextField(xml, m_ascSpendable))
		{
			OTLog::Error("Error in OTToken::ProcessXMLNode: token ID without value.\n");
			return (-1); // error condition
		}
		
		return 1;
	}
	
	else if (!strcmp("tokenSignature", xml->getNodeName())) 
	{		
		if (false == LoadEncodedTextField(xml, m_Signature))
		{
			OTLog::Error("Error in OTToken::ProcessXMLNode: token Signature without value.\n");
			return (-1); // error condition
		}
		
		return 1;
	}
	
	else if (!strcmp("protopurse", xml->getNodeName())) 
	{	// TODO for security, if the count here doesn't match what's loaded up, that should be part of
		// what is verified in each token when it's verified..
		m_nTokenCount	= atoi(xml->getAttributeValue("count"));
		m_nChosenIndex	= atoi(xml->getAttributeValue("chosenIndex"));

		nPublicTokenCount = 0;
		
		return 1;
	}
	
	else if (!strcmp("prototoken", xml->getNodeName())) 
	{		
		OTASCIIArmor * pArmoredPrototoken = new OTASCIIArmor;
		
		OT_ASSERT(NULL != pArmoredPrototoken);
		
		if (!LoadEncodedTextField(xml, *pArmoredPrototoken) || !pArmoredPrototoken->Exists())
		{
			OTLog::Error("Error in OTToken::ProcessXMLNode: prototoken field without value.\n");
			
			delete pArmoredPrototoken;
			pArmoredPrototoken = NULL;
			
			return (-1); // error condition
		}
		else 
		{			
			m_mapPublic[nPublicTokenCount] = pArmoredPrototoken;
			nPublicTokenCount++;
		}
		
		return 1;
	}
		
	else if (!strcmp("privateProtopurse", xml->getNodeName())) 
	{	
		nPrivateTokenCount = 0;
		
		return 1;
	}
	
	else if (!strcmp("privatePrototoken", xml->getNodeName())) 
	{		
		OTASCIIArmor * pArmoredPrototoken = new OTASCIIArmor;
		
		OT_ASSERT(NULL != pArmoredPrototoken);
		
		if (!LoadEncodedTextField(xml, *pArmoredPrototoken) || !pArmoredPrototoken->Exists())
		{
			OTLog::Error("Error in OTToken::ProcessXMLNode: privatePrototoken field without value.\n");
			
			delete pArmoredPrototoken;
			pArmoredPrototoken = NULL;
			
			return (-1); // error condition
		}
		else 
		{			
			m_mapPrivate[nPrivateTokenCount] = pArmoredPrototoken;
			nPrivateTokenCount++;
			
			OTLog::vOutput(4, "Loaded prototoken and adding to m_mapPrivate at index: %d\n", nPrivateTokenCount-1);
		}
		
		return 1;
	}
		
	return nReturnVal;
}
Пример #22
0
// OTMessageOutbuffer deletes the OTMessage when you call this.
//
bool OTMessageOutbuffer::RemoveSentMessage(const int64_t & lRequestNum, const OTString & strServerID, const OTString & strNymID)
{
    OTString strFolder, strFile;
    strFolder.Format("%s%s%s%s%s%s%s",
                     OTFolders::Nym().Get(),         OTLog::PathSeparator(),
                     strServerID.Get(),          OTLog::PathSeparator(),
                     "sent", /*todo hardcoding*/ OTLog::PathSeparator(),
                     strNymID.Get());
    strFile.Format("%lld.msg", lRequestNum);
    // ------------------------------------------------
    mapOfMessages::iterator it = m_mapMessages.begin();
    
    bool bReturnValue = false;
    
    while (it != m_mapMessages.end())
    {
        // -----------------------------
        const int64_t  & lTempReqNum   = it->first;
        // -----------------------
        if (lTempReqNum != lRequestNum)
        {
            ++it;
            continue;
        }
        // -----------------------
        OTMessage   * pMsg          = it->second;
        OT_ASSERT(NULL != pMsg);
        // -----------------------------
        //
        // If a server ID was passed in, but doesn't match the server ID on this message,
        // Then skip this one. (Same with the NymID.)
        if (!strServerID.Compare(pMsg->m_strServerID) ||
            !strNymID.   Compare(pMsg->m_strNymID))
        {
            ++it;
            continue;
        }
        // --------
        else
        {
            delete pMsg; pMsg = NULL;
            // ----------------------
            mapOfMessages::iterator temp_it = it;
            ++temp_it;
            m_mapMessages.erase(it);
            it = temp_it; // here's where it gets incremented. (During the erase, basically.)
            // ----------------------
            bReturnValue = true;
            break;
        }
    }
    // ----------------------------------
    // Whether we found it in RAM or not, let's make sure to delete it from
    // local storage, if it's there... (Since there's a list there we have to update,
    // anyway.)
    // We keep a list of the request numbers, so let's load it up, remove the number
    // from that list, and then save it again.
    // ----------------------------------
    OTNumList theNumList;
    std::string str_data_filename("sent.dat");  // todo hardcoding.
    if (OTDB::Exists(strFolder.Get(), str_data_filename))
    {
        OTString strNumList(OTDB::QueryPlainString(strFolder.Get(), str_data_filename));
        if (strNumList.Exists())
            theNumList.Add(strNumList);
        theNumList.Remove(lRequestNum);
    }
    else // it doesn't exist on disk, so let's just create it from the list we have in RAM so we can store it to disk.
    {
        it = m_mapMessages.begin();
        while (it != m_mapMessages.end())
        {
            // -----------------------------
            const int64_t  & lTempReqNum   = it->first;
            // -----------------------
            OTMessage   * pMsg          = it->second;
            OT_ASSERT(NULL != pMsg);
            // -----------------------------
            //
            // If a server ID was passed in, but doesn't match the server ID on this message,
            // Then skip this one. (Same with the NymID.)
            //
            if (!strServerID.Compare(pMsg->m_strServerID) ||
                !strNymID.   Compare(pMsg->m_strNymID))
            {
                ++it;
                continue;
            }
            // --------
            else
            {
                theNumList.Add(lTempReqNum);
            }
            ++it;
        }
    }// else
    // ----------------------------------
    // By this point, theNumList has either been loaded from local storage and had the number removed,
    // or it wasn't in local storage and thus we created it and added all the numbers to it from RAM (not
    // including the one being erased, since it was already removed from the RAM list, above.) So either
    // way, the number being removed is now ABSENT from theNumList.
    //
    // Therefore nothing left to do here, but save it back again!
    //
    OTString strOutput;
    theNumList.Output(strOutput);
    if (!OTDB::StorePlainString(strOutput.Get(), strFolder.Get(), str_data_filename))
    {
        OTLog::Error("OTMessageOutbuffer::RemoveSentMessage: Error: failed writing list of request numbers to storage.\n");
    }
    // ----------------------------------
    // Now that we've updated the numlist in local storage, let's
    // erase the sent message itself...
    //
    OTMessage * pMsg = new OTMessage;
    OT_ASSERT(NULL != pMsg);
    OTCleanup<OTMessage> theMsgAngel(pMsg);
    
    if (OTDB::Exists(strFolder.Get(), strFile.Get()) && pMsg->LoadContract(strFolder.Get(), strFile.Get()))
    {
        OTDB::EraseValueByKey(strFolder.Get(), strFile.Get());
        return true;
    }
    // ----------------------------------
	return bReturnValue;
}
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int32_t OTAccount::ProcessXMLNode(IrrXMLReader*& xml)
{
	int32_t nReturnVal = 0;

    const OTString strNodeName(xml->getNodeName());

	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do below, in the case of OTAccount.
	//if (nReturnVal = OTTransactionType::ProcessXMLNode(xml))
	//	return nReturnVal;

	if (strNodeName.Compare("assetAccount"))
	{
		OTString strAcctType;

		m_strVersion	= xml->getAttributeValue("version");
		strAcctType		= xml->getAttributeValue("type");

		if (!strAcctType.Exists())
		{
			OTLog::Error("OTAccount::ProcessXMLNode: Failed: Empty assetAccount 'type' attribute.\n");
			return (-1);
		}

		m_AcctType = TranslateAccountTypeStringToEnum(strAcctType);

		if (OTAccount::err_acct == m_AcctType)
		{
			OTLog::Error("OTAccount::ProcessXMLNode: Failed: assetAccount 'type' attribute contains unknown value.\n");
			return (-1);
		}

		// -------------------------------------------------
        const OTString strAcctAssetType	= xml->getAttributeValue("assetTypeID");

        if (strAcctAssetType.Exists())
            m_AcctAssetTypeID.SetString(strAcctAssetType);
		// -------------------------------------------------

		OTString	strAccountID(xml->getAttributeValue("accountID")),
        strServerID(xml->getAttributeValue("serverID")),
        strAcctUserID(xml->getAttributeValue("userID"));

		OTIdentifier	ACCOUNT_ID(strAccountID),
                        SERVER_ID(strServerID),
                        USER_ID(strAcctUserID);

		SetPurportedAccountID(ACCOUNT_ID);
		SetPurportedServerID(SERVER_ID);
		SetUserID(USER_ID);

		OTString strAssetTypeID(m_AcctAssetTypeID);
		OTLog::vOutput(3,
                       //	"\n===> Loading XML for Account into memory structures..."
                       "\n\nAccount Type: %s\nAccountID: %s\nUserID: %s\n"
                       "AssetTypeID: %s\nServerID: %s\n",
                       strAcctType.Get(), strAccountID.Get(), strAcctUserID.Get(),
                       strAssetTypeID.Get(), strServerID.Get());

		nReturnVal = 1;
	}

	else if (strNodeName.Compare("inboxHash"))
	{
		// -------------------------------------------------
        const OTString strHash	= xml->getAttributeValue("value");
        if (strHash.Exists())
            m_InboxHash.SetString(strHash);
		// -------------------------------------------------
		OTLog::vOutput(3, "Account inboxHash: %s\n", strHash.Get());
		// -------------------------------------------------
		nReturnVal = 1;
	}

	else if (strNodeName.Compare("outboxHash"))
	{
		// -------------------------------------------------
        const OTString strHash	= xml->getAttributeValue("value");
        if (strHash.Exists())
            m_OutboxHash.SetString(strHash);
		// -------------------------------------------------
		OTLog::vOutput(3, "Account outboxHash: %s\n", strHash.Get());
		// -------------------------------------------------
		nReturnVal = 1;
	}

    else if (strNodeName.Compare("MARKED_FOR_DELETION"))
    {
        m_bMarkForDeletion = true;
        OTLog::vOutput(3, "This asset account has been MARKED_FOR_DELETION (at some point prior.)\n");

        nReturnVal = 1;
    }

    else if (strNodeName.Compare("balance"))
	{
		m_BalanceDate	= xml->getAttributeValue("date");
		m_BalanceAmount	= xml->getAttributeValue("amount");

		// I convert to integer / int64_t and back to string.
		// (Just an easy way to keep the data clean.)

		int32_t nDate		= atoi(m_BalanceDate.Get());
		int64_t lAmount	= atol(m_BalanceAmount.Get());

		m_BalanceDate.Format("%d", nDate);
		m_BalanceAmount.Format("%lld", lAmount);

//		OTLog::vOutput(1, "\nBALANCE  --  %s\n",
//					   m_BalanceAmount.Get());
		OTLog::vOutput(3, "\nBALANCE  --  %s\nDATE     --  %s\n",
					   m_BalanceAmount.Get(), m_BalanceDate.Get());

		nReturnVal = 1;
	}

    else if (strNodeName.Compare("stashinfo"))
	{
		if (!IsStashAcct())
		{
			OTLog::Error("OTAccount::ProcessXMLNode: Error: Encountered stashinfo tag while loading NON-STASH account. \n");
			return (-1);
		}
		// ------------------------------------------------------------------------
		int64_t lTransNum = 0;
		const OTString	strStashTransNum	= xml->getAttributeValue("cronItemNum");
		if (!strStashTransNum.Exists() || ((lTransNum = atol(strStashTransNum.Get())) <= 0))
		{
			m_lStashTransNum = 0;
			OTLog::vError("OTAccount::ProcessXMLNode: Error: Bad transaction number for supposed corresponding cron item: %lld \n",
						 lTransNum);
			return (-1);
		}
		else
			m_lStashTransNum = lTransNum;

		// ------------------------------

		OTLog::vOutput(3, "\nSTASH INFO:   CronItemNum     --  %lld\n", m_lStashTransNum);

		nReturnVal = 1;
	}

	return nReturnVal;
}
Пример #24
0
// The LoadSet Functions will update the static values.
const bool OTPaths::LoadSetPrefixFolder	// eg. /usr/local/  
	(	
	OTSettings * pConfig,	//optional
	const OTString & strPrefixFolder				//optional
	//const bool & bIsRelative (cannot be relative);
	)
{
	/*
	The prefix path is special.

	This path is tested if it is different to the
	one that would be automatically selected by this program
	(aka either compiled into, or from the registry, or the default user data directory).

	If the set path is different to what would be supplied and the ‘override path’ value is set.
	Then we will use that path.

	Otherwise, we will update the path in the configuration to link against the updated path.

	Users will need to set the ‘override path’ flag in the configuration,
	if they want to manually set the prefix path.
	*/

	if (NULL == pConfig)  { OT_ASSERT(false); return false; }

	const bool bPreLoaded(pConfig->IsLoaded());

	if (!bPreLoaded)
	{
		pConfig->Reset();
		if(!pConfig->Load()) { OT_ASSERT(false); return false; }
	}

	{
		// get default path
		OTString strDefaultPrefixPath(OT_PREFIX_PATH);
		{
			if (!strDefaultPrefixPath.Exists()) { OTLog::sError("%s: Error: OT_PREFIX_PATH is not set!",__FUNCTION__); OT_ASSERT(false); }

#ifdef _WIN32
			OTString strTemp;
			if (OTPaths::Win_GetInstallFolderFromRegistry(strTemp))
			{
				strDefaultPrefixPath = strTemp;
			}
#endif

			if(!ToReal(strDefaultPrefixPath,strDefaultPrefixPath)) { OT_ASSERT(false); return false; }
			if(!FixPath(strDefaultPrefixPath,strDefaultPrefixPath,true)) { OT_ASSERT(false); return false; }
		}

		OTString strLocalPrefixPath = "";
		bool bPrefixPathOverride = false;

		{
			// now check the configuration to see what values we have:
			OTString strConfigPath = "";

			bool bIsNew = false;
			OTString strPrefixPathOverride("prefix_path_override");

			if(!pConfig->CheckSet_str("paths","prefix_path",strDefaultPrefixPath,strConfigPath,bIsNew)) { return false; }
			if(!pConfig->CheckSet_bool("paths",strPrefixPathOverride,false,bPrefixPathOverride,bIsNew,"; This will force the prefix not to change")) {return false; }

			// if the config dosn't have a prefix path set. Lets set the default.
			// if a prefix path was passed in, we will override with that later.
			if (!strConfigPath.Exists() || (3 > strConfigPath.GetLength())) {
				OTLog::sError("%s: Error: Bad %s in config, will reset!",__FUNCTION__,"prefix_path");

				strConfigPath = strDefaultPrefixPath; // set
				bPrefixPathOverride = false;

				// lets set the default path, and reset override
				bool bNewOrUpdate = false;
				if(!pConfig->Set_str("paths","prefix_path",strDefaultPrefixPath,bNewOrUpdate)) { return false; }
				if(!pConfig->Set_bool("paths",strPrefixPathOverride,false,bNewOrUpdate)) { return false; }
			}

			strLocalPrefixPath = strConfigPath;
		}

		{
			if (!bPrefixPathOverride)
			{
				bool bUpdate = false;

				// default
				if (!strLocalPrefixPath.Compare(strDefaultPrefixPath)) {
					strLocalPrefixPath = strDefaultPrefixPath;
					bUpdate = true;
				}

				// passed in
				if (strPrefixFolder.Exists() && (3 < strPrefixFolder.GetLength())) {
					// a prefix folder was passed in... lets use it, and update the config if the override isn't set
					OTString strTmp = strPrefixFolder;

					if(!ToReal(strTmp,strTmp)) { OT_ASSERT(false); return false; }
					if(!FixPath(strTmp,strTmp,true)) { OT_ASSERT(false); return false; }

					if (!strLocalPrefixPath.Compare(strTmp)) {
						strLocalPrefixPath = strTmp;
						bUpdate = true;
					}
				}

				// we need to update the path in the config
				if (bUpdate) {
					bool bNewOrUpdate = false;
					if(!pConfig->Set_str("paths","prefix_path",strLocalPrefixPath,bNewOrUpdate)) { return false; }
				}
			}
		}

		{
			if (!strLocalPrefixPath.Exists()) { OT_ASSERT(false); }

			if(!ToReal(strLocalPrefixPath,strLocalPrefixPath)) { OT_ASSERT(false); return false; }
			if(!FixPath(strLocalPrefixPath,strLocalPrefixPath,true)) { OT_ASSERT(false); return false; }
			m_strPrefixFolder = strLocalPrefixPath;
		}

	}

	if (!bPreLoaded)
	{
		if(!pConfig->Save()) { OT_ASSERT(false); return false; }
		pConfig->Reset();
	}
	return true;
}
Пример #25
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int OTOffer::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
	int nReturnVal = 0;
	
	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do below, in the case of OTAccount.
	//if (nReturnVal = OTContract::ProcessXMLNode(xml))
	//	return nReturnVal;
	
	if (!strcmp("marketOffer", xml->getNodeName()))
	{		
		m_strVersion		= xml->getAttributeValue("version");					

		OTString strIsSelling;
		strIsSelling		= xml->getAttributeValue("isSelling");
		if (strIsSelling.Compare("true"))
			m_bSelling = true;
		else
			m_bSelling = false;
				
		m_strContractType.Set((m_bSelling ? "ASK" : "BID"));

		const OTString	strServerID(xml->getAttributeValue("serverID")),
						strAssetTypeID(xml->getAttributeValue("assetTypeID")),
						strCurrencyTypeID(xml->getAttributeValue("currencyTypeID"));
		
		const OTIdentifier	SERVER_ID(strServerID),	
                            ASSET_ID(strAssetTypeID),		
							CURRENCY_TYPE_ID(strCurrencyTypeID);
		
		SetServerID(SERVER_ID);
		SetAssetID(ASSET_ID);
		SetCurrencyID(CURRENCY_TYPE_ID);
		// ------------------------------------
		const OTString strScale	= xml->getAttributeValue("marketScale");
		const long lScale		= strScale.Exists() ? atol(strScale.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire.
				
		if (false == isPowerOfTen( lScale ))
		{
			OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: marketScale *must* be 1, or a power of 10. Instead I got: %ld.\n",
						   lScale);
			return (-1);
		}
		else
			SetScale(lScale);
		// ------------------------------------
		const OTString strPriceLimit	= xml->getAttributeValue("priceLimit");
		const long lPriceLimit			= strPriceLimit.Exists() ? atol(strPriceLimit.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire.
		if (lPriceLimit < 1)
		{
			OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: priceLimit *must* be larger than 0. Instead I got: %ld.\n",
						   lPriceLimit);
			return (-1);
		}
		else
			SetPriceLimit(lPriceLimit);
		// ------------------------------------
		const OTString strTotal	= xml->getAttributeValue("totalAssetsOnOffer");
		const long lTotal		= strTotal.Exists() ? atol(strTotal.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire.
		if (lTotal < 1)
		{
			OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: totalAssetsOnOffer *must* be larger than 0. Instead I got: %ld.\n",
						   lTotal);
			return (-1);
		}
		else
			SetTotalAssetsOnOffer(lTotal);
		// ------------------------------------
		const OTString strFinished	= xml->getAttributeValue("finishedSoFar");
		const long lFinished		= strFinished.Exists() ? atol(strFinished.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire.
		if (lFinished < 0)
		{
			OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: finishedSoFar *must* be 0 or larger. Instead I got: %ld.\n",
						   lFinished);
			return (-1);
		}
		else
			SetFinishedSoFar(lFinished);
		// ------------------------------------
		const OTString	strMinInc	= xml->getAttributeValue("minimumIncrement");
		const long		lMinInc		= strMinInc.Exists() ? atol(strMinInc.Get()) : 0; // if it doesn't exist, the 0 here causes the below error to fire.
		if ((lMinInc < 1) || (lMinInc > lTotal)) // Minimum increment cannot logically be higher than the total assets on offer...
		{
			OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: minimumIncrement *must* be 1 or larger, \n"
						   "and must also be less than the total assets on offer. Instead I got: %ld.\n",
						   lMinInc);
			return (-1);
		}
		else
			SetMinimumIncrement(lMinInc);
		// -----------------------------------
		const OTString strTransNum = xml->getAttributeValue("transactionNum");
		const long lTransNum = strTransNum.Exists() ? atol(strTransNum.Get()) : 0;
		
		SetTransactionNum(lTransNum);
		// ----------------------------------------------------------------
		const OTString strValidFrom	= xml->getAttributeValue("validFrom");
		const OTString strValidTo	= xml->getAttributeValue("validTo");
		
		time_t tValidFrom	=	strValidFrom.Exists() ? atoi(strValidFrom.Get()) : 0;
		time_t tValidTo		=	strValidTo.Exists() ? atoi(strValidTo.Get()) : 0;

		if ((tValidTo < tValidFrom) && (tValidTo != 0))
		{
			long nFrom= static_cast<long> (tValidFrom), nTo= static_cast<long> (tValidTo);
			OTLog::vOutput(0, "OTOffer::ProcessXMLNode: Failure: validTo date (%ld) cannot be earlier than validFrom date (%ld).\n",
						   nFrom, nTo);
			return (-1);
		}
		
		SetValidFrom(tValidFrom);
		SetValidTo(tValidTo);
		
		// ---------------------
		
		OTLog::vOutput(4,
					   "\n\nOffer. Transaction Number: %ld\n Valid From: %d\n Valid To: %d\n"
					   " AssetTypeID: %s\n  CurrencyTypeID: %s\n ServerID: %s\n"
					   " Price Limit: %ld,  Total Assets on Offer: %ld,  %s so far: %ld\n "
					   " Scale: %ld.   Minimum Increment: %ld.  This offer is a%s.\n", 
					   m_lTransactionNum, m_VALID_FROM, m_VALID_TO,
					   strAssetTypeID.Get(), strCurrencyTypeID.Get(), strServerID.Get(),
					   GetPriceLimit(), GetTotalAssetsOnOffer(),  (m_bSelling ? "sold" : "bought"), 
					   GetFinishedSoFar(), GetScale(), GetMinimumIncrement(), 
					   (m_bSelling ? "n ASK" : " BID"));
		
		nReturnVal = 1;
	}
		
	return nReturnVal;	
}
Пример #26
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int OTAccount::ProcessXMLNode(IrrXMLReader*& xml)
{
	int nReturnVal = 0;

	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do below, in the case of OTAccount.
	//if (nReturnVal = OTContract::ProcessXMLNode(xml))
	//	return nReturnVal;

	if (!strcmp("assetAccount", xml->getNodeName())) 
	{
		OTString strAcctType;
		
		m_strVersion	= xml->getAttributeValue("version");					
		strAcctType		= xml->getAttributeValue("type");
		
		
		if (strAcctType.Compare("simple"))
			m_AcctType = OTAccount::simple;
		else if (strAcctType.Compare("issuer"))
			m_AcctType = OTAccount::issuer;
		else if (strAcctType.Compare("basket"))
			m_AcctType = OTAccount::basket;
		else
			m_AcctType = OTAccount::err_acct;
		
		m_AcctAssetTypeID.SetString(xml->getAttributeValue("assetTypeID"));
		
		OTString	strAccountID(xml->getAttributeValue("accountID")),
					strServerID(xml->getAttributeValue("serverID")),
					strAcctUserID(xml->getAttributeValue("userID"));
		
		OTIdentifier	ACCOUNT_ID(strAccountID), 
						SERVER_ID(strServerID),
						USER_ID(strAcctUserID);
		
		SetPurportedAccountID(ACCOUNT_ID);
		SetPurportedServerID(SERVER_ID);
		SetUserID(USER_ID);

		OTString strAssetTypeID(m_AcctAssetTypeID);
		OTLog::vOutput(1,
			//	"\n===> Loading XML for Account into memory structures..."
				"\n\nAccount Type: %s\nAccountID: %s\nUserID: %s\n"
				"AssetTypeID: %s\nServerID: %s\n", 
				strAcctType.Get(), strAccountID.Get(), strAcctUserID.Get(),
				strAssetTypeID.Get(), strServerID.Get());
		
		nReturnVal = 1;
	}
	
	else if (!strcmp("balance", xml->getNodeName())) 
	{
		m_BalanceDate	= xml->getAttributeValue("date");
		m_BalanceAmount	= xml->getAttributeValue("amount");
		
		// I convert to integer / long and back to string.
		// (Just an easy way to keep the data clean.)
		
		int nDate		= atoi(m_BalanceDate.Get());
		long lAmount	= atol(m_BalanceAmount.Get());
		
		m_BalanceDate.Format("%d", nDate);
		m_BalanceAmount.Format("%ld", lAmount);
		
//		OTLog::vOutput(1, "\nBALANCE  --  %s\n",
//					   m_BalanceAmount.Get());
		OTLog::vOutput(1, "\nBALANCE  --  %s\nDATE     --  %s\n",
					   m_BalanceAmount.Get(), m_BalanceDate.Get());
		
		nReturnVal = 1;
	}

	return nReturnVal;
}
Пример #27
0
// return -1 if error, 0 if nothing, and 1 if the node was processed.
int OTOffer::ProcessXMLNode(irr::io::IrrXMLReader*& xml)
{
	int nReturnVal = 0;
	
	// Here we call the parent class first.
	// If the node is found there, or there is some error,
	// then we just return either way.  But if it comes back
	// as '0', then nothing happened, and we'll continue executing.
	//
	// -- Note you can choose not to call the parent if
	// you don't want to use any of those xml tags.
	// As I do below, in the case of OTAccount.
	//if (nReturnVal = OTContract::ProcessXMLNode(xml))
	//	return nReturnVal;
	
	if (!strcmp("marketOffer", xml->getNodeName())) 
	{		
		m_strVersion		= xml->getAttributeValue("version");					

		OTString strIsSelling;
		strIsSelling		= xml->getAttributeValue("isSelling");
		if (strIsSelling.Compare("true"))
			m_bSelling = true;
		else
			m_bSelling = false;
				
		m_strContractType.Set((m_bSelling ? "ASK" : "BID"));

		const OTString	strServerID(xml->getAttributeValue("serverID")),
						strAssetTypeID(xml->getAttributeValue("assetTypeID")),
						strCurrencyTypeID(xml->getAttributeValue("currencyTypeID"));
		
		const OTIdentifier	SERVER_ID(strServerID),	ASSET_ID(strAssetTypeID),		
							CURRENCY_TYPE_ID(strCurrencyTypeID);
		
		SetServerID(SERVER_ID);
		SetAssetID(ASSET_ID);
		SetCurrencyID(CURRENCY_TYPE_ID);

		SetPriceLimit(			atol(xml->getAttributeValue("priceLimit")));
		SetTotalAssetsOnOffer(	atol(xml->getAttributeValue("totalAssetsOnOffer")));
		SetFinishedSoFar(		atol(xml->getAttributeValue("finishedSoFar")));
		SetScale(				atol(xml->getAttributeValue("marketScale")));
		SetMinimumIncrement(	atol(xml->getAttributeValue("minimumIncrement")));
		SetTransactionNum(		atol(xml->getAttributeValue("transactionNum")) );
		SetValidFrom(			atol(xml->getAttributeValue("validFrom")));
		SetValidTo(				atol(xml->getAttributeValue("validTo")));
		
		// ---------------------
		
		OTLog::vOutput(0,
					   "\n\nOffer. Transaction Number: %ld\n Valid From: %d\n Valid To: %d\n"
					   " AssetTypeID: %s\n  CurrencyTypeID: %s\n ServerID: %s\n"
					   " Price Limit: %ld,  Total Assets on Offer: %ld,  %s so far: %ld\n "
					   " Scale: %ld.   Minimum Increment: %ld.  This offer is a%s.\n", 
					   m_lTransactionNum, m_VALID_FROM, m_VALID_TO,
					   strAssetTypeID.Get(), strCurrencyTypeID.Get(), strServerID.Get(),
					   GetPriceLimit(), GetTotalAssetsOnOffer(),  (m_bSelling ? "sold" : "bought"), 
					   GetFinishedSoFar(), GetScale(), GetMinimumIncrement(), 
					   (m_bSelling ? "n ASK" : " BID"));
		
		nReturnVal = 1;
	}
		
	return nReturnVal;	
}