VBoxServiceUtils.cpp revision d3203e1a8d5b114c66238ae33506f6e1a3d79b9e
/* $Id$ */
/** @file
* VBoxServiceUtils - Some utility functions.
*/
/*
* Copyright (C) 2009 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
/** @todo return an iprt status code instead of BOOL */
char* pszBlock,
char* pszString,
{
UINT uiValueLen = 0;
/* The VS_FIXEDFILEINFO structure contains version information about a file.
This information is language and code page independent. */
if (!dwLen)
{
/* Don't print this to release log -- this confuses people if a file
* isn't present because it's optional / was not installed intentionally. */
return FALSE;
}
if (!lpData)
{
VBoxServiceError("Could not allocate temp buffer for file string lookup!\n");
return FALSE;
}
{
{
}
else VBoxServiceVerbose(3, "No file string value for \"%s\" in file \"%s\" available!\n", pszBlock, pszFileName);
}
return bRet;
}
/** @todo return an iprt status code instead of BOOL */
{
/* The VS_FIXEDFILEINFO structure contains version information about a file.
This information is language and code page independent. */
/* Try own fields defined in block "\\StringFileInfo\\040904b0\\FileVersion". */
int r = 0;
bRet = VBoxServiceGetFileString(pszFileName, "\\StringFileInfo\\040904b0\\FileVersion", szValue, &uiSize);
if (bRet)
{
}
else if (dwLen > 0)
{
/* Try regular fields - this maybe is not file provided by VBox! */
if (!lpData)
{
VBoxServiceError("Could not allocate temp buffer for file version string!\n");
return FALSE;
}
{
{
}
}
}
return bRet;
}
BOOL VBoxServiceGetFileVersionString(const char* pszPath, const char* pszFileName, char* pszVersion, UINT uiSize)
{
char szFullPath[_MAX_PATH] = {0};
int r = 0;
if (bRet)
else
return bRet;
}
#endif /* !RT_OS_WINDOWS */