Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
0ed53d0775
commit
cb7382a941
2 changed files with 54 additions and 0 deletions
|
@ -13,3 +13,7 @@ minidom = "0.15"
|
|||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1.3"
|
||||
|
||||
[patch.crates-io]
|
||||
jid = { path = "../xmpp-rs/jid" }
|
||||
minidom = { path = "../xmpp-rs/minidom" }
|
||||
|
|
50
src/lib.rs
50
src/lib.rs
|
@ -20,6 +20,8 @@ use nom::{
|
|||
use jid::BareJid;
|
||||
use minidom::Element;
|
||||
|
||||
pub static DEFAULT_NS: &'static str = "jabber:client";
|
||||
|
||||
pub type AccountName = String;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -105,6 +107,33 @@ fn parse_connect(i: &str) -> IResult<&str, Action> {
|
|||
Ok((i, Action::Connect(String::from(name))))
|
||||
}
|
||||
|
||||
fn parse_action_line(i: &str) -> IResult<&str, &str> {
|
||||
let (i, (_, line, _)) = tuple((
|
||||
many1(tag("\t")),
|
||||
take_until1("\n"),
|
||||
tag("\n"),
|
||||
))(i)?;
|
||||
Ok((i, line))
|
||||
}
|
||||
|
||||
fn parse_send(i: &str) -> IResult<&str, Action> {
|
||||
let (i , (name, _, _, _, lines)) = tuple((
|
||||
take_while1(is_not_space),
|
||||
space1,
|
||||
tag("sends:"),
|
||||
take_while1(|c| c == ' ' || c == '\r' || c == '\n'), // Spaces but \t
|
||||
recognize(many1(parse_action_line)),
|
||||
))(i)?;
|
||||
let lines = lines.trim();
|
||||
|
||||
let elem: Element =
|
||||
Element::from_reader_with_prefixes(
|
||||
&lines.as_bytes()[..],
|
||||
String::from(DEFAULT_NS),
|
||||
).unwrap();
|
||||
Ok((i, Action::Send(String::from(name), elem)))
|
||||
}
|
||||
|
||||
fn parse_action(i: &str) -> IResult<&str, Action> {
|
||||
delimited(
|
||||
allspaces,
|
||||
|
@ -260,4 +289,25 @@ rosa connects
|
|||
let spec = Spec { accounts, actions };
|
||||
assert_eq!(parse_spec(buf1), Ok(spec));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_action_send() {
|
||||
let buf = r#"rosa sends:
|
||||
|
||||
<presence
|
||||
type="unavailable"
|
||||
/>
|
||||
|
||||
"#;
|
||||
|
||||
let xml = b"<presence\n\t\ttype=\"unavailable\"\t\n/>";
|
||||
let action = Action::Send(
|
||||
String::from("rosa"),
|
||||
Element::from_reader_with_prefixes(
|
||||
&xml[..],
|
||||
String::from(DEFAULT_NS),
|
||||
).unwrap(),
|
||||
);
|
||||
assert_eq!(parse_send(buf).unwrap().1, action);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue