idevice/services/
syslog_relay.rs

1//! iOS Device SyslogRelay Service Abstraction
2
3use crate::{Idevice, IdeviceError, IdeviceService, obf};
4
5/// Client for interacting with the iOS device SyslogRelay service
6#[derive(Debug)]
7pub struct SyslogRelayClient {
8    /// The underlying device connection with established SyslogRelay service
9    pub idevice: Idevice,
10}
11
12impl IdeviceService for SyslogRelayClient {
13    /// Returns the SyslogRelay service name as registered with lockdownd
14    fn service_name() -> std::borrow::Cow<'static, str> {
15        obf!("com.apple.syslog_relay")
16    }
17
18    async fn from_stream(idevice: Idevice) -> Result<Self, crate::IdeviceError> {
19        Ok(Self::new(idevice))
20    }
21}
22
23impl SyslogRelayClient {
24    /// Creates a new SyslogRelay client from an existing device connection
25    ///
26    /// # Arguments
27    /// * `idevice` - Pre-established device connection
28    pub fn new(idevice: Idevice) -> Self {
29        Self { idevice }
30    }
31
32    /// Get the next log from the relay
33    ///
34    /// # Returns
35    /// A string containing the log
36    ///
37    /// # Errors
38    /// UnexpectedResponse if the service sends an EOF
39    pub async fn next(&mut self) -> Result<String, IdeviceError> {
40        let res = self.idevice.read_until_delim(b"\n\x00").await?;
41        match res {
42            Some(res) => Ok(String::from_utf8_lossy(&res).to_string()),
43            None => Err(IdeviceError::UnexpectedResponse),
44        }
45    }
46}