macros: Rename generate_element_with_only_attributes!() into generate_element!().

This commit is contained in:
Emmanuel Gil Peyrot 2018-05-28 16:42:35 +02:00
parent ef227c4617
commit 9c598fbdf9
16 changed files with 80 additions and 52 deletions

View file

@ -17,22 +17,24 @@ use ns;
use iq::{IqGetPayload, IqResultPayload};
use data_forms::{DataForm, DataFormType};
generate_element_with_only_attributes!(
generate_element!(
/// Structure representing a `<query xmlns='http://jabber.org/protocol/disco#info'/>` element.
///
/// It should only be used in an `<iq type='get'/>`, as it can only represent
/// the request, and not a result.
DiscoInfoQuery, "query", DISCO_INFO, [
DiscoInfoQuery, "query", DISCO_INFO,
attributes: [
/// Node on which we are doing the discovery.
node: Option<String> = "node" => optional,
]);
impl IqGetPayload for DiscoInfoQuery {}
generate_element_with_only_attributes!(
generate_element!(
/// Structure representing a `<feature xmlns='http://jabber.org/protocol/disco#info'/>` element.
#[derive(PartialEq)]
Feature, "feature", DISCO_INFO, [
Feature, "feature", DISCO_INFO,
attributes: [
/// Namespace of the feature we want to represent.
var: String = "var" => required,
]);
@ -185,21 +187,23 @@ impl From<DiscoInfoResult> for Element {
}
}
generate_element_with_only_attributes!(
generate_element!(
/// Structure representing a `<query xmlns='http://jabber.org/protocol/disco#items'/>` element.
///
/// It should only be used in an `<iq type='get'/>`, as it can only represent
/// the request, and not a result.
DiscoItemsQuery, "query", DISCO_ITEMS, [
DiscoItemsQuery, "query", DISCO_ITEMS,
attributes: [
/// Node on which we are doing the discovery.
node: Option<String> = "node" => optional,
]);
impl IqGetPayload for DiscoItemsQuery {}
generate_element_with_only_attributes!(
generate_element!(
/// Structure representing an `<item xmlns='http://jabber.org/protocol/disco#items'/>` element.
Item, "item", DISCO_ITEMS, [
Item, "item", DISCO_ITEMS,
attributes: [
/// JID of the entity pointed by this item.
jid: Jid = "jid" => required,
/// Node of the entity pointed by this item.

View file

@ -4,9 +4,10 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
generate_element_with_only_attributes!(
generate_element!(
/// Structure representing an `<encryption xmlns='urn:xmpp:eme:0'/>` element.
ExplicitMessageEncryption, "encryption", EME, [
ExplicitMessageEncryption, "encryption", EME,
attributes: [
/// Namespace of the encryption scheme used.
namespace: String = "namespace" => required,

View file

@ -12,7 +12,8 @@ generate_attribute!(Stanza, "stanza", {
Message => "message",
}, Default = Iq);
generate_element_with_only_attributes!(Open, "open", IBB, [
generate_element!(Open, "open", IBB,
attributes: [
block_size: u16 = "block-size" => required,
sid: String = "sid" => required,
stanza: Stanza = "stanza" => default,
@ -30,7 +31,8 @@ generate_element_with_text!(Data, "data", IBB,
impl IqSetPayload for Data {}
generate_element_with_only_attributes!(Close, "close", IBB, [
generate_element!(Close, "close", IBB,
attributes: [
sid: String = "sid" => required,
]);

View file

@ -6,7 +6,8 @@
use date::DateTime;
generate_element_with_only_attributes!(Idle, "idle", IDLE, [
generate_element!(Idle, "idle", IDLE,
attributes: [
since: DateTime = "since" => required,
]);

View file

@ -287,7 +287,8 @@ impl From<Checksum> for Element {
}
}
generate_element_with_only_attributes!(Received, "received", JINGLE_FT, [
generate_element!(Received, "received", JINGLE_FT,
attributes: [
name: ContentId = "name" => required,
creator: Creator = "creator" => required,
]);

View file

@ -8,7 +8,8 @@ use ibb::Stanza;
generate_id!(StreamId);
generate_element_with_only_attributes!(Transport, "transport", JINGLE_IBB, [
generate_element!(Transport, "transport", JINGLE_IBB,
attributes: [
block_size: u16 = "block-size" => required,
sid: StreamId = "sid" => required,
stanza: Stanza = "stanza" => default,

View file

@ -30,7 +30,8 @@ generate_id!(CandidateId);
generate_id!(StreamId);
generate_element_with_only_attributes!(Candidate, "candidate", JINGLE_S5B, [
generate_element!(Candidate, "candidate", JINGLE_S5B,
attributes: [
cid: CandidateId = "cid" => required,
host: IpAddr = "host" => required,
jid: Jid = "jid" => required,

View file

@ -285,15 +285,6 @@ macro_rules! generate_empty_element {
);
}
macro_rules! generate_element_with_only_attributes {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
);
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
);
}
macro_rules! generate_id {
($elem:ident) => (
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -473,6 +464,15 @@ macro_rules! generate_serialiser {
);
}
macro_rules! generate_element {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+,]) => (
generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
);
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, attributes: [$($(#[$attr_meta:meta])* $attr:ident: $attr_type:ty = $attr_name:tt => $attr_action:tt),+]) => (
generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [$($(#[$attr_meta])* $attr: $attr_type = $attr_name => $attr_action),*], children: []);
);
}
macro_rules! generate_element_with_children {
($(#[$meta:meta])* $elem:ident, $name:tt, $ns:ident, children: [$($(#[$child_meta:meta])* $child_ident:ident: $coucou:tt<$child_type:ty> = ($child_name:tt, $child_ns:ident) => $child_constructor:ident),*]) => (
generate_element_with_children!($(#[$meta])* $elem, $name, $ns, attributes: [], children: [$($(#[$child_meta])* $child_ident: $coucou<$child_type> = ($child_name, $child_ns) => $child_constructor),*]);

View file

@ -4,7 +4,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
generate_element_with_only_attributes!(Replace, "replace", MESSAGE_CORRECT, [
generate_element!(Replace, "replace", MESSAGE_CORRECT,
attributes: [
id: String = "id" => required,
]);

View file

@ -120,7 +120,8 @@ impl From<Actor> for Element {
}
}
generate_element_with_only_attributes!(Continue, "continue", MUC_USER, [
generate_element!(Continue, "continue", MUC_USER,
attributes: [
thread: Option<String> = "thread" => optional,
]);

View file

@ -58,9 +58,10 @@ generate_attribute!(
}
);
generate_element_with_only_attributes!(
generate_element!(
/// An affiliation element.
Affiliation, "affiliation", PUBSUB, [
Affiliation, "affiliation", PUBSUB,
attributes: [
/// The node this affiliation pertains to.
node: NodeName = "node" => required,
@ -78,17 +79,19 @@ generate_element_with_children!(
]
);
generate_element_with_only_attributes!(
generate_element!(
/// Request to create a new node.
Create, "create", PUBSUB, [
Create, "create", PUBSUB,
attributes: [
/// The node name to create, if `None` the service will generate one.
node: Option<NodeName> = "node" => optional,
]
);
generate_element_with_only_attributes!(
generate_element!(
/// Request for a default node configuration.
Default, "default", PUBSUB, [
Default, "default", PUBSUB,
attributes: [
/// The node targetted by this request, otherwise the entire service.
node: Option<NodeName> = "node" => optional,
@ -260,9 +263,10 @@ impl From<SubscribeOptions> for Element {
}
}
generate_element_with_only_attributes!(
generate_element!(
/// A request to subscribe a JID to a node.
Subscribe, "subscribe", PUBSUB, [
Subscribe, "subscribe", PUBSUB,
attributes: [
/// The JID being subscribed.
jid: Jid = "jid" => required,
@ -306,9 +310,10 @@ generate_element_with_children!(
]
);
generate_element_with_only_attributes!(
generate_element!(
/// An unsubscribe request.
Unsubscribe, "unsubscribe", PUBSUB, [
Unsubscribe, "unsubscribe", PUBSUB,
attributes: [
/// The JID affected by this request.
jid: Jid = "jid" => required,

View file

@ -6,7 +6,8 @@
generate_empty_element!(Request, "request", RECEIPTS);
generate_element_with_only_attributes!(Received, "received", RECEIPTS, [
generate_element!(Received, "received", RECEIPTS,
attributes: [
id: Option<String> = "id" => optional,
]);

View file

@ -6,8 +6,9 @@
use stanza_error::DefinedCondition;
generate_element_with_only_attributes!(
A, "a", SM, [
generate_element!(
A, "a", SM,
attributes: [
h: u32 = "h" => required,
]
);
@ -20,8 +21,9 @@ impl A {
generate_attribute!(ResumeAttr, "resume", bool);
generate_element_with_only_attributes!(
Enable, "enable", SM, [
generate_element!(
Enable, "enable", SM,
attributes: [
// TODO: should be the infinite integer set ≥ 1.
max: Option<u32> = "max" => optional,
resume: ResumeAttr = "resume" => default,
@ -47,8 +49,9 @@ impl Enable {
}
}
generate_element_with_only_attributes!(
Enabled, "enabled", SM, [
generate_element!(
Enabled, "enabled", SM,
attributes: [
id: Option<String> = "id" => optional,
location: Option<String> = "location" => optional,
// TODO: should be the infinite integer set ≥ 1.
@ -72,15 +75,17 @@ generate_empty_element!(
R, "r", SM
);
generate_element_with_only_attributes!(
Resume, "resume", SM, [
generate_element!(
Resume, "resume", SM,
attributes: [
h: u32 = "h" => required,
previd: String = "previd" => required,
]
);
generate_element_with_only_attributes!(
Resumed, "resumed", SM, [
generate_element!(
Resumed, "resumed", SM,
attributes: [
h: u32 = "h" => required,
previd: String = "previd" => required,
]

View file

@ -6,12 +6,14 @@
use jid::Jid;
generate_element_with_only_attributes!(StanzaId, "stanza-id", SID, [
generate_element!(StanzaId, "stanza-id", SID,
attributes: [
id: String = "id" => required,
by: Jid = "by" => required,
]);
generate_element_with_only_attributes!(OriginId, "origin-id", SID, [
generate_element!(OriginId, "origin-id", SID,
attributes: [
id: String = "id" => required,
]);

View file

@ -6,7 +6,8 @@
use jid::Jid;
generate_element_with_only_attributes!(Stream, "stream", STREAM, [
generate_element!(Stream, "stream", STREAM,
attributes: [
from: Option<Jid> = "from" => optional,
to: Option<Jid> = "to" => optional,
id: Option<String> = "id" => optional,

View file

@ -6,7 +6,8 @@
use jid::Jid;
generate_element_with_only_attributes!(Open, "open", WEBSOCKET, [
generate_element!(Open, "open", WEBSOCKET,
attributes: [
from: Option<Jid> = "from" => optional,
to: Option<Jid> = "to" => optional,
id: Option<String> = "id" => optional,