Changeset 52251 in vbox for trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
- Timestamp:
- Aug 1, 2014 6:07:28 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r52107 r52251 1283 1283 { 1284 1284 /* Provide credentials only if there are no logged in users. */ 1285 Bstr noLoggedInUsersValue;1285 Utf8Str noLoggedInUsersValue; 1286 1286 LONG64 ul64Timestamp = 0; 1287 Bstr flags;1288 1289 hrc = i_getGuestProperty( Bstr("/VirtualBox/GuestInfo/OS/NoLoggedInUsers").raw(),1290 noLoggedInUsersValue.asOutParam(), &ul64Timestamp, flags.asOutParam());1291 1292 if (SUCCEEDED(hrc) && noLoggedInUsersValue != Bstr("false"))1287 Utf8Str flags; 1288 1289 hrc = i_getGuestProperty("/VirtualBox/GuestInfo/OS/NoLoggedInUsers", 1290 &noLoggedInUsersValue, &ul64Timestamp, &flags); 1291 1292 if (SUCCEEDED(hrc) && noLoggedInUsersValue != "false") 1293 1293 { 1294 1294 /* And only if there are no connected clients. */ … … 5567 5567 * @note Temporarily locks this object for writing. 5568 5568 */ 5569 HRESULT Console::i_getGuestProperty( IN_BSTR aName, BSTR *aValue, LONG64 *aTimestamp, BSTR*aFlags)5569 HRESULT Console::i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags) 5570 5570 { 5571 5571 #ifndef VBOX_WITH_GUEST_PROPS 5572 5572 ReturnComNotImplemented(); 5573 5573 #else /* VBOX_WITH_GUEST_PROPS */ 5574 if (! VALID_PTR(aName))5575 return E_INVALIDARG;5576 if ( !VALID_PTR(aValue))5574 if (!RT_VALID_PTR(aValue)) 5575 return E_POINTER; 5576 if (aTimestamp != NULL && !RT_VALID_PTR(aTimestamp)) 5577 5577 return E_POINTER; 5578 if ((aTimestamp != NULL) && !VALID_PTR(aTimestamp)) 5579 return E_POINTER; 5580 if ((aFlags != NULL) && !VALID_PTR(aFlags)) 5578 if (aFlags != NULL && !RT_VALID_PTR(aFlags)) 5581 5579 return E_POINTER; 5582 5580 … … 5598 5596 { 5599 5597 VBOXHGCMSVCPARM parm[4]; 5600 Utf8Str Utf8Name = aName;5601 5598 char szBuffer[MAX_VALUE_LEN + MAX_FLAGS_LEN]; 5602 5599 5603 5600 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 5604 parm[0].u.pointer.addr = (void*) Utf8Name.c_str();5605 /* The + 1 is the null terminator */5606 parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1; 5601 parm[0].u.pointer.addr = (void*)aName.c_str(); 5602 parm[0].u.pointer.size = (uint32_t)aName.length() + 1; /* The + 1 is the null terminator */ 5603 5607 5604 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 5608 5605 parm[1].u.pointer.addr = szBuffer; 5609 5606 parm[1].u.pointer.size = sizeof(szBuffer); 5607 5608 parm[2].type = VBOX_HGCM_SVC_PARM_64BIT; 5609 parm[2].u.uint64 = 0; 5610 5611 parm[3].type = VBOX_HGCM_SVC_PARM_32BIT; 5612 parm[3].u.uint32 = 0; 5613 5610 5614 int vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", GET_PROP_HOST, 5611 5615 4, &parm[0]); 5612 5616 /* The returned string should never be able to be greater than our buffer */ 5613 5617 AssertLogRel(vrc != VERR_BUFFER_OVERFLOW); 5614 AssertLogRel(RT_FAILURE(vrc) || VBOX_HGCM_SVC_PARM_64BIT == parm[2].type); 5615 if (RT_SUCCESS(vrc) || (VERR_NOT_FOUND == vrc)) 5616 { 5618 AssertLogRel(RT_FAILURE(vrc) || parm[2].type == VBOX_HGCM_SVC_PARM_64BIT); 5619 if (RT_SUCCESS(vrc)) 5620 { 5621 *aValue = szBuffer; 5622 5623 if (aTimestamp) 5624 *aTimestamp = parm[2].u.uint64; 5625 5626 if (aFlags) 5627 *aFlags = &szBuffer[strlen(szBuffer) + 1]; 5628 5617 5629 rc = S_OK; 5618 if (vrc != VERR_NOT_FOUND) 5619 { 5620 Utf8Str strBuffer(szBuffer); 5621 strBuffer.cloneTo(aValue); 5622 5623 if (aTimestamp) 5624 *aTimestamp = parm[2].u.uint64; 5625 5626 if (aFlags) 5627 { 5628 size_t iFlags = strBuffer.length() + 1; 5629 Utf8Str(szBuffer + iFlags).cloneTo(aFlags); 5630 } 5631 } 5632 else 5633 aValue = NULL; 5630 } 5631 else if (vrc == VERR_NOT_FOUND) 5632 { 5633 *aValue = ""; 5634 rc = S_OK; 5634 5635 } 5635 5636 else 5636 rc = setError( E_UNEXPECTED,5637 tr("Theservice call failed with the error %Rrc"),5638 vrc);5637 rc = setError(VBOX_E_IPRT_ERROR, 5638 tr("The VBoxGuestPropSvc service call failed with the error %Rrc"), 5639 vrc); 5639 5640 } 5640 5641 catch(std::bad_alloc & /*e*/) … … 5642 5643 rc = E_OUTOFMEMORY; 5643 5644 } 5645 5644 5646 return rc; 5645 5647 #endif /* VBOX_WITH_GUEST_PROPS */ … … 5649 5651 * @note Temporarily locks this object for writing. 5650 5652 */ 5651 HRESULT Console::i_setGuestProperty( IN_BSTR aName, IN_BSTR aValue, IN_BSTRaFlags)5653 HRESULT Console::i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags) 5652 5654 { 5653 5655 #ifndef VBOX_WITH_GUEST_PROPS 5654 5656 ReturnComNotImplemented(); 5655 5657 #else /* VBOX_WITH_GUEST_PROPS */ 5656 if (!RT_VALID_PTR(aName))5657 return setError(E_INVALIDARG, tr("Name cannot be NULL or an invalid pointer"));5658 if (aValue != NULL && !RT_VALID_PTR(aValue))5659 return setError(E_INVALIDARG, tr("Invalid value pointer"));5660 if (aFlags != NULL && !RT_VALID_PTR(aFlags))5661 return setError(E_INVALIDARG, tr("Invalid flags pointer"));5662 5658 5663 5659 AutoCaller autoCaller(this); … … 5676 5672 VBOXHGCMSVCPARM parm[3]; 5677 5673 5678 Utf8Str Utf8Name = aName;5679 5674 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 5680 parm[0].u.pointer.addr = (void*)Utf8Name.c_str(); 5681 /* The + 1 is the null terminator */ 5682 parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1; 5683 5684 Utf8Str Utf8Value; 5685 if (aValue != NULL) 5686 { 5687 Utf8Value = aValue; 5688 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 5689 parm[1].u.pointer.addr = (void *)Utf8Value.c_str(); 5690 /* The + 1 is the null terminator */ 5691 parm[1].u.pointer.size = (uint32_t)Utf8Value.length() + 1; 5692 } 5693 5694 Utf8Str Utf8Flags; 5695 if (aFlags != NULL) 5696 { 5697 Utf8Flags = aFlags; 5675 parm[0].u.pointer.addr = (void*)aName.c_str(); 5676 parm[0].u.pointer.size = (uint32_t)aName.length() + 1; /* The + 1 is the null terminator */ 5677 5678 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 5679 parm[1].u.pointer.addr = (void *)aValue.c_str(); 5680 parm[1].u.pointer.size = (uint32_t)aValue.length() + 1; /* The + 1 is the null terminator */ 5681 5682 int vrc; 5683 if (aFlags.isEmpty()) 5684 { 5685 vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", SET_PROP_VALUE_HOST, 5686 2, &parm[0]); 5687 } 5688 else 5689 { 5698 5690 parm[2].type = VBOX_HGCM_SVC_PARM_PTR; 5699 parm[2].u.pointer.addr = (void*)Utf8Flags.c_str(); 5700 /* The + 1 is the null terminator */ 5701 parm[2].u.pointer.size = (uint32_t)Utf8Flags.length() + 1; 5702 } 5703 5704 int vrc; 5705 if (aValue != NULL && aFlags != NULL) 5691 parm[2].u.pointer.addr = (void*)aFlags.c_str(); 5692 parm[2].u.pointer.size = (uint32_t)aFlags.length() + 1; /* The + 1 is the null terminator */ 5693 5706 5694 vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", SET_PROP_HOST, 5707 5695 3, &parm[0]); 5708 else if (aValue != NULL) 5709 vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", SET_PROP_VALUE_HOST, 5710 2, &parm[0]); 5711 else 5712 vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", DEL_PROP_HOST, 5713 1, &parm[0]); 5714 HRESULT hrc; 5715 if (RT_SUCCESS(vrc)) 5716 hrc = S_OK; 5717 else 5718 hrc = setError(E_UNEXPECTED, tr("The service call failed with the error %Rrc"), vrc); 5696 } 5697 5698 HRESULT hrc = S_OK; 5699 if (RT_FAILURE(vrc)) 5700 hrc = setError(VBOX_E_IPRT_ERROR, tr("The VBoxGuestPropSvc service call failed with the error %Rrc"), vrc); 5719 5701 return hrc; 5720 5702 #endif /* VBOX_WITH_GUEST_PROPS */ 5721 5703 } 5722 5704 5705 HRESULT Console::i_deleteGuestProperty(const Utf8Str &aName) 5706 { 5707 #ifndef VBOX_WITH_GUEST_PROPS 5708 ReturnComNotImplemented(); 5709 #else /* VBOX_WITH_GUEST_PROPS */ 5710 5711 AutoCaller autoCaller(this); 5712 AssertComRCReturnRC(autoCaller.rc()); 5713 5714 /* protect mpUVM (if not NULL) */ 5715 SafeVMPtrQuiet ptrVM(this); 5716 if (FAILED(ptrVM.rc())) 5717 return ptrVM.rc(); 5718 5719 /* Note: validity of mVMMDev which is bound to uninit() is guaranteed by 5720 * ptrVM, so there is no need to hold a lock of this */ 5721 5722 using namespace guestProp; 5723 5724 VBOXHGCMSVCPARM parm[1]; 5725 5726 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 5727 parm[0].u.pointer.addr = (void*)aName.c_str(); 5728 parm[0].u.pointer.size = (uint32_t)aName.length() + 1; /* The + 1 is the null terminator */ 5729 5730 int vrc = m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", DEL_PROP_HOST, 5731 1, &parm[0]); 5732 5733 HRESULT hrc = S_OK; 5734 if (RT_FAILURE(vrc)) 5735 hrc = setError(VBOX_E_IPRT_ERROR, tr("The VBoxGuestPropSvc service call failed with the error %Rrc"), vrc); 5736 return hrc; 5737 #endif /* VBOX_WITH_GUEST_PROPS */ 5738 } 5723 5739 5724 5740 /**
Note:
See TracChangeset
for help on using the changeset viewer.