jingle, jingle_ft: Use the new generate_id! macro to simplify Sid/Cid generation.

This commit is contained in:
Emmanuel Gil Peyrot 2017-06-25 22:14:51 +01:00
parent 95a19b4bb4
commit a219501fed
2 changed files with 5 additions and 48 deletions

View file

@ -245,29 +245,14 @@ impl IntoElements for ReasonElement {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] generate_id!(SessionId);
pub struct Sid(String);
impl FromStr for Sid {
type Err = Error;
fn from_str(s: &str) -> Result<Sid, Error> {
// TODO: implement the NMTOKEN restrictions: https://www.w3.org/TR/2000/WD-xml-2e-20000814#NT-Nmtoken
Ok(Sid(String::from(s)))
}
}
impl IntoAttributeValue for Sid {
fn into_attribute_value(self) -> Option<String> {
return Some(self.0);
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Jingle { pub struct Jingle {
pub action: Action, pub action: Action,
pub initiator: Option<Jid>, pub initiator: Option<Jid>,
pub responder: Option<Jid>, pub responder: Option<Jid>,
pub sid: Sid, pub sid: SessionId,
pub contents: Vec<Content>, pub contents: Vec<Content>,
pub reason: Option<ReasonElement>, pub reason: Option<ReasonElement>,
pub other: Vec<Element>, pub other: Vec<Element>,
@ -333,7 +318,7 @@ mod tests {
let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'/>".parse().unwrap(); let elem: Element = "<jingle xmlns='urn:xmpp:jingle:1' action='session-initiate' sid='coucou'/>".parse().unwrap();
let jingle = Jingle::try_from(elem).unwrap(); let jingle = Jingle::try_from(elem).unwrap();
assert_eq!(jingle.action, Action::SessionInitiate); assert_eq!(jingle.action, Action::SessionInitiate);
assert_eq!(jingle.sid, Sid(String::from("coucou"))); assert_eq!(jingle.sid, SessionId(String::from("coucou")));
} }
#[test] #[test]

View file

@ -25,37 +25,9 @@ generate_attribute!(Mode, "mode", {
Udp => "udp", Udp => "udp",
}, Default = Tcp); }, Default = Tcp);
#[derive(Debug, Clone, PartialEq, Eq, Hash)] generate_id!(CandidateId);
pub struct CandidateId(String);
impl FromStr for CandidateId { generate_id!(StreamId);
type Err = Error;
fn from_str(s: &str) -> Result<CandidateId, Error> {
Ok(CandidateId(String::from(s)))
}
}
impl IntoAttributeValue for CandidateId {
fn into_attribute_value(self) -> Option<String> {
return Some(self.0);
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StreamId(String);
impl FromStr for StreamId {
type Err = Error;
fn from_str(s: &str) -> Result<StreamId, Error> {
Ok(StreamId(String::from(s)))
}
}
impl IntoAttributeValue for StreamId {
fn into_attribute_value(self) -> Option<String> {
return Some(self.0);
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Candidate { pub struct Candidate {