endpoint_sec/event/
event_screesharing_attach.rs

1//! [`EventScreensharingAttach`]
2
3use std::ffi::OsStr;
4use std::net::IpAddr;
5use std::str::FromStr;
6
7use endpoint_sec_sys::{es_address_type_t, es_event_screensharing_attach_t, es_graphical_session_id_t};
8
9/// Screen Sharing has attached from a graphical session..
10#[doc(alias = "es_event_screensharing_attach_t")]
11pub struct EventScreensharingAttach<'a> {
12    /// Raw event
13    pub(crate) raw: &'a es_event_screensharing_attach_t,
14}
15
16impl<'a> EventScreensharingAttach<'a> {
17    /// True iff remediation was successful.
18    #[inline(always)]
19    pub fn success(&self) -> bool {
20        self.raw.success
21    }
22
23    /// Type of source address.
24    #[inline(always)]
25    pub fn source_address_type(&self) -> es_address_type_t {
26        self.raw.source_address_type
27    }
28
29    /// Optional. Source address of connection, or empty. Depending on the transport used, the
30    /// source address may or may not be available.
31    #[inline(always)]
32    pub fn source_address(&self) -> &'a OsStr {
33        // Safety: 'a tied to self, object obtained through ES
34        unsafe { self.raw.source_address.as_os_str() }
35    }
36
37    /// Optional. For screen sharing initiated using an Apple ID (e.g., from Messages or FaceTime),
38    /// this is the viewer's (client's) Apple ID. It is not necessarily the Apple ID that invited
39    /// the screen sharing. Empty if unavailable.
40    #[inline(always)]
41    pub fn viewer_appleid(&self) -> &'a OsStr {
42        // Safety: 'a tied to self, object obtained through ES
43        unsafe { self.raw.viewer_appleid.as_os_str() }
44    }
45
46    /// Type of authentication.
47    #[inline(always)]
48    pub fn authentication_type(&self) -> &'a OsStr {
49        // Safety: 'a tied to self, object obtained through ES
50        unsafe { self.raw.authentication_type.as_os_str() }
51    }
52
53    /// Optional. Username used for authentication to Screen Sharing. `NULL` if authentication type
54    /// doesn't use an username (e.g. simple VNC password).
55    #[inline(always)]
56    pub fn authentication_username(&self) -> &'a OsStr {
57        // Safety: 'a tied to self, object obtained through ES
58        unsafe { self.raw.authentication_username.as_os_str() }
59    }
60
61    /// Optional. Username of the loginwindow session if available, `NULL` otherwise.
62    #[inline(always)]
63    pub fn session_username(&self) -> &'a OsStr {
64        // Safety: 'a tied to self, object obtained through ES
65        unsafe { self.raw.session_username.as_os_str() }
66    }
67
68    /// True iff there was an existing user session.
69    #[inline(always)]
70    pub fn existing_session(&self) -> bool {
71        self.raw.existing_session
72    }
73
74    /// Graphical session id of the screen shared.
75    #[inline(always)]
76    pub fn graphical_session_id(&self) -> es_graphical_session_id_t {
77        self.raw.graphical_session_id
78    }
79
80    /// Source address as an [`IpAddr`] from the standard library, if possible.
81    #[inline(always)]
82    pub fn source_address_std(&self) -> Option<IpAddr> {
83        let sa = self.source_address().to_str()?;
84        IpAddr::from_str(sa).ok()
85    }
86}
87
88// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
89unsafe impl Send for EventScreensharingAttach<'_> {}
90// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
91unsafe impl Sync for EventScreensharingAttach<'_> {}
92
93impl_debug_eq_hash_with_functions!(
94    EventScreensharingAttach<'a>;
95    success, source_address_type, source_address, viewer_appleid, authentication_type,
96    authentication_username, session_username, existing_session, graphical_session_id,
97);