ircbgb 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +19 -0
- data/.gitignore +7 -0
- data/Gemfile +20 -0
- data/Rakefile +31 -0
- data/ircbgb.gemspec +25 -0
- data/lib/ircbgb.rb +15 -0
- data/lib/ircbgb/behaviors.rb +17 -0
- data/lib/ircbgb/behaviors/negotiates_connection.rb +38 -0
- data/lib/ircbgb/behaviors/provides_commands.rb +20 -0
- data/lib/ircbgb/client.rb +103 -0
- data/lib/ircbgb/errors.rb +5 -0
- data/lib/ircbgb/matcher.rb +13 -0
- data/lib/ircbgb/message.rb +17 -0
- data/lib/ircbgb/message_parser.rb +567 -0
- data/lib/ircbgb/message_parser.rl +84 -0
- data/lib/ircbgb/server.rb +13 -0
- data/lib/ircbgb/user.rb +32 -0
- data/lib/ircbgb/version.rb +3 -0
- data/spec/ircbgb/client_spec.rb +171 -0
- data/spec/ircbgb/matcher_spec.rb +25 -0
- data/spec/ircbgb/message_parser_spec.rb +100 -0
- data/spec/ircbgb/message_spec.rb +39 -0
- data/spec/ircbgb/user_spec.rb +72 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/dummy_io.rb +70 -0
- data/spec/support/stubz.rb +49 -0
- data/spec/support/unblocked_tcp_socket.rb +60 -0
- metadata +93 -0
data/.autotest
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# vim: set filetype=ruby :
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
require 'autotest/growl'
|
5
|
+
|
6
|
+
Autotest.add_hook :initialize do |at|
|
7
|
+
at.testlib = 'minitest/spec'
|
8
|
+
|
9
|
+
at.clear_mappings
|
10
|
+
at.add_mapping(/^lib\/(.*)\.rb$/) { |f, m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
at.add_mapping(/^spec\/.*_spec\.rb$/) { |f,_| f }
|
12
|
+
at.add_mapping(/^spec\/spec_helper\.rb$/) { |f,_|
|
13
|
+
at.files_matching(/^spec\/.*_spec\.rb$/)
|
14
|
+
}
|
15
|
+
|
16
|
+
at.add_exception '.git'
|
17
|
+
at.add_exception 'coverage'
|
18
|
+
end
|
19
|
+
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in ircbgb.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# Who needs animal trials, let's test on humans directly.
|
7
|
+
group :human_testing do
|
8
|
+
gem 'autotest'
|
9
|
+
gem 'autotest-growl'
|
10
|
+
gem 'minitest-emoji'
|
11
|
+
gem 'simplecov'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'minitest'
|
16
|
+
end
|
17
|
+
|
18
|
+
group :development do
|
19
|
+
gem 'io_unblock', :path => '/Users/chaos/code/ruby/io_unblock/'
|
20
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs.push "lib"
|
6
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :ragel do
|
11
|
+
desc "Delete previously built files"
|
12
|
+
task :clean do
|
13
|
+
sh "rm lib/ircbgb/message_parser.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Generate parsers from Ragel definitions"
|
17
|
+
task :parser do
|
18
|
+
sh "ragel -R lib/ircbgb/message_parser.rl"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "Ragel it!"
|
23
|
+
task :ragel => ['ragel:clean', 'ragel:parser']
|
24
|
+
|
25
|
+
desc "Generate a coverage report from tests with simplecov"
|
26
|
+
task :coverage do
|
27
|
+
ENV['SCOV'] = '1'
|
28
|
+
Rake::Task['test'].invoke
|
29
|
+
end
|
30
|
+
|
31
|
+
task :default => [:test]
|
data/ircbgb.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ircbgb/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ircbgb"
|
7
|
+
s.version = Ircbgb::VERSION
|
8
|
+
s.authors = ["Ian D. Eccles"]
|
9
|
+
s.email = ["ian.eccles@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{An IRC client library}
|
12
|
+
s.description = %q{An IRC client library geared toward writing custom clients and bots}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ircbgb"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
#Eventually, for now use the local build
|
22
|
+
#s.add_dependency 'io_unblock'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
end
|
data/lib/ircbgb.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'socket'
|
3
|
+
require 'io_unblock'
|
4
|
+
require 'ircbgb/version'
|
5
|
+
require 'ircbgb/errors'
|
6
|
+
require 'ircbgb/matcher'
|
7
|
+
require 'ircbgb/behaviors'
|
8
|
+
require 'ircbgb/client'
|
9
|
+
require 'ircbgb/message_parser'
|
10
|
+
require 'ircbgb/message'
|
11
|
+
require 'ircbgb/server'
|
12
|
+
require 'ircbgb/user'
|
13
|
+
|
14
|
+
module Ircbgb
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ircbgb
|
2
|
+
module Behaviors
|
3
|
+
def self.included klass
|
4
|
+
puts "Including #{self} in #{klass}"
|
5
|
+
# Include behavior modules
|
6
|
+
klass.__send__ :include, ProvidesCommands
|
7
|
+
klass.__send__ :include, NegotiatesConnection
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize_behaviors
|
11
|
+
register_connection_negotiation
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'ircbgb/behaviors/provides_commands'
|
17
|
+
require 'ircbgb/behaviors/negotiates_connection'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Ircbgb::Behaviors
|
2
|
+
module NegotiatesConnection
|
3
|
+
# TODO: even though we expect these modules
|
4
|
+
# to be tightly coupled to Client, do we really
|
5
|
+
# want to modify instance variables in them?
|
6
|
+
|
7
|
+
private
|
8
|
+
def register_connection_negotiation
|
9
|
+
on_ping do |(pong, _)|
|
10
|
+
do_pong pong
|
11
|
+
@c_state = :connected if connecting?
|
12
|
+
end
|
13
|
+
|
14
|
+
on_433 do |pars|
|
15
|
+
if connecting?
|
16
|
+
next_nick = next_nickname
|
17
|
+
if next_nick
|
18
|
+
do_nick next_nick
|
19
|
+
else
|
20
|
+
do_quit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def negotiate_connection
|
27
|
+
do_user self.username, self.realname
|
28
|
+
do_nick next_nickname
|
29
|
+
end
|
30
|
+
|
31
|
+
def next_nickname
|
32
|
+
@next_nick_idx ||= 0
|
33
|
+
nicks[@next_nick_idx].tap do
|
34
|
+
@next_nick_idx += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ircbgb::Behaviors
|
2
|
+
module ProvidesCommands
|
3
|
+
def do_pong echo
|
4
|
+
write_command 'PONG', ":#{echo}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def do_user username, realname
|
8
|
+
write_command 'USER', "#{username} 0 * :#{realname}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def do_nick nick
|
12
|
+
write_command 'NICK', nick
|
13
|
+
end
|
14
|
+
|
15
|
+
def do_quit msg=nil
|
16
|
+
msg = ":#{msg}" if msg
|
17
|
+
write_command 'QUIT', msg
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Ircbgb
|
2
|
+
class Client
|
3
|
+
include Behaviors
|
4
|
+
CRLF = "\r\n".freeze
|
5
|
+
|
6
|
+
attr_reader :nicks, :servers
|
7
|
+
attr_accessor :realname, :username
|
8
|
+
|
9
|
+
# Can be initialized with a block
|
10
|
+
def initialize
|
11
|
+
@servers = []
|
12
|
+
@nicks = []
|
13
|
+
@realname = ''
|
14
|
+
@username = ''
|
15
|
+
@c_state = :connecting
|
16
|
+
@callbacks = {}
|
17
|
+
@read_buffer = ''
|
18
|
+
yield self if block_given?
|
19
|
+
initialize_behaviors
|
20
|
+
end
|
21
|
+
|
22
|
+
def connecting?
|
23
|
+
@c_state = :connecting
|
24
|
+
end
|
25
|
+
|
26
|
+
def connected?
|
27
|
+
@c_state == :connected
|
28
|
+
end
|
29
|
+
|
30
|
+
def nicks= nicks
|
31
|
+
@nicks = Array(nicks)
|
32
|
+
end
|
33
|
+
|
34
|
+
def servers= servs
|
35
|
+
@servers = Array(servs)
|
36
|
+
end
|
37
|
+
|
38
|
+
def uris
|
39
|
+
@servers.map { |s|
|
40
|
+
URI.parse(s).tap do |u|
|
41
|
+
u.port ||= 6667
|
42
|
+
end
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def start
|
47
|
+
uri = uris.first
|
48
|
+
@stream = IoUnblock::TcpSocket.new(uri.host, uri.port, {
|
49
|
+
started: lambda { |st| negotiate_connection },
|
50
|
+
read: lambda { |str| parse_message str }
|
51
|
+
})
|
52
|
+
@stream.start
|
53
|
+
Thread.pass until @stream.running?
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def stop
|
58
|
+
@stream && @stream.stop
|
59
|
+
@stream = nil
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def bind ev, block, opts=nil
|
64
|
+
@callbacks[ev] ||= []
|
65
|
+
@callbacks[ev] << block
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def trigger ev, msg
|
70
|
+
cbs = @callbacks[ev.downcase]
|
71
|
+
if cbs
|
72
|
+
cbs.each do |cb|
|
73
|
+
cb.call(msg.params, msg)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
def write_command cmd, args=nil
|
81
|
+
rest = args.nil? ? '' : " #{args}"
|
82
|
+
@stream.write "#{cmd.upcase}#{rest}#{CRLF}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_message str
|
86
|
+
@read_buffer << str
|
87
|
+
while pos = @read_buffer.index(CRLF)
|
88
|
+
msg_str = @read_buffer[0..(pos+1)]
|
89
|
+
@read_buffer = @read_buffer[(pos+2)..-1]
|
90
|
+
msg = MessageParser.parse(msg_str)
|
91
|
+
trigger msg.command, msg
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def method_missing meth, *args, &block
|
96
|
+
if meth[0..2] == 'on_'
|
97
|
+
bind meth[3..-1].downcase, block, args
|
98
|
+
else
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ircbgb
|
2
|
+
class Matcher
|
3
|
+
def initialize pattern
|
4
|
+
escaped = Regexp.escape(pattern)
|
5
|
+
regexed = escaped.gsub("\\*", '.*').gsub("\\?", '.')
|
6
|
+
@pattern = Regexp.new("\\A#{regexed}\\Z", Regexp::IGNORECASE)
|
7
|
+
end
|
8
|
+
|
9
|
+
def =~ str
|
10
|
+
str.to_s =~ @pattern
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ircbgb
|
2
|
+
class Message
|
3
|
+
attr_reader :source, :arguments, :command, :params
|
4
|
+
|
5
|
+
def initialize src, cmd, params
|
6
|
+
@source = src
|
7
|
+
@command = cmd.upcase
|
8
|
+
@params = params
|
9
|
+
end
|
10
|
+
|
11
|
+
def numeric?
|
12
|
+
# According to RFC 1459, this is strictly \A\d\d\d\Z, but we'll
|
13
|
+
# allow a little flexibility
|
14
|
+
!!(@command =~ /\A\d+\Z/)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,567 @@
|
|
1
|
+
|
2
|
+
# line 1 "lib/ircbgb/message_parser.rl"
|
3
|
+
# RFC 1459 Message Parser to be processed by Ragel
|
4
|
+
|
5
|
+
# line 58 "lib/ircbgb/message_parser.rl"
|
6
|
+
|
7
|
+
|
8
|
+
module Ircbgb
|
9
|
+
class MessageParser
|
10
|
+
|
11
|
+
|
12
|
+
# line 13 "lib/ircbgb/message_parser.rb"
|
13
|
+
class << self
|
14
|
+
attr_accessor :_irc_message_parser_actions
|
15
|
+
private :_irc_message_parser_actions, :_irc_message_parser_actions=
|
16
|
+
end
|
17
|
+
self._irc_message_parser_actions = [
|
18
|
+
0, 1, 0, 1, 3, 1, 6, 1,
|
19
|
+
7, 1, 8, 1, 9, 1, 10, 1,
|
20
|
+
11, 1, 12, 1, 13, 1, 14, 2,
|
21
|
+
1, 11, 2, 2, 7, 2, 3, 10,
|
22
|
+
2, 4, 8, 2, 5, 6, 2, 7,
|
23
|
+
6, 2, 13, 12, 3, 0, 1, 11,
|
24
|
+
4, 2, 7, 5, 6
|
25
|
+
]
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_accessor :_irc_message_parser_key_offsets
|
29
|
+
private :_irc_message_parser_key_offsets, :_irc_message_parser_key_offsets=
|
30
|
+
end
|
31
|
+
self._irc_message_parser_key_offsets = [
|
32
|
+
0, 0, 7, 11, 12, 17, 21, 26,
|
33
|
+
30, 35, 39, 44, 48, 53, 57, 62,
|
34
|
+
66, 71, 75, 80, 84, 89, 93, 98,
|
35
|
+
102, 107, 111, 116, 120, 125, 129, 134,
|
36
|
+
138, 140, 143, 146, 156, 165, 172, 178,
|
37
|
+
184, 198, 203, 208, 219, 233, 242, 248,
|
38
|
+
262, 268, 275, 281, 288, 294, 301, 307,
|
39
|
+
314, 320, 327, 333, 340, 346, 353, 360,
|
40
|
+
367, 374, 381, 388, 395, 402, 409, 418,
|
41
|
+
425, 431, 439, 441, 444, 446, 449, 451,
|
42
|
+
454, 457, 458, 461, 462, 465, 466, 474,
|
43
|
+
482, 491, 500, 509, 516
|
44
|
+
]
|
45
|
+
|
46
|
+
class << self
|
47
|
+
attr_accessor :_irc_message_parser_trans_keys
|
48
|
+
private :_irc_message_parser_trans_keys, :_irc_message_parser_trans_keys=
|
49
|
+
end
|
50
|
+
self._irc_message_parser_trans_keys = [
|
51
|
+
58, 48, 57, 65, 90, 97, 122, 13,
|
52
|
+
32, 48, 57, 10, 0, 10, 13, 32,
|
53
|
+
58, 0, 10, 13, 32, 0, 10, 13,
|
54
|
+
32, 58, 0, 10, 13, 32, 0, 10,
|
55
|
+
13, 32, 58, 0, 10, 13, 32, 0,
|
56
|
+
10, 13, 32, 58, 0, 10, 13, 32,
|
57
|
+
0, 10, 13, 32, 58, 0, 10, 13,
|
58
|
+
32, 0, 10, 13, 32, 58, 0, 10,
|
59
|
+
13, 32, 0, 10, 13, 32, 58, 0,
|
60
|
+
10, 13, 32, 0, 10, 13, 32, 58,
|
61
|
+
0, 10, 13, 32, 0, 10, 13, 32,
|
62
|
+
58, 0, 10, 13, 32, 0, 10, 13,
|
63
|
+
32, 58, 0, 10, 13, 32, 0, 10,
|
64
|
+
13, 32, 58, 0, 10, 13, 32, 0,
|
65
|
+
10, 13, 32, 58, 0, 10, 13, 32,
|
66
|
+
0, 10, 13, 32, 58, 0, 10, 13,
|
67
|
+
32, 0, 10, 13, 32, 58, 0, 10,
|
68
|
+
13, 32, 32, 58, 0, 10, 13, 0,
|
69
|
+
10, 13, 48, 57, 65, 90, 91, 96,
|
70
|
+
97, 122, 123, 125, 32, 45, 46, 48,
|
71
|
+
57, 65, 90, 97, 122, 32, 48, 57,
|
72
|
+
65, 90, 97, 122, 13, 32, 65, 90,
|
73
|
+
97, 122, 48, 57, 65, 90, 97, 122,
|
74
|
+
32, 33, 45, 46, 48, 57, 65, 90,
|
75
|
+
91, 96, 97, 122, 123, 125, 0, 10,
|
76
|
+
13, 32, 64, 0, 10, 13, 32, 64,
|
77
|
+
48, 49, 57, 65, 70, 71, 90, 97,
|
78
|
+
102, 103, 122, 32, 45, 46, 58, 48,
|
79
|
+
57, 65, 70, 71, 90, 97, 102, 103,
|
80
|
+
122, 32, 45, 46, 48, 57, 65, 90,
|
81
|
+
97, 122, 48, 57, 65, 90, 97, 122,
|
82
|
+
32, 45, 46, 58, 48, 57, 65, 70,
|
83
|
+
71, 90, 97, 102, 103, 122, 48, 57,
|
84
|
+
65, 70, 97, 102, 58, 48, 57, 65,
|
85
|
+
70, 97, 102, 48, 57, 65, 70, 97,
|
86
|
+
102, 58, 48, 57, 65, 70, 97, 102,
|
87
|
+
48, 57, 65, 70, 97, 102, 58, 48,
|
88
|
+
57, 65, 70, 97, 102, 48, 57, 65,
|
89
|
+
70, 97, 102, 58, 48, 57, 65, 70,
|
90
|
+
97, 102, 48, 57, 65, 70, 97, 102,
|
91
|
+
58, 48, 57, 65, 70, 97, 102, 48,
|
92
|
+
57, 65, 70, 97, 102, 58, 48, 57,
|
93
|
+
65, 70, 97, 102, 48, 57, 65, 70,
|
94
|
+
97, 102, 32, 48, 57, 65, 70, 97,
|
95
|
+
102, 48, 49, 57, 65, 70, 97, 102,
|
96
|
+
58, 48, 57, 65, 70, 97, 102, 48,
|
97
|
+
49, 57, 65, 70, 97, 102, 58, 48,
|
98
|
+
57, 65, 70, 97, 102, 48, 49, 57,
|
99
|
+
65, 70, 97, 102, 58, 48, 57, 65,
|
100
|
+
70, 97, 102, 48, 49, 57, 65, 70,
|
101
|
+
97, 102, 58, 48, 57, 65, 70, 97,
|
102
|
+
102, 48, 70, 102, 49, 57, 65, 69,
|
103
|
+
97, 101, 58, 48, 57, 65, 70, 97,
|
104
|
+
102, 48, 57, 65, 70, 97, 102, 46,
|
105
|
+
58, 48, 57, 65, 70, 97, 102, 48,
|
106
|
+
57, 46, 48, 57, 48, 57, 46, 48,
|
107
|
+
57, 48, 57, 32, 48, 57, 32, 48,
|
108
|
+
57, 32, 46, 48, 57, 46, 46, 48,
|
109
|
+
57, 46, 46, 58, 48, 57, 65, 70,
|
110
|
+
97, 102, 46, 58, 48, 57, 65, 70,
|
111
|
+
97, 102, 58, 70, 102, 48, 57, 65,
|
112
|
+
69, 97, 101, 58, 70, 102, 48, 57,
|
113
|
+
65, 69, 97, 101, 58, 70, 102, 48,
|
114
|
+
57, 65, 69, 97, 101, 32, 33, 45,
|
115
|
+
48, 57, 65, 125, 0
|
116
|
+
]
|
117
|
+
|
118
|
+
class << self
|
119
|
+
attr_accessor :_irc_message_parser_single_lengths
|
120
|
+
private :_irc_message_parser_single_lengths, :_irc_message_parser_single_lengths=
|
121
|
+
end
|
122
|
+
self._irc_message_parser_single_lengths = [
|
123
|
+
0, 1, 2, 1, 5, 4, 5, 4,
|
124
|
+
5, 4, 5, 4, 5, 4, 5, 4,
|
125
|
+
5, 4, 5, 4, 5, 4, 5, 4,
|
126
|
+
5, 4, 5, 4, 5, 4, 5, 4,
|
127
|
+
2, 3, 3, 0, 3, 1, 2, 0,
|
128
|
+
4, 5, 5, 1, 4, 3, 0, 4,
|
129
|
+
0, 1, 0, 1, 0, 1, 0, 1,
|
130
|
+
0, 1, 0, 1, 0, 1, 1, 1,
|
131
|
+
1, 1, 1, 1, 1, 1, 3, 1,
|
132
|
+
0, 2, 0, 1, 0, 1, 0, 1,
|
133
|
+
1, 1, 1, 1, 1, 1, 2, 2,
|
134
|
+
3, 3, 3, 3, 0
|
135
|
+
]
|
136
|
+
|
137
|
+
class << self
|
138
|
+
attr_accessor :_irc_message_parser_range_lengths
|
139
|
+
private :_irc_message_parser_range_lengths, :_irc_message_parser_range_lengths=
|
140
|
+
end
|
141
|
+
self._irc_message_parser_range_lengths = [
|
142
|
+
0, 3, 1, 0, 0, 0, 0, 0,
|
143
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
144
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
145
|
+
0, 0, 0, 0, 0, 0, 0, 0,
|
146
|
+
0, 0, 0, 5, 3, 3, 2, 3,
|
147
|
+
5, 0, 0, 5, 5, 3, 3, 5,
|
148
|
+
3, 3, 3, 3, 3, 3, 3, 3,
|
149
|
+
3, 3, 3, 3, 3, 3, 3, 3,
|
150
|
+
3, 3, 3, 3, 3, 3, 3, 3,
|
151
|
+
3, 3, 1, 1, 1, 1, 1, 1,
|
152
|
+
1, 0, 1, 0, 1, 0, 3, 3,
|
153
|
+
3, 3, 3, 2, 0
|
154
|
+
]
|
155
|
+
|
156
|
+
class << self
|
157
|
+
attr_accessor :_irc_message_parser_index_offsets
|
158
|
+
private :_irc_message_parser_index_offsets, :_irc_message_parser_index_offsets=
|
159
|
+
end
|
160
|
+
self._irc_message_parser_index_offsets = [
|
161
|
+
0, 0, 5, 9, 11, 17, 22, 28,
|
162
|
+
33, 39, 44, 50, 55, 61, 66, 72,
|
163
|
+
77, 83, 88, 94, 99, 105, 110, 116,
|
164
|
+
121, 127, 132, 138, 143, 149, 154, 160,
|
165
|
+
165, 168, 172, 176, 182, 189, 194, 199,
|
166
|
+
203, 213, 219, 225, 232, 242, 249, 253,
|
167
|
+
263, 267, 272, 276, 281, 285, 290, 294,
|
168
|
+
299, 303, 308, 312, 317, 321, 326, 331,
|
169
|
+
336, 341, 346, 351, 356, 361, 366, 373,
|
170
|
+
378, 382, 388, 390, 393, 395, 398, 400,
|
171
|
+
403, 406, 408, 411, 413, 416, 418, 424,
|
172
|
+
430, 437, 444, 451, 457
|
173
|
+
]
|
174
|
+
|
175
|
+
class << self
|
176
|
+
attr_accessor :_irc_message_parser_trans_targs
|
177
|
+
private :_irc_message_parser_trans_targs, :_irc_message_parser_trans_targs=
|
178
|
+
end
|
179
|
+
self._irc_message_parser_trans_targs = [
|
180
|
+
35, 2, 38, 38, 0, 3, 4, 2,
|
181
|
+
0, 92, 0, 0, 0, 0, 4, 33,
|
182
|
+
5, 0, 0, 3, 6, 5, 0, 0,
|
183
|
+
0, 6, 33, 7, 0, 0, 3, 8,
|
184
|
+
7, 0, 0, 0, 8, 33, 9, 0,
|
185
|
+
0, 3, 10, 9, 0, 0, 0, 10,
|
186
|
+
33, 11, 0, 0, 3, 12, 11, 0,
|
187
|
+
0, 0, 12, 33, 13, 0, 0, 3,
|
188
|
+
14, 13, 0, 0, 0, 14, 33, 15,
|
189
|
+
0, 0, 3, 16, 15, 0, 0, 0,
|
190
|
+
16, 33, 17, 0, 0, 3, 18, 17,
|
191
|
+
0, 0, 0, 18, 33, 19, 0, 0,
|
192
|
+
3, 20, 19, 0, 0, 0, 20, 33,
|
193
|
+
21, 0, 0, 3, 22, 21, 0, 0,
|
194
|
+
0, 22, 33, 23, 0, 0, 3, 24,
|
195
|
+
23, 0, 0, 0, 24, 33, 25, 0,
|
196
|
+
0, 3, 26, 25, 0, 0, 0, 26,
|
197
|
+
33, 27, 0, 0, 3, 28, 27, 0,
|
198
|
+
0, 0, 28, 33, 29, 0, 0, 3,
|
199
|
+
30, 29, 0, 0, 0, 30, 33, 31,
|
200
|
+
0, 0, 3, 32, 31, 32, 33, 0,
|
201
|
+
0, 0, 3, 34, 0, 0, 3, 34,
|
202
|
+
36, 40, 91, 40, 91, 0, 37, 36,
|
203
|
+
39, 36, 36, 36, 0, 37, 2, 38,
|
204
|
+
38, 0, 3, 4, 38, 38, 0, 36,
|
205
|
+
36, 36, 0, 37, 41, 40, 39, 40,
|
206
|
+
40, 91, 40, 91, 0, 0, 0, 0,
|
207
|
+
0, 0, 42, 0, 0, 0, 37, 43,
|
208
|
+
42, 44, 47, 47, 45, 47, 45, 0,
|
209
|
+
37, 45, 46, 62, 47, 47, 45, 47,
|
210
|
+
45, 0, 37, 45, 46, 45, 45, 45,
|
211
|
+
0, 45, 45, 45, 0, 37, 45, 46,
|
212
|
+
48, 47, 47, 45, 47, 45, 0, 49,
|
213
|
+
49, 49, 0, 50, 49, 49, 49, 0,
|
214
|
+
51, 51, 51, 0, 52, 51, 51, 51,
|
215
|
+
0, 53, 53, 53, 0, 54, 53, 53,
|
216
|
+
53, 0, 55, 55, 55, 0, 56, 55,
|
217
|
+
55, 55, 0, 57, 57, 57, 0, 58,
|
218
|
+
57, 57, 57, 0, 59, 59, 59, 0,
|
219
|
+
60, 59, 59, 59, 0, 61, 61, 61,
|
220
|
+
0, 37, 61, 61, 61, 0, 63, 49,
|
221
|
+
49, 49, 0, 64, 49, 49, 49, 0,
|
222
|
+
65, 51, 51, 51, 0, 66, 51, 51,
|
223
|
+
51, 0, 67, 53, 53, 53, 0, 68,
|
224
|
+
53, 53, 53, 0, 69, 55, 55, 55,
|
225
|
+
0, 70, 55, 55, 55, 0, 71, 88,
|
226
|
+
88, 57, 57, 57, 0, 72, 57, 57,
|
227
|
+
57, 0, 73, 59, 59, 0, 74, 60,
|
228
|
+
86, 59, 59, 0, 75, 0, 76, 84,
|
229
|
+
0, 77, 0, 78, 82, 0, 79, 0,
|
230
|
+
37, 80, 0, 37, 81, 0, 37, 0,
|
231
|
+
78, 83, 0, 78, 0, 76, 85, 0,
|
232
|
+
76, 0, 74, 60, 87, 59, 59, 0,
|
233
|
+
74, 60, 59, 59, 59, 0, 58, 89,
|
234
|
+
89, 57, 57, 57, 0, 58, 90, 90,
|
235
|
+
57, 57, 57, 0, 58, 71, 71, 57,
|
236
|
+
57, 57, 0, 37, 41, 91, 91, 91,
|
237
|
+
0, 0, 0
|
238
|
+
]
|
239
|
+
|
240
|
+
class << self
|
241
|
+
attr_accessor :_irc_message_parser_trans_actions
|
242
|
+
private :_irc_message_parser_trans_actions, :_irc_message_parser_trans_actions=
|
243
|
+
end
|
244
|
+
self._irc_message_parser_trans_actions = [
|
245
|
+
1, 44, 44, 44, 21, 0, 0, 15,
|
246
|
+
21, 0, 21, 21, 21, 21, 0, 0,
|
247
|
+
32, 21, 21, 11, 11, 9, 21, 21,
|
248
|
+
21, 0, 0, 32, 21, 21, 11, 11,
|
249
|
+
9, 21, 21, 21, 0, 0, 32, 21,
|
250
|
+
21, 11, 11, 9, 21, 21, 21, 0,
|
251
|
+
0, 32, 21, 21, 11, 11, 9, 21,
|
252
|
+
21, 21, 0, 0, 32, 21, 21, 11,
|
253
|
+
11, 9, 21, 21, 21, 0, 0, 32,
|
254
|
+
21, 21, 11, 11, 9, 21, 21, 21,
|
255
|
+
0, 0, 32, 21, 21, 11, 11, 9,
|
256
|
+
21, 21, 21, 0, 0, 32, 21, 21,
|
257
|
+
11, 11, 9, 21, 21, 21, 0, 0,
|
258
|
+
32, 21, 21, 11, 11, 9, 21, 21,
|
259
|
+
21, 0, 0, 32, 21, 21, 11, 11,
|
260
|
+
9, 21, 21, 21, 0, 0, 32, 21,
|
261
|
+
21, 11, 11, 9, 21, 21, 21, 0,
|
262
|
+
0, 32, 21, 21, 11, 11, 9, 21,
|
263
|
+
21, 21, 0, 0, 32, 21, 21, 11,
|
264
|
+
11, 9, 21, 21, 21, 0, 0, 32,
|
265
|
+
21, 21, 11, 11, 9, 0, 0, 21,
|
266
|
+
21, 21, 3, 29, 21, 21, 0, 13,
|
267
|
+
26, 48, 35, 48, 35, 21, 19, 7,
|
268
|
+
7, 7, 7, 7, 21, 0, 23, 23,
|
269
|
+
23, 21, 0, 0, 15, 15, 21, 7,
|
270
|
+
7, 7, 21, 41, 5, 38, 7, 38,
|
271
|
+
38, 5, 38, 5, 21, 21, 21, 21,
|
272
|
+
21, 21, 5, 21, 21, 21, 17, 5,
|
273
|
+
5, 5, 5, 5, 5, 5, 5, 21,
|
274
|
+
17, 5, 5, 5, 5, 5, 5, 5,
|
275
|
+
5, 21, 17, 5, 5, 5, 5, 5,
|
276
|
+
21, 5, 5, 5, 21, 17, 5, 5,
|
277
|
+
5, 5, 5, 5, 5, 5, 21, 5,
|
278
|
+
5, 5, 21, 5, 5, 5, 5, 21,
|
279
|
+
5, 5, 5, 21, 5, 5, 5, 5,
|
280
|
+
21, 5, 5, 5, 21, 5, 5, 5,
|
281
|
+
5, 21, 5, 5, 5, 21, 5, 5,
|
282
|
+
5, 5, 21, 5, 5, 5, 21, 5,
|
283
|
+
5, 5, 5, 21, 5, 5, 5, 21,
|
284
|
+
5, 5, 5, 5, 21, 5, 5, 5,
|
285
|
+
21, 17, 5, 5, 5, 21, 5, 5,
|
286
|
+
5, 5, 21, 5, 5, 5, 5, 21,
|
287
|
+
5, 5, 5, 5, 21, 5, 5, 5,
|
288
|
+
5, 21, 5, 5, 5, 5, 21, 5,
|
289
|
+
5, 5, 5, 21, 5, 5, 5, 5,
|
290
|
+
21, 5, 5, 5, 5, 21, 5, 5,
|
291
|
+
5, 5, 5, 5, 21, 5, 5, 5,
|
292
|
+
5, 21, 5, 5, 5, 21, 5, 5,
|
293
|
+
5, 5, 5, 21, 5, 21, 5, 5,
|
294
|
+
21, 5, 21, 5, 5, 21, 5, 21,
|
295
|
+
17, 5, 21, 17, 5, 21, 17, 21,
|
296
|
+
5, 5, 21, 5, 21, 5, 5, 21,
|
297
|
+
5, 21, 5, 5, 5, 5, 5, 21,
|
298
|
+
5, 5, 5, 5, 5, 21, 5, 5,
|
299
|
+
5, 5, 5, 5, 21, 5, 5, 5,
|
300
|
+
5, 5, 5, 21, 5, 5, 5, 5,
|
301
|
+
5, 5, 21, 17, 5, 5, 5, 5,
|
302
|
+
21, 21, 0
|
303
|
+
]
|
304
|
+
|
305
|
+
class << self
|
306
|
+
attr_accessor :_irc_message_parser_eof_actions
|
307
|
+
private :_irc_message_parser_eof_actions, :_irc_message_parser_eof_actions=
|
308
|
+
end
|
309
|
+
self._irc_message_parser_eof_actions = [
|
310
|
+
0, 21, 21, 21, 21, 21, 21, 21,
|
311
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
312
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
313
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
314
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
315
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
316
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
317
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
318
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
319
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
320
|
+
21, 21, 21, 21, 21, 21, 21, 21,
|
321
|
+
21, 21, 21, 21, 0
|
322
|
+
]
|
323
|
+
|
324
|
+
class << self
|
325
|
+
attr_accessor :irc_message_parser_start
|
326
|
+
end
|
327
|
+
self.irc_message_parser_start = 1;
|
328
|
+
class << self
|
329
|
+
attr_accessor :irc_message_parser_first_final
|
330
|
+
end
|
331
|
+
self.irc_message_parser_first_final = 92;
|
332
|
+
class << self
|
333
|
+
attr_accessor :irc_message_parser_error
|
334
|
+
end
|
335
|
+
self.irc_message_parser_error = 0;
|
336
|
+
|
337
|
+
class << self
|
338
|
+
attr_accessor :irc_message_parser_en_main
|
339
|
+
end
|
340
|
+
self.irc_message_parser_en_main = 1;
|
341
|
+
|
342
|
+
|
343
|
+
# line 64 "lib/ircbgb/message_parser.rl"
|
344
|
+
|
345
|
+
def self.parse str
|
346
|
+
data = str
|
347
|
+
server = ''
|
348
|
+
user_mask = ''
|
349
|
+
para = ''
|
350
|
+
rest = ''
|
351
|
+
params = []
|
352
|
+
source = nil
|
353
|
+
cmd = ''
|
354
|
+
|
355
|
+
|
356
|
+
# line 357 "lib/ircbgb/message_parser.rb"
|
357
|
+
begin
|
358
|
+
p ||= 0
|
359
|
+
pe ||= data.length
|
360
|
+
cs = irc_message_parser_start
|
361
|
+
end
|
362
|
+
|
363
|
+
# line 76 "lib/ircbgb/message_parser.rl"
|
364
|
+
|
365
|
+
# line 366 "lib/ircbgb/message_parser.rb"
|
366
|
+
begin
|
367
|
+
_klen, _trans, _keys, _acts, _nacts = nil
|
368
|
+
_goto_level = 0
|
369
|
+
_resume = 10
|
370
|
+
_eof_trans = 15
|
371
|
+
_again = 20
|
372
|
+
_test_eof = 30
|
373
|
+
_out = 40
|
374
|
+
while true
|
375
|
+
_trigger_goto = false
|
376
|
+
if _goto_level <= 0
|
377
|
+
if p == pe
|
378
|
+
_goto_level = _test_eof
|
379
|
+
next
|
380
|
+
end
|
381
|
+
if cs == 0
|
382
|
+
_goto_level = _out
|
383
|
+
next
|
384
|
+
end
|
385
|
+
end
|
386
|
+
if _goto_level <= _resume
|
387
|
+
_keys = _irc_message_parser_key_offsets[cs]
|
388
|
+
_trans = _irc_message_parser_index_offsets[cs]
|
389
|
+
_klen = _irc_message_parser_single_lengths[cs]
|
390
|
+
_break_match = false
|
391
|
+
|
392
|
+
begin
|
393
|
+
if _klen > 0
|
394
|
+
_lower = _keys
|
395
|
+
_upper = _keys + _klen - 1
|
396
|
+
|
397
|
+
loop do
|
398
|
+
break if _upper < _lower
|
399
|
+
_mid = _lower + ( (_upper - _lower) >> 1 )
|
400
|
+
|
401
|
+
if data[p].ord < _irc_message_parser_trans_keys[_mid]
|
402
|
+
_upper = _mid - 1
|
403
|
+
elsif data[p].ord > _irc_message_parser_trans_keys[_mid]
|
404
|
+
_lower = _mid + 1
|
405
|
+
else
|
406
|
+
_trans += (_mid - _keys)
|
407
|
+
_break_match = true
|
408
|
+
break
|
409
|
+
end
|
410
|
+
end # loop
|
411
|
+
break if _break_match
|
412
|
+
_keys += _klen
|
413
|
+
_trans += _klen
|
414
|
+
end
|
415
|
+
_klen = _irc_message_parser_range_lengths[cs]
|
416
|
+
if _klen > 0
|
417
|
+
_lower = _keys
|
418
|
+
_upper = _keys + (_klen << 1) - 2
|
419
|
+
loop do
|
420
|
+
break if _upper < _lower
|
421
|
+
_mid = _lower + (((_upper-_lower) >> 1) & ~1)
|
422
|
+
if data[p].ord < _irc_message_parser_trans_keys[_mid]
|
423
|
+
_upper = _mid - 2
|
424
|
+
elsif data[p].ord > _irc_message_parser_trans_keys[_mid+1]
|
425
|
+
_lower = _mid + 2
|
426
|
+
else
|
427
|
+
_trans += ((_mid - _keys) >> 1)
|
428
|
+
_break_match = true
|
429
|
+
break
|
430
|
+
end
|
431
|
+
end # loop
|
432
|
+
break if _break_match
|
433
|
+
_trans += _klen
|
434
|
+
end
|
435
|
+
end while false
|
436
|
+
cs = _irc_message_parser_trans_targs[_trans]
|
437
|
+
if _irc_message_parser_trans_actions[_trans] != 0
|
438
|
+
_acts = _irc_message_parser_trans_actions[_trans]
|
439
|
+
_nacts = _irc_message_parser_actions[_acts]
|
440
|
+
_acts += 1
|
441
|
+
while _nacts > 0
|
442
|
+
_nacts -= 1
|
443
|
+
_acts += 1
|
444
|
+
case _irc_message_parser_actions[_acts - 1]
|
445
|
+
when 0 then
|
446
|
+
# line 5 "lib/ircbgb/message_parser.rl"
|
447
|
+
begin
|
448
|
+
eof = pe end
|
449
|
+
when 1 then
|
450
|
+
# line 6 "lib/ircbgb/message_parser.rl"
|
451
|
+
begin
|
452
|
+
cmd = '' end
|
453
|
+
when 2 then
|
454
|
+
# line 7 "lib/ircbgb/message_parser.rl"
|
455
|
+
begin
|
456
|
+
server = '' end
|
457
|
+
when 3 then
|
458
|
+
# line 8 "lib/ircbgb/message_parser.rl"
|
459
|
+
begin
|
460
|
+
rest = '' end
|
461
|
+
when 4 then
|
462
|
+
# line 9 "lib/ircbgb/message_parser.rl"
|
463
|
+
begin
|
464
|
+
param = '' end
|
465
|
+
when 5 then
|
466
|
+
# line 10 "lib/ircbgb/message_parser.rl"
|
467
|
+
begin
|
468
|
+
user_mask = '' end
|
469
|
+
when 6 then
|
470
|
+
# line 11 "lib/ircbgb/message_parser.rl"
|
471
|
+
begin
|
472
|
+
user_mask << data[p] end
|
473
|
+
when 7 then
|
474
|
+
# line 12 "lib/ircbgb/message_parser.rl"
|
475
|
+
begin
|
476
|
+
server << data[p] end
|
477
|
+
when 8 then
|
478
|
+
# line 13 "lib/ircbgb/message_parser.rl"
|
479
|
+
begin
|
480
|
+
param << data[p] end
|
481
|
+
when 9 then
|
482
|
+
# line 14 "lib/ircbgb/message_parser.rl"
|
483
|
+
begin
|
484
|
+
params << param end
|
485
|
+
when 10 then
|
486
|
+
# line 15 "lib/ircbgb/message_parser.rl"
|
487
|
+
begin
|
488
|
+
rest << data[p] end
|
489
|
+
when 11 then
|
490
|
+
# line 16 "lib/ircbgb/message_parser.rl"
|
491
|
+
begin
|
492
|
+
cmd << data[p] end
|
493
|
+
when 12 then
|
494
|
+
# line 17 "lib/ircbgb/message_parser.rl"
|
495
|
+
begin
|
496
|
+
|
497
|
+
source = ::Ircbgb::User.parse(user_mask)
|
498
|
+
end
|
499
|
+
when 13 then
|
500
|
+
# line 20 "lib/ircbgb/message_parser.rl"
|
501
|
+
begin
|
502
|
+
|
503
|
+
source = ::Ircbgb::Server.new(server)
|
504
|
+
end
|
505
|
+
when 14 then
|
506
|
+
# line 26 "lib/ircbgb/message_parser.rl"
|
507
|
+
begin
|
508
|
+
|
509
|
+
raise ::Ircbgb::MessageFormatError, "invalid form #{data.inspect} at #{p} '#{data[p]}'"
|
510
|
+
end
|
511
|
+
# line 512 "lib/ircbgb/message_parser.rb"
|
512
|
+
end # action switch
|
513
|
+
end
|
514
|
+
end
|
515
|
+
if _trigger_goto
|
516
|
+
next
|
517
|
+
end
|
518
|
+
end
|
519
|
+
if _goto_level <= _again
|
520
|
+
if cs == 0
|
521
|
+
_goto_level = _out
|
522
|
+
next
|
523
|
+
end
|
524
|
+
p += 1
|
525
|
+
if p != pe
|
526
|
+
_goto_level = _resume
|
527
|
+
next
|
528
|
+
end
|
529
|
+
end
|
530
|
+
if _goto_level <= _test_eof
|
531
|
+
if p == eof
|
532
|
+
__acts = _irc_message_parser_eof_actions[cs]
|
533
|
+
__nacts = _irc_message_parser_actions[__acts]
|
534
|
+
__acts += 1
|
535
|
+
while __nacts > 0
|
536
|
+
__nacts -= 1
|
537
|
+
__acts += 1
|
538
|
+
case _irc_message_parser_actions[__acts - 1]
|
539
|
+
when 14 then
|
540
|
+
# line 26 "lib/ircbgb/message_parser.rl"
|
541
|
+
begin
|
542
|
+
|
543
|
+
raise ::Ircbgb::MessageFormatError, "invalid form #{data.inspect} at #{p} '#{data[p]}'"
|
544
|
+
end
|
545
|
+
# line 546 "lib/ircbgb/message_parser.rb"
|
546
|
+
end # eof action switch
|
547
|
+
end
|
548
|
+
if _trigger_goto
|
549
|
+
next
|
550
|
+
end
|
551
|
+
end
|
552
|
+
end
|
553
|
+
if _goto_level <= _out
|
554
|
+
break
|
555
|
+
end
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
# line 77 "lib/ircbgb/message_parser.rl"
|
560
|
+
|
561
|
+
params << rest unless rest.empty?
|
562
|
+
|
563
|
+
::Ircbgb::Message.new source, cmd, params
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|