VirtualBox

Changeset 43584 in vbox for trunk/src


Ignore:
Timestamp:
Oct 9, 2012 3:01:08 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81248
Message:

Main,VRDP,VBoxTray: location awareness extension (ported from 4.2).

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp

    r43224 r43584  
    4040#define LA_DO_ATTACH_AND_DETACH 4
    4141
     42
     43#define LA_UTCINFO_CLIENT_NAME      0
     44#define LA_UTCINFO_CLIENT_IPADDR    1
     45#define LA_UTCINFO_CLIENT_LOCATION  2
     46#define LA_UTCINFO_CLIENT_OTHERINFO 3
     47#define LA_UTCINFO_CLIENT_INFO_LAST 3
     48
     49#define LA_UTCINFO_PROP_NAME  0
     50#define LA_UTCINFO_PROP_VALUE 1
     51
     52
    4253struct VBOXLACONTEXT
    4354{
     
    6778        uint64_t u64LastNameTimestamp;
    6879
    69         char *pszPropName;        /* The actual Client/%ID%/Name property name with client id. */
     80        char *pszPropName;       /* The actual Client/%ID%/Name property name with client id. */
     81        char *pszPropIPAddr;      /* The actual Client/%ID%/IPAddr property name with client id. */
     82        char *pszPropLocation;   /* The actual Client/%ID%/Location property name with client id. */
     83        char *pszPropOtherInfo;  /* The actual Client/%ID%/OtherInfo property name with client id. */
     84
    7085        char *pszPropAttach;      /* The actual Client/%ID%/Attach property name with client id. */
    7186
     
    90105static const char *g_pszPropActiveClient = "/VirtualBox/HostInfo/VRDP/ActiveClient";
    91106
    92 static const char *g_pszPropNameTemplate = "/VirtualBox/HostInfo/VRDP/Client/%u/Name";
    93107static const char *g_pszPropAttachTemplate = "/VirtualBox/HostInfo/VRDP/Client/%u/Attach";
    94108
    95109static const char *g_pszVolatileEnvironment = "Volatile Environment";
    96110
    97 static const WCHAR *g_pwszUTCINFOClientName = L"UTCINFO_CLIENTNAME";
    98111static const WCHAR *g_pwszClientName = L"CLIENTNAME";
     112
     113static const WCHAR *g_pwszUTCINFOClientInfo[] = {
     114                                                  L"UTCINFO_CLIENTNAME",
     115                                                  L"UTCINFO_CLIENTIPA",
     116                                                  L"UTCINFO_CLIENTLOCATION",
     117                                                  L"UTCINFO_CLIENTOTHERINFO"
     118                                                };
     119
     120static const char *g_pszPropInfoTemplates[] = {
     121                                                "/VirtualBox/HostInfo/VRDP/Client/%u/Name",
     122                                                "/VirtualBox/HostInfo/VRDP/Client/%u/IPAddr",
     123                                                "/VirtualBox/HostInfo/VRDP/Client/%u/Location",
     124                                                "/VirtualBox/HostInfo/VRDP/Client/%u/OtherInfo"
     125                                              };
    99126
    100127#ifdef RT_ARCH_AMD64
     
    378405    LALOG(("LA: ExecuteActions leave\n"));
    379406}
    380        
     407
    381408static BOOL GetVolatileEnvironmentKey(WCHAR *pwszRegKey, DWORD cbRegKey)
    382409{
     
    484511    DWORD dwType;
    485512    lErr = RegQueryValueExW(hKey,
    486                             g_pwszUTCINFOClientName,
     513                            g_pwszUTCINFOClientInfo[LA_UTCINFO_CLIENT_NAME],
    487514                            NULL,
    488515                            &dwType,
     
    517544
    518545    lErr = RegQueryValueExW(hKey,
    519                             g_pwszUTCINFOClientName,
     546                            g_pwszUTCINFOClientInfo[LA_UTCINFO_CLIENT_NAME],
    520547                            NULL,
    521548                            NULL,
     
    602629}
    603630
    604 static void laOnClientName(const char *pszClientName)
    605 {
    606     /* pszClientName is UTF8, make an Unicode copy for registry. */
    607     PRTUTF16 putf16UnicodeName = NULL;
    608     size_t cchUnicodeName = 0;
    609     int rc = RTStrToUtf16Ex(pszClientName, MAX_CLIENT_NAME_CHARS,
    610                             &putf16UnicodeName, 0, &cchUnicodeName);
    611 
    612     if (RT_FAILURE(rc))
    613     {
    614         LALOG(("LA: RTStrToUniEx failed %Rrc\n", rc));
    615         return;
    616     }
    617 
    618     LALOG(("LA: unicode %d chars [%ls]\n", cchUnicodeName, putf16UnicodeName));
    619 
     631static void laOnClientLocationInfo(char *pszClientInfo[][2])
     632{
    620633    /*
    621      * Write the client name to:
    622      * HKCU\Volatile Environment\UTCINFO_CLIENTNAME or
    623      * HKCU\Volatile Environment\<SessionID>\UTCINFO_CLIENTNAME
     634     * Write the client location info to:
     635     * HKCU\Volatile Environment\<CLIENT_LOCATION_INFO> or
     636     * HKCU\Volatile Environment\<SessionID>\<CLIENT_LOCATION_INFO>
    624637     * depending on whether this is a Terminal Services or desktop session
    625638     * respectively.
     639     * The client location info are: Name, IPAddr, Location, OtherInfo
    626640     */
     641    unsigned int idx;
    627642    WCHAR wszRegKey[REG_KEY_LEN];
    628643    if (!GetVolatileEnvironmentKey(wszRegKey, sizeof(wszRegKey)))
    629644    {
    630645        LALOG(("LA: Failed to get 'Volatile Environment' registry key\n"));
    631         RTUtf16Free(putf16UnicodeName);
    632646        return;
    633647    }
     
    647661        LALOG(("LA: Failed to open key [%ls], error %lu\n",
    648662               wszRegKey, lRet));
    649         RTUtf16Free(putf16UnicodeName);
    650663        return;
    651664    }
    652665
    653     DWORD nDataLength = (DWORD)((cchUnicodeName + 1) * sizeof(WCHAR));
    654     lRet = RegSetValueExW(hKey,
    655                           g_pwszUTCINFOClientName,
    656                           0,
    657                           REG_SZ,
    658                           (BYTE *)putf16UnicodeName,
    659                           nDataLength);
    660 
    661     if (lRet != ERROR_SUCCESS)
    662     {
    663         LALOG(("LA: RegSetValueExW failed error %lu\n", lRet));
     666    PRTUTF16 putf16UnicodeClientInfo[LA_UTCINFO_CLIENT_INFO_LAST + 1] = {NULL};
     667    for (idx = 0; idx <= LA_UTCINFO_CLIENT_INFO_LAST; idx++)
     668    {
     669        if (pszClientInfo[idx][LA_UTCINFO_PROP_VALUE] == NULL)
     670            break;
     671
     672        /* pszClientInfo is UTF8, make an Unicode copy for registry. */
     673        size_t cchUnicodeClientInfo = 0;
     674
     675        int rc = RTStrToUtf16Ex(pszClientInfo[idx][LA_UTCINFO_PROP_VALUE], MAX_CLIENT_NAME_CHARS,
     676                                &putf16UnicodeClientInfo[idx], 0, &cchUnicodeClientInfo);
     677
     678        if (RT_FAILURE(rc))
     679        {
     680            LALOG(("LA: RTStrToUniEx failed %Rrc\n", rc));
     681            break;
     682        }
     683
     684        DWORD nDataLength = (DWORD)((cchUnicodeClientInfo + 1) * sizeof(WCHAR));
     685        lRet = RegSetValueExW(hKey,
     686                              g_pwszUTCINFOClientInfo[idx],
     687                              0,
     688                              REG_SZ,
     689                              (BYTE *)putf16UnicodeClientInfo[idx],
     690                              nDataLength);
     691
     692        if (lRet != ERROR_SUCCESS)
     693        {
     694            LALOG(("LA: RegSetValueExW failed error %lu for %s \n", lRet, g_pwszUTCINFOClientInfo[idx]));
     695        }
    664696    }
    665697
     
    668700    laBroadcastSettingChange();
    669701
    670     /* Also, write the client name to the environment of this process, as it
     702    /* Also, write these info (Name, IPAddr, Location and Other Info) to the environment of this process, as it
    671703     * doesn't listen for WM_SETTINGCHANGE messages.
    672704     */
    673     SetEnvironmentVariableW(g_pwszUTCINFOClientName, putf16UnicodeName);
    674 
    675     RTUtf16Free(putf16UnicodeName);
     705
     706    for (idx = 0; idx <= LA_UTCINFO_CLIENT_INFO_LAST; idx++)
     707    {
     708        if (putf16UnicodeClientInfo[idx] == NULL)
     709            break;
     710
     711        SetEnvironmentVariableW(g_pwszUTCINFOClientInfo[idx], putf16UnicodeClientInfo[idx]);
     712
     713        RTUtf16Free(putf16UnicodeClientInfo[idx]);
     714    }
    676715}
    677716
     
    884923    int l;
    885924
     925    char **pClientInfoMap[LA_UTCINFO_CLIENT_INFO_LAST + 1] = {
     926                                                               &pCtx->activeClient.pszPropName,
     927                                                               &pCtx->activeClient.pszPropIPAddr,
     928                                                               &pCtx->activeClient.pszPropLocation,
     929                                                               &pCtx->activeClient.pszPropOtherInfo,
     930                                                             };
     931
    886932    pCtx->activeClient.u32LastAttach = ~0;
    887933    pCtx->activeClient.u64LastAttachTimestamp = u64ActiveClientTS;
     
    894940    pCtx->activeClient.u64LastNameTimestamp = u64ActiveClientTS;
    895941
    896     if (pCtx->activeClient.pszPropName)
    897     {
    898         RTMemFree(pCtx->activeClient.pszPropName);
    899         pCtx->activeClient.pszPropName = NULL;
    900     }
    901     if (u32ActiveClientId != 0)
    902     {
    903         l = RTStrAPrintf(&pCtx->activeClient.pszPropName,
    904                          g_pszPropNameTemplate,
    905                          u32ActiveClientId);
    906         if (l == -1)
    907         {
    908             pCtx->activeClient.pszPropName = NULL;
    909             rc = VERR_NO_MEMORY;
     942    unsigned int idx;
     943
     944    for (idx = 0; idx <= LA_UTCINFO_CLIENT_INFO_LAST; idx++)
     945    {
     946        if (*pClientInfoMap[idx])
     947        {
     948            RTMemFree(*pClientInfoMap[idx]);
     949            *pClientInfoMap[idx] = NULL;
     950        }
     951
     952        if (u32ActiveClientId != 0)
     953        {
     954            l = RTStrAPrintf(pClientInfoMap[idx],
     955                             g_pszPropInfoTemplates[idx],
     956                             u32ActiveClientId);
     957
     958            if (l == -1)
     959            {
     960                *pClientInfoMap[idx] = NULL;
     961                rc = VERR_NO_MEMORY;
     962                break;
     963            }
    910964        }
    911965    }
     
    941995        {
    942996            l = RTStrAPrintf(&pCtx->activeClient.pszPropWaitPattern,
    943                              "%s|%s",
     997                             "%s|%s|%s|%s|%s",
    944998                             pCtx->activeClient.pszPropName,
    945                              pCtx->activeClient.pszPropAttach);
     999                             pCtx->activeClient.pszPropAttach,
     1000                             pCtx->activeClient.pszPropIPAddr,
     1001                             pCtx->activeClient.pszPropLocation,
     1002                             pCtx->activeClient.pszPropOtherInfo);
    9461003            if (l == -1)
    9471004            {
     
    9841041}
    9851042
    986 static void laProcessName(VBOXLACONTEXT *pCtx)
     1043static void laProcessClientInfo(VBOXLACONTEXT *pCtx)
    9871044{
    9881045    /* Check if the name was changed. */
    9891046    /* Get the name string and check if it was changed since last time.
    990      * Write the name to the registry if changed.
     1047     * Write Client name, IPAddr, Location and Other Info to the registry if the name has changed.
    9911048     */
    9921049    uint64_t u64Timestamp = 0;
    993     char *pszName = NULL;
    994 
    995     int rc = laGetString(pCtx->u32GuestPropHandle,
    996                          pCtx->activeClient.pszPropName,
     1050    int rc = VINF_SUCCESS;
     1051    unsigned int idx;
     1052
     1053    char *pClientInfoMap[][2] = {
     1054                                  {pCtx->activeClient.pszPropName, NULL},
     1055                                  {pCtx->activeClient.pszPropIPAddr, NULL},
     1056                                  {pCtx->activeClient.pszPropLocation, NULL},
     1057                                  {pCtx->activeClient.pszPropOtherInfo, NULL}
     1058                                 };
     1059
     1060    for (idx = 0; idx <= LA_UTCINFO_CLIENT_INFO_LAST; idx++)
     1061    {
     1062         rc = laGetString(pCtx->u32GuestPropHandle,
     1063                         pClientInfoMap[idx][LA_UTCINFO_PROP_NAME],
    9971064                         &u64Timestamp,
    998                          &pszName);
    999     if (RT_SUCCESS(rc))
    1000     {
    1001         LALOG(("LA: laProcessName: read [%s], at %lld\n",
    1002                pszName, u64Timestamp));
    1003 
     1065                         &pClientInfoMap[idx][LA_UTCINFO_PROP_VALUE]);
     1066
     1067         LALOG(("LA: laProcessClientInfo: read [%s], at %lld\n",
     1068                pClientInfoMap[idx][LA_UTCINFO_PROP_VALUE], u64Timestamp));
     1069
     1070        if (RT_FAILURE(rc))
     1071        {
     1072            LALOG(("LA: laProcessClientInfo failed at %s\n", pClientInfoMap[idx][LA_UTCINFO_PROP_NAME]));
     1073            break;
     1074        }
     1075    }
     1076
     1077    if (pClientInfoMap[LA_UTCINFO_CLIENT_NAME][LA_UTCINFO_PROP_VALUE] != NULL)
     1078    {
    10041079        if (u64Timestamp != pCtx->activeClient.u64LastNameTimestamp)
    10051080        {
    1006             laOnClientName(pszName);
     1081            laOnClientLocationInfo(pClientInfoMap);
    10071082
    10081083            pCtx->activeClient.u64LastNameTimestamp = u64Timestamp;
    10091084        }
    1010 
    1011     }
    1012 
    1013     if (pszName)
    1014     {
    1015         RTMemFree(pszName);
     1085    }
     1086
     1087    for (idx = 0; idx <= LA_UTCINFO_CLIENT_INFO_LAST; idx++)
     1088    {
     1089        if (pClientInfoMap[idx][LA_UTCINFO_PROP_VALUE])
     1090        {
     1091            RTMemFree(pClientInfoMap[idx][LA_UTCINFO_PROP_VALUE]);
     1092        }
    10161093    }
    10171094}
     
    12801357                        laProcessAttach(pCtx);
    12811358
    1282                         laProcessName(pCtx);
     1359                        laProcessClientInfo(pCtx);
    12831360
    12841361                        laDoActions(pCtx);
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r43131 r43584  
    690690    void guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
    691691    void guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
     692    void guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
     693    void guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
     694    void guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
    692695    void guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
    693696#endif
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r43168 r43584  
    877877}
    878878
     879void Console::guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr)
     880{
     881    if (!guestPropertiesVRDPEnabled())
     882        return;
     883
     884    LogFlowFunc(("\n"));
     885
     886    char szPropNm[256];
     887    Bstr bstrReadOnlyGuest(L"RDONLYGUEST");
     888
     889    RTStrPrintf(szPropNm, sizeof(szPropNm), "/VirtualBox/HostInfo/VRDP/Client/%u/IPAddr", u32ClientId);
     890    Bstr clientIPAddr(pszIPAddr);
     891
     892    mMachine->SetGuestProperty(Bstr(szPropNm).raw(),
     893                               clientIPAddr.raw(),
     894                               bstrReadOnlyGuest.raw());
     895
     896}
     897
     898void Console::guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation)
     899{
     900    if (!guestPropertiesVRDPEnabled())
     901        return;
     902
     903    LogFlowFunc(("\n"));
     904
     905    char szPropNm[256];
     906    Bstr bstrReadOnlyGuest(L"RDONLYGUEST");
     907
     908    RTStrPrintf(szPropNm, sizeof(szPropNm), "/VirtualBox/HostInfo/VRDP/Client/%u/Location", u32ClientId);
     909    Bstr clientLocation(pszLocation);
     910
     911    mMachine->SetGuestProperty(Bstr(szPropNm).raw(),
     912                               clientLocation.raw(),
     913                               bstrReadOnlyGuest.raw());
     914
     915}
     916
     917void Console::guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo)
     918{
     919    if (!guestPropertiesVRDPEnabled())
     920        return;
     921
     922    LogFlowFunc(("\n"));
     923
     924    char szPropNm[256];
     925    Bstr bstrReadOnlyGuest(L"RDONLYGUEST");
     926
     927    RTStrPrintf(szPropNm, sizeof(szPropNm), "/VirtualBox/HostInfo/VRDP/Client/%u/OtherInfo", u32ClientId);
     928    Bstr clientOtherInfo(pszOtherInfo);
     929
     930    mMachine->SetGuestProperty(Bstr(szPropNm).raw(),
     931                               clientOtherInfo.raw(),
     932                               bstrReadOnlyGuest.raw());
     933
     934}
     935
    879936void Console::guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached)
    880937{
     
    12031260    {
    12041261        guestPropertiesVRDPUpdateNameChange(u32ClientId, pszStatus + strlen("NAME="));
     1262    }
     1263    else if (RTStrNICmp(pszStatus, "CIPA=", strlen("CIPA=")) == 0)
     1264    {
     1265        guestPropertiesVRDPUpdateIPAddrChange(u32ClientId, pszStatus + strlen("CIPA="));
     1266    }
     1267    else if (RTStrNICmp(pszStatus, "CLOCATION=", strlen("CLOCATION=")) == 0)
     1268    {
     1269        guestPropertiesVRDPUpdateLocationChange(u32ClientId, pszStatus + strlen("CLOCATION="));
     1270    }
     1271    else if (RTStrNICmp(pszStatus, "COINFO=", strlen("COINFO=")) == 0)
     1272    {
     1273        guestPropertiesVRDPUpdateOtherInfoChange(u32ClientId, pszStatus + strlen("COINFO="));
    12051274    }
    12061275#endif
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