VBoxGuestR3LibGuestProp.cpp revision 3c3a5ab35783f4d31cb5d3a15db9daadeb804daa
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions,
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * guest properties.
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * Copyright (C) 2007 Sun Microsystems, Inc.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * available from http://www.virtualbox.org. This file is free software;
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * General Public License (GPL) as published by the Free Software
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3aa59619d4b10a8ba3e2f3d3001309b20fa567bavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
3aa59619d4b10a8ba3e2f3d3001309b20fa567bavboxsync * additional information or have any questions.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync/*******************************************************************************
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync* Header Files *
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync*******************************************************************************/
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsyncusing namespace guestProp;
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * Connects to the guest property service.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @returns VBox status code
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pu32ClientId Where to put the client id on success. The client id
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * must be passed to all the other calls to the service.
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsyncVBGLR3DECL(int) VbglR3GuestPropConnect(uint32_t *pu32ClientId)
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync Info.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync strcpy(Info.Loc.u.host.achName, "VBoxGuestPropSvc");
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync Info.u32ClientID = UINT32_MAX; /* try make valgrid shut up. */
cd1ce370c056a0c36a34b23281583353b8a51bc4vboxsync int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * Disconnect from the guest property service.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @returns VBox status code.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsyncVBGLR3DECL(int) VbglR3GuestPropDisconnect(uint32_t u32ClientId)
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync Info.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * Write a property value.
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * @returns VBox status code.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @param u32ClientId The client id returned by VbglR3InvsSvcConnect().
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @param pszName The property to save to. Utf8
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @param pszValue The value to store. Utf8. If this is NULL then
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * the property will be removed.
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * @param pszFlags The flags for the property
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsyncVBGLR3DECL(int) VbglR3GuestPropWrite(uint32_t u32ClientId, char *pszName, char *pszValue, char *pszFlags)
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
e8b6c391092b76836d83c32717155d5b323a2683vboxsync VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync VbglHGCMParmPtrSet(&Msg.flags, pszFlags, strlen(pszFlags) + 1);
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
07ddac0955239ed18e474aaea92b0583981ff778vboxsync Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * Write a property value.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @returns VBox status code.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param u32ClientId The client id returned by VbglR3InvsSvcConnect().
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pszName The property to save to. Utf8
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * @param pszValue The value to store. Utf8. If this is NULL then
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * the property will be removed.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @note if the property already exists and pszValue is not NULL then the
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * property's flags field will be left unchanged
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsyncVBGLR3DECL(int) VbglR3GuestPropWriteValue(uint32_t u32ClientId, char *pszName, char *pszValue)
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync VbglHGCMParmPtrSet(&Msg.value, pszValue, strlen(pszValue) + 1);
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync VbglHGCMParmPtrSet(&Msg.name, pszName, strlen(pszName) + 1);
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync * Retrieve a property.
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync * @returns VBox status code.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @retval VINF_SUCCESS on success, pszValue, pu64Timestamp and pszFlags
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * containing valid data.
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync * @retval VERR_BUFFER_OVERFLOW if the scratch buffer @a pcBuf is not large
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * enough. In this case the size needed will be placed in
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync * @a pcbBufActual if it is not NULL.
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsync * @retval VERR_NOT_FOUND if the key wasn't found.
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * @param pszName The value to read. Utf8
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pcBuf A scratch buffer to store the data retrieved into.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * The returned data is only valid for it's lifetime.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param cbBuf The size of @a pcBuf
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pszValue Where to store the pointer to the value retrieved.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pu64Timestamp Where to store the timestamp. Optional.
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * @param pszFlags Where to store the pointer to the flags. Optional.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @param pcbBufActual If @a pcBuf is not large enough, the size needed.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * Optional.
d7d635edfa61196a9ffe24d486ffec1c53b4e6f0vboxsyncVBGLR3DECL(int) VbglR3GuestPropRead(uint32_t u32ClientId, const char *pszName,
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync Msg.hdr.result = (uint32_t)VERR_WRONG_ORDER; /** @todo drop the cast when the result type has been fixed! */
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName),
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync if ((VERR_BUFFER_OVERFLOW == rc) && (pcbBufActual != NULL))
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync int rc2 = VbglHGCMParmUInt32Get(&Msg.size, pcbBufActual);
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync rc = VbglHGCMParmUInt64Get(&Msg.timestamp, pu64Timestamp);
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync bool found = false;
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync if (0 == pcBuf[i])
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync /* To my mind this is an internal error, but whatever */
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * Retrieve a property value, allocating space for it.
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * @returns VBox status code.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @retval VINF_SUCCESS on success, pszValue containing valid data.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @retval VERR_NOT_FOUND if the key wasn't found.
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync * @param u32ClientId The client id returned by VbglR3ClipboardConnect().
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pszName The value to read. Utf8
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync * @param ppszValue Where to store the pointer to the value returned.
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsyncVBGLR3DECL(int) VbglR3GuestPropReadValueAlloc(uint32_t u32ClientId,
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync const char *pszName,
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf,
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync /** @todo how should we handle the race condition here? */
4322eab57b88f880a55e6a4ae0cb76b870167f06vboxsync rc = VbglR3GuestPropRead(u32ClientId, pszName, pvBuf, cchBuf,
7b2222e6c060dfe168591f22543d3a80f96112b4vboxsync /* VERR_BUFFER_OVERFLOW has a different meaning here as a
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * return code */
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * Free the memory used by VbglR3GuestPropReadValueAlloc for returning a
36545c63b2aab948161e4a712913a4f2dce17d2fvboxsync * @param pszValue the memory to be freed. NULL pointers will be ignored.
return rc;