VirtualBox

Changeset 31480 in vbox


Ignore:
Timestamp:
Aug 9, 2010 12:28:25 PM (15 years ago)
Author:
vboxsync
Message:

Main: use Utf8Str for media properties (also fixes incorrect length assumption in conversation with media backend)

File:
1 edited

Legend:

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

    r31479 r31480  
    150150    bool hostDrive : 1;
    151151
    152     typedef std::map<Bstr, Bstr> PropertyMap;
    153     PropertyMap properties;
     152    settings::PropertiesMap mapProperties;
    154153
    155154    bool implicit : 1;
     
    993992        const Utf8Str &name = it->first;
    994993        const Utf8Str &value = it->second;
    995         m->properties[Bstr(name)] = Bstr(value);
     994        m->mapProperties[name] = value;
    996995    }
    997996
     
    19631962    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    19641963
    1965     Data::PropertyMap::const_iterator it = m->properties.find(Bstr(aName));
    1966     if (it == m->properties.end())
     1964    settings::PropertiesMap::const_iterator it = m->mapProperties.find(Utf8Str(aName));
     1965    if (it == m->mapProperties.end())
    19671966        return setError(VBOX_E_OBJECT_NOT_FOUND,
    19681967                        tr("Property '%ls' does not exist"), aName);
     
    19911990    }
    19921991
    1993     Data::PropertyMap::iterator it = m->properties.find(Bstr(aName));
    1994     if (it == m->properties.end())
     1992    settings::PropertiesMap::iterator it = m->mapProperties.find(Utf8Str(aName));
     1993    if (it == m->mapProperties.end())
    19951994        return setError(VBOX_E_OBJECT_NOT_FOUND,
    19961995                        tr("Property '%ls' does not exist"),
    19971996                        aName);
    19981997
    1999     if (aValue && !*aValue)
    2000         it->second = (const char *)NULL;
    2001     else
    2002         it->second = aValue;
     1998    it->second = aValue;
    20031999
    20042000    // save the global settings; for that we should hold only the VirtualBox lock
     
    20252021    NOREF(aNames);
    20262022
    2027     com::SafeArray<BSTR> names(m->properties.size());
    2028     com::SafeArray<BSTR> values(m->properties.size());
     2023    com::SafeArray<BSTR> names(m->mapProperties.size());
     2024    com::SafeArray<BSTR> values(m->mapProperties.size());
    20292025    size_t i = 0;
    20302026
    2031     for (Data::PropertyMap::const_iterator it = m->properties.begin();
    2032          it != m->properties.end();
     2027    for (settings::PropertiesMap::const_iterator it = m->mapProperties.begin();
     2028         it != m->mapProperties.end();
    20332029         ++it)
    20342030    {
     
    20632059         ++i)
    20642060    {
    2065         if (m->properties.find(Bstr(names[i])) == m->properties.end())
     2061        if (m->mapProperties.find(Utf8Str(names[i])) == m->mapProperties.end())
    20662062            return setError(VBOX_E_OBJECT_NOT_FOUND,
    20672063                            tr("Property '%ls' does not exist"), names[i]);
     
    20732069         ++i)
    20742070    {
    2075         Data::PropertyMap::iterator it = m->properties.find(Bstr(names[i]));
    2076         AssertReturn(it != m->properties.end(), E_FAIL);
    2077 
    2078         if (values[i] && !*values[i])
    2079             it->second = (const char *)NULL;
    2080         else
    2081             it->second = values[i];
     2071        settings::PropertiesMap::iterator it = m->mapProperties.find(Utf8Str(names[i]));
     2072        AssertReturn(it != m->mapProperties.end(), E_FAIL);
     2073
     2074        it->second = Utf8Str(values[i]);
    20822075    }
    20832076
     
    30273020    /* optional properties */
    30283021    data.properties.clear();
    3029     for (Data::PropertyMap::const_iterator it = m->properties.begin();
    3030          it != m->properties.end();
     3022    for (settings::PropertiesMap::const_iterator it = m->mapProperties.begin();
     3023         it != m->mapProperties.end();
    30313024         ++it)
    30323025    {
     
    30343027        if (!it->second.isEmpty())
    30353028        {
    3036             Utf8Str name = it->first;
    3037             Utf8Str value = it->second;
     3029            const Utf8Str &name = it->first;
     3030            const Utf8Str &value = it->second;
    30383031            data.properties[name] = value;
    30393032        }
     
    49194912         * properties is meant to be constant. */
    49204913
    4921         Assert(m->properties.empty());
     4914        Assert(m->mapProperties.empty());
    49224915
    49234916        for (MediumFormat::PropertyList::const_iterator it = m->formatObj->getProperties().begin();
     
    49254918             ++it)
    49264919        {
    4927             m->properties.insert(std::make_pair(it->strName, Utf8Str::Empty));
     4920            m->mapProperties.insert(std::make_pair(it->strName, Utf8Str::Empty));
    49284921        }
    49294922    }
     
    50155008
    50165009/* static */
    5017 DECLCALLBACK(int) Medium::vdConfigQuerySize(void *pvUser, const char *pszName,
     5010DECLCALLBACK(int) Medium::vdConfigQuerySize(void *pvUser,
     5011                                            const char *pszName,
    50185012                                            size_t *pcbValue)
    50195013{
     
    50235017    AssertReturn(that != NULL, VERR_GENERAL_FAILURE);
    50245018
    5025     Data::PropertyMap::const_iterator it =
    5026         that->m->properties.find(Bstr(pszName));
    5027     if (it == that->m->properties.end())
     5019    settings::PropertiesMap::const_iterator it = that->m->mapProperties.find(Utf8Str(pszName));
     5020    if (it == that->m->mapProperties.end())
    50285021        return VERR_CFGM_VALUE_NOT_FOUND;
    50295022
     
    50385031
    50395032/* static */
    5040 DECLCALLBACK(int) Medium::vdConfigQuery(void *pvUser, const char *pszName,
    5041                                         char *pszValue, size_t cchValue)
     5033DECLCALLBACK(int) Medium::vdConfigQuery(void *pvUser,
     5034                                        const char *pszName,
     5035                                        char *pszValue,
     5036                                        size_t cchValue)
    50425037{
    50435038    AssertReturn(VALID_PTR(pszValue), VERR_INVALID_POINTER);
     
    50465041    AssertReturn(that != NULL, VERR_GENERAL_FAILURE);
    50475042
    5048     Data::PropertyMap::const_iterator it =
    5049         that->m->properties.find(Bstr(pszName));
    5050     if (it == that->m->properties.end())
     5043    settings::PropertiesMap::const_iterator it = that->m->mapProperties.find(Utf8Str(pszName));
     5044    if (it == that->m->mapProperties.end())
    50515045        return VERR_CFGM_VALUE_NOT_FOUND;
    5052 
    5053     Utf8Str value = it->second;
    5054     if (value.length() >= cchValue)
    5055         return VERR_CFGM_NOT_ENOUGH_SPACE;
    50565046
    50575047    /* we interpret null values as "no value" in Medium */
    50585048    if (it->second.isEmpty())
    50595049        return VERR_CFGM_VALUE_NOT_FOUND;
     5050
     5051    const Utf8Str &value = it->second;
     5052    if (value.length() >= cchValue)
     5053        return VERR_CFGM_NOT_ENOUGH_SPACE;
    50605054
    50615055    memcpy(pszValue, value.c_str(), value.length() + 1);
Note: See TracChangeset for help on using the changeset viewer.

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