From 41428c499d872aecaa1bf492518a2dbd4aaa84b4 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Thu, 16 Jul 2015 15:35:09 -0400 Subject: [PATCH] Added support for SASL IRCv3 extension. --- src/client/data/caps.rs | 4 ++++ src/client/data/command.rs | 17 +++++++++++++++++ src/client/data/response.rs | 21 +++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/client/data/caps.rs b/src/client/data/caps.rs index 3024fe5..94c5aa4 100644 --- a/src/client/data/caps.rs +++ b/src/client/data/caps.rs @@ -6,6 +6,8 @@ pub enum Capability { /// [multi-prefix](http://ircv3.net/specs/extensions/multi-prefix-3.1.html) MultiPrefix, + /// [sasl](http://ircv3.net/specs/extensions/sasl-3.1.html) + Sasl, /// [account-notify](http://ircv3.net/specs/extensions/account-notify-3.1.html) AccountNotify, /// [away-notify](http://ircv3.net/specs/extensions/away-notify-3.1.html) @@ -50,6 +52,7 @@ impl AsRef for Capability { fn as_ref(&self) -> &str { match *self { Capability::MultiPrefix => "multi-prefix", + Capability::Sasl => "sasl", Capability::AccountNotify => "account-notify", Capability::AwayNotify => "away-notify", Capability::ExtendedJoin => "extended-join", @@ -76,6 +79,7 @@ mod test { #[test] fn to_str() { assert_eq!(MultiPrefix.as_ref(), "multi-prefix"); + assert_eq!(Sasl.as_ref(), "sasl"); assert_eq!(AccountNotify.as_ref(), "account-notify"); assert_eq!(AwayNotify.as_ref(), "away-notify"); assert_eq!(ExtendedJoin.as_ref(), "extended-join"); diff --git a/src/client/data/command.rs b/src/client/data/command.rs index 74298b7..e4b17b0 100644 --- a/src/client/data/command.rs +++ b/src/client/data/command.rs @@ -149,6 +149,8 @@ pub enum Command { CAP(Option, CapSubCommand, Option, Option), // IRCv3.1 extensions + /// AUTHENTICATE data + AUTHENTICATE(String), /// ACCOUNT [account name] ACCOUNT(String), // AWAY is already defined as a send-only message. @@ -334,6 +336,8 @@ impl Into for Command { Command::CAP(Some(k), s, Some(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) => Message::from_owned(None, string("ACCOUNT"), Some(vec![a]), None), @@ -1098,6 +1102,19 @@ impl<'a> From<&'a Message> for Result { } else { 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[..] { match m.suffix { Some(ref suffix) => if m.args.len() == 0 { diff --git a/src/client/data/response.rs b/src/client/data/response.rs index 0c81d09..29c7b83 100644 --- a/src/client/data/response.rs +++ b/src/client/data/response.rs @@ -213,6 +213,14 @@ make_response! { RPL_KEYVALUE = 761, /// 762 :end of metadata RPL_METADATAEND = 762, + /// 900 !@ :You are now logged in as + RPL_LOGGEDIN = 900, + /// 901 !@ :You are now logged out + RPL_LOGGEDOUT = 901, + /// 903 :SASL authentication successful + RPL_SASLSUCCESS = 903, + /// 908 :are available SASL mechanisms + RPL_SASLMECHS = 908, // Error replies /// 401 :No such nick/channel @@ -334,8 +342,17 @@ make_response! { /// 768 :key not set ERR_KEYNOTSET = 768, /// 769 :permission denied - ERR_KEYNOPERMISSION = 779 - + ERR_KEYNOPERMISSION = 779, + /// 902 :You must use a nick assigned to you. + ERR_NICKLOCKED = 902, + /// 904 :SASL authentication failed + ERR_SASLFAIL = 904, + /// 905 :SASL message too long + ERR_SASLTOOLONG = 905, + /// 906 :SASL authentication aborted + ERR_SASLABORT = 906, + /// 907 :You have already authenticated using SASL + ERR_SASLALREADY = 907 } impl Response {