VBoxServiceUtils.cpp revision e794d9028f49f95cf5a9dc4cb9ce2aa2231eac04
/* $Id$ */
/** @file
* VBoxServiceUtils - Some utility functions.
*/
/*
* Copyright (C) 2009-2010 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef RT_OS_WINDOWS
# include <Windows.h>
#endif
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#ifdef VBOX_WITH_GUEST_PROPS
/**
* Reads a guest property.
*
* @returns VBox status code, fully bitched.
*
* @param u32ClientId The HGCM client ID for the guest property session.
* @param pszPropName The property name.
* @param ppszValue Where to return the value. This is always set
* to NULL. Free it using RTStrFree().
* @param ppszFlags Where to return the value flags. Free it
* using RTStrFree(). Optional.
* @param puTimestamp Where to return the timestamp. This is only set
* on success. Optional.
*/
int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp)
{
int rc;
{
/*
* (Re-)Allocate the buffer and try read the property.
*/
if (!pvBuf)
{
rc = VERR_NO_MEMORY;
break;
}
char *pszValue;
char *pszFlags;
if (RT_FAILURE(rc))
{
if (rc == VERR_BUFFER_OVERFLOW)
{
/* try again with a bigger buffer. */
cbBuf *= 2;
continue;
}
if (rc == VERR_NOT_FOUND)
else
break;
}
if (!*ppszValue)
{
rc = VERR_NO_MEMORY;
break;
}
if (puTimestamp)
if (ppszFlags)
break; /* done */
}
return rc;
}
/**
* Reads a guest property as a 32-bit value.
*
* @returns VBox status code, fully bitched.
*
* @param u32ClientId The HGCM client ID for the guest property session.
* @param pszPropName The property name.
* @param pu32 Where to store the 32-bit value.
*
*/
int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max)
{
char *pszValue;
if (RT_SUCCESS(rc))
{
char *pszNext;
if ( RT_SUCCESS(rc)
{
}
}
return rc;
}
/**
* Wrapper around VbglR3GuestPropWriteValue that does value formatting and
* logging.
*
* @returns VBox status code. Errors will be logged.
*
* @param u32ClientId The HGCM client ID for the guest property session.
* @param pszName The property name.
* @param pszValueFormat The property format string. If this is NULL then
* the property will be deleted (if possible).
* @param ... Format arguments.
*/
int VBoxServiceWritePropF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...)
{
int rc;
if (pszValueFormat != NULL)
{
if (RT_FAILURE(rc))
}
else
{
if (RT_FAILURE(rc))
}
return rc;
}
#endif /* VBOX_WITH_GUEST_PROPS */
#ifdef RT_OS_WINDOWS
/**
* Helper for VBoxServiceGetFileVersion and attemps to read and parse
* FileVersion.
*
* @returns Success indicator.
*/
{
UINT cchStrValue = 0;
if (!VerQueryValueA(pVerData, "\\StringFileInfo\\040904b0\\FileVersion", (LPVOID *)&pStrValue, &cchStrValue))
return false;
/** @todo r=bird: get rid of this. Avoid sscanf like the plague! */
if (sscanf(pStrValue, "%ld.%ld.%ld.%ld", pdwMajor, pdwMinor, pdwBuildNumber, pdwRevisionNumber) != 4)
return false;
return true;
}
/**
* Worker for VBoxServiceGetFileVersionString.
*
* @returns VBox status code.
* @param pszFilename ASCII & ANSI & UTF-8 compliant name.
*/
static int VBoxServiceGetFileVersion(const char *pszFilename,
{
int rc;
/*
* Get the file version info.
*/
if (cbVerData)
{
if (pVerData)
{
{
/*
* Try query and parse the FileVersion string our selves first
* since this will give us the correct revision number when
* it goes beyond the range of an uint16_t / WORD.
*/
rc = VINF_SUCCESS;
else
{
/* Fall back on VS_FIXEDFILEINFO */
UINT cbFileInfoIgnored = 0;
{
rc = VINF_SUCCESS;
}
else
{
}
}
}
else
{
}
}
else
{
VBoxServiceVerbose(0, "Failed to allocate %u byte for file version info for '%s'\n", cbVerData, pszFilename);
}
}
else
{
VBoxServiceVerbose(3, "GetFileVersionInfoSize(%s) -> %u / %Rrc\n", pszFilename, GetLastError(), rc);
}
return rc;
}
/**
* Gets a re-formatted version string from the VS_FIXEDFILEINFO table.
*
* @returns VBox status code. The output buffer is always valid and the status
* code can safely be ignored.
*
* @param pszPath The base path.
* @param pszFilaname The filename.
* @param pszVersion Where to return the version string.
* @param cbVersion The size of the version string buffer. This MUST be
* at least 2 bytes!
*/
{
/*
* We will ALWAYS return with a valid output buffer.
*/
pszVersion[0] = '-';
/*
* Create the path and query the bits.
*/
char szFullPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
}
return rc;
}
#endif /* RT_OS_WINDOWS */