aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoffix Znet <zoffixznet@users.noreply.github.com>2017-08-13 12:52:23 -0400
committerGitHub <noreply@github.com>2017-08-13 12:52:23 -0400
commit3772beb5bbb355405066fdd393f68ec80cbfe8a8 (patch)
treeb433e6d31341be5066603c44901cc5a56b3d50a9
parentae1a1b9df8a4a5aa2ac24797cb2795bae811ac56 (diff)
parentbf3b492f3eda79a5b492a87750b26d4228777601 (diff)
Merge pull request #46 from the-eater/add-ssl-support
Add SSL support
-rw-r--r--META6.json1
-rw-r--r--lib/IRC/Client.pm617
-rw-r--r--lib/IRC/Client/Server.pm62
3 files changed, 18 insertions, 2 deletions
diff --git a/META6.json b/META6.json
index 40f461e..4042d2f 100644
--- a/META6.json
+++ b/META6.json
@@ -6,6 +6,7 @@
"description" : "Extendable Internet Relay Chat client",
"tags" : [ "Net", "IRC" ],
"depends" : [
+ "IO::Socket::Async::SSL"
],
"test-depends" : [
"Test",
diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6
index 400a326..db1b4d4 100644
--- a/lib/IRC/Client.pm6
+++ b/lib/IRC/Client.pm6
@@ -1,5 +1,7 @@
unit class IRC::Client;
+use IO::Socket::Async::SSL;
+
use IRC::Client::Message;
use IRC::Client::Grammar;
use IRC::Client::Server;
@@ -34,6 +36,8 @@ submethod BUILD (
Str:D :$host = 'localhost',
:$nick = ['P6Bot'],
:$alias = [],
+ Bool:D :$ssl = False,
+ Str :$ca-file,
Str:D :$username = 'Perl6IRC',
Str:D :$userhost = 'localhost',
Str:D :$userreal = 'Perl6 IRC Client',
@@ -56,7 +60,7 @@ submethod BUILD (
:nick[ |($conf<nick> // %all-conf<nick>) ],
:alias[ |($conf<alias> // %all-conf<alias>) ],
|%(
- <host password port username userhost userreal>
+ <host password port username userhost userreal ssl ca-file>
.map: { $_ => $conf{$_} // %all-conf{$_} }
),
);
@@ -168,7 +172,16 @@ method !change-nick ($server) {
method !connect-socket ($server) {
$!debug and debug-print 'Attempting to connect to server', :out, :$server;
- IO::Socket::Async.connect($server.host, $server.port).then: sub ($prom) {
+
+ my $socket;
+
+ if ($server.ssl) {
+ $socket = IO::Socket::Async::SSL.connect($server.host, $server.port, ca-file => $server.ca-file);
+ } else {
+ $socket = IO::Socket::Async.connect($server.host, $server.port);
+ }
+
+ $socket.then: sub ($prom) {
if $prom.status ~~ Broken {
$server.is-connected = False;
$!debug and debug-print 'Could not connect', :out, :$server;
diff --git a/lib/IRC/Client/Server.pm6 b/lib/IRC/Client/Server.pm6
index 2ed5d69..2952869 100644
--- a/lib/IRC/Client/Server.pm6
+++ b/lib/IRC/Client/Server.pm6
@@ -4,6 +4,8 @@ has @.channels where .all ~~ Str|Pair;
has @.nick where .all ~~ Str;
has @.alias where .all ~~ Str|Regex;
has Int $.port where 0 <= $_ <= 65535;
+has Bool $.ssl;
+has Str $.ca-file;
has Str $.label;
has Str $.host;
has Str $.password;