diff --git a/src/error.rs b/src/error.rs index 562e656..dbfbd8a 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,6 +9,7 @@ use std::io; use std::num; use std::string; use std::fmt; +use std::net; use base64; use minidom; @@ -23,6 +24,7 @@ pub enum Error { Base64Error(base64::DecodeError), ParseIntError(num::ParseIntError), ParseStringError(string::ParseError), + ParseAddrError(net::AddrParseError), JidParseError(jid::JidParseError), ChronoParseError(chrono::ParseError), } @@ -36,6 +38,7 @@ impl fmt::Display for Error { Error::Base64Error(ref e) => write!(fmt, "{}", e), Error::ParseIntError(ref e) => write!(fmt, "{}", e), Error::ParseStringError(ref e) => write!(fmt, "{}", e), + Error::ParseAddrError(ref e) => write!(fmt, "{}", e), Error::JidParseError(_) => write!(fmt, "JID parse error"), Error::ChronoParseError(ref e) => write!(fmt, "{}", e), } @@ -72,6 +75,12 @@ impl From for Error { } } +impl From for Error { + fn from(err: net::AddrParseError) -> Error { + Error::ParseAddrError(err) + } +} + impl From for Error { fn from(err: jid::JidParseError) -> Error { Error::JidParseError(err) diff --git a/src/jingle_s5b.rs b/src/jingle_s5b.rs index 4233d2d..c670124 100644 --- a/src/jingle_s5b.rs +++ b/src/jingle_s5b.rs @@ -6,6 +6,7 @@ use try_from::TryFrom; use std::str::FromStr; +use std::net::IpAddr; use minidom::{Element, IntoAttributeValue}; use jid::Jid; @@ -32,7 +33,7 @@ generate_id!(StreamId); generate_element_with_only_attributes!(Candidate, "candidate", ns::JINGLE_S5B, [ cid: CandidateId = "cid" => required, - host: String = "host" => required, + host: IpAddr = "host" => required, jid: Jid = "jid" => required, port: Option = "port" => optional, priority: u32 = "priority" => required, @@ -40,7 +41,7 @@ generate_element_with_only_attributes!(Candidate, "candidate", ns::JINGLE_S5B, [ ]); impl Candidate { - pub fn new(cid: CandidateId, host: String, jid: Jid, priority: u32) -> Candidate { + pub fn new(cid: CandidateId, host: IpAddr, jid: Jid, priority: u32) -> Candidate { Candidate { cid, host, @@ -238,14 +239,14 @@ mod tests { #[test] fn test_serialise_candidate() { - let elem: Element = "".parse().unwrap(); + let elem: Element = "".parse().unwrap(); let transport = Transport { sid: StreamId(String::from("coucou")), dstaddr: None, mode: Mode::Tcp, payload: TransportPayload::Candidates(vec!(Candidate { cid: CandidateId(String::from("coucou")), - host: String::from("coucou"), + host: IpAddr::from_str("127.0.0.1").unwrap(), jid: Jid::from_str("coucou@coucou").unwrap(), port: None, priority: 0u32,