VirtualBox

Changeset 3387

Show
Ignore:
Timestamp:
07/03/07 13:36:37 (2 years ago)
Author:
vboxsync
Message:

Main: com::GetVBoxUserHomeDirectory() now takes char * instead of Utf8Str because on XPCOM platforms, this function may be called before XPCOM has been initialized, when Utf8Str functionality is not yet available (because it uses XPCOM memory management).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/VBox/com/com.h

    r2981 r3387  
    2525 
    2626#include "VBox/com/defs.h" 
    27 #include "VBox/com/string.h" 
    2827 
    2928namespace com 
     
    5958 *  Returns the VirtualBox user home directory. 
    6059 * 
    61  *  On failure, this function will return a path that caused a failure (or a 
    62  *  null string if the faiulre is not path-related). 
     60 *  On failure, this function will return a path that caused a failure (or 
     61 *  NULL if the faiulre is not path-related). 
    6362 * 
    6463 *  On success, this function will try to create the returned directory if it 
    6564 *  doesn't exist yet. This may also fail with the corresponding status code. 
    66  *  
    67  *  @param aDir     Where to return the directory to. 
     65 * 
     66 *  If @a aDirLen is smaller than RTPATH_MAX then there is a great chance that 
     67 *  this method will return VERR_BUFFER_OVERFLOW. 
     68 * 
     69 *  @param aDir     Buffer to store the directory string in UTF-8 encoding. 
     70 *  @param aDirLen  Length of the supplied buffer including space for the 
     71 *                  terminating null character, in bytes. 
    6872 *  @return         VBox status code. 
    6973 */ 
    70 int GetVBoxUserHomeDirectory (Utf8Str &aDir); 
     74int GetVBoxUserHomeDirectory (char *aDir, size_t aDirLen); 
    7175 
    7276}; // namespace com 
  • trunk/include/VBox/com/string.h

    r2981 r3387  
    4343 *  implementation details. 
    4444 * 
    45  *  @note 
    46  *  This class follows the common ownership transfer rule, Regarding to passing 
    47  *  strings as method parameters, this means that the instance data is always 
    48  *  owned by the caller. 
     45 *  This class uses COM/XPCOM-provided memory management routines to allocate 
     46 *  and free string buffers. This makes it possible to: 
     47 *  - use it as a type of member variables of COM/XPCOM components and pass 
     48 *    their values to callers through component methods' output parameters 
     49 *    using the #cloneTo() operation; 
     50 *  - adopt (take ownership of) string buffers returned in output parameters 
     51 *    of COM methods using the #asOutParam() operation and correctly free them 
     52 *    afterwards. 
    4953 */ 
    5054class Bstr 
     
    243247 *  conjunction with Bstr to simplify conversions beetween UCS2 (|BSTR|) 
    244248 *  and UTF8. 
     249 * 
     250 *  This class uses COM/XPCOM-provided memory management routines to allocate 
     251 *  and free string buffers. This makes it possible to: 
     252 *  - use it as a type of member variables of COM/XPCOM components and pass 
     253 *    their values to callers through component methods' output parameters 
     254 *    using the #cloneTo() operation; 
     255 *  - adopt (take ownership of) string buffers returned in output parameters 
     256 *    of COM methods using the #asOutParam() operation and correctly free them 
     257 *    afterwards. 
    245258 */ 
    246259class Utf8Str 
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp

    r3231 r3387  
    61246124    else 
    61256125    { 
    6126         Utf8Str homeDir; 
    6127         GetVBoxUserHomeDirectory (homeDir); 
    6128  
    6129         RTPrintf ("Updating settings files in the following VirtualBox Home Directory:\n" 
    6130                   "\n    %s\n\n", homeDir.raw()); 
    6131  
    6132         vrc = handleUpdateSettings_processDir (homeDir, mode, skipinvalid); 
     6126        char homeDir [RTPATH_MAX]; 
     6127        vrc = GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 
     6128 
     6129        AssertRC (vrc); 
     6130        if (VBOX_SUCCESS (vrc)) 
     6131        { 
     6132            RTPrintf ("Updating settings files in the following VirtualBox Home Directory:\n" 
     6133                      "\n    %s\n\n", homeDir); 
     6134 
     6135            vrc = handleUpdateSettings_processDir (homeDir, mode, skipinvalid); 
     6136        } 
    61336137    } 
    61346138 
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r3330 r3387  
    139139 
    140140    /* Get the VirtualBox home directory. */ 
    141     int vrc = com::GetVBoxUserHomeDirectory (unconst (mData.mHomeDir)); 
    142     if (VBOX_FAILURE (vrc)) 
    143         return setError (E_FAIL, 
    144             tr ("Could not create the VirtualBox home directory '%s'" 
    145                 "(%Vrc)"), 
    146             mData.mHomeDir.raw(), vrc); 
     141    { 
     142        char homeDir [RTPATH_MAX]; 
     143        int vrc = com::GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 
     144        if (VBOX_FAILURE (vrc)) 
     145            return setError (E_FAIL, 
     146                tr ("Could not create the VirtualBox home directory '%s'" 
     147                    "(%Vrc)"), 
     148                homeDir, vrc); 
     149 
     150        unconst (mData.mHomeDir) = homeDir; 
     151    } 
    147152 
    148153    /* compose the global config file name (always full path) */ 
  • trunk/src/VBox/Main/glue/com.cpp

    r3191 r3387  
    133133} 
    134134 
    135 int GetVBoxUserHomeDirectory (Utf8Str &aDir
     135int GetVBoxUserHomeDirectory (char *aDir, size_t aDirLen
    136136{ 
     137    AssertReturn (aDir, VERR_INVALID_POINTER); 
     138    AssertReturn (aDirLen > 0, VERR_BUFFER_OVERFLOW); 
     139 
    137140    /* start with null */ 
    138     aDir.setNull()
     141    *aDir = 0
    139142 
    140143    const char *VBoxUserHome = RTEnvGet ("VBOX_USER_HOME"); 
     
    152155            vrc = RTPathAbs (VBoxUserHomeUtf8, path, sizeof (path)); 
    153156            if (RT_SUCCESS (vrc)) 
    154                 aDir = path; 
     157            { 
     158                if (aDirLen < strlen (path) + 1) 
     159                    vrc = VERR_BUFFER_OVERFLOW; 
     160                else 
     161                    strcpy (aDir, path); 
     162            } 
    155163            RTStrFree (VBoxUserHomeUtf8); 
    156164        } 
     
    161169        vrc = RTPathUserHome (path, sizeof (path)); 
    162170        if (RT_SUCCESS (vrc)) 
    163             aDir = Utf8StrFmt ("%s%c%s", path, RTPATH_DELIMITER, 
    164                                VBOX_USER_HOME_SUFFIX); 
     171        { 
     172            size_t len =  
     173                RTStrPrintf (aDir, aDirLen, "%s%c%s", 
     174                             path, RTPATH_DELIMITER, VBOX_USER_HOME_SUFFIX); 
     175            if (len != strlen (path) + 1 + strlen (VBOX_USER_HOME_SUFFIX)) 
     176                vrc = VERR_BUFFER_OVERFLOW; 
     177        } 
    165178    } 
    166179 
  • trunk/src/VBox/Main/glue/initterm.cpp

    r2981 r3387  
    184184 
    185185        /* prepare paths for registry files */ 
    186         Utf8Str homeDir
    187         int vrc = GetVBoxUserHomeDirectory (homeDir); 
     186        char homeDir [RTPATH_MAX]
     187        int vrc = GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 
    188188        if (RT_SUCCESS (vrc)) 
    189189        { 
    190             Utf8Str compReg = Utf8StrFmt ("%s%c%s", homeDir.raw(), 
    191                                           RTPATH_DELIMITER, "compreg.dat"); 
    192             Utf8Str xptiDat = Utf8StrFmt ("%s%c%s", homeDir.raw(), 
    193                                           RTPATH_DELIMITER, "xpti.dat"); 
     190            char compReg [RTPATH_MAX]; 
     191            char xptiDat [RTPATH_MAX]; 
     192 
     193            RTStrPrintf (compReg, sizeof (compReg), "%s%c%s", 
     194                         homeDir, RTPATH_DELIMITER, "compreg.dat"); 
     195            RTStrPrintf (xptiDat, sizeof (xptiDat), "%s%c%s", 
     196                         homeDir, RTPATH_DELIMITER, "xpti.dat"); 
     197 
    194198            dsProv = new DirectoryServiceProvider(); 
    195199            if (dsProv) 
     
    230234            if (RT_SUCCESS (vrc)) 
    231235            { 
    232                 nsCOMPtr<nsILocalFile> file; 
     236                nsCOMPtr <nsILocalFile> file; 
    233237                rc = NS_NewNativeLocalFile (nsEmbedCString (appDirCP), 
    234238                                            PR_FALSE, getter_AddRefs (file)); 
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r2981 r3387  
    202202    HRESULT rc; 
    203203 
     204    { 
     205        char homeDir [RTPATH_MAX]; 
     206        GetVBoxUserHomeDirectory (homeDir, sizeof (homeDir)); 
     207        printf ("VirtualBox Home Directory = '%s'\n", homeDir); 
     208    } 
     209 
    204210    printf ("Initializing COM...\n"); 
    205211 
     
    213219    ComPtr <IVirtualBox> virtualBox; 
    214220    ComPtr <ISession> session; 
     221 
     222#if 0 
     223    // Utf8Str test 
     224    //////////////////////////////////////////////////////////////////////////// 
     225 
     226    Utf8Str nullUtf8Str; 
     227    printf ("nullUtf8Str='%s'\n", nullUtf8Str.raw()); 
     228     
     229    Utf8Str simpleUtf8Str = "simpleUtf8Str"; 
     230    printf ("simpleUtf8Str='%s'\n", simpleUtf8Str.raw()); 
     231 
     232    Utf8Str utf8StrFmt = Utf8StrFmt ("[0=%d]%s[1=%d]", 
     233                                     0, "utf8StrFmt", 1); 
     234    printf ("utf8StrFmt='%s'\n", utf8StrFmt.raw()); 
     235 
     236#endif 
    215237 
    216238    printf ("Creating VirtualBox object...\n"); 
     
    454476#endif 
    455477 
    456 #if 1 
     478#if 0 
    457479    // find a registered hard disk by location 
    458480    /////////////////////////////////////////////////////////////////////////// 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy