GuestCtrlIO.cpp revision 22866e6b8e8304e8604724f7509c33253e7eedcf
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * IO helper for IGuest COM class implementations.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Copyright (C) 2011 Oracle Corporation
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * available from http://www.virtualbox.org. This file is free software;
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * you can redistribute it and/or modify it under the terms of the GNU
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * General Public License (GPL) as published by the Free Software
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync/******************************************************************************
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Header Files *
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync ******************************************************************************/
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync/******************************************************************************
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Structures and Typedefs *
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync ******************************************************************************/
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync/** @todo *NOT* thread safe yet! */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync/** @todo Add exception handling for STL stuff! */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncGuestProcessStreamBlock::GuestProcessStreamBlock(const GuestProcessStreamBlock &otherBlock)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync for (GuestCtrlStreamPairsIter it = otherBlock.m_mapPairs.begin();
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync it != otherBlock.end(); it++)
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync m_mapPairs[it->first] = new
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync if (it->second.pszValue)
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync RTMemFree(it->second.pszValue);
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync it->second.pszValue = NULL;
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync * Destroys the currently stored stream pairs.
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync * @return IPRT status code.
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync * Returns a 64-bit signed integer of a specified key.
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync * @return IPRT status code. VERR_NOT_FOUND if key was not found.
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync * @param pszKey Name of key to get the value for.
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsync * @param piVal Pointer to value to return.
3ba795251a7b9f108fb01a3cfb37d763db9188b9vboxsyncint GuestProcessStreamBlock::GetInt64Ex(const char *pszKey, int64_t *piVal)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns a 64-bit integer of a specified key.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return int64_t Value to return, 0 if not found / on failure.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param pszKey Name of key to get the value for.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncint64_t GuestProcessStreamBlock::GetInt64(const char *pszKey)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns the current number of stream pairs.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return uint32_t Current number of stream pairs.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns a string value of a specified key.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return uint32_t Pointer to string to return, NULL if not found / on failure.
b1d7d513c459787311cd09c440524044fa7ff8a9vboxsync * @param pszKey Name of key to get the value for.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncconst char* GuestProcessStreamBlock::GetString(const char *pszKey)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync GuestCtrlStreamPairMapIterConst itPairs = m_mapPairs.find(Utf8Str(pszKey));
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns a 32-bit unsigned integer of a specified key.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return IPRT status code. VERR_NOT_FOUND if key was not found.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param pszKey Name of key to get the value for.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param puVal Pointer to value to return.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncint GuestProcessStreamBlock::GetUInt32Ex(const char *pszKey, uint32_t *puVal)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns a 32-bit unsigned integer of a specified key.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return uint32_t Value to return, 0 if not found / on failure.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param pszKey Name of key to get the value for.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncuint32_t GuestProcessStreamBlock::GetUInt32(const char *pszKey)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Sets a value to a key or deletes a key by setting a NULL value.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return IPRT status code.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param pszKey Key name to process.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param pszValue Value to set. Set NULL for deleting the key.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncint GuestProcessStreamBlock::SetValue(const char *pszKey, const char *pszValue)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync /* Take a shortcut and prevent crashes on some funny versions
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * of STL if map is empty initially. */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync GuestCtrlStreamPairMapIter it = m_mapPairs.find(Utf8Key);
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync///////////////////////////////////////////////////////////////////////////////
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Adds data to the internal parser buffer. Useful if there
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * are multiple rounds of adding data needed.
45c4c3d2db1a166b7b1e92960adb823960821386vboxsync * @return IPRT status code.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param pbData Pointer to data to add.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @param cbData Size (in bytes) of data to add.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsyncint GuestProcessStream::AddData(const BYTE *pbData, size_t cbData)
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync /* Rewind the buffer if it's empty. */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync /* Try and see if we can simply append the data. */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync /* Move any buffered data to the front. */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync else if (m_cbOffset) /* Do we have something to move? */
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync memmove(m_pbBuffer, &m_pbBuffer[m_cbOffset], cbInBuf);
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync /* Do we need to grow the buffer? */
b1d7d513c459787311cd09c440524044fa7ff8a9vboxsync /* Finally, copy the data. */
b1d7d513c459787311cd09c440524044fa7ff8a9vboxsync * Destroys the the internal data buffer.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns the current offset of the parser within
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * the internal data buffer.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * @return uint32_t Parser offset.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Tries to parse the next upcoming pair block within the internal
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns VERR_NO_DATA is no data is in internal buffer or buffer has been
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * completely parsed already.
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * Returns VERR_MORE_DATA if current block was parsed (with zero or more pairs
b41f65ee355ae1d4b24473c6d6d70c653497429avboxsync * stored in stream block) but still contains incomplete (unterminated)
if ( !m_pbBuffer
|| !m_cbSize)
return VERR_NO_DATA;
return VERR_NO_DATA;
while (*pszStart)
if (pszSep)
return rc;
if ( !uDistance
uDistance++;
return rc;