Example #1
0
CVariant::CVariant(const CVariant& v)
    : m_data(0)
{
    if( v.GetData() != 0 ) {
        m_data = v.GetData()->Clone();
    }
}
Example #2
0
void CCallableStatement::SetParam(const CVariant& v,
                  const CDBParamVariant& param)
{
    if (param.IsPositional()) {
        // Decrement position by ONE.
        GetRpcCmd()->GetBindParams().Set(param.GetPosition() - 1, v.GetData());
    } else {
        GetRpcCmd()->GetBindParams().Set(param, v.GetData());
    }
}
Example #3
0
bool CKadScript::LoadData(const wstring& Path)
{
	CVariant Data;
	if(!ReadFile(Path, Data))
		return false;

	try
	{
		m_LastUsed = Data["LastUsed"].To<uint64>();
		if(!m_LastUsed)
			m_LastUsed = GetTime();

		m_Data->Set(Data["Data"]);

		if(Data.Has("KEY"))
		{
			CVariant SecretKey = Data["KEY"];
			if(SecretKey.Decrypt(GetParent<CKademlia>()->Root()->GetID().GetPrivateKey()))
			{
				m_SecretKey = new CAbstractKey;
				if(!m_SecretKey->SetKey(SecretKey.GetData(), SecretKey.GetSize()))
					m_SecretKey = NULL;
			}
		}

		m_Authentication = Data.Get("AUTH");
	}
	catch(const CException&)
	{
		return false;
	}
	return true;
}
Example #4
0
void CStatement::ExecuteLast()
{
    for(ParamList::iterator i = m_params.begin(); i != m_params.end(); ++i ) {
        GetLangCmd()->GetBindParams().Bind((*i).first, (*i).second->GetData());
    }
    for(unsigned int i = 0; i < m_posParams.size(); ++i) {
        CVariant* var = m_posParams[i];
        if (!var) {
            NCBI_DBAPI_THROW("Not all parameters were bound by position.");
        }
        GetLangCmd()->GetBindParams().Bind(i, var->GetData());
    }
    m_cmd->Send();
}
Example #5
0
void CUIntX::Init(const CVariant& Variant)
{
	if(Variant.GetSize() != GetSize())
		throw CException(LOG_ERROR | LOG_DEBUG, L"Variant is not a uInt128");
	memcpy(GetData(), Variant.GetData(), GetSize());
}
Example #6
0
CVariant CKademlia::StartLookup(const CUInt128& TargetID, const CVariant& CodeID, const TCallMap& Execute, const TStoreMap& Store, CPrivateKey* pStoreKey, const TLoadMap& Load
									, int Timeout, int HopLimit, int JumpCount, int SpreadCount, bool bTrace, const wstring& Name)
{
	if(!m_pKadHandler)
		return CVariant();

	if(!CodeID.IsValid() && Store.empty() && Load.empty())
	{
		LogLine(LOG_ERROR, L"Attempted to start an empty Lookup");
		return CVariant();
	}

	CPointer<CKadTask> pLookup = new CKadTask(TargetID, m_pLookupManager);
	pLookup->SetName(Name);

	if(Timeout != -1)
		pLookup->SetTimeOut(Timeout);

	if(HopLimit != -1)
		pLookup->SetHopLimit(HopLimit);
	if(JumpCount != -1)
		pLookup->SetJumpCount(JumpCount);
	if(SpreadCount != -1)
		pLookup->SetSpreadCount(SpreadCount);
	if(bTrace)
		pLookup->EnableTrace();

	if(pStoreKey)
		pLookup->SetStoreKey(pStoreKey);

	for(TStoreMap::const_iterator I = Store.begin(); I != Store.end(); I++)
		pLookup->Store(I->first, I->second.Path, I->second.Data);
	
	for(TLoadMap::const_iterator I = Load.begin(); I != Load.end(); I++)
		pLookup->Load(I->first, I->second.Path);

	if(CodeID.IsValid())
	{
		if(!pLookup->SetupScript(CodeID))
		{
			LogLine(LOG_ERROR, L"Attempted to start a smart lookup with an unavailable script: %s", ToHex(CodeID.GetData(), CodeID.GetSize()).c_str());
			return CVariant();
		}
	
		for(TCallMap::const_iterator I = Execute.begin(); I != Execute.end(); I++)
			pLookup->AddCall(I->second.Function, I->second.Parameters, I->first);
	}

	CVariant LookupID = m_pLookupManager->StartLookup(pLookup.Obj());

	return LookupID;
}