GuestCtrlIO.cpp revision effc8a978d53212c8daed0753f93f2b5df0598c6
/* $Id$ */
/** @file
*
* IO helper for IGuest COM class implementations.
*/
/*
* Copyright (C) 2011 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"
/******************************************************************************
* Structures and Typedefs *
******************************************************************************/
/** @todo *NOT* thread safe yet! */
: m_cbAllocated(0),
m_cbSize(0),
m_cbOffset(0),
m_cbParserOffset(0),
{
}
{
Destroy();
}
/**
* Destroys the stored stream pairs.
*/
void GuestProcessStream::Destroy()
{
ClearPairs();
if (m_pbBuffer)
}
void GuestProcessStream::ClearPairs()
{
{
}
m_mapPairs.clear();
}
/**
* 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.
*/
{
try
{
}
{
}
return NULL;
}
{
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;
}
{
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();
}
{
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;
}
int GuestProcessStream::Parse()
{
int rc = VINF_SUCCESS;
{
/* Search end of current pair (key=value\0). */
{
if (*pszEnd == '\0')
break;
pszEnd++;
}
if (uPairLen)
{
while ( *pszSep != '='
{
pszSep++;
}
/* No separator found (or incomplete key=value pair)? */
{
rc = VERR_MORE_DATA;
}
if (RT_FAILURE(rc))
break;
/* Get key (if present). */
if (uKeyLen)
{
if (!pszKey)
{
rc = VERR_NO_MEMORY;
break;
}
/* Get value (if present). */
if (uValLen)
{
if (!pszVal)
{
rc = VERR_NO_MEMORY;
break;
}
}
}
}
else /* No pair detected, check for a new block. */
{
do
{
if (*pszEnd == '\0')
{
rc = VERR_MORE_DATA;
break;
}
pszEnd++;
}
if (RT_FAILURE(rc))
break;
}
return rc;
}