- Timestamp:
- Oct 9, 2012 3:01:08 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 81248
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxLA.cpp
r43224 r43584 40 40 #define LA_DO_ATTACH_AND_DETACH 4 41 41 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 42 53 struct VBOXLACONTEXT 43 54 { … … 67 78 uint64_t u64LastNameTimestamp; 68 79 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 70 85 char *pszPropAttach; /* The actual Client/%ID%/Attach property name with client id. */ 71 86 … … 90 105 static const char *g_pszPropActiveClient = "/VirtualBox/HostInfo/VRDP/ActiveClient"; 91 106 92 static const char *g_pszPropNameTemplate = "/VirtualBox/HostInfo/VRDP/Client/%u/Name";93 107 static const char *g_pszPropAttachTemplate = "/VirtualBox/HostInfo/VRDP/Client/%u/Attach"; 94 108 95 109 static const char *g_pszVolatileEnvironment = "Volatile Environment"; 96 110 97 static const WCHAR *g_pwszUTCINFOClientName = L"UTCINFO_CLIENTNAME";98 111 static const WCHAR *g_pwszClientName = L"CLIENTNAME"; 112 113 static const WCHAR *g_pwszUTCINFOClientInfo[] = { 114 L"UTCINFO_CLIENTNAME", 115 L"UTCINFO_CLIENTIPA", 116 L"UTCINFO_CLIENTLOCATION", 117 L"UTCINFO_CLIENTOTHERINFO" 118 }; 119 120 static 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 }; 99 126 100 127 #ifdef RT_ARCH_AMD64 … … 378 405 LALOG(("LA: ExecuteActions leave\n")); 379 406 } 380 407 381 408 static BOOL GetVolatileEnvironmentKey(WCHAR *pwszRegKey, DWORD cbRegKey) 382 409 { … … 484 511 DWORD dwType; 485 512 lErr = RegQueryValueExW(hKey, 486 g_pwszUTCINFOClient Name,513 g_pwszUTCINFOClientInfo[LA_UTCINFO_CLIENT_NAME], 487 514 NULL, 488 515 &dwType, … … 517 544 518 545 lErr = RegQueryValueExW(hKey, 519 g_pwszUTCINFOClient Name,546 g_pwszUTCINFOClientInfo[LA_UTCINFO_CLIENT_NAME], 520 547 NULL, 521 548 NULL, … … 602 629 } 603 630 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 631 static void laOnClientLocationInfo(char *pszClientInfo[][2]) 632 { 620 633 /* 621 * Write the client nameto:622 * HKCU\Volatile Environment\ UTCINFO_CLIENTNAMEor623 * HKCU\Volatile Environment\<SessionID>\ UTCINFO_CLIENTNAME634 * Write the client location info to: 635 * HKCU\Volatile Environment\<CLIENT_LOCATION_INFO> or 636 * HKCU\Volatile Environment\<SessionID>\<CLIENT_LOCATION_INFO> 624 637 * depending on whether this is a Terminal Services or desktop session 625 638 * respectively. 639 * The client location info are: Name, IPAddr, Location, OtherInfo 626 640 */ 641 unsigned int idx; 627 642 WCHAR wszRegKey[REG_KEY_LEN]; 628 643 if (!GetVolatileEnvironmentKey(wszRegKey, sizeof(wszRegKey))) 629 644 { 630 645 LALOG(("LA: Failed to get 'Volatile Environment' registry key\n")); 631 RTUtf16Free(putf16UnicodeName);632 646 return; 633 647 } … … 647 661 LALOG(("LA: Failed to open key [%ls], error %lu\n", 648 662 wszRegKey, lRet)); 649 RTUtf16Free(putf16UnicodeName);650 663 return; 651 664 } 652 665 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 } 664 696 } 665 697 … … 668 700 laBroadcastSettingChange(); 669 701 670 /* Also, write the client nameto the environment of this process, as it702 /* Also, write these info (Name, IPAddr, Location and Other Info) to the environment of this process, as it 671 703 * doesn't listen for WM_SETTINGCHANGE messages. 672 704 */ 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 } 676 715 } 677 716 … … 884 923 int l; 885 924 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 886 932 pCtx->activeClient.u32LastAttach = ~0; 887 933 pCtx->activeClient.u64LastAttachTimestamp = u64ActiveClientTS; … … 894 940 pCtx->activeClient.u64LastNameTimestamp = u64ActiveClientTS; 895 941 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 } 910 964 } 911 965 } … … 941 995 { 942 996 l = RTStrAPrintf(&pCtx->activeClient.pszPropWaitPattern, 943 "%s|%s ",997 "%s|%s|%s|%s|%s", 944 998 pCtx->activeClient.pszPropName, 945 pCtx->activeClient.pszPropAttach); 999 pCtx->activeClient.pszPropAttach, 1000 pCtx->activeClient.pszPropIPAddr, 1001 pCtx->activeClient.pszPropLocation, 1002 pCtx->activeClient.pszPropOtherInfo); 946 1003 if (l == -1) 947 1004 { … … 984 1041 } 985 1042 986 static void laProcess Name(VBOXLACONTEXT *pCtx)1043 static void laProcessClientInfo(VBOXLACONTEXT *pCtx) 987 1044 { 988 1045 /* Check if the name was changed. */ 989 1046 /* Get the name string and check if it was changed since last time. 990 * Write the name to the registry ifchanged.1047 * Write Client name, IPAddr, Location and Other Info to the registry if the name has changed. 991 1048 */ 992 1049 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], 997 1064 &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 { 1004 1079 if (u64Timestamp != pCtx->activeClient.u64LastNameTimestamp) 1005 1080 { 1006 laOnClient Name(pszName);1081 laOnClientLocationInfo(pClientInfoMap); 1007 1082 1008 1083 pCtx->activeClient.u64LastNameTimestamp = u64Timestamp; 1009 1084 } 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 } 1016 1093 } 1017 1094 } … … 1280 1357 laProcessAttach(pCtx); 1281 1358 1282 laProcess Name(pCtx);1359 laProcessClientInfo(pCtx); 1283 1360 1284 1361 laDoActions(pCtx); -
trunk/src/VBox/Main/include/ConsoleImpl.h
r43131 r43584 690 690 void guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached); 691 691 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); 692 695 void guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId); 693 696 #endif -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r43168 r43584 877 877 } 878 878 879 void 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 898 void 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 917 void 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 879 936 void Console::guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached) 880 937 { … … 1203 1260 { 1204 1261 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=")); 1205 1274 } 1206 1275 #endif
Note:
See TracChangeset
for help on using the changeset viewer.