VirtualBox

Changeset 13552 in vbox


Ignore:
Timestamp:
Oct 24, 2008 12:33:39 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
38418
Message:

ConsoleImpl2.cpp: Implemented optional typing of VBoxInternal keys. 'string:', 'integer:' and 'bytes:', with no white space afterwards. Untested, hope it works. Fixes ticket #2481.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl2.cpp

    r13534 r13552  
    18861886     * Here we check the extra data entries for CFGM values
    18871887     * and create the nodes and insert the values on the fly. Existing
    1888      * values will be removed and reinserted. If a value is a valid number,
    1889      * it will be inserted as a number, otherwise as a string.
     1888     * values will be removed and reinserted. CFGM is typed, so by default
     1889     * we will guess whether it's a string or an integer (byte arrays are
     1890     * not currently supported). It's possible to override this autodetection
     1891     * by adding "string:", "integer:" or "bytes:" (future).
    18901892     *
    18911893     * We first perform a run on global extra data, then on the machine
     
    18931895     *
    18941896     */
     1897    /** @todo add support for removing nodes and byte blobs. */
    18951898    Bstr strExtraDataKey;
    18961899    bool fGlobalExtraData = true;
    18971900    for (;;)
    18981901    {
     1902        /*
     1903         * Get the next key
     1904         */
    18991905        Bstr strNextExtraDataKey;
    19001906        Bstr strExtraDataValue;
    1901 
    1902         /* get the next key */
    19031907        if (fGlobalExtraData)
    19041908            hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
     
    19201924            break;
    19211925        }
    1922 
    19231926        strExtraDataKey = strNextExtraDataKey;
     1927
     1928        /*
     1929         * We only care about keys starting with "VBoxInternal/"
     1930         */
    19241931        Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
    1925 
    1926         /* we only care about keys starting with "VBoxInternal/" */
    1927         if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
     1932        char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
     1933        if (strncmp(pszExtraDataKey, "VBoxInternal/", 13) != 0)
    19281934            continue;
    1929         char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
    1930 
    1931         /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
     1935        pszExtraDataKey += 13;
     1936
     1937        /*
     1938         * The key will be in the format "Node1/Node2/Value" or simply "Value".
     1939         * Split the two and get the node, delete the value and create the node
     1940         * if necessary.
     1941         */
    19321942        PCFGMNODE pNode;
    19331943        char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
    19341944        if (pszCFGMValueName)
    19351945        {
    1936             /* terminate the node and advance to the value */
     1946            /* terminate the node and advance to the value (Utf8Str might not
     1947               offically like this but wtf) */
    19371948            *pszCFGMValueName = '\0';
    19381949            pszCFGMValueName++;
     
    19411952            pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
    19421953            if (pNode)
    1943             {
    1944                 /* the value might already exist, remove it to be safe */
    19451954                CFGMR3RemoveValue(pNode, pszCFGMValueName);
    1946             }
    19471955            else
    19481956            {
    19491957                /* create the node */
    19501958                rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
    1951                 AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
    1952                 if (VBOX_FAILURE(rc) || !pNode)
     1959                if (VBOX_FAILURE(rc))
     1960                {
     1961                    AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
    19531962                    continue;
     1963                }
     1964                Assert(pNode);
    19541965            }
    19551966        }
    19561967        else
    19571968        {
     1969            /* root value (no node path). */
    19581970            pNode = pRoot;
    19591971            pszCFGMValueName = pszExtraDataKey;
    19601972            pszExtraDataKey--;
    1961 
    1962             /* the value might already exist, remove it to be safe */
    19631973            CFGMR3RemoveValue(pNode, pszCFGMValueName);
    19641974        }
    19651975
    1966         /* now let's have a look at the value */
     1976        /*
     1977         * Now let's have a look at the value.
     1978         * Empty strings means that we should remove the value, which we've
     1979         * already done above.
     1980         */
    19671981        Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
    19681982        const char *pszCFGMValue = strCFGMValueUtf8.raw();
    1969         /* empty value means remove value which we've already done */
    1970         if (pszCFGMValue && *pszCFGMValue)
    1971         {
    1972             /* if it's a valid number, we'll insert it as such, otherwise string */
     1983        if (    pszCFGMValue
     1984            && *pszCFGMValue)
     1985        {
    19731986            uint64_t u64Value;
    1974             char *pszNext = NULL;
    1975             if (   RTStrToUInt64Ex(pszCFGMValue, &pszNext, 0, &u64Value) == VINF_SUCCESS
    1976                 && (!pszNext || *pszNext == '\0') /* check if the _whole_ string is a valid number */
    1977                 )
    1978             {
     1987
     1988            /* check for type prefix first. */
     1989            if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
     1990                rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
     1991            else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
     1992            {
     1993                rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
     1994                if (RT_SUCCESS(rc))
     1995                    rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
     1996            }
     1997            else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
     1998                rc = VERR_NOT_IMPLEMENTED;
     1999            /* auto detect type. */
     2000            else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
    19792001                rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
    1980             }
    19812002            else
    1982             {
    19832003                rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
    1984             }
    1985             AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
     2004            AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
    19862005        }
    19872006    }
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