GuestCtrlPrivate.cpp revision 8df71e603498c05587c4b140537954a6039d2a67
/* $Id$ */
/** @file
*
* Internal helpers/structures for guest control functionality.
*/
/*
* Copyright (C) 2011-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/******************************************************************************
* Header Files *
******************************************************************************/
#include "GuestCtrlImplPrivate.h"
#ifdef DEBUG
# include "Logging.h"
#endif /* DEBUG */
/******************************************************************************
* Structures and Typedefs *
******************************************************************************/
uFlags(0),
fCanceled(false),
cbData(0),
{
}
uFlags(0),
fCanceled(false),
cbData(0),
{
}
GuestCtrlCallback::~GuestCtrlCallback(void)
{
Destroy();
}
int GuestCtrlCallback::Cancel(void)
{
if (!ASMAtomicReadBool(&fCanceled))
{
if (RT_SUCCESS(rc))
ASMAtomicXchgBool(&fCanceled, true);
}
return VINF_SUCCESS;
}
bool GuestCtrlCallback::Canceled(void)
{
return ASMAtomicReadBool(&fCanceled);
}
{
int rc = VINF_SUCCESS;
switch (enmType)
{
{
cbData = sizeof(CALLBACKDATAEXECSTATUS);
break;
}
{
cbData = sizeof(CALLBACKDATAEXECOUT);
break;
}
{
PCALLBACKDATAEXECINSTATUS pData = (PCALLBACKDATAEXECINSTATUS)RTMemAlloc(sizeof(CALLBACKDATAEXECINSTATUS));
cbData = sizeof(CALLBACKDATAEXECINSTATUS);
break;
}
default:
break;
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
}
return rc;
}
void GuestCtrlCallback::Destroy(void)
{
if (pvData)
{
}
cbData = 0;
if (hEventSem != NIL_RTSEMEVENT)
}
{
return RTSemEventSignal(hEventSem);
}
{
if (!uTimeoutMS)
if (RT_SUCCESS(rc))
{
/* Assign overall callback result. */
}
return rc;
}
///////////////////////////////////////////////////////////////////////////////
{
/* Rest is optional. */
int rc = VINF_SUCCESS;
if (cEnv)
{
{
char *pszEnv;
{
rc = VERR_NO_MEMORY;
break;
}
}
}
if (pcbEnv)
if (pcEnvVars)
return rc;
}
void GuestEnvironment::Clear(void)
{
}
{
int rc = VINF_SUCCESS;
++it)
{
}
return rc;
}
{
size_t s = 0;
++it, ++s)
{
}
return VINF_SUCCESS;
}
/* static */
{
if (pvEnv)
}
{
return Utf8Str("");
}
{
return strRet;
}
{
}
{
/** @todo Do some validation using regex. */
return VERR_INVALID_PARAMETER;
int rc = VINF_SUCCESS;
{
if (!RT_C_IS_ALNUM(*pszString++))
}
if (RT_SUCCESS(rc))
return rc;
}
{
/* Skip completely empty pairs. Note that we still need pairs with a valid
* (set) key and an empty value. */
return VINF_SUCCESS;
int rc = VINF_SUCCESS;
size_t p = 0;
{
{
break;
}
}
return rc;
}
{
return mEnvironment.size();
}
{
{
return VINF_SUCCESS;
}
return VERR_NOT_FOUND;
}
{
return *this;
}
{
++it)
{
}
return *this;
}
/**
* Appends environment variables to the environment block.
*
* Each var=value pair is separated by the null character ('\\0'). The whole
* block will be stored in one blob and disassembled on the guest side later to
* fit into the HGCM param structure.
*
* @returns VBox status code.
*
* @param pszEnvVar The environment variable=value to append to the
* environment block.
* @param ppvList This is actually a pointer to a char pointer
* variable which keeps track of the environment block
* that we're constructing.
* @param pcbList Pointer to the variable holding the current size of
* the environment block. (List is a misnomer, go
* ahead a be confused.)
* @param pcEnvVars Pointer to the variable holding count of variables
* stored in the environment block.
*/
int GuestEnvironment::appendToEnvBlock(const char *pszEnv, void **ppvList, size_t *pcbList, uint32_t *pcEnvVars)
{
int rc = VINF_SUCCESS;
if (*ppvList)
{
rc = VERR_NO_MEMORY;
else
{
}
}
else
{
char *pszTmp;
{
/* Reset counters. */
*pcEnvVars = 0;
*pcbList = 0;
}
}
if (RT_SUCCESS(rc))
{
}
return rc;
}
///////////////////////////////////////////////////////////////////////////////
/** @todo *NOT* thread safe yet! */
/** @todo Add exception handling for STL stuff! */
{
}
/*
GuestProcessStreamBlock::GuestProcessStreamBlock(const GuestProcessStreamBlock &otherBlock)
{
for (GuestCtrlStreamPairsIter it = otherBlock.m_mapPairs.begin();
it != otherBlock.end(); it++)
{
m_mapPairs[it->first] = new
if (it->second.pszValue)
{
RTMemFree(it->second.pszValue);
it->second.pszValue = NULL;
}
}
}*/
{
Clear();
}
/**
* Destroys the currently stored stream pairs.
*
* @return IPRT status code.
*/
void GuestProcessStreamBlock::Clear()
{
m_mapPairs.clear();
}
#ifdef DEBUG
void GuestProcessStreamBlock::Dump()
{
LogFlowFunc(("Dumping contents of stream block=0x%p (%ld items):\n",
this, m_mapPairs.size()));
{
}
}
#endif
/**
* Returns a 64-bit signed integer of a specified key.
*
* @return IPRT status code. VERR_NOT_FOUND if key was not found.
* @param pszKey Name of key to get the value for.
* @param piVal Pointer to value to return.
*/
{
if (pszValue)
{
return VINF_SUCCESS;
}
return VERR_NOT_FOUND;
}
/**
* Returns a 64-bit integer of a specified key.
*
* @return int64_t Value to return, 0 if not found / on failure.
* @param pszKey Name of key to get the value for.
*/
{
return iVal;
return 0;
}
/**
* Returns the current number of stream pairs.
*
* @return uint32_t Current number of stream pairs.
*/
{
return m_mapPairs.size();
}
/**
* Returns a string value of a specified key.
*
* @return uint32_t Pointer to string to return, NULL if not found / on failure.
* @param pszKey Name of key to get the value for.
*/
{
try
{
}
{
}
return NULL;
}
/**
* Returns a 32-bit unsigned integer of a specified key.
*
* @return IPRT status code. VERR_NOT_FOUND if key was not found.
* @param pszKey Name of key to get the value for.
* @param puVal Pointer to value to return.
*/
{
if (pszValue)
{
return VINF_SUCCESS;
}
return VERR_NOT_FOUND;
}
/**
* Returns a 32-bit unsigned integer of a specified key.
*
* @return uint32_t Value to return, 0 if not found / on failure.
* @param pszKey Name of key to get the value for.
*/
{
return uVal;
return 0;
}
/**
* Sets a value to a key or deletes a key by setting a NULL value.
*
* @return IPRT status code.
* @param pszKey Key name to process.
* @param pszValue Value to set. Set NULL for deleting the key.
*/
{
int rc = VINF_SUCCESS;
try
{
/* Take a shortcut and prevent crashes on some funny versions
* of STL if map is empty initially. */
if (!m_mapPairs.empty())
{
}
if (pszValue)
{
}
}
{
}
return rc;
}
///////////////////////////////////////////////////////////////////////////////
: m_cbAllocated(0),
m_cbSize(0),
m_cbOffset(0),
{
}
GuestProcessStream::~GuestProcessStream(void)
{
Destroy();
}
/**
* Adds data to the internal parser buffer. Useful if there
* are multiple rounds of adding data needed.
*
* @return IPRT status code.
* @param pbData Pointer to data to add.
* @param cbData Size (in bytes) of data to add.
*/
{
int rc = VINF_SUCCESS;
/* Rewind the buffer if it's empty. */
if (fAddToSet)
m_cbSize = m_cbOffset = 0;
/* Try and see if we can simply append the data. */
{
}
else
{
/* Move any buffered data to the front. */
if (cbInBuf == 0)
m_cbSize = m_cbOffset = 0;
else if (m_cbOffset) /* Do we have something to move? */
{
m_cbOffset = 0;
}
/* Do we need to grow the buffer? */
{
if (pvNew)
{
}
else
rc = VERR_NO_MEMORY;
}
/* Finally, copy the data. */
if (RT_SUCCESS(rc))
{
{
}
else
}
}
return rc;
}
/**
* Destroys the internal data buffer.
*/
void GuestProcessStream::Destroy(void)
{
if (m_pbBuffer)
{
m_pbBuffer = NULL;
}
m_cbAllocated = 0;
m_cbSize = 0;
m_cbOffset = 0;
}
#ifdef DEBUG
{
LogFlowFunc(("Dumping contents of stream=0x%p (cbAlloc=%u, cbSize=%u, cbOff=%u) to %s\n",
int rc = RTFileOpen(&hFile, pszFile, RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE);
if (RT_SUCCESS(rc))
{
}
}
#endif
/**
* Returns the current offset of the parser within
* the internal data buffer.
*
* @return uint32_t Parser offset.
*/
{
return m_cbOffset;
}
{
return m_cbSize;
}
/**
* Tries to parse the next upcoming pair block within the internal
* buffer.
*
* Returns VERR_NO_DATA is no data is in internal buffer or buffer has been
* completely parsed already.
*
* Returns VERR_MORE_DATA if current block was parsed (with zero or more pairs
* stored in stream block) but still contains incomplete (unterminated)
* data.
*
* Returns VINF_SUCCESS if current block was parsed until the next upcoming
* block (with zero or more pairs stored in stream block).
*
* @return IPRT status code.
* @param streamBlock Reference to guest stream block to fill.
*
*/
{
if ( !m_pbBuffer
|| !m_cbSize)
{
return VERR_NO_DATA;
}
if (m_cbOffset == m_cbSize)
return VERR_NO_DATA;
int rc = VINF_SUCCESS;
while (*pszStart)
{
{
rc = VERR_MORE_DATA;
break;
}
else
{
if (pszSep)
{
rc = VERR_MORE_DATA;
break;
}
/* Terminate the separator so that we can
* use pszStart as our key from now on. */
*pszSep = '\0';
if (RT_FAILURE(rc))
return rc;
}
/* Next pair. */
}
/* If we did not do any movement but we have stuff left
* in our buffer just skip the current termination so that
* we can try next time. */
if ( !uDistance
&& *pszStart == '\0'
&& m_cbOffset < m_cbSize)
{
uDistance++;
}
m_cbOffset += uDistance;
return rc;
}