macros: Remove backwards-compatibility variants introduced in the previous commit.
This commit is contained in:
parent
bcd42a26e3
commit
ae3a5b6725
18 changed files with 60 additions and 70 deletions
|
@ -41,7 +41,7 @@ macro_rules! generate_blocking_element {
|
|||
check_self!(child, "item", BLOCKING);
|
||||
check_no_unknown_attributes!(child, "item", ["jid"]);
|
||||
check_no_children!(child, "item");
|
||||
items.push(get_attr!(child, "jid", required));
|
||||
items.push(get_attr!(child, "jid", Required));
|
||||
}
|
||||
Ok($elem { items })
|
||||
}
|
||||
|
|
|
@ -46,14 +46,14 @@ impl TryFrom<Element> for Caps {
|
|||
check_self!(elem, "c", CAPS, "caps");
|
||||
check_no_children!(elem, "caps");
|
||||
check_no_unknown_attributes!(elem, "caps", ["hash", "ver", "ext", "node"]);
|
||||
let ver: String = get_attr!(elem, "ver", required);
|
||||
let ver: String = get_attr!(elem, "ver", Required);
|
||||
let hash = Hash {
|
||||
algo: get_attr!(elem, "hash", required),
|
||||
algo: get_attr!(elem, "hash", Required),
|
||||
hash: base64::decode(&ver)?,
|
||||
};
|
||||
Ok(Caps {
|
||||
ext: get_attr!(elem, "ext", optional),
|
||||
node: get_attr!(elem, "node", required),
|
||||
ext: get_attr!(elem, "ext", Option),
|
||||
node: get_attr!(elem, "node", Required),
|
||||
hash,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -106,9 +106,9 @@ impl TryFrom<Element> for Field {
|
|||
check_self!(elem, "field", DATA_FORMS);
|
||||
check_no_unknown_attributes!(elem, "field", ["label", "type", "var"]);
|
||||
let mut field = Field {
|
||||
var: get_attr!(elem, "var", required),
|
||||
type_: get_attr!(elem, "type", default),
|
||||
label: get_attr!(elem, "label", optional),
|
||||
var: get_attr!(elem, "var", Required),
|
||||
type_: get_attr!(elem, "type", Default),
|
||||
label: get_attr!(elem, "label", Option),
|
||||
required: false,
|
||||
options: vec![],
|
||||
values: vec![],
|
||||
|
@ -220,7 +220,7 @@ impl TryFrom<Element> for DataForm {
|
|||
fn try_from(elem: Element) -> Result<DataForm, Error> {
|
||||
check_self!(elem, "x", DATA_FORMS);
|
||||
check_no_unknown_attributes!(elem, "x", ["type"]);
|
||||
let type_ = get_attr!(elem, "type", required);
|
||||
let type_ = get_attr!(elem, "type", Required);
|
||||
let mut form = DataForm {
|
||||
type_,
|
||||
form_type: None,
|
||||
|
|
10
src/disco.rs
10
src/disco.rs
|
@ -71,14 +71,14 @@ impl TryFrom<Element> for Identity {
|
|||
["category", "type", "xml:lang", "name"]
|
||||
);
|
||||
|
||||
let category = get_attr!(elem, "category", required);
|
||||
let category = get_attr!(elem, "category", Required);
|
||||
if category == "" {
|
||||
return Err(Error::ParseError(
|
||||
"Identity must have a non-empty 'category' attribute.",
|
||||
));
|
||||
}
|
||||
|
||||
let type_ = get_attr!(elem, "type", required);
|
||||
let type_ = get_attr!(elem, "type", Required);
|
||||
if type_ == "" {
|
||||
return Err(Error::ParseError(
|
||||
"Identity must have a non-empty 'type' attribute.",
|
||||
|
@ -88,8 +88,8 @@ impl TryFrom<Element> for Identity {
|
|||
Ok(Identity {
|
||||
category,
|
||||
type_,
|
||||
lang: get_attr!(elem, "xml:lang", optional),
|
||||
name: get_attr!(elem, "name", optional),
|
||||
lang: get_attr!(elem, "xml:lang", Option),
|
||||
name: get_attr!(elem, "name", Option),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ impl TryFrom<Element> for DiscoInfoResult {
|
|||
check_no_unknown_attributes!(elem, "disco#info result", ["node"]);
|
||||
|
||||
let mut result = DiscoInfoResult {
|
||||
node: get_attr!(elem, "node", optional),
|
||||
node: get_attr!(elem, "node", Option),
|
||||
identities: vec![],
|
||||
features: vec![],
|
||||
extensions: vec![],
|
||||
|
|
|
@ -134,10 +134,10 @@ impl TryFrom<Element> for Iq {
|
|||
|
||||
fn try_from(root: Element) -> Result<Iq, Error> {
|
||||
check_self!(root, "iq", DEFAULT_NS);
|
||||
let from = get_attr!(root, "from", optional);
|
||||
let to = get_attr!(root, "to", optional);
|
||||
let id = get_attr!(root, "id", required);
|
||||
let type_: String = get_attr!(root, "type", required);
|
||||
let from = get_attr!(root, "from", Option);
|
||||
let to = get_attr!(root, "to", Option);
|
||||
let id = get_attr!(root, "id", Required);
|
||||
let type_: String = get_attr!(root, "type", Required);
|
||||
|
||||
let mut payload = None;
|
||||
let mut error_payload = None;
|
||||
|
|
|
@ -492,10 +492,10 @@ impl TryFrom<Element> for Jingle {
|
|||
check_no_unknown_attributes!(root, "Jingle", ["action", "initiator", "responder", "sid"]);
|
||||
|
||||
let mut jingle = Jingle {
|
||||
action: get_attr!(root, "action", required),
|
||||
initiator: get_attr!(root, "initiator", optional),
|
||||
responder: get_attr!(root, "responder", optional),
|
||||
sid: get_attr!(root, "sid", required),
|
||||
action: get_attr!(root, "action", Required),
|
||||
initiator: get_attr!(root, "initiator", Option),
|
||||
responder: get_attr!(root, "responder", Option),
|
||||
sid: get_attr!(root, "sid", Required),
|
||||
contents: vec![],
|
||||
reason: None,
|
||||
other: vec![],
|
||||
|
|
|
@ -163,7 +163,7 @@ impl TryFrom<Element> for File {
|
|||
}
|
||||
file.name = Some(child.text());
|
||||
} else if child.is("desc", ns::JINGLE_FT) {
|
||||
let lang = get_attr!(child, "xml:lang", default);
|
||||
let lang = get_attr!(child, "xml:lang", Default);
|
||||
let desc = Desc(child.text());
|
||||
if file.descs.insert(lang, desc).is_some() {
|
||||
return Err(Error::ParseError(
|
||||
|
@ -321,8 +321,8 @@ impl TryFrom<Element> for Checksum {
|
|||
));
|
||||
}
|
||||
Ok(Checksum {
|
||||
name: get_attr!(elem, "name", required),
|
||||
creator: get_attr!(elem, "creator", required),
|
||||
name: get_attr!(elem, "name", Required),
|
||||
creator: get_attr!(elem, "creator", Required),
|
||||
file: file.unwrap(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ pub enum JingleMI {
|
|||
|
||||
fn get_sid(elem: Element) -> Result<SessionId, Error> {
|
||||
check_no_unknown_attributes!(elem, "Jingle message", ["id"]);
|
||||
Ok(SessionId(get_attr!(elem, "id", required)))
|
||||
Ok(SessionId(get_attr!(elem, "id", Required)))
|
||||
}
|
||||
|
||||
fn check_empty_and_get_sid(elem: Element) -> Result<SessionId, Error> {
|
||||
|
|
|
@ -177,9 +177,9 @@ impl TryFrom<Element> for Transport {
|
|||
fn try_from(elem: Element) -> Result<Transport, Error> {
|
||||
check_self!(elem, "transport", JINGLE_S5B);
|
||||
check_no_unknown_attributes!(elem, "transport", ["sid", "dstaddr", "mode"]);
|
||||
let sid = get_attr!(elem, "sid", required);
|
||||
let dstaddr = get_attr!(elem, "dstaddr", optional);
|
||||
let mode = get_attr!(elem, "mode", default);
|
||||
let sid = get_attr!(elem, "sid", Required);
|
||||
let dstaddr = get_attr!(elem, "dstaddr", Option);
|
||||
let mode = get_attr!(elem, "mode", Default);
|
||||
|
||||
let mut payload = None;
|
||||
for child in elem.children() {
|
||||
|
@ -200,7 +200,7 @@ impl TryFrom<Element> for Transport {
|
|||
"Non-activated child already present in JingleS5B transport element.",
|
||||
));
|
||||
}
|
||||
let cid = get_attr!(child, "cid", required);
|
||||
let cid = get_attr!(child, "cid", Required);
|
||||
TransportPayload::Activated(cid)
|
||||
} else if child.is("candidate-error", ns::JINGLE_S5B) {
|
||||
if payload.is_some() {
|
||||
|
@ -215,7 +215,7 @@ impl TryFrom<Element> for Transport {
|
|||
"Non-candidate-used child already present in JingleS5B transport element.",
|
||||
));
|
||||
}
|
||||
let cid = get_attr!(child, "cid", required);
|
||||
let cid = get_attr!(child, "cid", Required);
|
||||
TransportPayload::CandidateUsed(cid)
|
||||
} else if child.is("proxy-error", ns::JINGLE_S5B) {
|
||||
if payload.is_some() {
|
||||
|
|
|
@ -152,7 +152,7 @@ impl TryFrom<Element> for Prefs {
|
|||
return Err(Error::ParseError("Unknown child in prefs element."));
|
||||
}
|
||||
}
|
||||
let default_ = get_attr!(elem, "default", required);
|
||||
let default_ = get_attr!(elem, "default", Required);
|
||||
Ok(Prefs {
|
||||
default_,
|
||||
always,
|
||||
|
|
|
@ -154,10 +154,10 @@ impl TryFrom<Element> for Message {
|
|||
|
||||
fn try_from(root: Element) -> Result<Message, Error> {
|
||||
check_self!(root, "message", DEFAULT_NS);
|
||||
let from = get_attr!(root, "from", optional);
|
||||
let to = get_attr!(root, "to", optional);
|
||||
let id = get_attr!(root, "id", optional);
|
||||
let type_ = get_attr!(root, "type", default);
|
||||
let from = get_attr!(root, "from", Option);
|
||||
let to = get_attr!(root, "to", Option);
|
||||
let id = get_attr!(root, "id", Option);
|
||||
let type_ = get_attr!(root, "type", Default);
|
||||
let mut bodies = BTreeMap::new();
|
||||
let mut subjects = BTreeMap::new();
|
||||
let mut thread = None;
|
||||
|
@ -165,7 +165,7 @@ impl TryFrom<Element> for Message {
|
|||
for elem in root.children() {
|
||||
if elem.is("body", ns::DEFAULT_NS) {
|
||||
check_no_children!(elem, "body");
|
||||
let lang = get_attr!(elem, "xml:lang", default);
|
||||
let lang = get_attr!(elem, "xml:lang", Default);
|
||||
let body = Body(elem.text());
|
||||
if bodies.insert(lang, body).is_some() {
|
||||
return Err(Error::ParseError(
|
||||
|
@ -174,7 +174,7 @@ impl TryFrom<Element> for Message {
|
|||
}
|
||||
} else if elem.is("subject", ns::DEFAULT_NS) {
|
||||
check_no_children!(elem, "subject");
|
||||
let lang = get_attr!(elem, "xml:lang", default);
|
||||
let lang = get_attr!(elem, "xml:lang", Default);
|
||||
let subject = Subject(elem.text());
|
||||
if subjects.insert(lang, subject).is_some() {
|
||||
return Err(Error::ParseError(
|
||||
|
|
|
@ -95,8 +95,8 @@ impl TryFrom<Element> for Actor {
|
|||
check_self!(elem, "actor", MUC_USER);
|
||||
check_no_unknown_attributes!(elem, "actor", ["jid", "nick"]);
|
||||
check_no_children!(elem, "actor");
|
||||
let jid: Option<Jid> = get_attr!(elem, "jid", optional);
|
||||
let nick = get_attr!(elem, "nick", optional);
|
||||
let jid: Option<Jid> = get_attr!(elem, "jid", Option);
|
||||
let nick = get_attr!(elem, "nick", Option);
|
||||
|
||||
match (jid, nick) {
|
||||
(Some(_), Some(_)) | (None, None) => {
|
||||
|
|
|
@ -263,10 +263,10 @@ impl TryFrom<Element> for Presence {
|
|||
let mut show = None;
|
||||
let mut priority = None;
|
||||
let mut presence = Presence {
|
||||
from: get_attr!(root, "from", optional),
|
||||
to: get_attr!(root, "to", optional),
|
||||
id: get_attr!(root, "id", optional),
|
||||
type_: get_attr!(root, "type", default),
|
||||
from: get_attr!(root, "from", Option),
|
||||
to: get_attr!(root, "to", Option),
|
||||
id: get_attr!(root, "id", Option),
|
||||
type_: get_attr!(root, "type", Default),
|
||||
show: Show::None,
|
||||
statuses: BTreeMap::new(),
|
||||
priority: 0i8,
|
||||
|
@ -285,7 +285,7 @@ impl TryFrom<Element> for Presence {
|
|||
} else if elem.is("status", ns::DEFAULT_NS) {
|
||||
check_no_unknown_attributes!(elem, "status", ["xml:lang"]);
|
||||
check_no_children!(elem, "status");
|
||||
let lang = get_attr!(elem, "xml:lang", default);
|
||||
let lang = get_attr!(elem, "xml:lang", Default);
|
||||
if presence.statuses.insert(lang, elem.text()).is_some() {
|
||||
return Err(Error::ParseError(
|
||||
"Status element present twice for the same xml:lang.",
|
||||
|
|
|
@ -115,7 +115,7 @@ fn parse_items(elem: Element, node: NodeName) -> Result<PubSubEvent, Error> {
|
|||
}
|
||||
check_no_children!(child, "retract");
|
||||
check_no_unknown_attributes!(child, "retract", ["id"]);
|
||||
let id = get_attr!(child, "id", required);
|
||||
let id = get_attr!(child, "id", Required);
|
||||
retracts.push(id);
|
||||
} else {
|
||||
return Err(Error::ParseError("Invalid child in items element."));
|
||||
|
@ -140,7 +140,7 @@ impl TryFrom<Element> for PubSubEvent {
|
|||
|
||||
let mut payload = None;
|
||||
for child in elem.children() {
|
||||
let node = get_attr!(child, "node", required);
|
||||
let node = get_attr!(child, "node", Required);
|
||||
if child.is("configuration", ns::PUBSUB_EVENT) {
|
||||
let mut payloads = child.children().cloned().collect::<Vec<_>>();
|
||||
let item = payloads.pop();
|
||||
|
@ -163,7 +163,7 @@ impl TryFrom<Element> for PubSubEvent {
|
|||
"More than one redirect in delete element.",
|
||||
));
|
||||
}
|
||||
let uri = get_attr!(item, "uri", required);
|
||||
let uri = get_attr!(item, "uri", Required);
|
||||
redirect = Some(uri);
|
||||
} else {
|
||||
return Err(Error::ParseError("Unknown child in delete element."));
|
||||
|
@ -179,10 +179,10 @@ impl TryFrom<Element> for PubSubEvent {
|
|||
check_no_children!(child, "subscription");
|
||||
payload = Some(PubSubEvent::Subscription {
|
||||
node,
|
||||
expiry: get_attr!(child, "expiry", optional),
|
||||
jid: get_attr!(child, "jid", optional),
|
||||
subid: get_attr!(child, "subid", optional),
|
||||
subscription: get_attr!(child, "subscription", optional),
|
||||
expiry: get_attr!(child, "expiry", Option),
|
||||
jid: get_attr!(child, "jid", Option),
|
||||
subid: get_attr!(child, "subid", Option),
|
||||
subscription: get_attr!(child, "subscription", Option),
|
||||
});
|
||||
} else {
|
||||
return Err(Error::ParseError("Unknown child in event element."));
|
||||
|
|
|
@ -131,7 +131,7 @@ impl TryFrom<Element> for SetResult {
|
|||
if set.first.is_some() {
|
||||
return Err(Error::ParseError("Set can’t have more than one first."));
|
||||
}
|
||||
set.first_index = get_attr!(child, "index", optional);
|
||||
set.first_index = get_attr!(child, "index", Option);
|
||||
set.first = Some(child.text());
|
||||
} else if child.is("last", ns::RSM) {
|
||||
if set.last.is_some() {
|
||||
|
|
|
@ -164,7 +164,7 @@ impl TryFrom<Element> for Failure {
|
|||
if child.is("text", ns::SASL) {
|
||||
check_no_unknown_attributes!(child, "text", ["xml:lang"]);
|
||||
check_no_children!(child, "text");
|
||||
let lang = get_attr!(child, "xml:lang", default);
|
||||
let lang = get_attr!(child, "xml:lang", Default);
|
||||
if texts.insert(lang, child.text()).is_some() {
|
||||
return Err(Error::ParseError(
|
||||
"Text element present twice for the same xml:lang in failure element.",
|
||||
|
|
|
@ -221,8 +221,8 @@ impl TryFrom<Element> for StanzaError {
|
|||
fn try_from(elem: Element) -> Result<StanzaError, Error> {
|
||||
check_self!(elem, "error", DEFAULT_NS);
|
||||
|
||||
let type_ = get_attr!(elem, "type", required);
|
||||
let by = get_attr!(elem, "by", optional);
|
||||
let type_ = get_attr!(elem, "type", Required);
|
||||
let by = get_attr!(elem, "by", Option);
|
||||
let mut defined_condition = None;
|
||||
let mut texts = BTreeMap::new();
|
||||
let mut other = None;
|
||||
|
@ -230,7 +230,7 @@ impl TryFrom<Element> for StanzaError {
|
|||
for child in elem.children() {
|
||||
if child.is("text", ns::XMPP_STANZAS) {
|
||||
check_no_children!(child, "text");
|
||||
let lang = get_attr!(elem, "xml:lang", default);
|
||||
let lang = get_attr!(elem, "xml:lang", Default);
|
||||
if texts.insert(lang, child.text()).is_some() {
|
||||
return Err(Error::ParseError(
|
||||
"Text element present twice for the same xml:lang.",
|
||||
|
|
|
@ -39,16 +39,6 @@ macro_rules! get_attr {
|
|||
None => ::std::default::Default::default(),
|
||||
}
|
||||
};
|
||||
// The remaining ones are only for backwards-compatibility.
|
||||
($elem:ident, $attr:tt, optional, $value:ident, $func:expr) => {
|
||||
get_attr!($elem, $attr, Option, $value, $func)
|
||||
};
|
||||
($elem:ident, $attr:tt, required, $value:ident, $func:expr) => {
|
||||
get_attr!($elem, $attr, Required, $value, $func)
|
||||
};
|
||||
($elem:ident, $attr:tt, default, $value:ident, $func:expr) => {
|
||||
get_attr!($elem, $attr, Default, $value, $func)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! generate_attribute {
|
||||
|
@ -242,7 +232,7 @@ macro_rules! generate_attribute_enum {
|
|||
check_ns_only!(elem, $name, $ns);
|
||||
check_no_children!(elem, $name);
|
||||
check_no_unknown_attributes!(elem, $name, [$attr]);
|
||||
Ok(match get_attr!(elem, $attr, required) {
|
||||
Ok(match get_attr!(elem, $attr, Required) {
|
||||
$($enum_name => $elem::$enum,)+
|
||||
_ => return Err(crate::util::error::Error::ParseError(concat!("Invalid ", $name, " ", $attr, " value."))),
|
||||
})
|
||||
|
@ -639,8 +629,8 @@ macro_rules! impl_pubsub_item {
|
|||
));
|
||||
}
|
||||
Ok($item(crate::pubsub::Item {
|
||||
id: get_attr!(elem, "id", optional),
|
||||
publisher: get_attr!(elem, "publisher", optional),
|
||||
id: get_attr!(elem, "id", Option),
|
||||
publisher: get_attr!(elem, "publisher", Option),
|
||||
payload,
|
||||
}))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue