Added support for SASL IRCv3 extension.

This commit is contained in:
Aaron Weiss 2015-07-16 15:35:09 -04:00
parent 2f7c7b116c
commit 41428c499d
3 changed files with 40 additions and 2 deletions

View file

@ -6,6 +6,8 @@
pub enum Capability { pub enum Capability {
/// [multi-prefix](http://ircv3.net/specs/extensions/multi-prefix-3.1.html) /// [multi-prefix](http://ircv3.net/specs/extensions/multi-prefix-3.1.html)
MultiPrefix, MultiPrefix,
/// [sasl](http://ircv3.net/specs/extensions/sasl-3.1.html)
Sasl,
/// [account-notify](http://ircv3.net/specs/extensions/account-notify-3.1.html) /// [account-notify](http://ircv3.net/specs/extensions/account-notify-3.1.html)
AccountNotify, AccountNotify,
/// [away-notify](http://ircv3.net/specs/extensions/away-notify-3.1.html) /// [away-notify](http://ircv3.net/specs/extensions/away-notify-3.1.html)
@ -50,6 +52,7 @@ impl AsRef<str> for Capability {
fn as_ref(&self) -> &str { fn as_ref(&self) -> &str {
match *self { match *self {
Capability::MultiPrefix => "multi-prefix", Capability::MultiPrefix => "multi-prefix",
Capability::Sasl => "sasl",
Capability::AccountNotify => "account-notify", Capability::AccountNotify => "account-notify",
Capability::AwayNotify => "away-notify", Capability::AwayNotify => "away-notify",
Capability::ExtendedJoin => "extended-join", Capability::ExtendedJoin => "extended-join",
@ -76,6 +79,7 @@ mod test {
#[test] #[test]
fn to_str() { fn to_str() {
assert_eq!(MultiPrefix.as_ref(), "multi-prefix"); assert_eq!(MultiPrefix.as_ref(), "multi-prefix");
assert_eq!(Sasl.as_ref(), "sasl");
assert_eq!(AccountNotify.as_ref(), "account-notify"); assert_eq!(AccountNotify.as_ref(), "account-notify");
assert_eq!(AwayNotify.as_ref(), "away-notify"); assert_eq!(AwayNotify.as_ref(), "away-notify");
assert_eq!(ExtendedJoin.as_ref(), "extended-join"); assert_eq!(ExtendedJoin.as_ref(), "extended-join");

View file

@ -149,6 +149,8 @@ pub enum Command {
CAP(Option<String>, CapSubCommand, Option<String>, Option<String>), CAP(Option<String>, CapSubCommand, Option<String>, Option<String>),
// IRCv3.1 extensions // IRCv3.1 extensions
/// AUTHENTICATE data
AUTHENTICATE(String),
/// ACCOUNT [account name] /// ACCOUNT [account name]
ACCOUNT(String), ACCOUNT(String),
// AWAY is already defined as a send-only message. // AWAY is already defined as a send-only message.
@ -334,6 +336,8 @@ impl Into<Message> for Command {
Command::CAP(Some(k), s, Some(c), p) => Command::CAP(Some(k), s, Some(c), p) =>
Message::from_owned(None, string("CAP"), Some(vec![k, s.string(), c]), p), Message::from_owned(None, string("CAP"), Some(vec![k, s.string(), c]), p),
Command::AUTHENTICATE(d) =>
Message::from_owned(None, string("AUTHENTICATE"), Some(vec![d]), None),
Command::ACCOUNT(a) => Command::ACCOUNT(a) =>
Message::from_owned(None, string("ACCOUNT"), Some(vec![a]), None), Message::from_owned(None, string("ACCOUNT"), Some(vec![a]), None),
@ -1098,6 +1102,19 @@ impl<'a> From<&'a Message> for Result<Command> {
} else { } else {
return Err(invalid_input()) return Err(invalid_input())
} }
} else if let "AUTHENTICATE" = &m.command[..] {
match m.suffix {
Some(ref suffix) => if m.args.len() == 0 {
Command::AUTHENTICATE(suffix.clone())
} else {
return Err(invalid_input())
},
None => if m.args.len() == 1 {
Command::AUTHENTICATE(m.args[0].clone())
} else {
return Err(invalid_input())
}
}
} else if let "ACCOUNT" = &m.command[..] { } else if let "ACCOUNT" = &m.command[..] {
match m.suffix { match m.suffix {
Some(ref suffix) => if m.args.len() == 0 { Some(ref suffix) => if m.args.len() == 0 {

View file

@ -213,6 +213,14 @@ make_response! {
RPL_KEYVALUE = 761, RPL_KEYVALUE = 761,
/// 762 :end of metadata /// 762 :end of metadata
RPL_METADATAEND = 762, RPL_METADATAEND = 762,
/// 900 <nick> <nick>!<ident>@<host> <account> :You are now logged in as <user>
RPL_LOGGEDIN = 900,
/// 901 <nick> <nick>!<ident>@<host> :You are now logged out
RPL_LOGGEDOUT = 901,
/// 903 <nick> :SASL authentication successful
RPL_SASLSUCCESS = 903,
/// 908 <nick> <mechanisms> :are available SASL mechanisms
RPL_SASLMECHS = 908,
// Error replies // Error replies
/// 401 <nickname> :No such nick/channel /// 401 <nickname> :No such nick/channel
@ -334,8 +342,17 @@ make_response! {
/// 768 <target> <key> :key not set /// 768 <target> <key> :key not set
ERR_KEYNOTSET = 768, ERR_KEYNOTSET = 768,
/// 769 <target> <key> :permission denied /// 769 <target> <key> :permission denied
ERR_KEYNOPERMISSION = 779 ERR_KEYNOPERMISSION = 779,
/// 902 <nick> :You must use a nick assigned to you.
ERR_NICKLOCKED = 902,
/// 904 <nick> :SASL authentication failed
ERR_SASLFAIL = 904,
/// 905 <nick> :SASL message too long
ERR_SASLTOOLONG = 905,
/// 906 <nick> :SASL authentication aborted
ERR_SASLABORT = 906,
/// 907 <nick> :You have already authenticated using SASL
ERR_SASLALREADY = 907
} }
impl Response { impl Response {