VirtualBox

Ignore:
Timestamp:
Jul 29, 2008 8:21:12 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
33826
Message:

Burn fix, cosmetics and some todos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp

    r10930 r10956  
    2828#include <iprt/mem.h>
    2929#include <iprt/assert.h>
    30 #include <iprt/autores>
     30#if 0 /** @todo this isn't work. As noted elsewhere, avoid complicated templates. */
     31# include <iprt/autores>
     32#endif
    3133#include <iprt/stdarg.h>
    3234#include <VBox/log.h>
     
    3537#include "VBGLR3Internal.h"
    3638
     39
    3740/*******************************************************************************
    3841*   Structures and Typedefs                                                    *
    3942*******************************************************************************/
    40 /** 
     43/**
    4144 * Structure containing information needed to enumerate through guest
    4245 * properties.
     
    4447struct VBGLR3GUESTPROPENUM
    4548{
     49    /** @todo add a magic and validate the handle. */
    4650    /** The buffer containing the raw enumeration data */
    4751    char *pchBuf;
     
    340344     * report the problem if that fails.
    341345     */
    342     uint32_t cchBuf = MAX_VALUE_LEN;
    343     RTMemAutoPtr<char> pcBuf;
    344     int rc = VERR_BUFFER_OVERFLOW;
     346    char       *pszValue = NULL;
     347    void       *pvBuf    = NULL;
     348    uint32_t    cchBuf   = MAX_VALUE_LEN;
     349    int         rc       = VERR_BUFFER_OVERFLOW;
    345350    for (unsigned i = 0; i < 10 && rc == VERR_BUFFER_OVERFLOW; ++i)
    346351    {
    347352        /* We leave a bit of space here in case the maximum value is raised. */
    348353        cchBuf += 1024;
    349         if (!pcBuf.realloc<RTMemRealloc>(cchBuf))
    350             rc = VERR_NO_MEMORY;
    351         if (RT_SUCCESS(rc))
    352             rc = VbglR3GuestPropRead(u32ClientId, pszName, pcBuf.get(), cchBuf,
    353                                      NULL, NULL, NULL, &cchBuf);
     354        void *pvTmpBuf = RTMemRealloc(pvBuf, cchBuf);
     355        if (pvTmpBuf)
     356        {
     357            pvBuf = pvTmpBuf;
     358            rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf,
     359                                     &pszValue, NULL, NULL, &cchBuf);
     360        }
    354361        else
    355362            rc = VERR_NO_MEMORY;
    356363    }
    357364    if (RT_SUCCESS(rc))
    358         *ppszValue = pcBuf.release();
    359     else if (rc == VERR_BUFFER_OVERFLOW)
    360         /* VERR_BUFFER_OVERFLOW has a different meaning here as a
    361          * return code, but we need to report the race. */
    362         rc = VERR_TOO_MUCH_DATA;
    363 
    364     return rc;
    365 }
     365    {
     366        Assert(pszValue == (char *)pvBuf);
     367        *ppszValue = pszValue;
     368    }
     369    else
     370    {
     371        RTMemFree(pvBuf);
     372        if (rc == VERR_BUFFER_OVERFLOW)
     373            /* VERR_BUFFER_OVERFLOW has a different meaning here as a
     374             * return code, but we need to report the race. */
     375            rc = VERR_TOO_MUCH_DATA;
     376    }
     377
     378    return rc;
     379}
     380
    366381
    367382/**
     
    421436/**
    422437 * Raw API for enumerating guest properties which match a given pattern.
    423  * 
     438 *
    424439 * @returns VINF_SUCCESS on success and pcBuf points to a packed array
    425440 *          of the form <name>, <value>, <timestamp string>, <flags>,
     
    480495 * Start enumerating guest properties which match a given pattern.
    481496 * This function creates a handle which can be used to continue enumerating.
    482  * @returns VINF_SUCCESS on success, ppHandle points to a handle for continuing
    483  *          the enumeration and ppszName, ppszValue, pu64Timestamp and
    484  *          ppszFlags are set.
    485  * @returns VERR_NOT_FOUND if no matching properties were found.  In this case
     497 *
     498 * @returns VBox status code.
     499 * @retval  VINF_SUCCESS on success, *ppHandle points to a handle for continuing
     500 *          the enumeration and *ppszName, *ppszValue, *pu64Timestamp and
     501 *          *ppszFlags are set.
     502 * @retval  VERR_NOT_FOUND if no matching properties were found.  In this case
    486503 *          the return parameters are not initialised.
    487  * @returns VERR_TOO_MUCH_DATA if it was not possible to determine the amount
     504 * @retval VERR_TOO_MUCH_DATA if it was not possible to determine the amount
    488505 *          of local space needed to store all the enumeration data.  This is
    489506 *          due to a race between allocating space and the host adding new
    490507 *          data, so retrying may help here.  Other parameters are left
    491508 *          uninitialised
    492  * @returns IPRT status value otherwise.  Other parameters are left
    493  *          uninitialised.
    494  * @param   ppaszPatterns the patterns against which the properties are
     509 *
     510 * @param   papszPatterns The patterns against which the properties are
    495511 *                        matched.  Pass NULL if everything should be matched.
    496  * @param   cPatterns     the number of patterns in @a ppaszPatterns.  0 means
     512 * @param   cPatterns     The number of patterns in @a papszPatterns.  0 means
    497513 *                        match everything.
    498514 * @param   ppHandle      where the handle for continued enumeration is stored
     
    508524 */
    509525VBGLR3DECL(int) VbglR3GuestPropEnum(uint32_t u32ClientId,
    510                                     char **ppaszPatterns,
     526                                    char **papszPatterns,
    511527                                    int cPatterns,
    512528                                    PVBGLR3GUESTPROPENUM *ppHandle,
     
    516532                                    char **ppszFlags)
    517533{
     534#if 1 /* the RTMemAutoPtr doesn't compile */
     535    return VERR_NOT_IMPLEMENTED;
     536#else
    518537    int rc = VINF_SUCCESS;
    519538    RTMemAutoPtr<VBGLR3GUESTPROPENUM, VbglR3GuestPropEnumFree> pHandle;
     
    527546    uint32_t cchPatterns = 1;
    528547    for (int i = 0; i < cPatterns; ++i)
    529         cchPatterns += strlen(ppaszPatterns[i]) + 1;
     548        cchPatterns += strlen(papszPatterns[i]) + 1;
    530549    /* Pack the pattern array */
    531550    RTMemAutoPtr<char> pPatterns;
    532551    pPatterns = reinterpret_cast<char *>(RTMemAlloc(cchPatterns));
    533     char *pPatternsRaw = pPatterns.get();
     552    char *pchPatternsRaw = pPatterns.get();
    534553    for (int i = 0; i < cPatterns; ++i)
    535         pPatternsRaw = strcpy(pPatternsRaw, ppaszPatterns[i]) + strlen(ppaszPatterns[i]) + 1;
    536     *pPatternsRaw = 0;
     554    {
     555        size_t cb = strlen(papszPatterns[i]) + 1;
     556        memcpy(pchPatternsRaw, papszPatterns[i], cb);
     557        pchPatternsRaw += cb;
     558    }
     559    *pchPatternsRaw = '\0';
    537560
    538561    /* Randomly chosen initial size for the buffer to hold the enumeration
     
    574597        *ppHandle = pHandle.release();
    575598    return rc;
     599#endif
    576600}
    577601
     
    579603/**
    580604 * Get the next guest property.  See @a VbglR3GuestPropEnum.
    581  * @param  pHandle       handle obtained from @a VbglR3GuestPropEnum.
    582  * @param  ppszName      where to store the next property name.  This will be
     605 *
     606 * @returns VBox status code.
     607 *
     608 * @param  pHandle       Handle obtained from @a VbglR3GuestPropEnum.
     609 * @param  ppszName      Where to store the next property name.  This will be
    583610 *                       set to NULL if there are no more properties to
    584611 *                       enumerate.  This pointer should not be freed.
    585  * @param  ppszValue     where to store the next property value.  This will be
     612 * @param  ppszValue     Where to store the next property value.  This will be
    586613 *                       set to NULL if there are no more properties to
    587614 *                       enumerate.  This pointer should not be freed.
    588  * @param  pu64Timestamp where to store the next property timestamp.  This
     615 * @param  pu64Timestamp Where to store the next property timestamp.  This
    589616 *                       will be set to zero if there are no more properties
    590617 *                       to enumerate.
    591  * @param  ppszFlags     where to store the next property flags.  This will be
     618 * @param  ppszFlags     Where to store the next property flags.  This will be
    592619 *                       set to NULL if there are no more properties to
    593620 *                       enumerate.  This pointer should not be freed.
     
    601628    uint32_t iBuf = pHandle->iBuf;
    602629    char *pszName = pHandle->pchBuf + iBuf;
    603     /** @todo replace these with safe strlen's and return an error if needed. */
     630    /** @todo replace these with safe memchr's and return an error if needed. */
    604631    iBuf += strlen(pszName) + 1;
    605632    char *pszValue = pHandle->pchBuf + iBuf;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette