endpoint_sec/event/
event_od_attribute_value_remove.rs

1//! [`EventOdAttributeValueRemove`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_event_od_attribute_value_remove_t, es_od_record_type_t};
6
7use crate::Process;
8
9/// Notification that an attribute value was removed to a record.
10///
11/// Attributes conceptually have the type `Map String (Set String)`.
12/// Each OD record has a Map of attribute name to Set of attribute value.
13/// When an attribute value is removed, it is inserted into the set of values for that name.
14///
15/// Removing a value that was never added is a no-op.
16#[doc(alias = "es_event_od_attribute_value_remove_t")]
17pub struct EventOdAttributeValueRemove<'a> {
18    /// The raw reference.
19    pub(crate) raw: &'a es_event_od_attribute_value_remove_t,
20    /// The version of the message.
21    pub(crate) version: u32,
22}
23
24impl<'a> EventOdAttributeValueRemove<'a> {
25    /// Process that instigated operation (XPC caller).
26    #[inline(always)]
27    pub fn instigator(&self) -> Process<'a> {
28        // Safety: 'a tied to self, object obtained through ES
29        Process::new(unsafe { self.raw.instigator.as_ref() }, self.version)
30    }
31
32    /// Result code for the operation.
33    #[inline(always)]
34    pub fn error_code(&self) -> i32 {
35        self.raw.error_code
36    }
37    /// The type of the record to which the attribute value was removed.
38    #[inline(always)]
39    pub fn record_type(&self) -> es_od_record_type_t {
40        self.raw.record_type
41    }
42
43    /// The name of the record to which the attribute value was removed.
44    #[inline(always)]
45    pub fn record_name(&self) -> &'a OsStr {
46        // Safety: 'a tied to self, object obtained through ES
47        unsafe { self.raw.record_name.as_os_str() }
48    }
49
50    /// The name of the attribute to which the value was removed.
51    #[inline(always)]
52    pub fn attribute_name(&self) -> &'a OsStr {
53        // Safety: 'a tied to self, object obtained through ES
54        unsafe { self.raw.attribute_name.as_os_str() }
55    }
56
57    /// The value that was removed.
58    #[inline(always)]
59    pub fn attribute_value(&self) -> &'a OsStr {
60        // Safety: 'a tied to self, object obtained through ES
61        unsafe { self.raw.attribute_value.as_os_str() }
62    }
63
64    /// OD node being mutated.
65    ///
66    /// Typically one of "/Local/Default", "/LDAPv3/<server>" or "/Active Directory/<domain>".
67    #[inline(always)]
68    pub fn node_name(&self) -> &'a OsStr {
69        // Safety: 'a tied to self, object obtained through ES
70        unsafe { self.raw.node_name.as_os_str() }
71    }
72
73    /// Optional. If node_name is "/Local/Default", this is, the path of the database against which
74    /// OD is authenticating.
75    #[inline(always)]
76    pub fn db_path(&self) -> Option<&'a OsStr> {
77        if self.node_name() == OsStr::new("/Local/Default") {
78            // Safety: 'a tied to self, object obtained through ES
79            Some(unsafe { self.raw.db_path.as_os_str() })
80        } else {
81            None
82        }
83    }
84}
85
86// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
87unsafe impl Send for EventOdAttributeValueRemove<'_> {}
88// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
89unsafe impl Sync for EventOdAttributeValueRemove<'_> {}
90
91impl_debug_eq_hash_with_functions!(EventOdAttributeValueRemove<'a> with version; instigator, error_code, record_type, record_name, attribute_name, attribute_value, node_name, db_path);