VirtualBox

Changeset 22560 in vbox


Ignore:
Timestamp:
Aug 28, 2009 5:17:17 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
51587
Message:

Main/GuestProperties: fix setting empty strings as guest properties and clean up as per a @todo

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

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

    r22519 r22560  
    17881788
    17891789#ifdef VBOX_WITH_GUEST_PROPS
    1790     /** @todo r=bird: functions! methods! */
    17911790    /*
    17921791     * Guest property service
    17931792     */
    1794     try
    1795     {
    1796         /* Load the service */
    1797         rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
    1798 
    1799         if (RT_FAILURE(rc))
    1800         {
    1801             LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
    1802             /* That is not a fatal failure. */
    1803             rc = VINF_SUCCESS;
    1804         }
    1805         else
    1806         {
    1807             /* Pull over the properties from the server. */
    1808             SafeArray<BSTR> namesOut;
    1809             SafeArray<BSTR> valuesOut;
    1810             SafeArray<ULONG64> timestampsOut;
    1811             SafeArray<BSTR> flagsOut;
    1812             hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
    1813                                                 ComSafeArrayAsOutParam(valuesOut),
    1814                                                 ComSafeArrayAsOutParam(timestampsOut),
    1815                                                 ComSafeArrayAsOutParam(flagsOut));         H();
    1816             size_t cProps = namesOut.size();
    1817             if (   valuesOut.size() != cProps
    1818                 || timestampsOut.size() != cProps
    1819                 || flagsOut.size() != cProps
    1820                )
    1821                 rc = VERR_INVALID_PARAMETER;
    1822 
    1823             std::vector<Utf8Str> utf8Names, utf8Values, utf8Flags;
    1824             std::vector<char *> names, values, flags;
    1825             std::vector<ULONG64> timestamps;
    1826             for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
    1827                 if (   !VALID_PTR(namesOut[i])
    1828                     || !VALID_PTR(valuesOut[i])
    1829                     || !VALID_PTR(flagsOut[i])
    1830                    )
    1831                     rc = VERR_INVALID_POINTER;
    1832             for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
    1833             {
    1834                 utf8Names.push_back(Bstr(namesOut[i]));
    1835                 utf8Values.push_back(Bstr(valuesOut[i]));
    1836                 timestamps.push_back(timestampsOut[i]);
    1837                 utf8Flags.push_back(Bstr(flagsOut[i]));
    1838             }
    1839             for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
    1840             {
    1841                 names.push_back(utf8Names[i].mutableRaw());
    1842                 values.push_back(utf8Values[i].mutableRaw());
    1843                 flags.push_back(utf8Flags[i].mutableRaw());
    1844             }
    1845             names.push_back(NULL);
    1846             values.push_back(NULL);
    1847             timestamps.push_back(0);
    1848             flags.push_back(NULL);
    1849 
    1850             /* Setup the service. */
    1851             VBOXHGCMSVCPARM parms[4];
    1852 
    1853             parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
    1854             parms[0].u.pointer.addr = &names.front();
    1855             parms[0].u.pointer.size = 0;  /* We don't actually care. */
    1856             parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
    1857             parms[1].u.pointer.addr = &values.front();
    1858             parms[1].u.pointer.size = 0;  /* We don't actually care. */
    1859             parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
    1860             parms[2].u.pointer.addr = &timestamps.front();
    1861             parms[2].u.pointer.size = 0;  /* We don't actually care. */
    1862             parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
    1863             parms[3].u.pointer.addr = &flags.front();
    1864             parms[3].u.pointer.size = 0;  /* We don't actually care. */
    1865 
    1866             pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
    1867 
    1868             /* Set the VBox version string as a guest property */
    1869             parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
    1870             parms[0].u.pointer.addr = (void *)"/VirtualBox/HostInfo/VBoxVer";
    1871             parms[0].u.pointer.size = sizeof("/VirtualBox/HostInfo/VBoxVer");
    1872             parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
    1873             parms[1].u.pointer.addr = (void *)VBOX_VERSION_STRING;
    1874             parms[1].u.pointer.size = sizeof(VBOX_VERSION_STRING);
    1875             parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
    1876             parms[2].u.pointer.addr = (void *)"TRANSIENT, RDONLYGUEST";
    1877             parms[2].u.pointer.size = sizeof("TRANSIENT, RDONLYGUEST");
    1878             pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3, &parms[0]);
    1879 
    1880             /* Set the VBox SVN revision as a guest property */
    1881             parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
    1882             parms[0].u.pointer.addr = (void *)"/VirtualBox/HostInfo/VBoxRev";
    1883             parms[0].u.pointer.size = sizeof("/VirtualBox/HostInfo/VBoxRev");
    1884             parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
    1885             parms[1].u.pointer.addr = (void *)VBoxSVNRevString();
    1886             parms[1].u.pointer.size = strlen(VBoxSVNRevString()) + 1;
    1887             parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
    1888             parms[2].u.pointer.addr = (void *)"TRANSIENT, RDONLYGUEST";
    1889             parms[2].u.pointer.size = sizeof("TRANSIENT, RDONLYGUEST");
    1890             pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3, &parms[0]);
    1891 
    1892             /* Initialize the remote execution properties for ready-on access by the guest */
    1893             Utf8Str utf8ValEmpty = "";
    1894             parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
    1895             parms[0].u.pointer.addr = (void *)"/VirtualBox/HostGuest/SysprepArgs";
    1896             parms[0].u.pointer.size = sizeof("/VirtualBox/HostGuest/SysprepArgs");
    1897             parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
    1898             parms[1].u.pointer.addr = (void*)utf8ValEmpty.c_str();
    1899             parms[1].u.pointer.size = (uint32_t)utf8ValEmpty.length() + 1;
    1900             parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
    1901             parms[2].u.pointer.addr = (void *)"TRANSIENT, RDONLYGUEST";
    1902             parms[2].u.pointer.size = sizeof("TRANSIENT, RDONLYGUEST");
    1903             pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3, &parms[0]);
    1904 
    1905             /* Register the host notification callback */
    1906             HGCMSVCEXTHANDLE hDummy;
    1907             HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
    1908                                               Console::doGuestPropNotification,
    1909                                               pvConsole);
    1910 
    1911             Log(("Set VBoxGuestPropSvc property store\n"));
    1912         }
    1913     }
    1914     catch(std::bad_alloc & /*e*/)
    1915     {
    1916         return VERR_NO_MEMORY;
    1917     }
     1793
     1794    rc = configGuestProperties(pConsole);
    19181795#endif /* VBOX_WITH_GUEST_PROPS defined */
    19191796
     
    28722749}
    28732750
     2751#ifdef VBOX_WITH_GUEST_PROPS
     2752/**
     2753 * Set an array of guest properties
     2754 */
     2755static void configSetProperties(VMMDev * const pVMMDev, void *names,
     2756                                void *values, void *timestamps, void *flags)
     2757{
     2758    VBOXHGCMSVCPARM parms[4];
     2759
     2760    parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
     2761    parms[0].u.pointer.addr = names;
     2762    parms[0].u.pointer.size = 0;  /* We don't actually care. */
     2763    parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
     2764    parms[1].u.pointer.addr = values;
     2765    parms[1].u.pointer.size = 0;  /* We don't actually care. */
     2766    parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
     2767    parms[2].u.pointer.addr = timestamps;
     2768    parms[2].u.pointer.size = 0;  /* We don't actually care. */
     2769    parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
     2770    parms[3].u.pointer.addr = flags;
     2771    parms[3].u.pointer.size = 0;  /* We don't actually care. */
     2772
     2773    pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
     2774                           &parms[0]);
     2775}
     2776
     2777/**
     2778 * Set a single guest property
     2779 */
     2780static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
     2781                              const char *pszValue, const char *pszFlags)
     2782{
     2783    VBOXHGCMSVCPARM parms[4];
     2784
     2785    AssertPtrReturnVoid(pszName);
     2786    AssertPtrReturnVoid(pszValue);
     2787    AssertPtrReturnVoid(pszFlags);
     2788    parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
     2789    parms[0].u.pointer.addr = (void *)pszName;
     2790    parms[0].u.pointer.size = strlen(pszName) + 1;
     2791    parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
     2792    parms[1].u.pointer.addr = (void *)pszValue;
     2793    parms[1].u.pointer.size = strlen(pszValue) + 1;
     2794    parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
     2795    parms[2].u.pointer.addr = (void *)pszFlags;
     2796    parms[2].u.pointer.size = strlen(pszFlags) + 1;
     2797    pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
     2798                           &parms[0]);
     2799}
     2800#endif /* VBOX_WITH_GUEST_PROPS */
     2801
     2802/**
     2803 * Set up the Guest Property service, populate it with properties read from
     2804 * the machine XML and set a couple of initial properties.
     2805 */
     2806/* static */ int Console::configGuestProperties(void *pvConsole)
     2807{
     2808#ifdef VBOX_WITH_GUEST_PROPS
     2809    AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
     2810    ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
     2811
     2812    /* Load the service */
     2813    int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
     2814
     2815    if (RT_FAILURE(rc))
     2816    {
     2817        LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
     2818        /* That is not a fatal failure. */
     2819        rc = VINF_SUCCESS;
     2820    }
     2821    else
     2822    {
     2823        /* Pull over the properties from the server. */
     2824        SafeArray<BSTR> namesOut;
     2825        SafeArray<BSTR> valuesOut;
     2826        SafeArray<ULONG64> timestampsOut;
     2827        SafeArray<BSTR> flagsOut;
     2828        HRESULT hrc = pConsole->mControl->PullGuestProperties
     2829                                      (ComSafeArrayAsOutParam(namesOut),
     2830                                       ComSafeArrayAsOutParam(valuesOut),
     2831                                       ComSafeArrayAsOutParam(timestampsOut),
     2832                                       ComSafeArrayAsOutParam(flagsOut));
     2833        AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%#x\n", hrc),
     2834                        VERR_GENERAL_FAILURE);
     2835        size_t cProps = namesOut.size();
     2836        if (   valuesOut.size() != cProps
     2837            || timestampsOut.size() != cProps
     2838            || flagsOut.size() != cProps
     2839           )
     2840            AssertFailedReturn(VERR_INVALID_PARAMETER);
     2841
     2842        try
     2843        {
     2844            std::vector<Utf8Str> utf8Names, utf8Values, utf8Flags;
     2845            std::vector<const char *> names, values, flags;
     2846            std::vector<ULONG64> timestamps;
     2847            for (unsigned i = 0; i < cProps; ++i)
     2848            {
     2849                AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
     2850                utf8Names.push_back(Bstr(namesOut[i]));
     2851                names.push_back(utf8Names.back().c_str());
     2852                AssertPtrReturn(names[i], VERR_NO_MEMORY);
     2853                if (valuesOut[i])
     2854                {
     2855                    utf8Values.push_back(Bstr(valuesOut[i]));
     2856                    values.push_back(utf8Values.back().c_str());
     2857                }
     2858                else
     2859                    values.push_back("");
     2860                AssertPtrReturn(values[i], VERR_NO_MEMORY);
     2861                timestamps.push_back(timestampsOut[i]);
     2862                if (flagsOut[i])
     2863                {
     2864                    utf8Flags.push_back(Bstr(flagsOut[i]));
     2865                    flags.push_back(utf8Flags.back().c_str());
     2866                }
     2867                else
     2868                    flags.push_back("");
     2869                AssertPtrReturn(flags[i], VERR_NO_MEMORY);
     2870            }
     2871            names.push_back(NULL);
     2872            values.push_back(NULL);
     2873            timestamps.push_back(0);
     2874            flags.push_back(NULL);
     2875
     2876            configSetProperties(pConsole->mVMMDev,
     2877                                (void *)&names.front(),
     2878                                (void *)&values.front(),
     2879                                (void *)&timestamps.front(),
     2880                                (void *)&flags.front());
     2881        }
     2882        catch(std::bad_alloc & /*e*/)
     2883        {
     2884            return VERR_NO_MEMORY;
     2885        }
     2886
     2887        /* Set the VBox version string as a guest property */
     2888        configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
     2889                          VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
     2890        /* Set the VBox SVN revision as a guest property */
     2891        configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
     2892                          VBoxSVNRevString(), "TRANSIENT, RDONLYGUEST");
     2893        /* Initialize the remote execution properties for ready-on access by
     2894         * the guest */
     2895        configSetProperty(pConsole->mVMMDev,
     2896                          "/VirtualBox/HostGuest/SysprepArgs", "",
     2897                          "TRANSIENT, RDONLYGUEST");
     2898
     2899        /* Register the host notification callback */
     2900        HGCMSVCEXTHANDLE hDummy;
     2901        HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
     2902                                          Console::doGuestPropNotification,
     2903                                          pvConsole);
     2904
     2905        Log(("Set VBoxGuestPropSvc property store\n"));
     2906    }
     2907    return VINF_SUCCESS;
     2908#else /* !VBOX_WITH_GUEST_PROPS */
     2909    return VERR_NOT_SUPPORTED;
     2910#endif /* !VBOX_WITH_GUEST_PROPS */
     2911}
  • trunk/src/VBox/Main/MachineImpl.cpp

    r22487 r22560  
    83328332        it->strValue.cloneTo(&values[i]);
    83338333        timestamps[i] = it->mTimestamp;
    8334         writeFlags(it->mFlags, szFlags);
    8335         Bstr(szFlags).cloneTo(&flags[i]);
     8334        /* If it is NULL, keep it NULL. */
     8335        if (it->mFlags)
     8336        {
     8337            writeFlags(it->mFlags, szFlags);
     8338            Bstr(szFlags).cloneTo(&flags[i]);
     8339        }
     8340        else
     8341            flags[i] = NULL;
    83368342        ++i;
    83378343    }
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r22480 r22560  
    431431
    432432    static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
     433    static DECLCALLBACK(int) configGuestProperties(void *pvConsole);
    433434    static int configNetwork(Console *pThis, const char *pszDevice,
    434435                             unsigned uInstance, unsigned uLun,
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