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