mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
jingle_s5b: Make Candidate.host an IpAddr instead of a String.
This commit is contained in:
parent
3310f29704
commit
53e23cbf65
2 changed files with 14 additions and 4 deletions
|
@ -9,6 +9,7 @@ use std::io;
|
||||||
use std::num;
|
use std::num;
|
||||||
use std::string;
|
use std::string;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::net;
|
||||||
|
|
||||||
use base64;
|
use base64;
|
||||||
use minidom;
|
use minidom;
|
||||||
|
@ -23,6 +24,7 @@ pub enum Error {
|
||||||
Base64Error(base64::DecodeError),
|
Base64Error(base64::DecodeError),
|
||||||
ParseIntError(num::ParseIntError),
|
ParseIntError(num::ParseIntError),
|
||||||
ParseStringError(string::ParseError),
|
ParseStringError(string::ParseError),
|
||||||
|
ParseAddrError(net::AddrParseError),
|
||||||
JidParseError(jid::JidParseError),
|
JidParseError(jid::JidParseError),
|
||||||
ChronoParseError(chrono::ParseError),
|
ChronoParseError(chrono::ParseError),
|
||||||
}
|
}
|
||||||
|
@ -36,6 +38,7 @@ impl fmt::Display for Error {
|
||||||
Error::Base64Error(ref e) => write!(fmt, "{}", e),
|
Error::Base64Error(ref e) => write!(fmt, "{}", e),
|
||||||
Error::ParseIntError(ref e) => write!(fmt, "{}", e),
|
Error::ParseIntError(ref e) => write!(fmt, "{}", e),
|
||||||
Error::ParseStringError(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::JidParseError(_) => write!(fmt, "JID parse error"),
|
||||||
Error::ChronoParseError(ref e) => write!(fmt, "{}", e),
|
Error::ChronoParseError(ref e) => write!(fmt, "{}", e),
|
||||||
}
|
}
|
||||||
|
@ -72,6 +75,12 @@ impl From<string::ParseError> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<net::AddrParseError> for Error {
|
||||||
|
fn from(err: net::AddrParseError) -> Error {
|
||||||
|
Error::ParseAddrError(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<jid::JidParseError> for Error {
|
impl From<jid::JidParseError> for Error {
|
||||||
fn from(err: jid::JidParseError) -> Error {
|
fn from(err: jid::JidParseError) -> Error {
|
||||||
Error::JidParseError(err)
|
Error::JidParseError(err)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
use try_from::TryFrom;
|
use try_from::TryFrom;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::net::IpAddr;
|
||||||
|
|
||||||
use minidom::{Element, IntoAttributeValue};
|
use minidom::{Element, IntoAttributeValue};
|
||||||
use jid::Jid;
|
use jid::Jid;
|
||||||
|
@ -32,7 +33,7 @@ generate_id!(StreamId);
|
||||||
|
|
||||||
generate_element_with_only_attributes!(Candidate, "candidate", ns::JINGLE_S5B, [
|
generate_element_with_only_attributes!(Candidate, "candidate", ns::JINGLE_S5B, [
|
||||||
cid: CandidateId = "cid" => required,
|
cid: CandidateId = "cid" => required,
|
||||||
host: String = "host" => required,
|
host: IpAddr = "host" => required,
|
||||||
jid: Jid = "jid" => required,
|
jid: Jid = "jid" => required,
|
||||||
port: Option<u16> = "port" => optional,
|
port: Option<u16> = "port" => optional,
|
||||||
priority: u32 = "priority" => required,
|
priority: u32 = "priority" => required,
|
||||||
|
@ -40,7 +41,7 @@ generate_element_with_only_attributes!(Candidate, "candidate", ns::JINGLE_S5B, [
|
||||||
]);
|
]);
|
||||||
|
|
||||||
impl Candidate {
|
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 {
|
Candidate {
|
||||||
cid,
|
cid,
|
||||||
host,
|
host,
|
||||||
|
@ -238,14 +239,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialise_candidate() {
|
fn test_serialise_candidate() {
|
||||||
let elem: Element = "<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='coucou'><candidate cid='coucou' host='coucou' jid='coucou@coucou' priority='0'/></transport>".parse().unwrap();
|
let elem: Element = "<transport xmlns='urn:xmpp:jingle:transports:s5b:1' sid='coucou'><candidate cid='coucou' host='127.0.0.1' jid='coucou@coucou' priority='0'/></transport>".parse().unwrap();
|
||||||
let transport = Transport {
|
let transport = Transport {
|
||||||
sid: StreamId(String::from("coucou")),
|
sid: StreamId(String::from("coucou")),
|
||||||
dstaddr: None,
|
dstaddr: None,
|
||||||
mode: Mode::Tcp,
|
mode: Mode::Tcp,
|
||||||
payload: TransportPayload::Candidates(vec!(Candidate {
|
payload: TransportPayload::Candidates(vec!(Candidate {
|
||||||
cid: CandidateId(String::from("coucou")),
|
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(),
|
jid: Jid::from_str("coucou@coucou").unwrap(),
|
||||||
port: None,
|
port: None,
|
||||||
priority: 0u32,
|
priority: 0u32,
|
||||||
|
|
Loading…
Reference in a new issue