Changeset 13552 in vbox
- Timestamp:
- Oct 24, 2008 12:33:39 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 38418
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl2.cpp
r13534 r13552 1886 1886 * Here we check the extra data entries for CFGM values 1887 1887 * 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). 1890 1892 * 1891 1893 * We first perform a run on global extra data, then on the machine … … 1893 1895 * 1894 1896 */ 1897 /** @todo add support for removing nodes and byte blobs. */ 1895 1898 Bstr strExtraDataKey; 1896 1899 bool fGlobalExtraData = true; 1897 1900 for (;;) 1898 1901 { 1902 /* 1903 * Get the next key 1904 */ 1899 1905 Bstr strNextExtraDataKey; 1900 1906 Bstr strExtraDataValue; 1901 1902 /* get the next key */1903 1907 if (fGlobalExtraData) 1904 1908 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(), … … 1920 1924 break; 1921 1925 } 1922 1923 1926 strExtraDataKey = strNextExtraDataKey; 1927 1928 /* 1929 * We only care about keys starting with "VBoxInternal/" 1930 */ 1924 1931 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) 1928 1934 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 */ 1932 1942 PCFGMNODE pNode; 1933 1943 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/'); 1934 1944 if (pszCFGMValueName) 1935 1945 { 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) */ 1937 1948 *pszCFGMValueName = '\0'; 1938 1949 pszCFGMValueName++; … … 1941 1952 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey); 1942 1953 if (pNode) 1943 {1944 /* the value might already exist, remove it to be safe */1945 1954 CFGMR3RemoveValue(pNode, pszCFGMValueName); 1946 }1947 1955 else 1948 1956 { 1949 1957 /* create the node */ 1950 1958 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)); 1953 1962 continue; 1963 } 1964 Assert(pNode); 1954 1965 } 1955 1966 } 1956 1967 else 1957 1968 { 1969 /* root value (no node path). */ 1958 1970 pNode = pRoot; 1959 1971 pszCFGMValueName = pszExtraDataKey; 1960 1972 pszExtraDataKey--; 1961 1962 /* the value might already exist, remove it to be safe */1963 1973 CFGMR3RemoveValue(pNode, pszCFGMValueName); 1964 1974 } 1965 1975 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 */ 1967 1981 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue); 1968 1982 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 { 1973 1986 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))) 1979 2001 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value); 1980 }1981 2002 else 1982 {1983 2003 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)); 1986 2005 } 1987 2006 }
Note:
See TracChangeset
for help on using the changeset viewer.