[28967] | 1 | /* $Id: VBoxServicePropCache.cpp 102753 2024-01-03 17:24:32Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * VBoxServicePropCache - Guest property cache.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[28967] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[28967] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
[57358] | 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[28967] | 32 | #include <iprt/assert.h>
|
---|
| 33 | #include <iprt/list.h>
|
---|
| 34 | #include <iprt/mem.h>
|
---|
| 35 | #include <iprt/string.h>
|
---|
| 36 |
|
---|
| 37 | #include <VBox/VBoxGuestLib.h>
|
---|
[102753] | 38 | #include <VBox/HostServices/GuestPropertySvc.h> /* For GUEST_PROP_MAX_VALUE_LEN */
|
---|
[28967] | 39 | #include "VBoxServiceInternal.h"
|
---|
| 40 | #include "VBoxServiceUtils.h"
|
---|
[28969] | 41 | #include "VBoxServicePropCache.h"
|
---|
[28967] | 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
[29040] | 45 | /** @todo Docs */
|
---|
[58029] | 46 | static PVBOXSERVICEVEPROPCACHEENTRY vgsvcPropCacheFindInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName,
|
---|
| 47 | uint32_t fFlags)
|
---|
[28967] | 48 | {
|
---|
[62851] | 49 | RT_NOREF1(fFlags);
|
---|
[44098] | 50 | AssertPtrReturn(pCache, NULL);
|
---|
| 51 | AssertPtrReturn(pszName, NULL);
|
---|
| 52 |
|
---|
[29026] | 53 | /** @todo This is a O(n) lookup, maybe improve this later to O(1) using a
|
---|
| 54 | * map.
|
---|
| 55 | * r=bird: Use a string space (RTstrSpace*). That is O(log n) in its current
|
---|
| 56 | * implementation (AVL tree). However, this is not important at the
|
---|
| 57 | * moment. */
|
---|
[64766] | 58 | PVBOXSERVICEVEPROPCACHEENTRY pNode = NULL;
|
---|
[29040] | 59 | if (RT_SUCCESS(RTCritSectEnter(&pCache->CritSect)))
|
---|
[29026] | 60 | {
|
---|
[64766] | 61 | PVBOXSERVICEVEPROPCACHEENTRY pNodeIt;
|
---|
[30082] | 62 | RTListForEach(&pCache->NodeHead, pNodeIt, VBOXSERVICEVEPROPCACHEENTRY, NodeSucc)
|
---|
[28983] | 63 | {
|
---|
| 64 | if (strcmp(pNodeIt->pszName, pszName) == 0)
|
---|
| 65 | {
|
---|
| 66 | pNode = pNodeIt;
|
---|
| 67 | break;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
[29040] | 70 | RTCritSectLeave(&pCache->CritSect);
|
---|
[28967] | 71 | }
|
---|
[28983] | 72 | return pNode;
|
---|
[28967] | 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | /** @todo Docs */
|
---|
[58029] | 77 | static PVBOXSERVICEVEPROPCACHEENTRY vgsvcPropCacheInsertEntryInternal(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName)
|
---|
[29040] | 78 | {
|
---|
[44098] | 79 | AssertPtrReturn(pCache, NULL);
|
---|
| 80 | AssertPtrReturn(pszName, NULL);
|
---|
| 81 |
|
---|
[29040] | 82 | PVBOXSERVICEVEPROPCACHEENTRY pNode = (PVBOXSERVICEVEPROPCACHEENTRY)RTMemAlloc(sizeof(VBOXSERVICEVEPROPCACHEENTRY));
|
---|
| 83 | if (pNode)
|
---|
| 84 | {
|
---|
| 85 | pNode->pszName = RTStrDup(pszName);
|
---|
[44098] | 86 | if (!pNode->pszName)
|
---|
| 87 | {
|
---|
| 88 | RTMemFree(pNode);
|
---|
[44099] | 89 | return NULL;
|
---|
[44098] | 90 | }
|
---|
[29040] | 91 | pNode->pszValue = NULL;
|
---|
| 92 | pNode->fFlags = 0;
|
---|
| 93 | pNode->pszValueReset = NULL;
|
---|
| 94 |
|
---|
| 95 | int rc = RTCritSectEnter(&pCache->CritSect);
|
---|
| 96 | if (RT_SUCCESS(rc))
|
---|
| 97 | {
|
---|
[58029] | 98 | RTListAppend(&pCache->NodeHead, &pNode->NodeSucc);
|
---|
[29040] | 99 | rc = RTCritSectLeave(&pCache->CritSect);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | return pNode;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
[31878] | 106 | /** @todo Docs */
|
---|
[58029] | 107 | static int vgsvcPropCacheWritePropF(uint32_t u32ClientId, const char *pszName, uint32_t fFlags, const char *pszValueFormat, ...)
|
---|
[31878] | 108 | {
|
---|
[44098] | 109 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
| 110 |
|
---|
[31878] | 111 | int rc;
|
---|
| 112 | if (pszValueFormat != NULL)
|
---|
| 113 | {
|
---|
| 114 | va_list va;
|
---|
| 115 | va_start(va, pszValueFormat);
|
---|
| 116 |
|
---|
| 117 | char *pszValue;
|
---|
| 118 | if (RTStrAPrintfV(&pszValue, pszValueFormat, va) >= 0)
|
---|
| 119 | {
|
---|
[58029] | 120 | if (fFlags & VGSVCPROPCACHE_FLAGS_TRANSIENT)
|
---|
[31893] | 121 | {
|
---|
| 122 | /*
|
---|
| 123 | * Because a value can be temporary we have to make sure it also
|
---|
| 124 | * gets deleted when the property cache did not have the chance to
|
---|
| 125 | * gracefully clean it up (due to a hard VM reset etc), so set this
|
---|
[36219] | 126 | * guest property using the TRANSRESET flag..
|
---|
[31893] | 127 | */
|
---|
[36219] | 128 | rc = VbglR3GuestPropWrite(u32ClientId, pszName, pszValue, "TRANSRESET");
|
---|
[36178] | 129 | if (rc == VERR_PARSE_ERROR)
|
---|
| 130 | {
|
---|
[36219] | 131 | /* Host does not support the "TRANSRESET" flag, so only
|
---|
[36179] | 132 | * use the "TRANSIENT" flag -- better than nothing :-). */
|
---|
[36178] | 133 | rc = VbglR3GuestPropWrite(u32ClientId, pszName, pszValue, "TRANSIENT");
|
---|
[36214] | 134 | /** @todo r=bird: Remember that the host doesn't support
|
---|
| 135 | * this. */
|
---|
[36178] | 136 | }
|
---|
[31893] | 137 | }
|
---|
| 138 | else
|
---|
[36249] | 139 | rc = VbglR3GuestPropWriteValue(u32ClientId, pszName, pszValue /* No transient flags set */);
|
---|
[31878] | 140 | RTStrFree(pszValue);
|
---|
| 141 | }
|
---|
[31918] | 142 | else
|
---|
| 143 | rc = VERR_NO_MEMORY;
|
---|
[31878] | 144 | va_end(va);
|
---|
| 145 | }
|
---|
| 146 | else
|
---|
| 147 | rc = VbglR3GuestPropWriteValue(u32ClientId, pszName, NULL);
|
---|
| 148 | return rc;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 |
|
---|
[29040] | 152 | /**
|
---|
| 153 | * Creates a property cache.
|
---|
| 154 | *
|
---|
| 155 | * @returns IPRT status code.
|
---|
| 156 | * @param pCache Pointer to the cache.
|
---|
| 157 | * @param uClientId The HGCM handle of to the guest property service.
|
---|
| 158 | */
|
---|
[58029] | 159 | int VGSvcPropCacheCreate(PVBOXSERVICEVEPROPCACHE pCache, uint32_t uClientId)
|
---|
[29040] | 160 | {
|
---|
[44098] | 161 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
[29040] | 162 | /** @todo Prevent init the cache twice!
|
---|
| 163 | * r=bird: Use a magic. */
|
---|
[30082] | 164 | RTListInit(&pCache->NodeHead);
|
---|
[29040] | 165 | pCache->uClientID = uClientId;
|
---|
| 166 | return RTCritSectInit(&pCache->CritSect);
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 |
|
---|
[31915] | 170 | /**
|
---|
| 171 | * Updates a cache entry without submitting any changes to the host.
|
---|
[58029] | 172 | *
|
---|
[31915] | 173 | * This is handy for defining default values/flags.
|
---|
| 174 | *
|
---|
| 175 | * @returns VBox status code.
|
---|
| 176 | *
|
---|
| 177 | * @param pCache The property cache.
|
---|
| 178 | * @param pszName The property name.
|
---|
| 179 | * @param fFlags The property flags to set.
|
---|
| 180 | * @param pszValueReset The property reset value.
|
---|
| 181 | */
|
---|
[58029] | 182 | int VGSvcPropCacheUpdateEntry(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, uint32_t fFlags, const char *pszValueReset)
|
---|
[28967] | 183 | {
|
---|
[44098] | 184 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
| 185 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
[58029] | 186 | PVBOXSERVICEVEPROPCACHEENTRY pNode = vgsvcPropCacheFindInternal(pCache, pszName, 0);
|
---|
[29040] | 187 | if (pNode == NULL)
|
---|
[58029] | 188 | pNode = vgsvcPropCacheInsertEntryInternal(pCache, pszName);
|
---|
[29040] | 189 |
|
---|
[28983] | 190 | int rc;
|
---|
[28967] | 191 | if (pNode != NULL)
|
---|
| 192 | {
|
---|
[29040] | 193 | rc = RTCritSectEnter(&pCache->CritSect);
|
---|
[28983] | 194 | if (RT_SUCCESS(rc))
|
---|
[28967] | 195 | {
|
---|
[29026] | 196 | pNode->fFlags = fFlags;
|
---|
[28967] | 197 | if (pszValueReset)
|
---|
[28983] | 198 | {
|
---|
[29040] | 199 | if (pNode->pszValueReset)
|
---|
[28983] | 200 | RTStrFree(pNode->pszValueReset);
|
---|
| 201 | pNode->pszValueReset = RTStrDup(pszValueReset);
|
---|
[44098] | 202 | AssertPtr(pNode->pszValueReset);
|
---|
[28983] | 203 | }
|
---|
[29040] | 204 | rc = RTCritSectLeave(&pCache->CritSect);
|
---|
[28967] | 205 | }
|
---|
| 206 | }
|
---|
[28983] | 207 | else
|
---|
[29040] | 208 | rc = VERR_NO_MEMORY;
|
---|
[28983] | 209 | return rc;
|
---|
[28967] | 210 | }
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | /**
|
---|
| 214 | * Updates the local guest property cache and writes it to HGCM if outdated.
|
---|
| 215 | *
|
---|
[31915] | 216 | * @returns VBox status code.
|
---|
[102753] | 217 | * @retval VERR_BUFFER_OVERFLOW if the property name or value exceeds the limit.
|
---|
[29026] | 218 | * @param pCache The property cache.
|
---|
[28967] | 219 | * @param pszName The property name.
|
---|
| 220 | * @param pszValueFormat The property format string. If this is NULL then
|
---|
| 221 | * the property will be deleted (if possible).
|
---|
| 222 | * @param ... Format arguments.
|
---|
| 223 | */
|
---|
[58029] | 224 | int VGSvcPropCacheUpdate(PVBOXSERVICEVEPROPCACHE pCache, const char *pszName, const char *pszValueFormat, ...)
|
---|
[28967] | 225 | {
|
---|
[44098] | 226 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
| 227 | AssertPtrReturn(pszName, VERR_INVALID_POINTER);
|
---|
[28967] | 228 |
|
---|
[45874] | 229 | Assert(pCache->uClientID);
|
---|
| 230 |
|
---|
[102753] | 231 | if (RTStrNLen(pszName, GUEST_PROP_MAX_NAME_LEN) > GUEST_PROP_MAX_NAME_LEN - 1 /* Terminator */)
|
---|
| 232 | return VERR_BUFFER_OVERFLOW;
|
---|
| 233 |
|
---|
[29026] | 234 | /*
|
---|
| 235 | * Format the value first.
|
---|
| 236 | */
|
---|
[28967] | 237 | char *pszValue = NULL;
|
---|
| 238 | if (pszValueFormat)
|
---|
| 239 | {
|
---|
| 240 | va_list va;
|
---|
| 241 | va_start(va, pszValueFormat);
|
---|
[28978] | 242 | RTStrAPrintfV(&pszValue, pszValueFormat, va);
|
---|
[28967] | 243 | va_end(va);
|
---|
[29026] | 244 | if (!pszValue)
|
---|
| 245 | return VERR_NO_STR_MEMORY;
|
---|
[102753] | 246 | if (RTStrNLen(pszValue, GUEST_PROP_MAX_VALUE_LEN) > GUEST_PROP_MAX_VALUE_LEN - 1 /* Terminator */)
|
---|
| 247 | {
|
---|
| 248 | RTStrFree(pszValue);
|
---|
| 249 | return VERR_BUFFER_OVERFLOW;
|
---|
| 250 | }
|
---|
[28967] | 251 | }
|
---|
| 252 |
|
---|
[58029] | 253 | PVBOXSERVICEVEPROPCACHEENTRY pNode = vgsvcPropCacheFindInternal(pCache, pszName, 0);
|
---|
[28978] | 254 |
|
---|
[28983] | 255 | /* Lock the cache. */
|
---|
[29040] | 256 | int rc = RTCritSectEnter(&pCache->CritSect);
|
---|
[28983] | 257 | if (RT_SUCCESS(rc))
|
---|
[28978] | 258 | {
|
---|
[28983] | 259 | if (pNode == NULL)
|
---|
[58029] | 260 | pNode = vgsvcPropCacheInsertEntryInternal(pCache, pszName);
|
---|
[29026] | 261 |
|
---|
[28983] | 262 | AssertPtr(pNode);
|
---|
| 263 | if (pszValue) /* Do we have a value to check for? */
|
---|
[28967] | 264 | {
|
---|
[28983] | 265 | bool fUpdate = false;
|
---|
| 266 | /* Always update this property, no matter what? */
|
---|
[58029] | 267 | if (pNode->fFlags & VGSVCPROPCACHE_FLAGS_ALWAYS_UPDATE)
|
---|
[28983] | 268 | fUpdate = true;
|
---|
| 269 | /* Did the value change so we have to update? */
|
---|
| 270 | else if (pNode->pszValue && strcmp(pNode->pszValue, pszValue) != 0)
|
---|
| 271 | fUpdate = true;
|
---|
| 272 | /* No value stored at the moment but we have a value now? */
|
---|
[29026] | 273 | else if (pNode->pszValue == NULL)
|
---|
[28983] | 274 | fUpdate = true;
|
---|
[29026] | 275 |
|
---|
[28983] | 276 | if (fUpdate)
|
---|
| 277 | {
|
---|
| 278 | /* Write the update. */
|
---|
[58029] | 279 | rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pszValue);
|
---|
| 280 | VGSvcVerbose(4, "[PropCache %p]: Written '%s'='%s' (flags: %x), rc=%Rrc\n",
|
---|
[44098] | 281 | pCache, pNode->pszName, pszValue, pNode->fFlags, rc);
|
---|
[45874] | 282 | if (RT_SUCCESS(rc)) /* Only update the node's value on successful write. */
|
---|
| 283 | {
|
---|
| 284 | RTStrFree(pNode->pszValue);
|
---|
| 285 | pNode->pszValue = RTStrDup(pszValue);
|
---|
| 286 | if (!pNode->pszValue)
|
---|
| 287 | rc = VERR_NO_MEMORY;
|
---|
| 288 | }
|
---|
[28983] | 289 | }
|
---|
| 290 | else
|
---|
[29040] | 291 | rc = VINF_NO_CHANGE; /* No update needed. */
|
---|
[28983] | 292 | }
|
---|
[29026] | 293 | else
|
---|
[28983] | 294 | {
|
---|
| 295 | /* No value specified. Deletion (or no action required). */
|
---|
| 296 | if (pNode->pszValue) /* Did we have a value before? Then the value needs to be deleted. */
|
---|
| 297 | {
|
---|
[58029] | 298 | rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNode->pszName,
|
---|
[31878] | 299 | 0, /* Flags */ NULL /* Value */);
|
---|
[58029] | 300 | VGSvcVerbose(4, "[PropCache %p]: Deleted '%s'='%s' (flags: %x), rc=%Rrc\n",
|
---|
[44098] | 301 | pCache, pNode->pszName, pNode->pszValue, pNode->fFlags, rc);
|
---|
[45874] | 302 | if (RT_SUCCESS(rc)) /* Only delete property value on successful Vbgl deletion. */
|
---|
| 303 | {
|
---|
| 304 | /* Delete property (but do not remove from cache) if not deleted yet. */
|
---|
| 305 | RTStrFree(pNode->pszValue);
|
---|
| 306 | pNode->pszValue = NULL;
|
---|
| 307 | }
|
---|
[28983] | 308 | }
|
---|
| 309 | else
|
---|
[29040] | 310 | rc = VINF_NO_CHANGE; /* No update needed. */
|
---|
[28967] | 311 | }
|
---|
[29026] | 312 |
|
---|
[28983] | 313 | /* Release cache. */
|
---|
[31925] | 314 | RTCritSectLeave(&pCache->CritSect);
|
---|
[28967] | 315 | }
|
---|
[29026] | 316 |
|
---|
[58029] | 317 | VGSvcVerbose(4, "[PropCache %p]: Updating '%s' resulted in rc=%Rrc\n", pCache, pszName, rc);
|
---|
[45874] | 318 |
|
---|
[29026] | 319 | /* Delete temp stuff. */
|
---|
| 320 | RTStrFree(pszValue);
|
---|
[28967] | 321 | return rc;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 |
|
---|
[29026] | 325 | /**
|
---|
[31912] | 326 | * Updates all cache values which are matching the specified path.
|
---|
| 327 | *
|
---|
| 328 | * @returns VBox status code.
|
---|
| 329 | *
|
---|
| 330 | * @param pCache The property cache.
|
---|
| 331 | * @param pszValue The value to set. A NULL will delete the value.
|
---|
| 332 | * @param fFlags Flags to set.
|
---|
| 333 | * @param pszPathFormat The path format string. May not be null and has
|
---|
| 334 | * to be an absolute path.
|
---|
| 335 | * @param ... Format arguments.
|
---|
| 336 | */
|
---|
[58029] | 337 | int VGSvcPropCacheUpdateByPath(PVBOXSERVICEVEPROPCACHE pCache, const char *pszValue, uint32_t fFlags,
|
---|
| 338 | const char *pszPathFormat, ...)
|
---|
[31912] | 339 | {
|
---|
[62851] | 340 | RT_NOREF1(fFlags);
|
---|
[44098] | 341 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
| 342 | AssertPtrReturn(pszPathFormat, VERR_INVALID_POINTER);
|
---|
| 343 |
|
---|
[31912] | 344 | int rc = VERR_NOT_FOUND;
|
---|
| 345 | if (RT_SUCCESS(RTCritSectEnter(&pCache->CritSect)))
|
---|
| 346 | {
|
---|
| 347 | /*
|
---|
| 348 | * Format the value first.
|
---|
| 349 | */
|
---|
| 350 | char *pszPath = NULL;
|
---|
| 351 | va_list va;
|
---|
| 352 | va_start(va, pszPathFormat);
|
---|
| 353 | RTStrAPrintfV(&pszPath, pszPathFormat, va);
|
---|
| 354 | va_end(va);
|
---|
| 355 | if (!pszPath)
|
---|
| 356 | {
|
---|
[31933] | 357 | rc = VERR_NO_STR_MEMORY;
|
---|
| 358 | }
|
---|
| 359 | else
|
---|
| 360 | {
|
---|
| 361 | /* Iterate through all nodes and compare their paths. */
|
---|
[64766] | 362 | PVBOXSERVICEVEPROPCACHEENTRY pNodeIt;
|
---|
[31933] | 363 | RTListForEach(&pCache->NodeHead, pNodeIt, VBOXSERVICEVEPROPCACHEENTRY, NodeSucc)
|
---|
[31912] | 364 | {
|
---|
[31933] | 365 | if (RTStrStr(pNodeIt->pszName, pszPath) == pNodeIt->pszName)
|
---|
| 366 | {
|
---|
| 367 | /** @todo Use some internal function to update the node directly, this is slow atm. */
|
---|
[58029] | 368 | rc = VGSvcPropCacheUpdate(pCache, pNodeIt->pszName, pszValue);
|
---|
[31933] | 369 | }
|
---|
| 370 | if (RT_FAILURE(rc))
|
---|
| 371 | break;
|
---|
[31912] | 372 | }
|
---|
[31933] | 373 | RTStrFree(pszPath);
|
---|
[31912] | 374 | }
|
---|
| 375 | RTCritSectLeave(&pCache->CritSect);
|
---|
| 376 | }
|
---|
| 377 | return rc;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 |
|
---|
| 381 | /**
|
---|
[29885] | 382 | * Flushes the cache by writing every item regardless of its state.
|
---|
| 383 | *
|
---|
| 384 | * @param pCache The property cache.
|
---|
| 385 | */
|
---|
[58029] | 386 | int VGSvcPropCacheFlush(PVBOXSERVICEVEPROPCACHE pCache)
|
---|
[29885] | 387 | {
|
---|
[44098] | 388 | AssertPtrReturn(pCache, VERR_INVALID_POINTER);
|
---|
| 389 |
|
---|
[29885] | 390 | int rc = VINF_SUCCESS;
|
---|
| 391 | if (RT_SUCCESS(RTCritSectEnter(&pCache->CritSect)))
|
---|
| 392 | {
|
---|
[64766] | 393 | PVBOXSERVICEVEPROPCACHEENTRY pNodeIt;
|
---|
[30082] | 394 | RTListForEach(&pCache->NodeHead, pNodeIt, VBOXSERVICEVEPROPCACHEENTRY, NodeSucc)
|
---|
[29885] | 395 | {
|
---|
[58029] | 396 | rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNodeIt->pszName, pNodeIt->fFlags, pNodeIt->pszValue);
|
---|
[29885] | 397 | if (RT_FAILURE(rc))
|
---|
| 398 | break;
|
---|
| 399 | }
|
---|
| 400 | RTCritSectLeave(&pCache->CritSect);
|
---|
| 401 | }
|
---|
| 402 | return rc;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 |
|
---|
| 406 | /**
|
---|
[29026] | 407 | * Reset all temporary properties and destroy the cache.
|
---|
| 408 | *
|
---|
| 409 | * @param pCache The property cache.
|
---|
| 410 | */
|
---|
[58029] | 411 | void VGSvcPropCacheDestroy(PVBOXSERVICEVEPROPCACHE pCache)
|
---|
[28967] | 412 | {
|
---|
[44099] | 413 | AssertPtrReturnVoid(pCache);
|
---|
[28967] | 414 | Assert(pCache->uClientID);
|
---|
| 415 |
|
---|
[29040] | 416 | /* Lock the cache. */
|
---|
| 417 | int rc = RTCritSectEnter(&pCache->CritSect);
|
---|
| 418 | if (RT_SUCCESS(rc))
|
---|
[28967] | 419 | {
|
---|
[34406] | 420 | PVBOXSERVICEVEPROPCACHEENTRY pNode = RTListGetFirst(&pCache->NodeHead, VBOXSERVICEVEPROPCACHEENTRY, NodeSucc);
|
---|
[29040] | 421 | while (pNode)
|
---|
| 422 | {
|
---|
[31934] | 423 | PVBOXSERVICEVEPROPCACHEENTRY pNext = RTListNodeIsLast(&pCache->NodeHead, &pNode->NodeSucc)
|
---|
| 424 | ? NULL :
|
---|
| 425 | RTListNodeGetNext(&pNode->NodeSucc,
|
---|
| 426 | VBOXSERVICEVEPROPCACHEENTRY, NodeSucc);
|
---|
| 427 | RTListNodeRemove(&pNode->NodeSucc);
|
---|
| 428 |
|
---|
[58029] | 429 | if (pNode->fFlags & VGSVCPROPCACHE_FLAGS_TEMPORARY)
|
---|
| 430 | rc = vgsvcPropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pNode->pszValueReset);
|
---|
[30013] | 431 |
|
---|
[29040] | 432 | AssertPtr(pNode->pszName);
|
---|
| 433 | RTStrFree(pNode->pszName);
|
---|
| 434 | RTStrFree(pNode->pszValue);
|
---|
| 435 | RTStrFree(pNode->pszValueReset);
|
---|
| 436 | pNode->fFlags = 0;
|
---|
[30013] | 437 |
|
---|
[29040] | 438 | RTMemFree(pNode);
|
---|
[30013] | 439 |
|
---|
[29040] | 440 | pNode = pNext;
|
---|
| 441 | }
|
---|
| 442 | RTCritSectLeave(&pCache->CritSect);
|
---|
[28967] | 443 | }
|
---|
[29026] | 444 |
|
---|
[29040] | 445 | /* Destroy critical section. */
|
---|
| 446 | RTCritSectDelete(&pCache->CritSect);
|
---|
[28967] | 447 | }
|
---|
[29026] | 448 |
|
---|