From: VMware, Inc <> Date: Mon, 26 Sep 2011 18:25:58 +0000 (-0700) Subject: Use individual arguments for the components of opening a menu and opening a specific... X-Git-Tag: 2011.09.23-491607~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e08b5f4c0dc2dc83ce662c827fad16253b8e9fd8;p=thirdparty%2Fopen-vm-tools.git Use individual arguments for the components of opening a menu and opening a specific item in a menu. Rather than having the library do all the serialization to a DynBuf (containing an ASCII representation sent over the backdoor) return the individual items in their original form and defer the serialization to the plugin which is more acquainted with the transport requirements. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.cpp b/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.cpp index 685ed1ee3..1cc438d1a 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.cpp +++ b/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.cpp @@ -204,7 +204,6 @@ GHI_GetBinaryHandlers(const char *pathUtf8) // IN: full path to the executable { return GHIPlatformGetBinaryHandlers(ghiPlatformData, pathUtf8); } -#endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__ /* @@ -227,12 +226,12 @@ GHI_GetBinaryHandlers(const char *pathUtf8) // IN: full path to the executable *---------------------------------------------------------------------------- */ -Bool -GHI_OpenStartMenuTree(const char *rootUtf8, // IN: root of the tree - uint32 flags, // IN: flags from VMX - DynBuf *buf) // OUT: number of items +Bool GHI_OpenStartMenuTree(const char *rootUtf8, // IN: + uint32 flags, // IN: + uint32 &handle, // OUT: handle for menu + uint32 &numItems) // OUT: number of items in menu { - return GHIPlatformOpenStartMenuTree(ghiPlatformData, rootUtf8, flags, buf); + return GHIPlatformOpenStartMenuTree(ghiPlatformData, rootUtf8, flags, handle, numItems); } @@ -256,11 +255,15 @@ GHI_OpenStartMenuTree(const char *rootUtf8, // IN: root of the tree */ Bool -GHI_GetStartMenuItem(uint32 handle, // IN: tree handle - uint32 itemIndex, // IN: the index of the item in the tree - DynBuf *buf) // OUT: item +GHI_GetStartMenuItem(uint32 handle, // IN: tree handle + uint32 itemIndex, // IN: the index of the item in the tree + Bool &isSubmenu, // OUT: True if this item is a submenu + utf::string &menuPath, // OUT: Path to the submenu (if this item is a submenu) + utf::string &itemPathURI, // OUT: URI for the item (empty if this is a submenu) + utf::string &itemName) // OUT: The name/label for the item { - return GHIPlatformGetStartMenuItem(ghiPlatformData, handle, itemIndex, buf); + return GHIPlatformGetStartMenuItem(ghiPlatformData, handle, itemIndex, + isSubmenu, menuPath, itemPathURI, itemName); } @@ -286,6 +289,7 @@ GHI_CloseStartMenuTree(uint32 handle) // IN: handle to the tree to be closed { return GHIPlatformCloseStartMenuTree(ghiPlatformData, handle); } +#endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__ /* diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.h b/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.h index bfb994152..6f099309a 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.h +++ b/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegration.h @@ -28,7 +28,9 @@ #if defined(__cplusplus) #if !defined(OPEN_VM_TOOLS) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) #include "appUtilFileTypes.h" +#include "stringxx/string.hh" #endif // !OPEN_VM_TOOLS && !__FREEBSD__ && !sun && !__APPLE__ + #include #include #include @@ -55,10 +57,6 @@ Bool GHI_IsSupported(void); void GHI_Init(GMainLoop *mainLoop, const char **envp, GHIHostCallbacks hostCallbacks); void GHI_Cleanup(void); -Bool GHI_OpenStartMenuTree(const char *rootUtf8, uint32 flags, DynBuf *buf); -Bool GHI_GetStartMenuItem(uint32 handle, uint32 itemIndex, DynBuf *buf); -Bool GHI_CloseStartMenuTree(uint32 handle); - Bool GHI_ShellOpen(const char *fileURIUtf8); Bool GHI_ShellAction(const char *actionURI, const char *targetURI, @@ -112,6 +110,17 @@ typedef struct GHIBinaryIconInfo { } GHIBinaryIconInfo; Bool GHI_GetBinaryInfo(const char *pathUriUtf8, std::string &friendlyName, std::list &iconList); + +#if !defined(OPEN_VM_TOOLS) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) +Bool GHI_OpenStartMenuTree(const char *rootUtf8, uint32 flags, uint32 &handle, uint32 &numItems); +Bool GHI_GetStartMenuItem(uint32 handle, + uint32 itemIndex, + Bool &isSubmenu, + utf::string &menuPath, + utf::string &itemPathURI, + utf::string &itemName); +Bool GHI_CloseStartMenuTree(uint32 handle); +#endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__ #endif // __cplusplus #endif // _GH_INTEGRATION_H_ diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegrationInt.h b/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegrationInt.h index 014e70fba..a8d518267 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegrationInt.h +++ b/open-vm-tools/services/plugins/unity/ghIntegration/ghIntegrationInt.h @@ -42,16 +42,6 @@ typedef struct _GHIPlatform GHIPlatform; Bool GHIPlatformIsSupported(void); GHIPlatform *GHIPlatformInit(GMainLoop *mainLoop, const char **envp, GHIHostCallbacks hostcallbacks); void GHIPlatformCleanup(GHIPlatform *ghip); -Bool GHIPlatformOpenStartMenuTree(GHIPlatform *ghip, - const char *rootUtf8, - uint32 flags, - DynBuf *buf); -Bool GHIPlatformGetStartMenuItem(GHIPlatform *ghip, - uint32 handle, - uint32 itemIndex, - DynBuf *buf); -Bool GHIPlatformCloseStartMenuTree(GHIPlatform *ghip, - uint32 handle); Bool GHIPlatformShellOpen(GHIPlatform *ghip, const char *fileUtf8); Bool GHIPlatformShellAction(GHIPlatform *ghip, @@ -128,6 +118,21 @@ void GHIPlatformUnregisterNotifyIconCallback(vmware::tools::NotifyIconCallback * #if !defined(OPEN_VM_TOOLS) && !defined(__FreeBSD__) && !defined(sun) && !defined(__APPLE__) const FileTypeList& GHIPlatformGetBinaryHandlers(GHIPlatform *ghip, const char *pathUtf8); + +Bool GHIPlatformOpenStartMenuTree(GHIPlatform *ghip, + const char *rootUtf8, + uint32 flags, + uint32 &handle, + uint32 &numItems); +Bool GHIPlatformGetStartMenuItem(GHIPlatform *ghip, + uint32 handle, + uint32 itemIndex, + Bool &isSubmenu, + utf::string &menuPath, + utf::string &itemPathURI, + utf::string &itemName); +Bool GHIPlatformCloseStartMenuTree(GHIPlatform *ghip, + uint32 handle); #endif // !OPEN_VM_TOOLS && !__FreeBSD__ && !sun && !__APPLE__ Bool GHIPlatformGetBinaryInfo(GHIPlatform *ghip, const char *pathUriUtf8, std::string &friendlyName, std::list &iconList); diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc b/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc index 24069c7e8..d44d62347 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc +++ b/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc @@ -594,7 +594,6 @@ GHIPlatformGetBinaryHandlers(GHIPlatform *ghip, // IN: platform-specific st { return sEmptyFileTypeList; } -#endif // OPEN_VM_TOOLS /* @@ -624,16 +623,16 @@ Bool GHIPlatformOpenStartMenuTree(GHIPlatform *ghip, // IN: platform-specific state const char *rootUtf8, // IN: root of the tree uint32 flags, // IN: flags - DynBuf *buf) // OUT: number of items + uint32 &handle, // OUT: menu handle + uint32 &numItems) // OUT: number of items { Bool success = FALSE; #ifdef REDIST_GMENU std::pair descriptor; if (ghip->menuItemManager->OpenMenuTree(rootUtf8, &descriptor)) { - char tmp[2 * sizeof MAKESTR(UINT_MAX)]; - Str_Sprintf(tmp, sizeof tmp, "%u %u", descriptor.first, descriptor.second); - DynBuf_AppendString(buf, tmp); + handle = descriptor.first; + numItems = descriptor.second; success = TRUE; } #endif @@ -642,6 +641,85 @@ GHIPlatformOpenStartMenuTree(GHIPlatform *ghip, // IN: platform-specific } +/* + *---------------------------------------------------------------------------- + * + * GHIPlatformGetStartMenuItem -- + * + * Get start menu item at a given index. This function should be called + * in the loop to get all items for a menu sub-tree. + * If there are no more items, the function will return FALSE. + * + * Results: + * TRUE if there's an item at a given index, FALSE otherwise. + * + * Side effects: + * None + * + *---------------------------------------------------------------------------- + */ + +Bool +GHIPlatformGetStartMenuItem(GHIPlatform *ghip, // IN: platform-specific state + uint32 handle, // IN: tree handle + uint32 itemIndex, // IN: the index of the item in the tree + Bool &isSubmenu, // OUT: True if this item is a submenu + utf::string &menuPath, // OUT: Path to the submenu (if this item is a submenu) + utf::string &itemPathURI, // OUT: URI for the item (empty if this is a submenu) + utf::string &itemName) // OUT: The name/label for the item +{ + Bool success = FALSE; + +#ifdef REDIST_GMENU + const MenuItem* menuItem; + const Glib::ustring* path; + + if (ghip->menuItemManager->GetMenuItem(handle, itemIndex, &menuItem, &path)) { + Glib::ustring key = *path + "/" + menuItem->key; + menuPath = key; + + isSubmenu = menuItem->isFolder; + + itemPathURI = menuItem->execPath.c_str(); + itemName = menuItem->displayName.c_str(); + success = TRUE; + } +#endif + + return success; +} + + +/* + *---------------------------------------------------------------------------- + * + * GHIPlatformCloseStartMenu -- + * + * Free all memory associated with this start menu tree and cleanup. + * + * Results: + * TRUE if the handle is valid + * FALSE otherwise + * + * Side effects: + * None + * + *---------------------------------------------------------------------------- + */ + +Bool +GHIPlatformCloseStartMenuTree(GHIPlatform *ghip, // IN: platform-specific state + uint32 handle) // IN: handle to the tree to be closed +{ +#ifdef REDIST_GMENU + return ghip->menuItemManager->CloseMenuTree(handle); +#else + return FALSE; +#endif +} +#endif // OPEN_VM_TOOLS + + /* *----------------------------------------------------------------------------- * @@ -721,89 +799,6 @@ GHIPlatformMenuItemToURI(GHIPlatform *ghip, // IN } -/* - *---------------------------------------------------------------------------- - * - * GHIPlatformGetStartMenuItem -- - * - * Get start menu item at a given index. This function should be called - * in the loop to get all items for a menu sub-tree. - * If there are no more items, the function will return FALSE. - * - * Upon returning, 'buf' will hold a nul-delimited array of strings: - * 1. User-visible item name. - * 2. UNITY_START_MENU_ITEM_* flag. - * 3. Executable path. - * 4. Localized user-visible item name. - * - * Results: - * TRUE if there's an item at a given index, FALSE otherwise. - * - * Side effects: - * None - * - *---------------------------------------------------------------------------- - */ - -Bool -GHIPlatformGetStartMenuItem(GHIPlatform *ghip, // IN: platform-specific state - uint32 handle, // IN: tree handle - uint32 itemIndex, // IN: the index of the item in the tree - DynBuf *buf) // OUT: item -{ - Bool success = FALSE; - -#ifdef REDIST_GMENU - const MenuItem* menuItem; - const Glib::ustring* path; - - if (ghip->menuItemManager->GetMenuItem(handle, itemIndex, &menuItem, &path)) { - Glib::ustring key = *path + "/" + menuItem->key; - DynBuf_AppendString(buf, key.c_str()); - - char tmp[sizeof MAKESTR(UINT_MAX)]; - Str_Sprintf(tmp, sizeof tmp, "%u", menuItem->isFolder ? 1 : 0); - DynBuf_AppendString(buf, tmp); - - DynBuf_AppendString(buf, menuItem->execPath.c_str()); - DynBuf_AppendString(buf, menuItem->displayName.c_str()); - success = TRUE; - } -#endif - - return success; -} - - -/* - *---------------------------------------------------------------------------- - * - * GHIPlatformCloseStartMenu -- - * - * Free all memory associated with this start menu tree and cleanup. - * - * Results: - * TRUE if the handle is valid - * FALSE otherwise - * - * Side effects: - * None - * - *---------------------------------------------------------------------------- - */ - -Bool -GHIPlatformCloseStartMenuTree(GHIPlatform *ghip, // IN: platform-specific state - uint32 handle) // IN: handle to the tree to be closed -{ -#ifdef REDIST_GMENU - return ghip->menuItemManager->CloseMenuTree(handle); -#else - return FALSE; -#endif -} - - #if 0 // REMOVE AFTER IMPLEMENTING GHIPlatformShellAction /* *----------------------------------------------------------------------------- diff --git a/open-vm-tools/services/plugins/unity/ghiTclo.cpp b/open-vm-tools/services/plugins/unity/ghiTclo.cpp index 28e13f1a7..2633493d7 100644 --- a/open-vm-tools/services/plugins/unity/ghiTclo.cpp +++ b/open-vm-tools/services/plugins/unity/ghiTclo.cpp @@ -439,6 +439,9 @@ GHITcloOpenStartMenu(RpcInData *data) // IN/OUT DynBuf *buf = &gTcloUpdate; uint32 flags = 0; uint32 index = 0; + uint32 menuHandle = 0; + uint32 numItems = 0; + Bool ret = TRUE; /* Check our arguments. */ @@ -485,13 +488,19 @@ GHITcloOpenStartMenu(RpcInData *data) // IN/OUT } DynBuf_SetSize(buf, 0); - if (!GHI_OpenStartMenuTree(rootUtf8, flags, buf)) { +#if !defined(OPEN_VM_TOOLS) + if (!GHI_OpenStartMenuTree(rootUtf8, flags, menuHandle, numItems)) { Debug("%s: Could not open start menu.\n", __FUNCTION__); ret = RPCIN_SETRETVALS(data, "Could not get start menu count", FALSE); goto exit; + } else { + char temp[256]; + Str_Sprintf(temp, sizeof temp, "%d %d", menuHandle, numItems); + DynBuf_AppendString(buf, temp); } +#endif // OPEN_VM_TOOLS /* * Write the final result into the result out parameters and return! @@ -533,6 +542,12 @@ GHITcloGetStartMenuItem(RpcInData *data) // IN/OUT Bool ret = TRUE; uint32 itemIndex = 0; uint32 handle = 0; +#if !defined(OPEN_VM_TOOLS) + Bool isSubmenu; + utf::string menuPath; + utf::string itemPathURI; + utf::string itemName; +#endif // OPEN_VM_TOOLS /* Check our arguments. */ ASSERT(data); @@ -567,13 +582,25 @@ GHITcloGetStartMenuItem(RpcInData *data) // IN/OUT } DynBuf_SetSize(buf, 0); - if (!GHI_GetStartMenuItem(handle, itemIndex, buf)) { +#if !defined(OPEN_VM_TOOLS) + if (!GHI_GetStartMenuItem(handle, itemIndex, + isSubmenu, menuPath, itemPathURI, itemName)) { Debug("%s: Could not get start menu item.\n", __FUNCTION__); return RPCIN_SETRETVALS(data, "Could not get start menu item", FALSE); } + DynBuf_AppendString(buf, menuPath.c_str()); + DynBuf_AppendString(buf, isSubmenu ? "1" : "0"); + DynBuf_AppendString(buf, itemPathURI.c_str()); + DynBuf_AppendString(buf, itemName.c_str()); +#else + return RPCIN_SETRETVALS(data, + "Could not get start menu item", + FALSE); +#endif // OPEN_VM_TOOLS + /* * Write the final result into the result out parameters and return! */ @@ -631,7 +658,9 @@ GHITcloCloseStartMenu(RpcInData *data) // IN/OUT FALSE); } +#if !defined(OPEN_VM_TOOLS) GHI_CloseStartMenuTree(handle); +#endif // OPEN_VM_TOOLS return RPCIN_SETRETVALS(data, "", TRUE); }