net-yail 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/net/yail/irc_bot.rb +1 -0
- data/lib/net/yail/yail-version.rb +1 -1
- data/lib/net/yail.rb +35 -9
- metadata +3 -3
data/lib/net/yail/irc_bot.rb
CHANGED
@@ -24,6 +24,7 @@ class IRCBot
|
|
24
24
|
# If set, :loud and :silent options are ignored.
|
25
25
|
# * <tt>:log_io</tt>: Optional, ignored if you specify your own :log - sends given object to
|
26
26
|
# Logger's constructor. Must be filename or IO object.
|
27
|
+
# * <tt>:use_ssl</tt>: Defaults to false. If true, attempts to use SSL for connection.
|
27
28
|
def initialize(options = {})
|
28
29
|
@start_time = Time.now
|
29
30
|
@options = options
|
data/lib/net/yail.rb
CHANGED
@@ -290,6 +290,7 @@ class YAIL
|
|
290
290
|
# If set, :loud and :silent options are ignored.
|
291
291
|
# * <tt>:log_io</tt>: Optional, ignored if you specify your own :log - sends given object to
|
292
292
|
# Logger's constructor. Must be filename or IO object.
|
293
|
+
# * <tt>:use_ssl</tt>: Defaults to false. If true, attempts to use SSL for connection.
|
293
294
|
def initialize(options = {})
|
294
295
|
@me = ''
|
295
296
|
@nicknames = options[:nicknames]
|
@@ -302,6 +303,7 @@ class YAIL
|
|
302
303
|
@log_loud = options[:loud] || false
|
303
304
|
@throttle_seconds = options[:throttle_seconds] || 1
|
304
305
|
@password = options[:server_password]
|
306
|
+
@ssl = options[:use_ssl] || false
|
305
307
|
|
306
308
|
# Special handling to avoid mucking with Logger constants if we're using a different logger
|
307
309
|
if options[:log]
|
@@ -331,6 +333,7 @@ class YAIL
|
|
331
333
|
# Build our socket - if something goes wrong, it's immediately a dead socket.
|
332
334
|
begin
|
333
335
|
@socket = TCPSocket.new(@address, @port)
|
336
|
+
setup_ssl if @ssl
|
334
337
|
rescue StandardError => boom
|
335
338
|
@log.fatal "+++ERROR: Unable to open socket connection in Net::YAIL.initialize: #{boom.inspect}"
|
336
339
|
@dead_socket = true
|
@@ -418,11 +421,32 @@ class YAIL
|
|
418
421
|
|
419
422
|
private
|
420
423
|
|
424
|
+
# If user asked for SSL, this is where we set it all up
|
425
|
+
def setup_ssl
|
426
|
+
require 'openssl'
|
427
|
+
ssl_context = OpenSSL::SSL::SSLContext.new()
|
428
|
+
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
429
|
+
@socket = OpenSSL::SSL::SSLSocket.new(@socket, ssl_context)
|
430
|
+
@socket.sync = true
|
431
|
+
@socket.connect
|
432
|
+
end
|
433
|
+
|
434
|
+
# Depending on protocol (SSL vs. not), reads atomic messages from socket. This could be the
|
435
|
+
# start of more generic message reading for other protocols, but for now reads a single line
|
436
|
+
# for IRC and any number of lines from SSL IRC.
|
437
|
+
def read_socket_messages
|
438
|
+
# Simple non-ssl socket == return a single line
|
439
|
+
return [@socket.gets] unless @ssl
|
440
|
+
|
441
|
+
# SSL socket == return all lines available
|
442
|
+
return @socket.readpartial(Buffering::BLOCK_SIZE).split($/).collect {|message| message}
|
443
|
+
end
|
444
|
+
|
421
445
|
# Reads incoming data - should only be called by io_loop, and only when
|
422
446
|
# we've already ensured that data is, in fact, available.
|
423
447
|
def read_incoming_data
|
424
448
|
begin
|
425
|
-
|
449
|
+
messages = read_socket_messages.compact
|
426
450
|
rescue StandardError => boom
|
427
451
|
@dead_socket = true
|
428
452
|
@log.fatal "+++ERROR in read_incoming_data -> @socket.gets: #{boom.inspect}"
|
@@ -430,19 +454,21 @@ class YAIL
|
|
430
454
|
end
|
431
455
|
|
432
456
|
# If we somehow got no data here, the socket is closed. Run away!!!
|
433
|
-
if !
|
457
|
+
if !messages || messages.empty?
|
434
458
|
@dead_socket = true
|
435
459
|
return
|
436
460
|
end
|
437
461
|
|
438
|
-
|
439
|
-
|
440
|
-
|
462
|
+
# Chomp and push each message
|
463
|
+
for message in messages
|
464
|
+
message.chomp!
|
465
|
+
@log.debug "+++INCOMING: #{message.inspect}"
|
441
466
|
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
467
|
+
# Only synchronize long enough to push our incoming string onto the
|
468
|
+
# input buffer
|
469
|
+
@input_buffer_mutex.synchronize do
|
470
|
+
@input_buffer.push(message)
|
471
|
+
end
|
446
472
|
end
|
447
473
|
end
|
448
474
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 1.4.
|
8
|
+
- 3
|
9
|
+
version: 1.4.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeremy Echols
|
@@ -14,7 +14,7 @@ autorequire: net/yail
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-20 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|