Skip to content

Commit

Permalink
Add response for successful AddDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcoxson committed Jan 10, 2025
1 parent 84c9467 commit 4ced487
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/add_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,34 @@ fn main() {
)
};
stream.write_all(&request).unwrap();

let mut buf = Vec::new();
let size = stream.read_to_end(&mut buf).unwrap();
println!("{:?}", buf);

let buffer = &mut buf[0..size].to_vec();
if size == 16 {
let packet_size = &buffer[0..4];
let packet_size = u32::from_le_bytes(packet_size.try_into().unwrap());
// Pull the rest of the packet
let mut packet = vec![0; packet_size as usize];
let _ = stream.read(&mut packet).unwrap();
// Append the packet to the buffer
buffer.append(&mut packet);
}

println!("{:?}", buffer);
let parsed: raw_packet::RawPacket = buffer.try_into().unwrap();
match parsed.plist.get("Result") {
Some(plist::Value::Integer(r)) => {
if r.as_unsigned().unwrap() == 1 {
println!("Success");
} else {
println!("Failure");
}
}
_ => {
println!("Failure");
}
}
}
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,29 @@ async fn handle_stream(
};

let mut central_data = data.lock().await;
if let Err(e) = central_data.add_network_device(
let ip_address = match ip_address.parse() {
Ok(i) => i,
Err(_) => {
warn!("Bad IP requested: {ip_address}");
return;
}
};
let res = match central_data.add_network_device(
udid.to_owned(),
ip_address.parse().unwrap(),
ip_address,
service_name.to_owned(),
connection_type.to_owned(),
data.clone(),
) {
error!("Failed to add requested device to muxer: {e:?}");
return;
}
Ok(_) => 1,
Err(e) => {
error!("Failed to add requested device to muxer: {e:?}");
0
}
};

let mut p = plist::Dictionary::new();
p.insert("Result".into(), "OK".into());
p.insert("Result".into(), res.into());
let res: Vec<u8> = RawPacket::new(p, 1, 8, parsed.tag).into();
if let Err(e) = socket.write_all(&res).await {
warn!("Failed to send back success message: {e:?}");
Expand Down

0 comments on commit 4ced487

Please sign in to comment.