From 3536281a74489b361412172d77048ac761b9a1cd Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Wed, 8 Jan 2025 17:39:48 -0700 Subject: [PATCH] Add add_service function to lockdownd client This is all subject to restructure --- src/lib.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d4b015a..aedca44 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ const LOCKDOWND_PORT: u16 = 62078; mod pairing_file; -use log::debug; +use log::{debug, error}; use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode}; use serde::{Deserialize, Serialize}; use std::io::{self, BufWriter, Read, Write}; @@ -173,6 +173,44 @@ impl LockdowndClient { Ok(()) } + + /// Asks lockdownd to pretty please start a service for us + /// # Arguments + /// `identifier` - The identifier for the service you want to start + /// # Returns + /// The port number and whether to enable SSL on success, `IdeviceError` on failure + pub fn start_service( + &mut self, + identifier: impl Into, + ) -> Result<(u16, bool), IdeviceError> { + let identifier = identifier.into(); + let mut req = plist::Dictionary::new(); + req.insert("Request".into(), "StartService".into()); + req.insert("Service".into(), identifier.into()); + self.send_plist(plist::Value::Dictionary(req))?; + let response = self.read_plist()?; + println!("{response:?}"); + match response.get("EnableServiceSSL") { + Some(plist::Value::Boolean(ssl)) => match response.get("Port") { + Some(plist::Value::Integer(port)) => { + if let Some(port) = port.as_unsigned() { + Ok((port as u16, *ssl)) + } else { + error!("Port isn't an unsiged integer!"); + Err(IdeviceError::UnexpectedResponse) + } + } + _ => { + error!("Response didn't contain an integer port"); + Err(IdeviceError::UnexpectedResponse) + } + }, + _ => { + error!("Response didn't contain EnableServiceSSL bool!"); + Err(IdeviceError::UnexpectedResponse) + } + } + } } #[derive(Error, Debug)]