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