mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
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;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Forwarded, Error> {
|
||||
if !elem.is("forwarded", ns::FORWARD) {
|
||||
return Err(Error::ParseError("This is not a forwarded element."));
|
||||
}
|
||||
check_self!(elem, "forwarded", ns::FORWARD);
|
||||
let mut delay = None;
|
||||
let mut stanza = None;
|
||||
for child in elem.children() {
|
||||
|
|
|
@ -29,9 +29,7 @@ impl TryFrom<Element> for Query {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Query, Error> {
|
||||
if !elem.is("query", ns::REGISTER) {
|
||||
return Err(Error::ParseError("This is not an ibr element."));
|
||||
}
|
||||
check_self!(elem, "query", ns::REGISTER, "IBR query");
|
||||
let mut query = Query {
|
||||
registered: false,
|
||||
fields: HashMap::new(),
|
||||
|
|
|
@ -207,9 +207,7 @@ impl TryFrom<Element> for Iq {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(root: Element) -> Result<Iq, Error> {
|
||||
if !root.is("iq", ns::DEFAULT_NS) {
|
||||
return Err(Error::ParseError("This is not an iq element."));
|
||||
}
|
||||
check_self!(root, "iq", ns::DEFAULT_NS);
|
||||
let from = get_attr!(root, "from", optional);
|
||||
let to = get_attr!(root, "to", optional);
|
||||
let id = get_attr!(root, "id", optional);
|
||||
|
|
|
@ -119,9 +119,7 @@ impl TryFrom<Element> for Content {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Content, Error> {
|
||||
if !elem.is("content", ns::JINGLE) {
|
||||
return Err(Error::ParseError("This is not a content element."));
|
||||
}
|
||||
check_self!(elem, "content", ns::JINGLE);
|
||||
|
||||
let mut content = Content {
|
||||
creator: get_attr!(elem, "creator", required),
|
||||
|
@ -252,9 +250,7 @@ impl TryFrom<Element> for ReasonElement {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<ReasonElement, Error> {
|
||||
if !elem.is("reason", ns::JINGLE) {
|
||||
return Err(Error::ParseError("This is not a reason element."));
|
||||
}
|
||||
check_self!(elem, "reason", ns::JINGLE);
|
||||
let mut reason = None;
|
||||
let mut text = None;
|
||||
for child in elem.children() {
|
||||
|
@ -344,9 +340,7 @@ impl TryFrom<Element> for Jingle {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(root: Element) -> Result<Jingle, Error> {
|
||||
if !root.is("jingle", ns::JINGLE) {
|
||||
return Err(Error::ParseError("This is not a Jingle element."));
|
||||
}
|
||||
check_self!(root, "jingle", ns::JINGLE, "Jingle");
|
||||
|
||||
let mut jingle = Jingle {
|
||||
action: get_attr!(root, "action", required),
|
||||
|
|
|
@ -111,7 +111,7 @@ impl TryFrom<Element> for Transport {
|
|||
type Err = 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 dstaddr = get_attr!(elem, "dstaddr", optional);
|
||||
let mode = get_attr!(elem, "mode", default);
|
||||
|
@ -159,9 +159,6 @@ impl TryFrom<Element> for Transport {
|
|||
mode: mode,
|
||||
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;
|
||||
|
||||
fn try_from(root: Element) -> Result<Message, Error> {
|
||||
if !root.is("message", ns::DEFAULT_NS) {
|
||||
return Err(Error::ParseError("This is not a message element."));
|
||||
}
|
||||
check_self!(root, "message", ns::DEFAULT_NS);
|
||||
let from = get_attr!(root, "from", optional);
|
||||
let to = get_attr!(root, "to", optional);
|
||||
let id = get_attr!(root, "id", optional);
|
||||
|
|
|
@ -22,9 +22,7 @@ impl TryFrom<Element> for Muc {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Muc, Error> {
|
||||
if !elem.is("x", ns::MUC) {
|
||||
return Err(Error::ParseError("This is not an x element."));
|
||||
}
|
||||
check_self!(elem, "x", ns::MUC);
|
||||
check_no_attributes!(elem, "x");
|
||||
|
||||
let mut password = None;
|
||||
|
|
|
@ -93,9 +93,7 @@ impl TryFrom<Element> for Actor {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Actor, Error> {
|
||||
if !elem.is("actor", ns::MUC_USER) {
|
||||
return Err(Error::ParseError("This is not a actor element."));
|
||||
}
|
||||
check_self!(elem, "actor", ns::MUC_USER);
|
||||
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
||||
for _ in elem.children() {
|
||||
return Err(Error::ParseError("Unknown child in actor element."));
|
||||
|
@ -160,9 +158,7 @@ impl TryFrom<Element> for Item {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Item, Error> {
|
||||
if !elem.is("item", ns::MUC_USER) {
|
||||
return Err(Error::ParseError("This is not a item element."));
|
||||
}
|
||||
check_self!(elem, "item", ns::MUC_USER);
|
||||
check_no_unknown_attributes!(elem, "item", ["affiliation", "jid", "nick", "role"]);
|
||||
let mut actor: Option<Actor> = None;
|
||||
let mut continue_: Option<Continue> = None;
|
||||
|
@ -221,9 +217,7 @@ impl TryFrom<Element> for MucUser {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<MucUser, Error> {
|
||||
if !elem.is("x", ns::MUC_USER) {
|
||||
return Err(Error::ParseError("This is not an x element."));
|
||||
}
|
||||
check_self!(elem, "x", ns::MUC_USER);
|
||||
check_no_attributes!(elem, "x");
|
||||
let mut status = vec!();
|
||||
let mut items = vec!();
|
||||
|
|
|
@ -248,9 +248,7 @@ impl TryFrom<Element> for Presence {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(root: Element) -> Result<Presence, Error> {
|
||||
if !root.is("presence", ns::DEFAULT_NS) {
|
||||
return Err(Error::ParseError("This is not a presence element."));
|
||||
}
|
||||
check_self!(root, "presence", ns::DEFAULT_NS);
|
||||
let mut show = None;
|
||||
let mut priority = None;
|
||||
let mut presence = Presence {
|
||||
|
|
|
@ -28,9 +28,7 @@ impl TryFrom<Element> for Set {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Set, Error> {
|
||||
if !elem.is("set", ns::RSM) {
|
||||
return Err(Error::ParseError("This is not a RSM element."));
|
||||
}
|
||||
check_self!(elem, "set", ns::RSM, "RSM set");
|
||||
let mut set = Set {
|
||||
after: None,
|
||||
before: None,
|
||||
|
@ -136,7 +134,7 @@ mod tests {
|
|||
Error::ParseError(string) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "This is not a RSM element.");
|
||||
assert_eq!(message, "This is not a RSM set element.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -62,9 +62,7 @@ impl TryFrom<Element> for StanzaError {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<StanzaError, Error> {
|
||||
if !elem.is("error", ns::DEFAULT_NS) {
|
||||
return Err(Error::ParseError("This is not an error element."));
|
||||
}
|
||||
check_self!(elem, "error", ns::DEFAULT_NS);
|
||||
|
||||
let type_ = get_attr!(elem, "type", required);
|
||||
let by = get_attr!(elem, "by", optional);
|
||||
|
|
|
@ -20,9 +20,7 @@ impl TryFrom<Element> for Version {
|
|||
type Err = Error;
|
||||
|
||||
fn try_from(elem: Element) -> Result<Version, Error> {
|
||||
if !elem.is("query", ns::VERSION) {
|
||||
return Err(Error::ParseError("This is not a version element."));
|
||||
}
|
||||
check_self!(elem, "query", ns::VERSION, "version");
|
||||
check_no_attributes!(elem, "version");
|
||||
let mut name = None;
|
||||
let mut version = None;
|
||||
|
|
Loading…
Reference in a new issue