(&self)
| 71 | } |
| 72 | |
| 73 | fn enumerate_rules(&self) -> Result<Vec<INetFwRule>, FirewallError> { |
| 74 | let enumerator = unsafe { self.rules._NewEnum() } |
| 75 | .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?; |
| 76 | let enum_variant: IEnumVARIANT = enumerator |
| 77 | .cast() |
| 78 | .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?; |
| 79 | |
| 80 | let mut results = Vec::new(); |
| 81 | loop { |
| 82 | let mut fetched = 0u32; |
| 83 | let mut safe_variant = SafeVariant::new(); |
| 84 | let hr = unsafe { enum_variant.Next(std::slice::from_mut(safe_variant.as_mut()), &mut fetched) }; |
| 85 | if hr == S_FALSE || fetched == 0 { |
| 86 | break; |
| 87 | } |
| 88 | hr.ok() |
| 89 | .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?; |
| 90 | |
| 91 | let dispatch = IDispatch::try_from(safe_variant.as_ref()) |
| 92 | .map_err(|error: windows::core::Error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?; |
| 93 | let rule: INetFwRule = dispatch |
| 94 | .cast() |
| 95 | .map_err(|error| t!("firewall.ruleEnumerationFailed", error = error.to_string()).to_string())?; |
| 96 | results.push(rule); |
| 97 | |
| 98 | // SafeVariant will automatically call VariantClear when it goes out of scope |
| 99 | } |
| 100 | |
| 101 | Ok(results) |
| 102 | } |
| 103 | |
| 104 | fn find_by_selector(&self, selector: &FirewallRule) -> Result<Option<INetFwRule>, FirewallError> { |
| 105 | // HRESULT 0x80070002 is HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), returned when the |
no test coverage detected