Use check_self!() where it makes sense.
This commit is contained in:
parent
e0438f9b88
commit
6bb466eea2
12 changed files with 62 additions and 95 deletions
|
|
@ -26,9 +26,7 @@ impl TryFrom<Element> for Forwarded {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Forwarded, Error> {
|
fn try_from(elem: Element) -> Result<Forwarded, Error> {
|
||||||
if !elem.is("forwarded", ns::FORWARD) {
|
check_self!(elem, "forwarded", ns::FORWARD);
|
||||||
return Err(Error::ParseError("This is not a forwarded element."));
|
|
||||||
}
|
|
||||||
let mut delay = None;
|
let mut delay = None;
|
||||||
let mut stanza = None;
|
let mut stanza = None;
|
||||||
for child in elem.children() {
|
for child in elem.children() {
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,7 @@ impl TryFrom<Element> for Query {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Query, Error> {
|
fn try_from(elem: Element) -> Result<Query, Error> {
|
||||||
if !elem.is("query", ns::REGISTER) {
|
check_self!(elem, "query", ns::REGISTER, "IBR query");
|
||||||
return Err(Error::ParseError("This is not an ibr element."));
|
|
||||||
}
|
|
||||||
let mut query = Query {
|
let mut query = Query {
|
||||||
registered: false,
|
registered: false,
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
|
|
|
||||||
|
|
@ -207,9 +207,7 @@ impl TryFrom<Element> for Iq {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(root: Element) -> Result<Iq, Error> {
|
fn try_from(root: Element) -> Result<Iq, Error> {
|
||||||
if !root.is("iq", ns::DEFAULT_NS) {
|
check_self!(root, "iq", ns::DEFAULT_NS);
|
||||||
return Err(Error::ParseError("This is not an iq element."));
|
|
||||||
}
|
|
||||||
let from = get_attr!(root, "from", optional);
|
let from = get_attr!(root, "from", optional);
|
||||||
let to = get_attr!(root, "to", optional);
|
let to = get_attr!(root, "to", optional);
|
||||||
let id = get_attr!(root, "id", optional);
|
let id = get_attr!(root, "id", optional);
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,7 @@ impl TryFrom<Element> for Content {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Content, Error> {
|
fn try_from(elem: Element) -> Result<Content, Error> {
|
||||||
if !elem.is("content", ns::JINGLE) {
|
check_self!(elem, "content", ns::JINGLE);
|
||||||
return Err(Error::ParseError("This is not a content element."));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut content = Content {
|
let mut content = Content {
|
||||||
creator: get_attr!(elem, "creator", required),
|
creator: get_attr!(elem, "creator", required),
|
||||||
|
|
@ -252,9 +250,7 @@ impl TryFrom<Element> for ReasonElement {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<ReasonElement, Error> {
|
fn try_from(elem: Element) -> Result<ReasonElement, Error> {
|
||||||
if !elem.is("reason", ns::JINGLE) {
|
check_self!(elem, "reason", ns::JINGLE);
|
||||||
return Err(Error::ParseError("This is not a reason element."));
|
|
||||||
}
|
|
||||||
let mut reason = None;
|
let mut reason = None;
|
||||||
let mut text = None;
|
let mut text = None;
|
||||||
for child in elem.children() {
|
for child in elem.children() {
|
||||||
|
|
@ -344,9 +340,7 @@ impl TryFrom<Element> for Jingle {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(root: Element) -> Result<Jingle, Error> {
|
fn try_from(root: Element) -> Result<Jingle, Error> {
|
||||||
if !root.is("jingle", ns::JINGLE) {
|
check_self!(root, "jingle", ns::JINGLE, "Jingle");
|
||||||
return Err(Error::ParseError("This is not a Jingle element."));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut jingle = Jingle {
|
let mut jingle = Jingle {
|
||||||
action: get_attr!(root, "action", required),
|
action: get_attr!(root, "action", required),
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ impl TryFrom<Element> for Transport {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Transport, Error> {
|
fn try_from(elem: Element) -> Result<Transport, Error> {
|
||||||
if elem.is("transport", ns::JINGLE_S5B) {
|
check_self!(elem, "transport", ns::JINGLE_S5B);
|
||||||
let sid = get_attr!(elem, "sid", required);
|
let sid = get_attr!(elem, "sid", required);
|
||||||
let dstaddr = get_attr!(elem, "dstaddr", optional);
|
let dstaddr = get_attr!(elem, "dstaddr", optional);
|
||||||
let mode = get_attr!(elem, "mode", default);
|
let mode = get_attr!(elem, "mode", default);
|
||||||
|
|
@ -159,9 +159,6 @@ impl TryFrom<Element> for Transport {
|
||||||
mode: mode,
|
mode: mode,
|
||||||
payload: payload,
|
payload: payload,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
Err(Error::ParseError("This is not an JingleS5B transport element."))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -189,9 +189,7 @@ impl TryFrom<Element> for Message {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(root: Element) -> Result<Message, Error> {
|
fn try_from(root: Element) -> Result<Message, Error> {
|
||||||
if !root.is("message", ns::DEFAULT_NS) {
|
check_self!(root, "message", ns::DEFAULT_NS);
|
||||||
return Err(Error::ParseError("This is not a message element."));
|
|
||||||
}
|
|
||||||
let from = get_attr!(root, "from", optional);
|
let from = get_attr!(root, "from", optional);
|
||||||
let to = get_attr!(root, "to", optional);
|
let to = get_attr!(root, "to", optional);
|
||||||
let id = get_attr!(root, "id", optional);
|
let id = get_attr!(root, "id", optional);
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,7 @@ impl TryFrom<Element> for Muc {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Muc, Error> {
|
fn try_from(elem: Element) -> Result<Muc, Error> {
|
||||||
if !elem.is("x", ns::MUC) {
|
check_self!(elem, "x", ns::MUC);
|
||||||
return Err(Error::ParseError("This is not an x element."));
|
|
||||||
}
|
|
||||||
check_no_attributes!(elem, "x");
|
check_no_attributes!(elem, "x");
|
||||||
|
|
||||||
let mut password = None;
|
let mut password = None;
|
||||||
|
|
|
||||||
|
|
@ -93,9 +93,7 @@ impl TryFrom<Element> for Actor {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Actor, Error> {
|
fn try_from(elem: Element) -> Result<Actor, Error> {
|
||||||
if !elem.is("actor", ns::MUC_USER) {
|
check_self!(elem, "actor", ns::MUC_USER);
|
||||||
return Err(Error::ParseError("This is not a actor element."));
|
|
||||||
}
|
|
||||||
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
||||||
for _ in elem.children() {
|
for _ in elem.children() {
|
||||||
return Err(Error::ParseError("Unknown child in actor element."));
|
return Err(Error::ParseError("Unknown child in actor element."));
|
||||||
|
|
@ -160,9 +158,7 @@ impl TryFrom<Element> for Item {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Item, Error> {
|
fn try_from(elem: Element) -> Result<Item, Error> {
|
||||||
if !elem.is("item", ns::MUC_USER) {
|
check_self!(elem, "item", ns::MUC_USER);
|
||||||
return Err(Error::ParseError("This is not a item element."));
|
|
||||||
}
|
|
||||||
check_no_unknown_attributes!(elem, "item", ["affiliation", "jid", "nick", "role"]);
|
check_no_unknown_attributes!(elem, "item", ["affiliation", "jid", "nick", "role"]);
|
||||||
let mut actor: Option<Actor> = None;
|
let mut actor: Option<Actor> = None;
|
||||||
let mut continue_: Option<Continue> = None;
|
let mut continue_: Option<Continue> = None;
|
||||||
|
|
@ -221,9 +217,7 @@ impl TryFrom<Element> for MucUser {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<MucUser, Error> {
|
fn try_from(elem: Element) -> Result<MucUser, Error> {
|
||||||
if !elem.is("x", ns::MUC_USER) {
|
check_self!(elem, "x", ns::MUC_USER);
|
||||||
return Err(Error::ParseError("This is not an x element."));
|
|
||||||
}
|
|
||||||
check_no_attributes!(elem, "x");
|
check_no_attributes!(elem, "x");
|
||||||
let mut status = vec!();
|
let mut status = vec!();
|
||||||
let mut items = vec!();
|
let mut items = vec!();
|
||||||
|
|
|
||||||
|
|
@ -248,9 +248,7 @@ impl TryFrom<Element> for Presence {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(root: Element) -> Result<Presence, Error> {
|
fn try_from(root: Element) -> Result<Presence, Error> {
|
||||||
if !root.is("presence", ns::DEFAULT_NS) {
|
check_self!(root, "presence", ns::DEFAULT_NS);
|
||||||
return Err(Error::ParseError("This is not a presence element."));
|
|
||||||
}
|
|
||||||
let mut show = None;
|
let mut show = None;
|
||||||
let mut priority = None;
|
let mut priority = None;
|
||||||
let mut presence = Presence {
|
let mut presence = Presence {
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,7 @@ impl TryFrom<Element> for Set {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Set, Error> {
|
fn try_from(elem: Element) -> Result<Set, Error> {
|
||||||
if !elem.is("set", ns::RSM) {
|
check_self!(elem, "set", ns::RSM, "RSM set");
|
||||||
return Err(Error::ParseError("This is not a RSM element."));
|
|
||||||
}
|
|
||||||
let mut set = Set {
|
let mut set = Set {
|
||||||
after: None,
|
after: None,
|
||||||
before: None,
|
before: None,
|
||||||
|
|
@ -136,7 +134,7 @@ mod tests {
|
||||||
Error::ParseError(string) => string,
|
Error::ParseError(string) => string,
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "This is not a RSM element.");
|
assert_eq!(message, "This is not a RSM set element.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,7 @@ impl TryFrom<Element> for StanzaError {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<StanzaError, Error> {
|
fn try_from(elem: Element) -> Result<StanzaError, Error> {
|
||||||
if !elem.is("error", ns::DEFAULT_NS) {
|
check_self!(elem, "error", ns::DEFAULT_NS);
|
||||||
return Err(Error::ParseError("This is not an error element."));
|
|
||||||
}
|
|
||||||
|
|
||||||
let type_ = get_attr!(elem, "type", required);
|
let type_ = get_attr!(elem, "type", required);
|
||||||
let by = get_attr!(elem, "by", optional);
|
let by = get_attr!(elem, "by", optional);
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,7 @@ impl TryFrom<Element> for Version {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn try_from(elem: Element) -> Result<Version, Error> {
|
fn try_from(elem: Element) -> Result<Version, Error> {
|
||||||
if !elem.is("query", ns::VERSION) {
|
check_self!(elem, "query", ns::VERSION, "version");
|
||||||
return Err(Error::ParseError("This is not a version element."));
|
|
||||||
}
|
|
||||||
check_no_attributes!(elem, "version");
|
check_no_attributes!(elem, "version");
|
||||||
let mut name = None;
|
let mut name = None;
|
||||||
let mut version = None;
|
let mut version = None;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue