本文整理汇总了C++中CDatum::GetElement方法的典型用法代码示例。如果您正苦于以下问题:C++ CDatum::GetElement方法的具体用法?C++ CDatum::GetElement怎么用?C++ CDatum::GetElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDatum
的用法示例。
在下文中一共展示了CDatum::GetElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleResult
bool CRunSession::HandleResult (CHexeProcess::ERunCodes iRun, CDatum dResult)
// HandleResult
//
// Handles the result from a run
{
switch (iRun)
{
case CHexeProcess::runOK:
case CHexeProcess::runError:
SendMessageReply(MSG_REPLY_DATA, dResult);
// FALSE means we're done with the session
return false;
case CHexeProcess::runAsyncRequest:
{
SendMessageCommand(dResult.GetElement(0),
dResult.GetElement(1),
GenerateAddress(PORT_HEXE_COMMAND),
dResult.GetElement(2),
MESSAGE_TIMEOUT);
m_iState = stateWaitingForHexarcReply;
return true;
}
default:
// LATER:
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, CString("LATER"));
return false;
}
}
示例2: ValidateAuthDescCreate
bool CCryptosaurEngine::ValidateAuthDescCreate (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx, CDatum dAuthDesc)
// ValidateAuthDescCreate
//
// Make sure that the authDesc structure has the proper fields for creating
// a new user (either admin or not).
{
if (!strEquals(dAuthDesc.GetElement(FIELD_TYPE), AUTH_TYPE_SHA1))
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(ERR_INVALID_AUTHDESC_TYPE, dAuthDesc.GetElement(FIELD_TYPE).AsString()), Msg);
return false;
}
if (dAuthDesc.GetElement(FIELD_CREDENTIALS).IsNil())
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, ERR_AUTHDESC_CREDENTIALS_REQUIRED, Msg);
return false;
}
if (dAuthDesc.GetElement(FIELD_ACTUAL).IsNil())
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, ERR_AUTHDESC_ACTUAL_REQUIRED, Msg);
return false;
}
return true;
}
示例3: CreateSecondaryData
void CAeonView::CreateSecondaryData (const CTableDimensions &PrimaryDims, const CRowKey &PrimaryKey, CDatum dFullData, SEQUENCENUMBER RowID, CDatum *retdData)
// CreateSecondaryData
//
// Creates the data for a secondary view row.
{
int i, j;
CComplexStruct *pData = new CComplexStruct;
// If the list of columns is empty then we just add the primary key
if (m_Columns.GetCount() == 0)
pData->SetElement(FIELD_PRIMARY_KEY, PrimaryKey.AsDatum(PrimaryDims));
// Otherwise we add all the fields listed in the columns array
else
{
for (i = 0; i < m_Columns.GetCount(); i++)
{
// The special string "primaryKey" means that we insert the
// primary key as a special field.
if (strEquals(m_Columns[i], FIELD_PRIMARY_KEY))
pData->SetElement(FIELD_PRIMARY_KEY, PrimaryKey.AsDatum(PrimaryDims));
// The special string "*" means that we insert all existing
// fields.
else if (strEquals(m_Columns[i], STR_ALL_COLUMNS))
{
for (j = 0; j < dFullData.GetCount(); j++)
{
CDatum dKey = dFullData.GetKey(j);
CDatum dValue = dFullData.GetElement(j);
if (!dValue.IsNil())
pData->SetElement(dKey, dValue);
}
}
// Add the field by name.
else
{
CDatum dColData = dFullData.GetElement(m_Columns[i]);
if (!dColData.IsNil())
pData->SetElement(m_Columns[i], dColData);
}
}
}
// Done
*retdData = CDatum(pData);
}
示例4: ExecuteScript
int ExecuteScript (const SOptions &Options)
{
int i, j;
// Load the script file
CDatum dScript;
CString sError;
if (!CDatum::CreateFromFile(Options.sScriptFile, CDatum::formatAEONScript, &dScript, &sError))
{
printf("ERROR: %s\n", (LPSTR)sError);
return 1;
}
// Get the server to connect to
CString sServer = dScript.GetElement(FIELD_SERVER);
if (sServer.IsEmpty())
sServer = Options.sServer;
// Connect
CSocket theSocket;
if (!ConnectToArcology(STR_ARC_CONSOLE, sServer, Options, &theSocket))
return 1;
// Run the script
CDatum dCommands = dScript.GetElement(FIELD_COMMANDS);
for (i = 0; i < dCommands.GetCount(); i++)
{
CDatum dCommand = dCommands.GetElement(i);
// Generate a command-line from the command
CStringBuffer Buffer;
for (j = 0; j < dCommand.GetCount(); j++)
{
if (j != 0)
Buffer.Write(" ", 1);
dCommand.Serialize(CDatum::formatAEONScript, Buffer);
}
// Run
printf("%s\n", (LPSTR)(const CString &)Buffer);
CString sResult = ExecuteArcologyCommand(theSocket, Buffer);
PrintUTF8(sResult);
printf("\n");
}
// Done
return 0;
}
示例5:
CComplexArray::CComplexArray (CDatum dSrc)
// ComplexArray constructor
{
int i;
if (dSrc.GetBasicType() == CDatum::typeStruct)
{
InsertEmpty(1);
SetElement(0, dSrc);
}
else
{
int iCount = dSrc.GetCount();
// Clone from another complex array
if (iCount > 0)
{
InsertEmpty(iCount);
for (i = 0; i < iCount; i++)
SetElement(i, dSrc.GetElement(i));
}
}
}
示例6: MsgCreateTable
void CAeonEngine::MsgCreateTable (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)
// MsgCreateTable
//
// Aeon.createTable {tableDesc}
//
// {tableDesc} = { name:MyTable1 type:standard x:{keyType:utf8} y:{keyType:int32} z:{keyType:dateTime} }
{
CString sError;
// Get the table desc and table name
CDatum dTableDesc = Msg.dPayload.GetElement(0);
const CString &sTable = dTableDesc.GetElement(FIELD_NAME);
// Make sure we are allowed access to this table
if (!ValidateTableAccess(Msg, pSecurityCtx, sTable))
return;
// See if the table descriptor specifies storage volumes; if so, then we
// make sure that the calling service has admin rights.
if (!dTableDesc.GetElement(FIELD_PRIMARY_VOLUME).IsNil()
|| !dTableDesc.GetElement(FIELD_BACKUP_VOLUMES).IsNil())
{
if (!ValidateAdminAccess(Msg, pSecurityCtx))
return;
}
// Create
bool bExists;
if (!CreateTable(dTableDesc, NULL, &bExists, &sError))
{
if (bExists)
SendMessageReplyError(MSG_ERROR_ALREADY_EXISTS, sError, Msg);
else
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
return;
}
// Done
SendMessageReply(MSG_OK, CDatum(), Msg);
}
示例7: ValidateAuthDescActual
bool CCryptosaurEngine::ValidateAuthDescActual (CDatum dAuthDesc, const CString &sScope, CDatum dUserData)
// ValidateAuthDescActual
//
// Validates that dAuthDesc is valid authorization from the actual user.
{
CDatum dAuthToken = dAuthDesc.GetElement(FIELD_AUTH_TOKEN);
CDatum dCredentials = dAuthDesc.GetElement(FIELD_CREDENTIALS);
// Do we have an authToken?
if (!dAuthToken.IsNil())
{
// Get the key to sign with (the key is guaranteed to exist because we
// checked at boot time).
CIPInteger *pAuthTokenKey = m_Keys.GetAt(KEY_CRYPTOSAUR_AUTH_TOKEN);
// Validate
CDatum dData;
if (!CCryptosaurInterface::ValidateAuthToken(dAuthToken, *pAuthTokenKey, &dData))
return false;
// The proper user?
if (!strEquals(strToLower(dData.GetElement(FIELD_USERNAME)), strToLower(dUserData.GetElement(FIELD_USERNAME))))
return false;
// AuthToken for actual?
if (!dData.GetElement(FIELD_SCOPE).IsNil())
return false;
// OK
return true;
}
// Otherwise, we better have credentials
else if (!dCredentials.IsNil())
{
// Compare credentials against user record
CDatum dTrueAuthDesc = dUserData.GetElement(FIELD_AUTH_DESC);
if (!((const CIPInteger &)dCredentials == (const CIPInteger &)dTrueAuthDesc.GetElement(FIELD_CREDENTIALS)))
return false;
// OK
return true;
}
// Otherwise we fail.
else
return false;
}
示例8: DeserializeAEONScript
bool IComplexDatum::DeserializeAEONScript (CDatum::ESerializationFormats iFormat, const CString &sTypename, CCharStream *pStream)
// DeserializeAEONScript
//
// Deserialize AEONScript
{
int i;
DWORD dwFlags = OnGetSerializeFlags();
// If we have an open brace then we've stored everything as a structure.
if (pStream->GetChar() == '{')
{
// Object must support this
if (!(dwFlags & FLAG_SERIALIZE_AS_STRUCT))
return false;
// Parse the structure
CAEONScriptParser Parser(pStream);
CDatum dData;
CAEONScriptParser::ETokens iToken = Parser.ParseToken(&dData);
if (iToken != CAEONScriptParser::tkDatum)
return false;
// Take all the fields in the structure and apply them to our object
// (our descendants will do the right thing).
for (i = 0; i < dData.GetCount(); i++)
SetElement(dData.GetKey(i), dData.GetElement(i));
}
// Otherwise we expect base64 encoded data
else
{
// Backup one character because we want the OnDeserialize call to read it.
pStream->UnreadChar();
// Deserialize
CBase64Decoder Decoder(pStream->GetByteStream());
if (!OnDeserialize(iFormat, sTypename, Decoder))
return false;
// Read the next character into the stream
pStream->RefreshStream();
pStream->ReadChar();
}
return true;
}
示例9: AppendStruct
void CComplexStruct::AppendStruct (CDatum dDatum)
// AppendStruct
//
// Appends the element of the given structure
{
int i;
if (dDatum.GetBasicType() == CDatum::typeStruct)
{
for (i = 0; i < dDatum.GetCount(); i++)
SetElement(dDatum.GetKey(i), dDatum.GetElement(i));
}
}
示例10: MsgValidateAuthToken
void CCryptosaurEngine::MsgValidateAuthToken (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)
// MsgValidateAuthToken
//
// Cryptosaur.validateAuthToken {authToken}
{
// Any service can validate a token
if (!ValidateMessage(Msg, pSecurityCtx, false))
return;
// Get the key to sign with (the key is guaranteed to exist because we
// checked at boot time).
CIPInteger *pAuthTokenKey = m_Keys.GetAt(KEY_CRYPTOSAUR_AUTH_TOKEN);
// Validate
CDatum dData;
if (!CCryptosaurInterface::ValidateAuthToken(Msg.dPayload.GetElement(0), *pAuthTokenKey, &dData))
{
SendMessageReply(MSG_REPLY_DATA, CDatum(), Msg);
return;
}
// A sandboxed authtoken is not valid outside of its scope.
// (But it is valid in admin services).
const CString &sScope = dData.GetElement(FIELD_SCOPE);
if (!sScope.IsEmpty()
&& pSecurityCtx
&& !pSecurityCtx->IsNamespaceAccessible(sScope))
{
SendMessageReply(MSG_REPLY_DATA, CDatum(), Msg);
return;
}
// Return the data in the auth token
SendMessageReply(MSG_REPLY_DATA, dData, Msg);
}
示例11: OutputDatum
void CHexeMarkupEvaluator::OutputDatum (CDatum dValue)
// OutputDatum
//
// Outputs a datum to the resulting HTML page. NOTE: We expect the values to be
// HTML compatible (i.e., caller is responsible for escaping).
{
int i;
if (dValue.GetBasicType() == CDatum::typeArray)
{
for (i = 0; i < dValue.GetCount(); i++)
OutputDatum(dValue.GetElement(i));
}
else
{
m_Output.Write(dValue.AsString());
}
}
示例12: CreateSanitizedUserRecord
CDatum CUserInfoSession::CreateSanitizedUserRecord (CDatum dRecord)
// CreateSanitizedUserRecord
//
// Creates a user record suitable for returning to clients. In partincular,
// we remove the authentication information.
{
int i;
// Create a destination
CComplexStruct *pDest = new CComplexStruct;
// Copy all appropriate fields
for (i = 0; i < dRecord.GetCount(); i++)
{
// If this is an auth field, then skip it
if (strEquals(dRecord.GetKey(i), FIELD_AUTH_DESC))
;
else if (strEndsWith(dRecord.GetKey(i), FIELD_AUTH_DESC_SUFFIX))
;
// Otherwise, copy it
else
pDest->SetElement(dRecord.GetKey(i), dRecord.GetElement(i));
}
// Done
return CDatum(pDest);
}
示例13: ExecuteUpgrade
CString ExecuteUpgrade (CSocket &theSocket, const CString &sCmd)
{
int i;
CString sRoot = fileGetPath(fileGetExecutableFilespec());
// Make a list of all executable files to upgrade
TArray<CString> FileList;
if (!fileGetFileList(sRoot, NULL_STR, CString("*.exe"), FFL_FLAG_RELATIVE_FILESPEC, &FileList))
return CString("ERROR: Unable to obtain a list of executable files to upgrade.");
// Prepare a request upgrade command
CStringBuffer Output;
Output.Write("requestUpgrade (", 16);
for (i = 0; i < FileList.GetCount(); i++)
{
CString sFilespec = fileAppend(sRoot, FileList[i]);
// Version
SFileVersionInfo Info;
if (!fileGetVersionInfo(sFilespec, &Info))
{
printf("ERROR: Unable to get file version: %s\n", (LPSTR)sFilespec);
continue;
}
CIPInteger Version(Info.dwProductVersion);
CString sVersion = Version.AsString();
// Checksum
DWORD dwChecksum = fileChecksumAdler32(sFilespec);
if (dwChecksum == 0)
{
printf("ERROR: Unable to get file checksum: %s\n", (LPSTR)sFilespec);
continue;
}
CString sOutput = strPattern("{filename:\"%s\" version:%s checksum:%d} ", FileList[i], sVersion, dwChecksum);
Output.Write(sOutput);
}
Output.Write(")", 1);
// Send the command
CString sSend = CString::CreateFromHandoff(Output);
CString sResult;
CDatum dResult;
ExecuteArcologyCommand(theSocket, sSend, &sResult, &dResult);
if (strEquals(sResult, CString("ERROR")))
return dResult.AsString();
// Show all the files to upgrade
CDatum dUpgradeDesc = dResult.GetElement(0).GetElement(FIELD_UPGRADE_DESC);
for (i = 0; i < dUpgradeDesc.GetCount(); i++)
{
CDatum dFileDesc = dUpgradeDesc.GetElement(i);
printf("Upgrading %s\n", (LPSTR)dFileDesc.GetElement(FIELD_FILENAME).AsString());
}
// Confirm
CString sConfirm = GetInputLine(CString("\nAre you sure you want to upgrade the arcology? [y/n] : "));
if (*sConfirm.GetParsePointer() != 'y' && *sConfirm.GetParsePointer() != 'Y')
return NULL_STR;
// Upload the new files.
for (i = 0; i < dUpgradeDesc.GetCount(); i++)
{
CDatum dFileDesc = dUpgradeDesc.GetElement(i);
const CString &sFilename = dFileDesc.GetElement(FIELD_FILENAME);
CString sFilespec = fileAppend(sRoot, sFilename);
CString sResult = UploadFile(theSocket, CMD_UPLOAD_UPGRADE, sFilename, sFilespec);
printf("%s\n", (LPSTR)sResult);
}
// Complete the upgrade
return ExecuteArcologyCommand(theSocket, CMD_COMPLETE_UPGRADE);
}
示例14: ParseTableAndView
bool CAeonEngine::ParseTableAndView (const SArchonMessage &Msg,
const CHexeSecurityCtx *pSecurityCtx,
CDatum dTableAndView,
CAeonTable **retpTable,
DWORD *retdwViewID,
CDatum dKey,
CRowKey *retKey)
// ParseTableAndView
//
// Parses a datum as follows:
//
// If a single string, it specifies a table and the default view.
// If an array with two strings, the first is the table name; the second is the view name.
{
CString sError;
// If we're not ready, then error
if (!m_bReady)
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, ERR_NOT_READY, Msg);
return false;
}
// Parse the table names
CString sTable;
CString sView;
if (dTableAndView.GetCount() < 2)
sTable = dTableAndView.AsString();
else
{
sTable = dTableAndView.GetElement(0).AsString();
sView = dTableAndView.GetElement(1).AsString();
}
// Make sure we have access
if (pSecurityCtx && !pSecurityCtx->IsNamespaceAccessible(sTable))
{
SendMessageReplyError(MSG_ERROR_NOT_ALLOWED, strPattern(ERR_NOT_IN_SANDBOX, sTable, pSecurityCtx->GetSandboxName()), Msg);
return false;
}
// Get the table
CAeonTable *pTable;
if (!FindTable(sTable, &pTable))
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
return false;
}
// Get the view. If we want a key, take this opportunity to parse it.
DWORD dwViewID;
if (retKey)
{
if (!pTable->FindViewAndPath(sView, &dwViewID, dKey, retKey, &sError))
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
return false;
}
}
// Otherwise just get the view.
else
{
if (!pTable->FindView(sView, &dwViewID))
{
SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(ERR_UNKNOWN_VIEW, sTable, sView), Msg);
return false;
}
}
// Done
if (retpTable)
*retpTable = pTable;
if (retdwViewID)
*retdwViewID = dwViewID;
return true;
}
示例15: CreateTable
bool CAeonEngine::CreateTable (CDatum dDesc, CAeonTable **retpTable, bool *retbExists, CString *retsError)
// CreateTable
//
// Creates a new table.
{
// Prefill
if (retbExists)
*retbExists = false;
// No storage
if (m_LocalVolumes.GetCount() == 0)
{
*retsError = STR_ERROR_NO_LOCAL_STORAGE;
return false;
}
// Check to see if this is a valid name
const CString &sName = dDesc.GetElement(FIELD_NAME);
if (!CAeonTable::ValidateTableName(sName))
{
if (retsError)
*retsError = strPattern(STR_ERROR_INVALID_TABLE_NAME, sName);
return false;
}
// Add the table (if it doesn't already exist)
CSmartLock Lock(m_cs);
CAeonTable *pTable;
if (m_Tables.Find(sName, &pTable))
{
// If the table already exists see if we need to re-initialized it
// based on a new descriptor
bool bUpdated;
if (!pTable->Recreate(GetProcessCtx(), dDesc, &bUpdated, retsError))
return false;
// If we updated the table then we succeeded
if (bUpdated)
{
if (retpTable)
*retpTable = pTable;
return true;
}
// Otherwise we reply that the table already exists.
if (retsError)
*retsError = strPattern(STR_ERROR_TABLE_ALREADY_EXISTS, sName);
if (retbExists)
*retbExists = true;
return false;
}
// Create a new table.
// NOTE: We rely on the fact that we've locked the engine to prevent
// local storage from changing while the table is created.
pTable = new CAeonTable;
if (!pTable->Create(GetProcessCtx(), &m_LocalVolumes, dDesc, retsError))
{
delete pTable;
return false;
}
int iNewTableIndex = m_Tables.GetCount();
m_Tables.Insert(sName, pTable);
// Done
if (retpTable)
*retpTable = pTable;
return true;
}