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