mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add add_service function to lockdownd client
This is all subject to restructure
This commit is contained in:
40
src/lib.rs
40
src/lib.rs
@@ -4,7 +4,7 @@ const LOCKDOWND_PORT: u16 = 62078;
|
|||||||
|
|
||||||
mod pairing_file;
|
mod pairing_file;
|
||||||
|
|
||||||
use log::debug;
|
use log::{debug, error};
|
||||||
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::io::{self, BufWriter, Read, Write};
|
use std::io::{self, BufWriter, Read, Write};
|
||||||
@@ -173,6 +173,44 @@ impl LockdowndClient {
|
|||||||
|
|
||||||
Ok(())
|
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<String>,
|
||||||
|
) -> 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)]
|
#[derive(Error, Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user