Changeset 62799 in vbox for trunk/src/VBox/HostServices/GuestProperties
- Timestamp:
- Aug 1, 2016 9:28:52 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/GuestProperties/service.cpp
r60392 r62799 410 410 static DECLCALLBACK(int) threadNotifyHost(RTTHREAD self, void *pvUser); 411 411 #endif 412 413 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(Service); 412 414 }; 413 415 … … 472 474 int Service::validateValue(const char *pszValue, uint32_t cbValue) 473 475 { 474 LogFlowFunc(("cbValue=%d\n", cbValue)); 476 LogFlowFunc(("cbValue=%d\n", cbValue)); RT_NOREF1(pszValue); 475 477 476 478 int rc = VINF_SUCCESS; … … 512 514 rc = VERR_INVALID_PARAMETER; 513 515 /** @todo validate the array sizes... */ 514 515 for (unsigned i = 0; RT_SUCCESS(rc) && papszNames[i] != NULL; ++i) 516 { 517 if ( !RT_VALID_PTR(papszNames[i]) 518 || !RT_VALID_PTR(papszValues[i]) 519 || !RT_VALID_PTR(papszFlags[i]) 520 ) 521 rc = VERR_INVALID_POINTER; 522 else 523 { 524 uint32_t fFlagsIgn; 525 rc = validateFlags(papszFlags[i], &fFlagsIgn); 526 } 527 } 528 529 if (RT_SUCCESS(rc)) 530 { 531 /* 532 * Add the properties. No way to roll back here. 533 */ 534 for (unsigned i = 0; papszNames[i] != NULL; ++i) 535 { 536 uint32_t fFlags; 537 rc = validateFlags(papszFlags[i], &fFlags); 538 AssertRCBreak(rc); 539 540 Property *pProp = getPropertyInternal(papszNames[i]); 541 if (pProp) 542 { 543 /* Update existing property. */ 544 pProp->mValue = papszValues[i]; 545 pProp->mTimestamp = pau64Timestamps[i]; 546 pProp->mFlags = fFlags; 547 } 516 else 517 { 518 for (unsigned i = 0; RT_SUCCESS(rc) && papszNames[i] != NULL; ++i) 519 { 520 if ( !RT_VALID_PTR(papszNames[i]) 521 || !RT_VALID_PTR(papszValues[i]) 522 || !RT_VALID_PTR(papszFlags[i]) 523 ) 524 rc = VERR_INVALID_POINTER; 548 525 else 549 526 { 550 /* Create a new property */ 551 pProp = new Property(papszNames[i], papszValues[i], pau64Timestamps[i], fFlags); 552 if (!pProp) 527 uint32_t fFlagsIgn; 528 rc = validateFlags(papszFlags[i], &fFlagsIgn); 529 } 530 } 531 if (RT_SUCCESS(rc)) 532 { 533 /* 534 * Add the properties. No way to roll back here. 535 */ 536 for (unsigned i = 0; papszNames[i] != NULL; ++i) 537 { 538 uint32_t fFlags; 539 rc = validateFlags(papszFlags[i], &fFlags); 540 AssertRCBreak(rc); 541 542 Property *pProp = getPropertyInternal(papszNames[i]); 543 if (pProp) 553 544 { 554 rc = VERR_NO_MEMORY; 555 break; 545 /* Update existing property. */ 546 pProp->mValue = papszValues[i]; 547 pProp->mTimestamp = pau64Timestamps[i]; 548 pProp->mFlags = fFlags; 556 549 } 557 if (RTStrSpaceInsert(&mhProperties, &pProp->mStrCore))558 mcProperties++;559 550 else 560 551 { 561 delete pProp; 562 rc = VERR_INTERNAL_ERROR_3; 563 AssertFailedBreak(); 552 /* Create a new property */ 553 pProp = new Property(papszNames[i], papszValues[i], pau64Timestamps[i], fFlags); 554 if (!pProp) 555 { 556 rc = VERR_NO_MEMORY; 557 break; 558 } 559 if (RTStrSpaceInsert(&mhProperties, &pProp->mStrCore)) 560 mcProperties++; 561 else 562 { 563 delete pProp; 564 rc = VERR_INTERNAL_ERROR_3; 565 AssertFailedBreak(); 566 } 564 567 } 565 568 } … … 586 589 int rc; 587 590 const char *pcszName = NULL; /* shut up gcc */ 588 char *pchBuf; 589 uint32_t cbName, cbBuf; 591 char *pchBuf = NULL; /* shut up MSC */ 592 uint32_t cbName; 593 uint32_t cbBuf = 0; /* shut up MSC */ 590 594 591 595 /* … … 1022 1026 buffer += '\0'; 1023 1027 u64Timestamp = prop.mTimestamp; 1024 } 1025 } 1026 /* Write out the data. */ 1027 if (RT_SUCCESS(rc)) 1028 { 1029 paParms[1].setUInt64(u64Timestamp); 1030 paParms[3].setUInt32((uint32_t)buffer.size()); 1031 if (buffer.size() <= cbBuf) 1032 buffer.copy(pchBuf, cbBuf); 1033 else 1034 rc = VERR_BUFFER_OVERFLOW; 1028 1029 /* Write out the data. */ 1030 if (RT_SUCCESS(rc)) 1031 { 1032 paParms[1].setUInt64(u64Timestamp); 1033 paParms[3].setUInt32((uint32_t)buffer.size()); 1034 if (buffer.size() <= cbBuf) 1035 buffer.copy(pchBuf, cbBuf); 1036 else 1037 rc = VERR_BUFFER_OVERFLOW; 1038 } 1039 } 1035 1040 } 1036 1041 return rc; … … 1061 1066 */ 1062 1067 LogFlowThisFunc(("\n")); 1063 if ( (cParms != 4)/* Hardcoded value as the next lines depend on it. */1068 if ( cParms != 4 /* Hardcoded value as the next lines depend on it. */ 1064 1069 || RT_FAILURE(paParms[0].getString(&pszPatterns, &cchPatterns)) /* patterns */ 1065 1070 || RT_FAILURE(paParms[1].getUInt64(&u64Timestamp)) /* timestamp */ … … 1067 1072 ) 1068 1073 rc = VERR_INVALID_PARAMETER; 1069 1070 if (RT_SUCCESS(rc))1074 else 1075 { 1071 1076 LogFlow(("pszPatterns=%s, u64Timestamp=%llu\n", pszPatterns, u64Timestamp)); 1072 1077 1073 /* 1074 * If no timestamp was supplied or no notification was found in the queue 1075 * of old notifications, enqueue the request in the waiting queue. 1076 */ 1077 Property prop; 1078 if (RT_SUCCESS(rc) && u64Timestamp != 0) 1079 rc = getOldNotification(pszPatterns, u64Timestamp, &prop); 1080 if (RT_SUCCESS(rc)) 1081 { 1082 if (prop.isNull()) 1083 { 1078 /* 1079 * If no timestamp was supplied or no notification was found in the queue 1080 * of old notifications, enqueue the request in the waiting queue. 1081 */ 1082 Property prop; 1083 if (RT_SUCCESS(rc) && u64Timestamp != 0) 1084 rc = getOldNotification(pszPatterns, u64Timestamp, &prop); 1085 if (RT_SUCCESS(rc)) 1086 { 1087 if (prop.isNull()) 1088 { 1089 /* 1090 * Check if the client already had the same request. 1091 * Complete the old request with an error in this case. 1092 * Protection against clients, which cancel and resubmits requests. 1093 */ 1094 CallList::iterator it = mGuestWaiters.begin(); 1095 while (it != mGuestWaiters.end()) 1096 { 1097 const char *pszPatternsExisting; 1098 uint32_t cchPatternsExisting; 1099 int rc3 = it->mParms[0].getString(&pszPatternsExisting, &cchPatternsExisting); 1100 1101 if ( RT_SUCCESS(rc3) 1102 && u32ClientId == it->u32ClientId 1103 && RTStrCmp(pszPatterns, pszPatternsExisting) == 0) 1104 { 1105 /* Complete the old request. */ 1106 mpHelpers->pfnCallComplete(it->mHandle, VERR_INTERRUPTED); 1107 it = mGuestWaiters.erase(it); 1108 } 1109 else 1110 ++it; 1111 } 1112 1113 mGuestWaiters.push_back(GuestCall(u32ClientId, callHandle, GET_NOTIFICATION, 1114 cParms, paParms, rc)); 1115 rc = VINF_HGCM_ASYNC_EXECUTE; 1116 } 1084 1117 /* 1085 * Check if the client already had the same request. 1086 * Complete the old request with an error in this case. 1087 * Protection against clients, which cancel and resubmits requests. 1118 * Otherwise reply at once with the enqueued notification we found. 1088 1119 */ 1089 CallList::iterator it = mGuestWaiters.begin(); 1090 while (it != mGuestWaiters.end()) 1120 else 1091 1121 { 1092 const char *pszPatternsExisting; 1093 uint32_t cchPatternsExisting; 1094 int rc3 = it->mParms[0].getString(&pszPatternsExisting, &cchPatternsExisting); 1095 1096 if ( RT_SUCCESS(rc3) 1097 && u32ClientId == it->u32ClientId 1098 && RTStrCmp(pszPatterns, pszPatternsExisting) == 0) 1099 { 1100 /* Complete the old request. */ 1101 mpHelpers->pfnCallComplete(it->mHandle, VERR_INTERRUPTED); 1102 it = mGuestWaiters.erase(it); 1103 } 1104 else 1105 ++it; 1122 int rc2 = getNotificationWriteOut(cParms, paParms, prop); 1123 if (RT_FAILURE(rc2)) 1124 rc = rc2; 1106 1125 } 1107 1108 mGuestWaiters.push_back(GuestCall(u32ClientId, callHandle, GET_NOTIFICATION,1109 cParms, paParms, rc));1110 rc = VINF_HGCM_ASYNC_EXECUTE;1111 }1112 /*1113 * Otherwise reply at once with the enqueued notification we found.1114 */1115 else1116 {1117 int rc2 = getNotificationWriteOut(cParms, paParms, prop);1118 if (RT_FAILURE(rc2))1119 rc = rc2;1120 1126 } 1121 1127 } … … 1425 1431 void Service::dbgInfo(void *pvUser, PCDBGFINFOHLP pHlp, const char *pszArgs) 1426 1432 { 1433 RT_NOREF1(pszArgs); 1427 1434 SELF *pSelf = reinterpret_cast<SELF *>(pvUser); 1428 1435 pSelf->dbgInfoShow(pHlp); … … 1519 1526 #ifdef ASYNC_HOST_NOTIFY 1520 1527 /* static */ 1521 DECLCALLBACK(int) Service::threadNotifyHost(RTTHREAD self, void *pvUser) 1522 { 1528 DECLCALLBACK(int) Service::threadNotifyHost(RTTHREAD hThreadSelf, void *pvUser) 1529 { 1530 RT_NOREF1(hThreadSelf); 1523 1531 Service *pThis = (Service *)pvUser; 1524 1532 int rc = VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.