VirtualBox

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

Last change on this file since 75495 was 75495, checked in by vboxsync, 6 years ago

HGCM,Main,SharedFolder,SharedClipboard,GuestProperties: Added HGCM service helpers for statistics and dbg info registration/deregistration. A PUVM is passed to HGCMService (where the helpers are implemented) when the service is loaded. Since this drags in both dbg.h and stam.h, LOG_GROUP defines now have to be at the top of the include list as everywhere else (i.e. hgcmsvc.h will define LOG_GROUP default by dragging in log.h). Added generic statistics of HGCM message processing and function level statistics to the shared folder service.

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