VirtualBox

source: vbox/trunk/include/VBox/HostServices/GuestPropertySvc.h@ 70089

Last change on this file since 70089 was 70089, checked in by vboxsync, 7 years ago

Build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 17.4 KB
Line 
1/** @file
2 * Guest property service - Common header for host service and guest clients.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_HostService_GuestPropertyService_h
27#define ___VBox_HostService_GuestPropertyService_h
28
29#include <VBox/VMMDevCoreTypes.h>
30#include <VBox/VBoxGuestCoreTypes.h>
31#include <VBox/log.h>
32#include <VBox/hgcmsvc.h>
33#include <iprt/assertcompile.h>
34#include <iprt/string.h>
35
36
37/** Maximum length for property names */
38#define GUEST_PROP_MAX_NAME_LEN 64
39/** Maximum length for property values */
40#define GUEST_PROP_MAX_VALUE_LEN 128
41/** Maximum number of properties per guest */
42#define GUEST_PROP_MAX_PROPS 256
43/** Maximum size for enumeration patterns */
44#define GUEST_PROP_MAX_PATTERN_LEN 1024
45/** Maximum number of changes we remember for guest notifications */
46#define GUEST_PROP_MAX_GUEST_NOTIFICATIONS 256
47
48
49/** @name GUEST_PROP_F_XXX - The guest property flag values which are currently accepted.
50 * @{
51 */
52#define GUEST_PROP_F_NILFLAG UINT32_C(0)
53/** Transient until VM gets shut down. */
54#define GUEST_PROP_F_TRANSIENT RT_BIT_32(1)
55#define GUEST_PROP_F_RDONLYGUEST RT_BIT_32(2)
56#define GUEST_PROP_F_RDONLYHOST RT_BIT_32(3)
57/** Transient until VM gets a reset / restarts.
58 * Implies TRANSIENT. */
59#define GUEST_PROP_F_TRANSRESET RT_BIT_32(4)
60#define GUEST_PROP_F_READONLY (GUEST_PROP_F_RDONLYGUEST | GUEST_PROP_F_RDONLYHOST)
61#define GUEST_PROP_F_ALLFLAGS (GUEST_PROP_F_TRANSIENT | GUEST_PROP_F_READONLY | GUEST_PROP_F_TRANSRESET)
62/** @} */
63
64/**
65 * Get the name of a flag as a string.
66 * @returns the name, or NULL if fFlag is invalid.
67 * @param fFlag the flag. Must be a value from the ePropFlags enumeration
68 * list.
69 */
70DECLINLINE(const char *) GuestPropFlagName(uint32_t fFlag)
71{
72 switch (fFlag)
73 {
74 case GUEST_PROP_F_TRANSIENT:
75 return "TRANSIENT";
76 case GUEST_PROP_F_RDONLYGUEST:
77 return "RDONLYGUEST";
78 case GUEST_PROP_F_RDONLYHOST:
79 return "RDONLYHOST";
80 case GUEST_PROP_F_READONLY:
81 return "READONLY";
82 case GUEST_PROP_F_TRANSRESET:
83 return "TRANSRESET";
84 default:
85 break;
86 }
87 return NULL;
88}
89
90/**
91 * Get the length of a flag name as returned by flagName.
92 * @returns the length, or 0 if fFlag is invalid.
93 * @param fFlag the flag. Must be a value from the ePropFlags enumeration
94 * list.
95 */
96DECLINLINE(size_t) GuestPropFlagNameLen(uint32_t fFlag)
97{
98 const char *pcszName = GuestPropFlagName(fFlag);
99 return RT_LIKELY(pcszName != NULL) ? strlen(pcszName) : 0;
100}
101
102/**
103 * Maximum length for the property flags field. We only ever return one of
104 * RDONLYGUEST, RDONLYHOST and RDONLY
105 */
106#define GUEST_PROP_MAX_FLAGS_LEN sizeof("TRANSIENT, RDONLYGUEST, TRANSRESET")
107
108/**
109 * Parse a guest properties flags string for flag names and make sure that
110 * there is no junk text in the string.
111 *
112 * @returns IPRT status code
113 * @retval VERR_INVALID_PARAMETER if the flag string is not valid
114 * @param pcszFlags the flag string to parse
115 * @param pfFlags where to store the parse result. May not be NULL.
116 * @note This function is also inline because it must be accessible from
117 * several modules and it does not seem reasonable to put it into
118 * its own library.
119 */
120DECLINLINE(int) GuestPropValidateFlags(const char *pcszFlags, uint32_t *pfFlags)
121{
122 static const uint32_t s_aFlagList[] =
123 {
124 GUEST_PROP_F_TRANSIENT, GUEST_PROP_F_READONLY, GUEST_PROP_F_RDONLYGUEST, GUEST_PROP_F_RDONLYHOST, GUEST_PROP_F_TRANSRESET
125 };
126 const char *pcszNext = pcszFlags;
127 int rc = VINF_SUCCESS;
128 uint32_t fFlags = 0;
129 AssertLogRelReturn(VALID_PTR(pfFlags), VERR_INVALID_POINTER);
130
131 if (pcszFlags)
132 {
133 while (' ' == *pcszNext)
134 ++pcszNext;
135 while ((*pcszNext != '\0') && RT_SUCCESS(rc))
136 {
137 unsigned i = 0;
138 for (; i < RT_ELEMENTS(s_aFlagList); ++i)
139 if (RTStrNICmp(pcszNext, GuestPropFlagName(s_aFlagList[i]), GuestPropFlagNameLen(s_aFlagList[i])) == 0)
140 break;
141 if (RT_ELEMENTS(s_aFlagList) == i)
142 rc = VERR_PARSE_ERROR;
143 else
144 {
145 fFlags |= s_aFlagList[i];
146 pcszNext += GuestPropFlagNameLen(s_aFlagList[i]);
147 while (' ' == *pcszNext)
148 ++pcszNext;
149 if (',' == *pcszNext)
150 ++pcszNext;
151 else if (*pcszNext != '\0')
152 rc = VERR_PARSE_ERROR;
153 while (' ' == *pcszNext)
154 ++pcszNext;
155 }
156 }
157 }
158 if (RT_SUCCESS(rc))
159 *pfFlags = fFlags;
160 return rc;
161}
162
163
164/**
165 * Write out flags to a string.
166 *
167 * @returns IPRT status code
168 * @param fFlags The flags to write out.
169 * @param pszFlags Where to write the flags string.
170 * @param cbFlags The size of the destination buffer (in bytes).
171 */
172DECLINLINE(int) GuestPropWriteFlags(uint32_t fFlags, char* pszFlags, size_t cbFlags)
173{
174 /* Putting READONLY before the other RDONLY flags keeps the result short. */
175 static const uint32_t s_aFlagList[] =
176 {
177 GUEST_PROP_F_TRANSIENT, GUEST_PROP_F_READONLY, GUEST_PROP_F_RDONLYGUEST, GUEST_PROP_F_RDONLYHOST, GUEST_PROP_F_TRANSRESET
178 };
179 int rc = VINF_SUCCESS;
180
181 AssertLogRelReturn(VALID_PTR(pszFlags), VERR_INVALID_POINTER);
182 if ((fFlags & ~GUEST_PROP_F_ALLFLAGS) == GUEST_PROP_F_NILFLAG)
183 {
184 /* TRANSRESET implies TRANSIENT. For compatability with old clients we
185 always set TRANSIENT when TRANSRESET appears. */
186 if (fFlags & GUEST_PROP_F_TRANSRESET)
187 fFlags |= GUEST_PROP_F_TRANSIENT;
188
189 char *pszTemp = NULL;
190
191
192 unsigned i;
193 for (i = 0; i < RT_ELEMENTS(s_aFlagList); ++i)
194 {
195 if (s_aFlagList[i] == (fFlags & s_aFlagList[i]))
196 {
197 RTStrAAppend(&pszTemp, GuestPropFlagName(s_aFlagList[i]));
198 fFlags &= ~s_aFlagList[i];
199 if (fFlags != GUEST_PROP_F_NILFLAG)
200 RTStrAAppend(&pszTemp, ", ");
201 }
202 }
203
204 if ( RT_SUCCESS(rc)
205 && pszTemp)
206 rc = RTStrCopy(pszFlags, cbFlags, pszTemp);
207
208 if (pszTemp)
209 RTStrFree(pszTemp);
210
211 Assert(fFlags == GUEST_PROP_F_NILFLAG); /* bad s_aFlagList */
212 }
213 else
214 rc = VERR_INVALID_PARAMETER;
215 return rc;
216}
217
218
219/** @name The service functions which are callable by host.
220 * @{
221 */
222/** Set properties in a block.
223 * The parameters are pointers to NULL-terminated arrays containing the
224 * parameters. These are, in order, name, value, timestamp, flags. Strings are
225 * stored as pointers to mutable utf8 data. All parameters must be supplied. */
226#define GUEST_PROP_FN_HOST_SET_PROPS 1
227/** Get the value attached to a guest property.
228 * The parameter format matches that of GET_PROP. */
229#define GUEST_PROP_FN_HOST_GET_PROP 2
230/** Set the value attached to a guest property.
231 * The parameter format matches that of SET_PROP. */
232#define GUEST_PROP_FN_HOST_SET_PROP 3
233/** Set the value attached to a guest property.
234 * The parameter format matches that of SET_PROP_VALUE. */
235#define GUEST_PROP_FN_HOST_SET_PROP_VALUE 4
236/** Remove a guest property.
237 * The parameter format matches that of DEL_PROP. */
238#define GUEST_PROP_FN_HOST_DEL_PROP 5
239/** Enumerate guest properties.
240 * The parameter format matches that of ENUM_PROPS. */
241#define GUEST_PROP_FN_HOST_ENUM_PROPS 6
242/** Set global flags for the service.
243 * Currently RDONLYGUEST is supported. Takes one 32-bit unsigned integer
244 * parameter for the flags. */
245#define GUEST_PROP_FN_HOST_SET_GLOBAL_FLAGS 7
246/** Return the pointer to a debug info function enumerating all guest
247 * properties. */
248#define GUEST_PROP_FN_HOST_GET_DBGF_INFO 8
249/** @} */
250
251
252/** @name The service functions which are called by guest.
253 *
254 * @note The numbers may not change!
255 * @{
256 */
257/** Get a guest property */
258#define GUEST_PROP_FN_GET_PROP 1
259/** Set a guest property */
260#define GUEST_PROP_FN_SET_PROP 2
261/** Set just the value of a guest property */
262#define GUEST_PROP_FN_SET_PROP_VALUE 3
263/** Delete a guest property */
264#define GUEST_PROP_FN_DEL_PROP 4
265/** Enumerate guest properties */
266#define GUEST_PROP_FN_ENUM_PROPS 5
267/** Poll for guest notifications */
268#define GUEST_PROP_FN_GET_NOTIFICATION 6
269/** @} */
270
271
272/**
273 * Data structure to pass to the service extension callback.
274 * We use this to notify the host of changes to properties.
275 */
276typedef struct GUESTPROPHOSTCALLBACKDATA
277{
278 /** Magic number to identify the structure (GUESTPROPHOSTCALLBACKDATA_MAGIC). */
279 uint32_t u32Magic;
280 /** The name of the property that was changed */
281 const char *pcszName;
282 /** The new property value, or NULL if the property was deleted */
283 const char *pcszValue;
284 /** The timestamp of the modification */
285 uint64_t u64Timestamp;
286 /** The flags field of the modified property */
287 const char *pcszFlags;
288} GUESTPROPHOSTCALLBACKDATA;
289/** Poitner to a data structure to pass to the service extension callback. */
290typedef GUESTPROPHOSTCALLBACKDATA *PGUESTPROPHOSTCALLBACKDATA;
291
292/** Magic number for sanity checking the HOSTCALLBACKDATA structure */
293#define GUESTPROPHOSTCALLBACKDATA_MAGIC UINT32_C(0x69c87a78)
294
295/**
296 * HGCM parameter structures. Packing is explicitly defined as this is a wire format.
297 */
298/** The guest is requesting the value of a property */
299typedef struct GuestPropMsgGetProperty
300{
301 VBGLIOCHGCMCALL hdr;
302
303 /**
304 * The property name (IN pointer)
305 * This must fit to a number of criteria, namely
306 * - Only Utf8 strings are allowed
307 * - Less than or equal to MAX_NAME_LEN bytes in length
308 * - Zero terminated
309 */
310 HGCMFunctionParameter name;
311
312 /**
313 * The returned string data will be placed here. (OUT pointer)
314 * This call returns two null-terminated strings which will be placed one
315 * after another: value and flags.
316 */
317 HGCMFunctionParameter buffer;
318
319 /**
320 * The property timestamp. (OUT uint64_t)
321 */
322 HGCMFunctionParameter timestamp;
323
324 /**
325 * If the buffer provided was large enough this will contain the size of
326 * the returned data. Otherwise it will contain the size of the buffer
327 * needed to hold the data and VERR_BUFFER_OVERFLOW will be returned.
328 * (OUT uint32_t)
329 */
330 HGCMFunctionParameter size;
331} GuestPropMsgGetProperty;
332AssertCompileSize(GuestPropMsgGetProperty, 40 + 4 * (ARCH_BITS == 64 ? 16 : 12));
333
334/** The guest is requesting to change a property */
335typedef struct GuestPropMsgSetProperty
336{
337 VBGLIOCHGCMCALL hdr;
338
339 /**
340 * The property name. (IN pointer)
341 * This must fit to a number of criteria, namely
342 * - Only Utf8 strings are allowed
343 * - Less than or equal to MAX_NAME_LEN bytes in length
344 * - Zero terminated
345 */
346 HGCMFunctionParameter name;
347
348 /**
349 * The value of the property (IN pointer)
350 * Criteria as for the name parameter, but with length less than or equal to
351 * MAX_VALUE_LEN.
352 */
353 HGCMFunctionParameter value;
354
355 /**
356 * The property flags (IN pointer)
357 * This is a comma-separated list of the format flag=value
358 * The length must be less than or equal to MAX_FLAGS_LEN and only
359 * known flag names and values will be accepted.
360 */
361 HGCMFunctionParameter flags;
362} GuestPropMsgSetProperty;
363AssertCompileSize(GuestPropMsgSetProperty, 40 + 3 * (ARCH_BITS == 64 ? 16 : 12));
364
365/** The guest is requesting to change the value of a property */
366typedef struct GuestPropMsgSetPropertyValue
367{
368 VBGLIOCHGCMCALL hdr;
369
370 /**
371 * The property name. (IN pointer)
372 * This must fit to a number of criteria, namely
373 * - Only Utf8 strings are allowed
374 * - Less than or equal to MAX_NAME_LEN bytes in length
375 * - Zero terminated
376 */
377 HGCMFunctionParameter name;
378
379 /**
380 * The value of the property (IN pointer)
381 * Criteria as for the name parameter, but with length less than or equal to
382 * MAX_VALUE_LEN.
383 */
384 HGCMFunctionParameter value;
385} GuestPropMsgSetPropertyValue;
386AssertCompileSize(GuestPropMsgSetPropertyValue, 40 + 2 * (ARCH_BITS == 64 ? 16 : 12));
387
388/** The guest is requesting to remove a property */
389typedef struct GuestPropMsgDelProperty
390{
391 VBGLIOCHGCMCALL hdr;
392
393 /**
394 * The property name. This must fit to a number of criteria, namely
395 * - Only Utf8 strings are allowed
396 * - Less than or equal to MAX_NAME_LEN bytes in length
397 * - Zero terminated
398 */
399 HGCMFunctionParameter name;
400} GuestPropMsgDelProperty;
401AssertCompileSize(GuestPropMsgDelProperty, 40 + 1 * (ARCH_BITS == 64 ? 16 : 12));
402
403/** The guest is requesting to enumerate properties */
404typedef struct GuestPropMsgEnumProperties
405{
406 VBGLIOCHGCMCALL hdr;
407
408 /**
409 * Array of patterns to match the properties against, separated by '|'
410 * characters. For backwards compatibility, '\\0' is also accepted
411 * as a separater.
412 * (IN pointer)
413 * If only a single, empty pattern is given then match all.
414 */
415 HGCMFunctionParameter patterns;
416 /**
417 * On success, null-separated array of strings in which the properties are
418 * returned. (OUT pointer)
419 * The number of strings in the array is always a multiple of four,
420 * and in sequences of name, value, timestamp (hexadecimal string) and the
421 * flags as a comma-separated list in the format "name=value". The list
422 * is terminated by an empty string after a "flags" entry (or at the
423 * start).
424 */
425 HGCMFunctionParameter strings;
426 /**
427 * On success, the size of the returned data. If the buffer provided is
428 * too small, the size of buffer needed. (OUT uint32_t)
429 */
430 HGCMFunctionParameter size;
431} GuestPropMsgEnumProperties;
432AssertCompileSize(GuestPropMsgEnumProperties, 40 + 3 * (ARCH_BITS == 64 ? 16 : 12));
433
434/**
435 * The guest is polling for notifications on changes to properties, specifying
436 * a set of patterns to match the names of changed properties against and
437 * optionally the timestamp of the last notification seen.
438 * On success, VINF_SUCCESS will be returned and the buffer will contain
439 * details of a property notification. If no new notification is available
440 * which matches one of the specified patterns, the call will block until one
441 * is.
442 * If the last notification could not be found by timestamp, VWRN_NOT_FOUND
443 * will be returned and the oldest available notification will be returned.
444 * If a zero timestamp is specified, the call will always wait for a new
445 * notification to arrive.
446 * If the buffer supplied was not large enough to hold the notification,
447 * VERR_BUFFER_OVERFLOW will be returned and the size parameter will contain
448 * the size of the buffer needed.
449 *
450 * The protocol for a guest to obtain notifications is to call
451 * GET_NOTIFICATION in a loop. On the first call, the ingoing timestamp
452 * parameter should be set to zero. On subsequent calls, it should be set to
453 * the outgoing timestamp from the previous call.
454 */
455typedef struct GuestPropMsgGetNotification
456{
457 VBGLIOCHGCMCALL hdr;
458
459 /**
460 * A list of patterns to match the guest event name against, separated by
461 * vertical bars (|) (IN pointer)
462 * An empty string means match all.
463 */
464 HGCMFunctionParameter patterns;
465 /**
466 * The timestamp of the last change seen (IN uint64_t)
467 * This may be zero, in which case the oldest available change will be
468 * sent. If the service does not remember an event matching the
469 * timestamp, then VWRN_NOT_FOUND will be returned, and the guest should
470 * assume that it has missed a certain number of notifications.
471 *
472 * The timestamp of the change being notified of (OUT uint64_t)
473 * Undefined on failure.
474 */
475 HGCMFunctionParameter timestamp;
476
477 /**
478 * The returned data, if any, will be placed here. (OUT pointer)
479 * This call returns three null-terminated strings which will be placed
480 * one after another: name, value and flags. For a delete notification,
481 * value and flags will be empty strings. Undefined on failure.
482 */
483 HGCMFunctionParameter buffer;
484
485 /**
486 * On success, the size of the returned data. (OUT uint32_t)
487 * On buffer overflow, the size of the buffer needed to hold the data.
488 * Undefined on failure.
489 */
490 HGCMFunctionParameter size;
491} GuestPropMsgGetNotification;
492AssertCompileSize(GuestPropMsgGetNotification, 40 + 4 * (ARCH_BITS == 64 ? 16 : 12));
493
494
495#endif /* !___VBox_HostService_GuestPropertySvc_h */
496
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette