Changeset 3756 in vbox
- Timestamp:
- Jul 21, 2007 7:00:53 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 23067
- Location:
- trunk/src/VBox/Main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r3668 r3756 1171 1171 CFGLDRSetBool (filter, "active", !!data.mActive); 1172 1172 1173 #ifndef VBOX_WITH_USBFILTER 1173 1174 // all are optional 1174 1175 if (data.mVendorId.string()) … … 1195 1196 else 1196 1197 AssertMsgFailed (("Invalid action: %d\n", data.mAction)); 1198 1199 #else /* VBOX_WITH_USBFILTER */ 1200 // all are optional 1201 Bstr str; 1202 (*it)->COMGETTER (VendorId) (str.asOutParam()); 1203 if (!str.isNull()) 1204 CFGLDRSetBSTR (filter, "vendorid", str); 1205 1206 (*it)->COMGETTER (ProductId) (str.asOutParam()); 1207 if (!str.isNull()) 1208 CFGLDRSetBSTR (filter, "productid", str); 1209 1210 (*it)->COMGETTER (Revision) (str.asOutParam()); 1211 if (!str.isNull()) 1212 CFGLDRSetBSTR (filter, "revision", str); 1213 1214 (*it)->COMGETTER (Manufacturer) (str.asOutParam()); 1215 if (!str.isNull()) 1216 CFGLDRSetBSTR (filter, "manufacturer", str); 1217 1218 (*it)->COMGETTER (Product) (str.asOutParam()); 1219 if (!str.isNull()) 1220 CFGLDRSetBSTR (filter, "product", str); 1221 1222 (*it)->COMGETTER (SerialNumber) (str.asOutParam()); 1223 if (!str.isNull()) 1224 CFGLDRSetBSTR (filter, "serialnumber", str); 1225 1226 (*it)->COMGETTER (Port) (str.asOutParam()); 1227 if (!str.isNull()) 1228 CFGLDRSetBSTR (filter, "port", str); 1229 1230 // action is mandatory 1231 ULONG action = USBDeviceFilterAction_InvalidUSBDeviceFilterAction; 1232 (*it)->COMGETTER (Action) (&action); 1233 if (action == USBDeviceFilterAction_USBDeviceFilterIgnore) 1234 CFGLDRSetString (filter, "action", "Ignore"); 1235 else if (action == USBDeviceFilterAction_USBDeviceFilterHold) 1236 CFGLDRSetString (filter, "action", "Hold"); 1237 else 1238 AssertMsgFailed (("Invalid action: %d\n", action)); 1239 #endif /* VBOX_WITH_USBFILTER */ 1197 1240 1198 1241 CFGLDRReleaseNode (filter); … … 1930 1973 if (aDevice->isMatch (data)) 1931 1974 { 1932 if (data.mAction == USBDeviceFilterAction_USBDeviceFilterIgnore) 1975 #ifndef VBOX_WITH_USBFILTER 1976 USBDeviceFilterAction_T action = data.mAction; 1977 #else 1978 ULONG action = USBDeviceFilterAction_InvalidUSBDeviceFilterAction; 1979 (*it)->COMGETTER (Action) (&action); 1980 #endif 1981 if (action == USBDeviceFilterAction_USBDeviceFilterIgnore) 1933 1982 { 1934 1983 /* request to give the device back to the host*/ … … 1937 1986 return S_OK; 1938 1987 } 1939 if ( data.mAction == USBDeviceFilterAction_USBDeviceFilterHold)1988 if (action == USBDeviceFilterAction_USBDeviceFilterHold) 1940 1989 break; 1941 1990 } -
trunk/src/VBox/Main/HostUSBDeviceImpl.cpp
r3668 r3756 822 822 return false; 823 823 824 #ifndef VBOX_WITH_USBFILTER 824 825 if (!aData.mVendorId.isMatch (mUsb->idVendor)) 825 826 { … … 892 893 && aData.mSerialNumber.string().isEmpty()) 893 894 return false; 895 896 #else /* VBOX_WITH_USBFILTER */ 897 if (USBFilterMatchDevice (&aData.mUSBFilter, mUsb)) 898 { 899 /* Don't match busy devices with a 100% wildcard filter - this will 900 later become a filter prop (ring-3 only). */ 901 if ( mUsb->enmState == USBDEVICESTATE_USED_BY_HOST_CAPTURABLE 902 && !USBFilterHasAnySubstatialCriteria (&aData.mUSBFilter)) 903 return false; 904 } 905 #endif /* VBOX_WITH_USBFILTER */ 894 906 895 907 LogFlowThisFunc (("returns true\n")); -
trunk/src/VBox/Main/Makefile.kmk
r3720 r3756 42 42 DEFS += VBOX_WITH_UNIXY_TAP_NETWORKING 43 43 endif 44 44 45 45 46 #PROGRAMS = tstCFGLdr … … 218 219 endif 219 220 221 ## Alternative USB filtering. 222 #ifeq ($(filter-out darwin,$(BUILD_TARGET)),) 223 #VBoxSVC_DEFS += VBOX_WITH_USBFILTER 224 #VBoxSVC_LIBS += $(PATH_LIB)/USBFilter$(VBOX_SUFF_LIB) 225 #endif 226 227 220 228 # 221 229 # VBoxSVC wrapper module -
trunk/src/VBox/Main/USBControllerImpl.cpp
r3668 r3756 560 560 561 561 /* all are optional */ 562 #ifndef VBOX_WITH_USBFILTER 562 563 if (data.mVendorId.string()) 563 564 CFGLDRSetBSTR (filter, "vendorid", data.mVendorId.string()); … … 576 577 if (data.mRemote.string()) 577 578 CFGLDRSetBSTR (filter, "remote", data.mRemote.string()); 579 580 #else /* VBOX_WITH_USBFILTER */ 581 Bstr str; 582 (*it)->COMGETTER (VendorId) (str.asOutParam()); 583 if (!str.isNull()) 584 CFGLDRSetBSTR (filter, "vendorid", str); 585 586 (*it)->COMGETTER (ProductId) (str.asOutParam()); 587 if (!str.isNull()) 588 CFGLDRSetBSTR (filter, "productid", str); 589 590 (*it)->COMGETTER (Revision) (str.asOutParam()); 591 if (!str.isNull()) 592 CFGLDRSetBSTR (filter, "revision", str); 593 594 (*it)->COMGETTER (Manufacturer) (str.asOutParam()); 595 if (!str.isNull()) 596 CFGLDRSetBSTR (filter, "manufacturer", str); 597 598 (*it)->COMGETTER (Product) (str.asOutParam()); 599 if (!str.isNull()) 600 CFGLDRSetBSTR (filter, "product", str); 601 602 (*it)->COMGETTER (SerialNumber) (str.asOutParam()); 603 if (!str.isNull()) 604 CFGLDRSetBSTR (filter, "serialnumber", str); 605 606 (*it)->COMGETTER (Port) (str.asOutParam()); 607 if (!str.isNull()) 608 CFGLDRSetBSTR (filter, "port", str); 609 610 if (data.mRemote.string()) 611 CFGLDRSetBSTR (filter, "remote", data.mRemote.string()); 612 #endif /* VBOX_WITH_USBFILTER */ 578 613 579 614 CFGLDRReleaseNode (filter); … … 1062 1097 1063 1098 /* query fields */ 1099 #ifdef VBOX_WITH_USBFILTER 1100 USBFILTER dev; 1101 USBFilterInit (&dev, USBFILTERTYPE_CAPTURE); 1102 #endif 1064 1103 1065 1104 USHORT vendorId = 0; … … 1067 1106 ComAssertComRCRet (rc, false); 1068 1107 ComAssertRet (vendorId, false); 1108 #ifdef VBOX_WITH_USBFILTER 1109 int vrc = USBFilterSetNumExact (&dev, USBFILTERIDX_VENDOR_ID, vendorId, true); AssertRC(vrc); 1110 #endif 1069 1111 1070 1112 USHORT productId = 0; … … 1072 1114 ComAssertComRCRet (rc, false); 1073 1115 ComAssertRet (productId, false); 1116 #ifdef VBOX_WITH_USBFILTER 1117 vrc = USBFilterSetNumExact (&dev, USBFILTERIDX_PRODUCT_ID, productId, true); AssertRC(vrc); 1118 #endif 1074 1119 1075 1120 USHORT revision; 1076 1121 rc = aUSBDevice->COMGETTER(Revision) (&revision); 1077 1122 ComAssertComRCRet (rc, false); 1123 #ifdef VBOX_WITH_USBFILTER 1124 vrc = USBFilterSetNumExact (&dev, USBFILTERIDX_DEVICE, revision, true); AssertRC(vrc); 1125 #endif 1078 1126 1079 1127 Bstr manufacturer; 1080 1128 rc = aUSBDevice->COMGETTER(Manufacturer) (manufacturer.asOutParam()); 1081 1129 ComAssertComRCRet (rc, false); 1130 #ifdef VBOX_WITH_USBFILTER 1131 if (!manufacturer.isNull()) 1132 USBFilterSetStringExact (&dev, USBFILTERIDX_MANUFACTURER_STR, Utf8Str(manufacturer), true); 1133 #endif 1082 1134 1083 1135 Bstr product; 1084 1136 rc = aUSBDevice->COMGETTER(Product) (product.asOutParam()); 1085 1137 ComAssertComRCRet (rc, false); 1138 #ifdef VBOX_WITH_USBFILTER 1139 if (!product.isNull()) 1140 USBFilterSetStringExact (&dev, USBFILTERIDX_PRODUCT_STR, Utf8Str(product), true); 1141 #endif 1086 1142 1087 1143 Bstr serialNumber; 1088 1144 rc = aUSBDevice->COMGETTER(SerialNumber) (serialNumber.asOutParam()); 1089 1145 ComAssertComRCRet (rc, false); 1146 #ifdef VBOX_WITH_USBFILTER 1147 if (!serialNumber.isNull()) 1148 USBFilterSetStringExact (&dev, USBFILTERIDX_SERIAL_NUMBER_STR, Utf8Str(serialNumber), true); 1149 #endif 1090 1150 1091 1151 Bstr address; … … 1096 1156 rc = aUSBDevice->COMGETTER(Port)(&port); 1097 1157 ComAssertComRCRet (rc, false); 1158 #ifdef VBOX_WITH_USBFILTER 1159 USBFilterSetNumExact (&dev, USBFILTERIDX_PORT, port, true); 1160 #endif 1098 1161 1099 1162 BOOL remote = FALSE; … … 1112 1175 const USBDeviceFilter::Data &aData = (*it)->data(); 1113 1176 1177 1114 1178 if (!aData.mActive) 1115 1179 continue; 1180 if (!aData.mRemote.isMatch (remote)) 1181 continue; 1182 1183 #ifndef VBOX_WITH_USBFILTER 1116 1184 if (!aData.mVendorId.isMatch (vendorId)) 1117 1185 continue; … … 1133 1201 #endif 1134 1202 1135 if (!aData.mRemote.isMatch (remote)) 1203 #else /* VBOX_WITH_USBFILTER */ 1204 if (!USBFilterMatch (&aData.mUSBFilter, &dev)) 1136 1205 continue; 1206 #endif /* VBOX_WITH_USBFILTER */ 1137 1207 1138 1208 match = true; -
trunk/src/VBox/Main/USBDeviceFilterImpl.cpp
r3668 r3756 28 28 29 29 #include <iprt/cpputils.h> 30 31 #ifdef VBOX_WITH_USBFILTER 32 //////////////////////////////////////////////////////////////////////////////// 33 // Internal Helpers 34 //////////////////////////////////////////////////////////////////////////////// 35 36 /** 37 * Converts a USBFilter field into a string. 38 * 39 * (This function is also used by HostUSBDeviceFilter.) 40 * 41 * @param aFilter The filter. 42 * @param aIdx The field index. 43 * @param aStr The output string. 44 */ 45 static void usbFilterFieldToString (PCUSBFILTER aFilter, USBFILTERIDX aIdx, BSTR *aStr) 46 { 47 const USBFILTERMATCH matchingMethod = USBFilterGetMatchingMethod (aFilter, aIdx); 48 Assert (matchingMethod != USBFILTERMATCH_INVALID); 49 50 if (USBFilterIsMethodNumeric (matchingMethod)) 51 { 52 int value = USBFilterGetNum (aFilter, aIdx); 53 Assert(value >= 0 && value <= 0xffff); 54 55 char str[16]; 56 RTStrPrintf (str, sizeof(str), "%x", value); 57 Bstr ((const char *)str).cloneTo (aStr); 58 } 59 else if (USBFilterIsMethodString (matchingMethod)) 60 Bstr (USBFilterGetString (aFilter, aIdx)).cloneTo (aStr); 61 else 62 Bstr ().cloneTo (aStr); 63 } 64 65 /** 66 * Interprets a string and assigns it to a USBFilter field. 67 * 68 * (This function is also used by HostUSBDeviceFilter.) 69 * 70 * @param aFilter The filter. 71 * @param aIdx The field index. 72 * @param aStr The input string. 73 * @param aName The field name for use in the error string. 74 * @param aErrStr Where to return the error string on failure. 75 * 76 * @return COM status code. 77 * @remark The idea was to have this as a static function, but tr() doesn't wanna work without a class :-/ 78 */ 79 /*static*/ HRESULT 80 USBDeviceFilter::usbFilterFieldFromString (PUSBFILTER aFilter, USBFILTERIDX aIdx, INPTR BSTR aStr, const char *aName, Utf8Str &aErrStr) 81 { 82 int vrc; 83 Utf8Str str (aStr); 84 if (str.isNull()) 85 vrc = USBFilterSetIgnore (aFilter, aIdx); 86 else 87 { 88 const char *psz = str; 89 if (USBFilterIsNumericField (aIdx)) 90 { 91 /* Is it a lonely number? */ 92 char *pszNext; 93 uint64_t u64; 94 vrc = RTStrToUInt64Ex (psz, &pszNext, 16, &u64); 95 if (RT_SUCCESS(vrc)) 96 pszNext = RTStrStripL (pszNext); 97 if ( vrc == VINF_SUCCESS 98 && !*pszNext) 99 { 100 if (u64 > 0xffff) 101 { 102 aErrStr = Utf8StrFmt (tr ("The %s value '%s' is too big (max 0xFFFF)"), aName, str.raw()); 103 return E_INVALIDARG; 104 } 105 106 vrc = USBFilterSetNumExact (aFilter, aIdx, (uint16_t)u64, true /* fMustBePresent */); 107 } 108 else 109 vrc = USBFilterSetNumExpression (aFilter, aIdx, psz, true /* fMustBePresent */); 110 } 111 else 112 { 113 /* Any wildcard in the string? */ 114 Assert (USBFilterIsStringField (aIdx)); 115 if ( strchr (psz, '*') 116 || strchr (psz, '?') 117 /* || strchr (psz, '[') - later */ 118 ) 119 vrc = USBFilterSetStringPattern (aFilter, aIdx, psz, true /* fMustBePresent */); 120 else 121 vrc = USBFilterSetStringExact (aFilter, aIdx, psz, true /* fMustBePresent */); 122 } 123 } 124 125 if (RT_FAILURE(vrc)) 126 { 127 if (vrc == VERR_INVALID_PARAMETER) 128 { 129 aErrStr = Utf8StrFmt (tr ("The %s filter expression '%s' is not valid"), aName, str.raw()); 130 return E_INVALIDARG; 131 } 132 if (vrc == VERR_BUFFER_OVERFLOW) 133 { 134 aErrStr = Utf8StrFmt (tr ("Insufficient expression space for the '%s' filter expression '%s'"), aName, str.raw()); 135 return E_FAIL; 136 } 137 AssertRC (vrc); 138 aErrStr = Utf8StrFmt (tr ("Encountered unexpected status %Vrc when setting '%s' to '%s'"), vrc, aName, str.raw()); 139 return E_FAIL; 140 } 141 142 return S_OK; 143 } 144 #endif /* VBOX_WITH_USBFILTER */ 145 30 146 31 147 //////////////////////////////////////////////////////////////////////////////// … … 84 200 85 201 /* initialize all filters to any match using null string */ 202 #ifndef VBOX_WITH_USBFILTER 86 203 mData->mVendorId = NULL; 87 204 mData->mProductId = NULL; … … 91 208 mData->mSerialNumber = NULL; 92 209 mData->mPort = NULL; 210 #else /* VBOX_WITH_USBFILTER */ 211 USBFilterInit(&mData->mUSBFilter, USBFILTERTYPE_CAPTURE); 212 #endif /* VBOX_WITH_USBFILTER */ 93 213 mData->mRemote = NULL; 94 214 … … 155 275 156 276 /* initialize all filters to any match using null string */ 277 #ifndef VBOX_WITH_USBFILTER 157 278 mData->mVendorId = NULL; 158 279 mData->mProductId = NULL; … … 162 283 mData->mSerialNumber = NULL; 163 284 mData->mPort = NULL; 285 #else /* VBOX_WITH_USBFILTER */ 286 USBFilterInit (&mData->mUSBFilter, USBFILTERTYPE_CAPTURE); 287 #endif /* VBOX_WITH_USBFILTER */ 164 288 mData->mRemote = NULL; 165 289 … … 391 515 STDMETHODIMP USBDeviceFilter::COMGETTER(VendorId) (BSTR *aVendorId) 392 516 { 517 #ifndef VBOX_WITH_USBFILTER 393 518 if (!aVendorId) 394 519 return E_POINTER; … … 402 527 403 528 return S_OK; 529 #else 530 return usbFilterFieldGetter (USBFILTERIDX_VENDOR_ID, aVendorId); 531 #endif 404 532 } 405 533 406 534 STDMETHODIMP USBDeviceFilter::COMSETTER(VendorId) (INPTR BSTR aVendorId) 407 535 { 536 #ifndef VBOX_WITH_USBFILTER 408 537 AutoCaller autoCaller (this); 409 538 CheckComRCReturnRC (autoCaller.rc()); … … 441 570 442 571 return S_OK; 572 #else /* VBOX_WITH_USBFILTER */ 573 return usbFilterFieldSetter (USBFILTERIDX_VENDOR_ID, aVendorId, tr ("Vendor ID")); 574 #endif /* VBOX_WITH_USBFILTER */ 443 575 } 444 576 445 577 STDMETHODIMP USBDeviceFilter::COMGETTER(ProductId) (BSTR *aProductId) 446 578 { 579 #ifndef VBOX_WITH_USBFILTER 447 580 if (!aProductId) 448 581 return E_POINTER; … … 456 589 457 590 return S_OK; 591 #else 592 return usbFilterFieldGetter (USBFILTERIDX_PRODUCT_ID, aProductId); 593 #endif 458 594 } 459 595 460 596 STDMETHODIMP USBDeviceFilter::COMSETTER(ProductId) (INPTR BSTR aProductId) 461 597 { 598 #ifndef VBOX_WITH_USBFILTER 462 599 AutoCaller autoCaller (this); 463 600 CheckComRCReturnRC (autoCaller.rc()); … … 495 632 496 633 return S_OK; 497 } 634 #else /* VBOX_WITH_USBFILTER */ 635 return usbFilterFieldSetter (USBFILTERIDX_PRODUCT_ID, aProductId, tr ("Product ID")); 636 #endif /* VBOX_WITH_USBFILTER */ 637 } 498 638 499 639 STDMETHODIMP USBDeviceFilter::COMGETTER(Revision) (BSTR *aRevision) 500 640 { 641 #ifndef VBOX_WITH_USBFILTER 501 642 if (!aRevision) 502 643 return E_POINTER; … … 510 651 511 652 return S_OK; 653 #else 654 return usbFilterFieldGetter (USBFILTERIDX_DEVICE, aRevision); 655 #endif 512 656 } 513 657 514 658 STDMETHODIMP USBDeviceFilter::COMSETTER(Revision) (INPTR BSTR aRevision) 515 659 { 660 #ifndef VBOX_WITH_USBFILTER 516 661 AutoCaller autoCaller (this); 517 662 CheckComRCReturnRC (autoCaller.rc()); … … 549 694 550 695 return S_OK; 696 #else /* VBOX_WITH_USBFILTER */ 697 return usbFilterFieldSetter (USBFILTERIDX_DEVICE, aRevision, tr ("Revision")); 698 #endif /* VBOX_WITH_USBFILTER */ 551 699 } 552 700 553 701 STDMETHODIMP USBDeviceFilter::COMGETTER(Manufacturer) (BSTR *aManufacturer) 554 702 { 703 #ifndef VBOX_WITH_USBFILTER 555 704 if (!aManufacturer) 556 705 return E_POINTER; … … 562 711 563 712 mData->mManufacturer.string().cloneTo (aManufacturer); 564 return S_OK; 713 714 return S_OK; 715 #else 716 return usbFilterFieldGetter (USBFILTERIDX_MANUFACTURER_STR, aManufacturer); 717 #endif 565 718 } 566 719 567 720 STDMETHODIMP USBDeviceFilter::COMSETTER(Manufacturer) (INPTR BSTR aManufacturer) 568 721 { 722 #ifndef VBOX_WITH_USBFILTER 569 723 AutoCaller autoCaller (this); 570 724 CheckComRCReturnRC (autoCaller.rc()); … … 595 749 596 750 return S_OK; 751 #else /* VBOX_WITH_USBFILTER */ 752 return usbFilterFieldSetter (USBFILTERIDX_MANUFACTURER_STR, aManufacturer, tr ("Manufacturer")); 753 #endif /* VBOX_WITH_USBFILTER */ 597 754 } 598 755 599 756 STDMETHODIMP USBDeviceFilter::COMGETTER(Product) (BSTR *aProduct) 600 757 { 758 #ifndef VBOX_WITH_USBFILTER 601 759 if (!aProduct) 602 760 return E_POINTER; … … 610 768 611 769 return S_OK; 770 #else 771 return usbFilterFieldGetter (USBFILTERIDX_PRODUCT_STR, aProduct); 772 #endif 612 773 } 613 774 614 775 STDMETHODIMP USBDeviceFilter::COMSETTER(Product) (INPTR BSTR aProduct) 615 776 { 777 #ifndef VBOX_WITH_USBFILTER 616 778 AutoCaller autoCaller (this); 617 779 CheckComRCReturnRC (autoCaller.rc()); … … 642 804 643 805 return S_OK; 806 #else /* VBOX_WITH_USBFILTER */ 807 return usbFilterFieldSetter (USBFILTERIDX_PRODUCT_STR, aProduct, tr ("Product")); 808 #endif /* VBOX_WITH_USBFILTER */ 644 809 } 645 810 646 811 STDMETHODIMP USBDeviceFilter::COMGETTER(SerialNumber) (BSTR *aSerialNumber) 647 812 { 813 #ifndef VBOX_WITH_USBFILTER 648 814 if (!aSerialNumber) 649 815 return E_POINTER; … … 657 823 658 824 return S_OK; 825 #else 826 return usbFilterFieldGetter (USBFILTERIDX_SERIAL_NUMBER_STR, aSerialNumber); 827 #endif 659 828 } 660 829 661 830 STDMETHODIMP USBDeviceFilter::COMSETTER(SerialNumber) (INPTR BSTR aSerialNumber) 662 831 { 832 #ifndef VBOX_WITH_USBFILTER 663 833 AutoCaller autoCaller (this); 664 834 CheckComRCReturnRC (autoCaller.rc()); … … 689 859 690 860 return S_OK; 861 #else /* VBOX_WITH_USBFILTER */ 862 return usbFilterFieldSetter (USBFILTERIDX_SERIAL_NUMBER_STR, aSerialNumber, tr ("Serial number")); 863 #endif /* VBOX_WITH_USBFILTER */ 691 864 } 692 865 693 866 STDMETHODIMP USBDeviceFilter::COMGETTER(Port) (BSTR *aPort) 694 867 { 868 #ifndef VBOX_WITH_USBFILTER 695 869 if (!aPort) 696 870 return E_POINTER; … … 704 878 705 879 return S_OK; 880 #else 881 return usbFilterFieldGetter (USBFILTERIDX_PORT, aPort); 882 #endif 706 883 } 707 884 708 885 STDMETHODIMP USBDeviceFilter::COMSETTER(Port) (INPTR BSTR aPort) 709 886 { 887 #ifndef VBOX_WITH_USBFILTER 710 888 AutoCaller autoCaller (this); 711 889 CheckComRCReturnRC (autoCaller.rc()); … … 743 921 744 922 return S_OK; 923 #else /* VBOX_WITH_USBFILTER */ 924 return usbFilterFieldSetter (USBFILTERIDX_PORT, aPort, tr ("Port number")); 925 #endif /* VBOX_WITH_USBFILTER */ 745 926 } 746 927 … … 795 976 //////////////////////////////////////////////////////////////////////////////// 796 977 797 /** 978 /** 798 979 * @note Locks this object for writing. 799 980 */ … … 819 1000 } 820 1001 821 /** 1002 /** 822 1003 * @note Locks this object for writing, together with the peer object (also 823 1004 * for writing) if there is one. … … 863 1044 AutoCaller thatCaller (mPeer); 864 1045 AssertComRCReturnVoid (thatCaller.rc()); 865 1046 866 1047 /* peer is not modified, lock it for reading */ 867 1048 AutoMultiLock <2> alock (this->wlock(), AutoLock::maybeRlock (mPeer)); 868 1049 869 1050 if (mData.isShared()) 870 1051 { … … 878 1059 unconst (mPeer).setNull(); 879 1060 } 1061 1062 #ifdef VBOX_WITH_USBFILTER 1063 /** 1064 * Generic USB filter field getter. 1065 * 1066 * @param aIdx The field index. 1067 * @param aStr Where to store the value. 1068 * 1069 * @return COM status. 1070 */ 1071 HRESULT USBDeviceFilter::usbFilterFieldGetter (USBFILTERIDX aIdx, BSTR *aStr) 1072 { 1073 if (!aStr) 1074 return E_POINTER; 1075 1076 AutoCaller autoCaller (this); 1077 CheckComRCReturnRC (autoCaller.rc()); 1078 1079 AutoReaderLock alock (this); 1080 1081 usbFilterFieldToString (&mData->mUSBFilter, aIdx, aStr); 1082 1083 return S_OK; 1084 } 1085 1086 /** 1087 * Generic USB filter field setter. 1088 * 1089 * @param aIdx The field index. 1090 * @param aStr The new value. 1091 * @param aName The translated field name (for error messages). 1092 * 1093 * @return COM status. 1094 */ 1095 HRESULT USBDeviceFilter::usbFilterFieldSetter (USBFILTERIDX aIdx, Bstr aStr, Utf8Str aName) 1096 { 1097 AutoCaller autoCaller (this); 1098 CheckComRCReturnRC (autoCaller.rc()); 1099 1100 /* the machine needs to be mutable */ 1101 Machine::AutoMutableStateDependency adep (mParent->parent()); 1102 CheckComRCReturnRC (adep.rc()); 1103 1104 AutoLock alock (this); 1105 1106 Bstr old; 1107 usbFilterFieldToString (&mData->mUSBFilter, aIdx, old.asOutParam()); 1108 if (old != aStr) 1109 { 1110 mData.backup(); 1111 1112 Utf8Str errStr; 1113 HRESULT rc = usbFilterFieldFromString (&mData->mUSBFilter, aIdx, aStr, aName, errStr); 1114 if (FAILED (rc)) 1115 { 1116 mData.rollback(); 1117 return setError (rc, "%s", errStr.raw()); 1118 } 1119 1120 /* leave the lock before informing callbacks */ 1121 alock.unlock(); 1122 1123 return mParent->onDeviceFilterChange (this); 1124 } 1125 1126 return S_OK; 1127 } 1128 #endif /* VBOX_WITH_USBFILTER */ 880 1129 881 1130 //////////////////////////////////////////////////////////////////////////////// … … 932 1181 mData->mName = aName; 933 1182 mData->mActive = aActive; 1183 #ifndef VBOX_WITH_USBFILTER 934 1184 mData->mAction = aAction; 935 1185 … … 942 1192 mData->mSerialNumber = NULL; 943 1193 mData->mPort = NULL; 1194 #else /* VBOX_WITH_USBFILTER */ 1195 USBFilterInit (&mData->mUSBFilter, USBFILTERTYPE_IGNORE); 1196 #endif /* VBOX_WITH_USBFILTER */ 944 1197 mData->mRemote = NULL; 945 1198 … … 952 1205 do 953 1206 { 1207 #ifndef VBOX_WITH_USBFILTER 1208 rc = COMSETTER(Action) (aAction); 1209 CheckComRCBreakRC (rc); 1210 #endif /* VBOX_WITH_USBFILTER */ 954 1211 rc = COMSETTER(VendorId) (aVendorId); 955 1212 CheckComRCBreakRC (rc); … … 1001 1258 mData->mName = aName; 1002 1259 mData->mActive = FALSE; 1260 #ifndef VBOX_WITH_USBFILTER 1003 1261 mData->mAction = USBDeviceFilterAction_USBDeviceFilterIgnore; 1262 #endif /* !VBOX_WITH_USBFILTER */ 1004 1263 1005 1264 mInList = false; 1006 1265 1266 #ifndef VBOX_WITH_USBFILTER 1007 1267 /* initialize all filters to any match using null string */ 1008 1268 mData->mVendorId = NULL; … … 1013 1273 mData->mSerialNumber = NULL; 1014 1274 mData->mPort = NULL; 1275 #else /* VBOX_WITH_USBFILTER */ 1276 USBFilterInit (&mData->mUSBFilter, USBFILTERTYPE_IGNORE); 1277 #endif /* VBOX_WITH_USBFILTER */ 1015 1278 mData->mRemote = NULL; 1016 1279 … … 1121 1384 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(VendorId) (BSTR *aVendorId) 1122 1385 { 1386 #ifndef VBOX_WITH_USBFILTER 1123 1387 if (!aVendorId) 1124 1388 return E_POINTER; … … 1132 1396 1133 1397 return S_OK; 1398 #else 1399 return usbFilterFieldGetter (USBFILTERIDX_VENDOR_ID, aVendorId); 1400 #endif 1134 1401 } 1135 1402 1136 1403 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(VendorId) (INPTR BSTR aVendorId) 1137 1404 { 1405 #ifndef VBOX_WITH_USBFILTER 1138 1406 AutoCaller autoCaller (this); 1139 1407 CheckComRCReturnRC (autoCaller.rc()); … … 1166 1434 1167 1435 return S_OK; 1436 #else /* VBOX_WITH_USBFILTER */ 1437 return usbFilterFieldSetter (USBFILTERIDX_VENDOR_ID, aVendorId, tr ("Vendor ID")); 1438 #endif /* VBOX_WITH_USBFILTER */ 1168 1439 } 1169 1440 1170 1441 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(ProductId) (BSTR *aProductId) 1171 1442 { 1443 #ifndef VBOX_WITH_USBFILTER 1172 1444 if (!aProductId) 1173 1445 return E_POINTER; … … 1181 1453 1182 1454 return S_OK; 1455 #else 1456 return usbFilterFieldGetter (USBFILTERIDX_PRODUCT_ID, aProductId); 1457 #endif 1183 1458 } 1184 1459 1185 1460 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(ProductId) (INPTR BSTR aProductId) 1186 1461 { 1462 #ifndef VBOX_WITH_USBFILTER 1187 1463 AutoCaller autoCaller (this); 1188 1464 CheckComRCReturnRC (autoCaller.rc()); … … 1215 1491 1216 1492 return S_OK; 1493 #else /* VBOX_WITH_USBFILTER */ 1494 return usbFilterFieldSetter (USBFILTERIDX_PRODUCT_ID, aProductId, tr ("Product ID")); 1495 #endif /* VBOX_WITH_USBFILTER */ 1217 1496 } 1218 1497 1219 1498 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(Revision) (BSTR *aRevision) 1220 1499 { 1500 #ifndef VBOX_WITH_USBFILTER 1221 1501 if (!aRevision) 1222 1502 return E_POINTER; … … 1230 1510 1231 1511 return S_OK; 1512 #else 1513 return usbFilterFieldGetter (USBFILTERIDX_DEVICE, aRevision); 1514 #endif 1232 1515 } 1233 1516 1234 1517 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Revision) (INPTR BSTR aRevision) 1235 1518 { 1519 #ifndef VBOX_WITH_USBFILTER 1236 1520 AutoCaller autoCaller (this); 1237 1521 CheckComRCReturnRC (autoCaller.rc()); … … 1264 1548 1265 1549 return S_OK; 1550 #else /* VBOX_WITH_USBFILTER */ 1551 return usbFilterFieldSetter (USBFILTERIDX_DEVICE, aRevision, tr ("Revision")); 1552 #endif /* VBOX_WITH_USBFILTER */ 1266 1553 } 1267 1554 1268 1555 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(Manufacturer) (BSTR *aManufacturer) 1269 1556 { 1557 #ifndef VBOX_WITH_USBFILTER 1270 1558 if (!aManufacturer) 1271 1559 return E_POINTER; … … 1279 1567 1280 1568 return S_OK; 1569 #else 1570 return usbFilterFieldGetter (USBFILTERIDX_MANUFACTURER_STR, aManufacturer); 1571 #endif 1281 1572 } 1282 1573 1283 1574 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Manufacturer) (INPTR BSTR aManufacturer) 1284 1575 { 1576 #ifndef VBOX_WITH_USBFILTER 1285 1577 AutoCaller autoCaller (this); 1286 1578 CheckComRCReturnRC (autoCaller.rc()); … … 1306 1598 1307 1599 return S_OK; 1600 #else /* VBOX_WITH_USBFILTER */ 1601 return usbFilterFieldSetter (USBFILTERIDX_MANUFACTURER_STR, aManufacturer, tr ("Manufacturer")); 1602 #endif /* VBOX_WITH_USBFILTER */ 1308 1603 } 1309 1604 1310 1605 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(Product) (BSTR *aProduct) 1311 1606 { 1607 #ifndef VBOX_WITH_USBFILTER 1312 1608 if (!aProduct) 1313 1609 return E_POINTER; … … 1321 1617 1322 1618 return S_OK; 1619 #else 1620 return usbFilterFieldGetter (USBFILTERIDX_PRODUCT_STR, aProduct); 1621 #endif 1323 1622 } 1324 1623 1325 1624 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Product) (INPTR BSTR aProduct) 1326 1625 { 1626 #ifndef VBOX_WITH_USBFILTER 1327 1627 AutoCaller autoCaller (this); 1328 1628 CheckComRCReturnRC (autoCaller.rc()); … … 1348 1648 1349 1649 return S_OK; 1650 #else /* VBOX_WITH_USBFILTER */ 1651 return usbFilterFieldSetter (USBFILTERIDX_PRODUCT_STR, aProduct, tr ("Product")); 1652 #endif /* VBOX_WITH_USBFILTER */ 1350 1653 } 1351 1654 1352 1655 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(SerialNumber) (BSTR *aSerialNumber) 1353 1656 { 1657 #ifndef VBOX_WITH_USBFILTER 1354 1658 if (!aSerialNumber) 1355 1659 return E_POINTER; … … 1363 1667 1364 1668 return S_OK; 1669 #else /* VBOX_WITH_USBFILTER */ 1670 return usbFilterFieldGetter (USBFILTERIDX_SERIAL_NUMBER_STR, aSerialNumber); 1671 #endif /* VBOX_WITH_USBFILTER */ 1365 1672 } 1366 1673 1367 1674 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(SerialNumber) (INPTR BSTR aSerialNumber) 1368 1675 { 1676 #ifndef VBOX_WITH_USBFILTER 1369 1677 AutoCaller autoCaller (this); 1370 1678 CheckComRCReturnRC (autoCaller.rc()); … … 1390 1698 1391 1699 return S_OK; 1700 #else /* VBOX_WITH_USBFILTER */ 1701 return usbFilterFieldSetter (USBFILTERIDX_SERIAL_NUMBER_STR, aSerialNumber, tr ("Serial number")); 1702 #endif /* VBOX_WITH_USBFILTER */ 1392 1703 } 1393 1704 1394 1705 STDMETHODIMP HostUSBDeviceFilter::COMGETTER(Port) (BSTR *aPort) 1395 1706 { 1707 #ifndef VBOX_WITH_USBFILTER 1396 1708 if (!aPort) 1397 1709 return E_POINTER; … … 1405 1717 1406 1718 return S_OK; 1719 #else /* VBOX_WITH_USBFILTER */ 1720 return usbFilterFieldGetter (USBFILTERIDX_PORT, aPort); 1721 #endif /* VBOX_WITH_USBFILTER */ 1407 1722 } 1408 1723 1409 1724 STDMETHODIMP HostUSBDeviceFilter::COMSETTER(Port) (INPTR BSTR aPort) 1410 1725 { 1726 #ifndef VBOX_WITH_USBFILTER 1411 1727 AutoCaller autoCaller (this); 1412 1728 CheckComRCReturnRC (autoCaller.rc()); … … 1439 1755 1440 1756 return S_OK; 1757 #else /* VBOX_WITH_USBFILTER */ 1758 return usbFilterFieldSetter (USBFILTERIDX_PORT, aPort, tr ("Port number")); 1759 #endif /* VBOX_WITH_USBFILTER */ 1441 1760 } 1442 1761 … … 1476 1795 AutoReaderLock alock (this); 1477 1796 1797 #ifndef VBOX_WITH_USBFILTER 1478 1798 *aAction = mData->mAction; 1799 #else /* VBOX_WITH_USBFILTER */ 1800 switch (USBFilterGetFilterType (&mData->mUSBFilter)) 1801 { 1802 case USBFILTERTYPE_IGNORE: *aAction = USBDeviceFilterAction_USBDeviceFilterIgnore; break; 1803 case USBFILTERTYPE_CAPTURE: *aAction = USBDeviceFilterAction_USBDeviceFilterHold; break; 1804 default: *aAction = USBDeviceFilterAction_InvalidUSBDeviceFilterAction; break; 1805 } 1806 #endif /* VBOX_WITH_USBFILTER */ 1479 1807 1480 1808 return S_OK; … … 1488 1816 AutoLock alock (this); 1489 1817 1818 #ifndef VBOX_WITH_USBFILTER 1490 1819 if (mData->mAction != aAction) 1491 1820 { … … 1498 1827 } 1499 1828 1500 return S_OK; 1501 } 1502 1829 #else /* VBOX_WITH_USBFILTER */ 1830 USBFILTERTYPE filterType; 1831 switch (aAction) 1832 { 1833 case USBDeviceFilterAction_USBDeviceFilterIgnore: filterType = USBFILTERTYPE_IGNORE; break; 1834 case USBDeviceFilterAction_USBDeviceFilterHold: filterType = USBFILTERTYPE_CAPTURE; break; 1835 case USBDeviceFilterAction_InvalidUSBDeviceFilterAction: 1836 return setError (E_INVALIDARG, 1837 tr ("Action value InvalidUSBDeviceFilterAction is not permitted")); 1838 default: 1839 return setError (E_INVALIDARG, 1840 tr ("Invalid action %d"), 1841 aAction); 1842 } 1843 if (USBFilterGetFilterType (&mData->mUSBFilter) != filterType) 1844 { 1845 int vrc = USBFilterSetFilterType (&mData->mUSBFilter, filterType); 1846 if (RT_FAILURE (vrc)) 1847 return setError (E_INVALIDARG, 1848 tr ("Unexpected error %Vrc"), 1849 vrc); 1850 1851 /* leave the lock before informing callbacks */ 1852 alock.unlock(); 1853 1854 return mParent->onUSBDeviceFilterChange (this); 1855 } 1856 #endif /* VBOX_WITH_USBFILTER */ 1857 1858 return S_OK; 1859 } 1860 1861 1862 #ifdef VBOX_WITH_USBFILTER 1863 /** 1864 * Generic USB filter field getter. 1865 * 1866 * @param aIdx The field index. 1867 * @param aStr Where to store the value. 1868 * 1869 * @return COM status. 1870 */ 1871 HRESULT HostUSBDeviceFilter::usbFilterFieldGetter (USBFILTERIDX aIdx, BSTR *aStr) 1872 { 1873 if (!aStr) 1874 return E_POINTER; 1875 1876 AutoCaller autoCaller (this); 1877 CheckComRCReturnRC (autoCaller.rc()); 1878 1879 AutoReaderLock alock (this); 1880 1881 usbFilterFieldToString (&mData->mUSBFilter, aIdx, aStr); 1882 1883 return S_OK; 1884 } 1885 1886 1887 /** 1888 * Generic USB filter field setter. 1889 * 1890 * @param aIdx The field index. 1891 * @param aStr The new value. 1892 * @param aName The translated field name (for error messages). 1893 * 1894 * @return COM status. 1895 */ 1896 HRESULT HostUSBDeviceFilter::usbFilterFieldSetter (USBFILTERIDX aIdx, Bstr aStr, Utf8Str aName) 1897 { 1898 AutoCaller autoCaller (this); 1899 CheckComRCReturnRC (autoCaller.rc()); 1900 1901 AutoLock alock (this); 1902 1903 Bstr old; 1904 usbFilterFieldToString (&mData->mUSBFilter, aIdx, old.asOutParam()); 1905 if (old != aStr) 1906 { 1907 //mData.backup(); 1908 1909 Utf8Str errStr; 1910 HRESULT rc = USBDeviceFilter::usbFilterFieldFromString (&mData->mUSBFilter, aIdx, aStr, aName, errStr); 1911 if (FAILED (rc)) 1912 { 1913 //mData.rollback(); 1914 return setError (rc, "%s", errStr.raw()); 1915 } 1916 1917 /* leave the lock before informing callbacks */ 1918 alock.unlock(); 1919 1920 return mParent->onUSBDeviceFilterChange (this); 1921 } 1922 1923 return S_OK; 1924 } 1925 #endif /* VBOX_WITH_USBFILTER */ 1926 -
trunk/src/VBox/Main/include/USBDeviceFilterImpl.h
r3412 r3756 28 28 29 29 #include "Matching.h" 30 #ifdef VBOX_WITH_USBFILTER 31 # include <VBox/usbfilter.h> 32 #endif /* VBOX_WITH_USBFILTER */ 30 33 31 34 class USBController; … … 45 48 struct Data 46 49 { 50 #ifndef VBOX_WITH_USBFILTER 47 51 struct ConvForRegexp 48 52 { … … 65 69 typedef matching::Matchable 66 70 <matching::ParsedRegexpFilter <ConvForRegexp, false> > BstrFilter; 71 #endif /* VBOX_WITH_USBFILTER */ 67 72 68 73 typedef matching::Matchable <matching::ParsedBoolFilter> BOOLFilter; 69 74 70 75 Data() : mActive (FALSE), mId (NULL) {} 76 #ifdef VBOX_WITH_USBFILTER 77 Data (const Data &aThat) : mName (aThat.mName), mActive (aThat.mActive), 78 mRemote (aThat.mRemote), mId (NULL) 79 { 80 USBFilterClone (&mUSBFilter, &aThat.mUSBFilter); 81 } 82 #endif /* VBOX_WITH_USBFILTER */ 71 83 72 84 bool operator== (const Data &that) const 73 85 { 86 #ifndef VBOX_WITH_USBFILTER 74 87 return this == &that || 75 88 (mName == that.mName && … … 83 96 mPort.string() == that. mPort.string() && 84 97 mRemote.string() == that. mRemote.string()); 98 #else /* VBOX_WITH_USBFILTER */ 99 return this == &that 100 || ( mName == that.mName 101 && mActive == that.mActive 102 && USBFilterIsIdentical (&mUSBFilter, &that.mUSBFilter)); 103 #endif /* VBOX_WITH_USBFILTER */ 85 104 } 86 105 … … 88 107 BOOL mActive; 89 108 109 #ifndef VBOX_WITH_USBFILTER 90 110 USHORTFilter mVendorId; 91 111 USHORTFilter mProductId; … … 95 115 BstrFilter mSerialNumber; 96 116 USHORTFilter mPort; 117 #else /* VBOX_WITH_USBFILTER */ 118 USBFILTER mUSBFilter; 119 #endif /* VBOX_WITH_USBFILTER */ 97 120 BOOLFilter mRemote; 98 121 … … 175 198 static const wchar_t *getComponentName() { return L"USBDeviceFilter"; } 176 199 200 #ifdef VBOX_WITH_USBFILTER 201 // tr() wants to belong to a class it seems, thus this one here. 202 static HRESULT usbFilterFieldFromString (PUSBFILTER aFilter, USBFILTERIDX aIdx, INPTR BSTR aStr, const char *aName, Utf8Str &aErrStr); 203 #endif 204 177 205 private: 206 #ifdef VBOX_WITH_USBFILTER 207 HRESULT usbFilterFieldGetter (USBFILTERIDX aIdx, BSTR *aStr); 208 HRESULT usbFilterFieldSetter (USBFILTERIDX aIdx, Bstr aStr, Utf8Str aName); 209 #endif 178 210 179 211 const ComObjPtr <USBController, ComWeakRef> mParent; … … 202 234 struct Data : public USBDeviceFilter::Data 203 235 { 236 #ifndef VBOX_WITH_USBFILTER 204 237 Data() : mAction (USBDeviceFilterAction_USBDeviceFilterIgnore) {} 205 206 238 USBDeviceFilterAction_T mAction; 239 #else /* VBOX_WITH_USBFILTER */ 240 Data() {} 241 #endif /* VBOX_WITH_USBFILTER */ 207 242 }; 208 243 … … 277 312 278 313 private: 314 #ifdef VBOX_WITH_USBFILTER 315 HRESULT usbFilterFieldGetter (USBFILTERIDX aIdx, BSTR *aStr); 316 HRESULT usbFilterFieldSetter (USBFILTERIDX aIdx, Bstr aStr, Utf8Str aName); 317 #endif 279 318 280 319 const ComObjPtr <Host, ComWeakRef> mParent;
Note:
See TracChangeset
for help on using the changeset viewer.