cheezmiz 0.0.1
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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +661 -0
- data/README.rdoc +41 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/cheezmiz.geany +20 -0
- data/cheezmiz.gemspec +68 -0
- data/docs/chikka-1.capture +37 -0
- data/examples/callbacks.rb +84 -0
- data/lib/broker.rb +120 -0
- data/lib/cheezmiz.rb +20 -0
- data/lib/helper.rb +59 -0
- data/lib/protocol.rb +34 -0
- data/lib/protocol/buddy.rb +49 -0
- data/lib/protocol/client_ready.rb +28 -0
- data/lib/protocol/connection_established.rb +25 -0
- data/lib/protocol/information.rb +74 -0
- data/lib/protocol/keep_alive.rb +34 -0
- data/lib/protocol/login.rb +49 -0
- data/lib/protocol/message.rb +108 -0
- data/lib/protocol/submit.rb +56 -0
- data/lib/protocol/system_message.rb +32 -0
- data/lib/protocol/unknown_operation.rb +25 -0
- data/test/helper.rb +27 -0
- data/test/test_cheezmiz.rb +22 -0
- metadata +83 -0
data/lib/helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
class IO
|
20
|
+
def while_reading(data = nil)
|
21
|
+
while buf = readpartial_rescued(1024)
|
22
|
+
data << buf if data
|
23
|
+
yield buf if block_given?
|
24
|
+
end
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def readpartial_rescued(size)
|
31
|
+
readpartial(size)
|
32
|
+
rescue EOFError
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class String
|
38
|
+
def underscore
|
39
|
+
self.gsub(/::/, '/').
|
40
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
41
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
42
|
+
tr("-", "_").
|
43
|
+
downcase
|
44
|
+
end
|
45
|
+
|
46
|
+
def camelize(first_letter_in_uppercase = true)
|
47
|
+
if first_letter_in_uppercase
|
48
|
+
self.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
49
|
+
else
|
50
|
+
self.first + camelize(self)[1..-1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Module
|
56
|
+
def simple_name
|
57
|
+
self.name.split(/::/).last
|
58
|
+
end
|
59
|
+
end
|
data/lib/protocol.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
|
21
|
+
%w{ message
|
22
|
+
connection_established
|
23
|
+
login
|
24
|
+
information
|
25
|
+
buddy
|
26
|
+
client_ready
|
27
|
+
submit
|
28
|
+
keep_alive
|
29
|
+
system_message
|
30
|
+
unknown_operation
|
31
|
+
}.each { |lib| require "protocol/#{lib}" }
|
32
|
+
|
33
|
+
module Cheezmiz
|
34
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
require 'message'
|
21
|
+
|
22
|
+
module Cheezmiz
|
23
|
+
class BuddyListRequest < Message
|
24
|
+
def params_lut
|
25
|
+
end
|
26
|
+
|
27
|
+
def operation_code
|
28
|
+
'91'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class BuddyListBegin < Message
|
33
|
+
def params_lut
|
34
|
+
end
|
35
|
+
|
36
|
+
def operation_code
|
37
|
+
'30'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class BuddyListEnd < Message
|
42
|
+
def params_lut
|
43
|
+
end
|
44
|
+
|
45
|
+
def operation_code
|
46
|
+
'39'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
require 'message'
|
21
|
+
|
22
|
+
module Cheezmiz
|
23
|
+
class ClientReady < Message
|
24
|
+
def operation_code
|
25
|
+
'89'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
require 'message'
|
21
|
+
|
22
|
+
module Cheezmiz
|
23
|
+
class ConnectionEstablished < Message
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
require 'message'
|
21
|
+
|
22
|
+
module Cheezmiz
|
23
|
+
INFORMATION_COMMON_PARAMS =
|
24
|
+
{
|
25
|
+
:account => '001',
|
26
|
+
:manage => '002',
|
27
|
+
:fax => '005',
|
28
|
+
:_006 => '006',
|
29
|
+
:provider => '007',
|
30
|
+
:id => '010',
|
31
|
+
:alias => '012',
|
32
|
+
:alert => '013',
|
33
|
+
:ordinal => '015',
|
34
|
+
:first_name => '016',
|
35
|
+
:last_name => '017',
|
36
|
+
:email => '018',
|
37
|
+
:age => '019',
|
38
|
+
:sex => '020',
|
39
|
+
:_021 => '021',
|
40
|
+
:phone => '022',
|
41
|
+
:status => '023',
|
42
|
+
:city => '024',
|
43
|
+
:state => '025',
|
44
|
+
:country => '026',
|
45
|
+
:forward => '027',
|
46
|
+
:store => '028',
|
47
|
+
:_029 => '029',
|
48
|
+
:listed => '030',
|
49
|
+
:address => '031',
|
50
|
+
:extra => '032',
|
51
|
+
:_041 => '041',
|
52
|
+
:_051 => '051'
|
53
|
+
}
|
54
|
+
|
55
|
+
class AccountInformation < Message
|
56
|
+
def params_lut
|
57
|
+
INFORMATION_COMMON_PARAMS
|
58
|
+
end
|
59
|
+
|
60
|
+
def operation_code
|
61
|
+
'41'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class BuddyInformation < Message
|
66
|
+
def params_lut
|
67
|
+
INFORMATION_COMMON_PARAMS
|
68
|
+
end
|
69
|
+
|
70
|
+
def operation_code
|
71
|
+
'31'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
require 'message'
|
21
|
+
|
22
|
+
module Cheezmiz
|
23
|
+
class KeepAliveRequest < Message
|
24
|
+
def operation_code
|
25
|
+
'40'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class KeepAliveResponse < Message
|
30
|
+
def operation_code
|
31
|
+
'90'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
20
|
+
require 'message'
|
21
|
+
|
22
|
+
module Cheezmiz
|
23
|
+
class LoginRequest < Message
|
24
|
+
def params_lut
|
25
|
+
{
|
26
|
+
:username => '005',
|
27
|
+
:password => '002',
|
28
|
+
:timezone => '004',
|
29
|
+
:window_size => '003'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def operation_code
|
34
|
+
'01'
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_params(params)
|
38
|
+
params[:timezone] ||= 8
|
39
|
+
params[:window_size] ||= 5 # 2..13
|
40
|
+
params
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class LoginResponse < Message
|
45
|
+
def operation_code
|
46
|
+
'051'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# cheezmiz - a ruby library for Chikka
|
2
|
+
# Copyright (C) 2010 parasquid
|
3
|
+
#
|
4
|
+
# This file is part of cheezmiz
|
5
|
+
#
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Affero General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Affero General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Affero General Public License
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
$: << File.expand_path(File.dirname(__FILE__) + "/../")
|
20
|
+
require 'protocol'
|
21
|
+
require 'helper'
|
22
|
+
|
23
|
+
module Cheezmiz
|
24
|
+
class Message
|
25
|
+
def initialize(params = nil)
|
26
|
+
if params.respond_to?(:each_pair)
|
27
|
+
@params = params
|
28
|
+
else
|
29
|
+
@params, @sequence_number = decode(params)
|
30
|
+
@prototype = params
|
31
|
+
end
|
32
|
+
check_params @params if self.respond_to? :check_params
|
33
|
+
@options = populate_from(@params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.parse(stream)
|
37
|
+
message = case stream
|
38
|
+
when /^CTPv1\.[123] Kamusta/ then ConnectionEstablished.new stream
|
39
|
+
when /^30:/ then BuddyListBegin.new stream
|
40
|
+
when /^31:/ then BuddyInformation.new stream
|
41
|
+
when /^39:/ then BuddyListEnd.new stream
|
42
|
+
when /^40:/ then KeepAliveRequest.new stream
|
43
|
+
when /^41:/ then AccountInformation.new stream
|
44
|
+
when /^51:/ then LoginResponse.new stream
|
45
|
+
when /^55:/ then SystemMessage.new stream
|
46
|
+
when /^64:/ then SubmitResponse.new stream
|
47
|
+
else UnknownOperation.new stream
|
48
|
+
end
|
49
|
+
message
|
50
|
+
end
|
51
|
+
|
52
|
+
def sequence_number
|
53
|
+
@sequence_number
|
54
|
+
end
|
55
|
+
|
56
|
+
def data_fields
|
57
|
+
@params
|
58
|
+
end
|
59
|
+
|
60
|
+
def operation
|
61
|
+
self.class.simple_name.underscore.to_sym
|
62
|
+
end
|
63
|
+
|
64
|
+
def prototype
|
65
|
+
@prototype || "#{header}#{data}"
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def data
|
71
|
+
data = ''
|
72
|
+
@options.each do |key, value|
|
73
|
+
data << "#{key}:#{value}\t"
|
74
|
+
end
|
75
|
+
data
|
76
|
+
end
|
77
|
+
|
78
|
+
def header
|
79
|
+
"#{operation_code}:NNN\t"
|
80
|
+
end
|
81
|
+
|
82
|
+
def decode(message)
|
83
|
+
params = {}
|
84
|
+
if message && self.respond_to?(:params_lut) && params_lut
|
85
|
+
message[8..-5].split(/\t/).each do |field|
|
86
|
+
field_key, field_data = field.split(/:/)
|
87
|
+
if params_lut.invert[field_key]
|
88
|
+
params[params_lut.invert[field_key]] = field_data
|
89
|
+
end
|
90
|
+
end
|
91
|
+
sequence = message[0..7].split(/:/)[1]
|
92
|
+
end
|
93
|
+
return params, sequence
|
94
|
+
end
|
95
|
+
|
96
|
+
def populate_from(params)
|
97
|
+
params.merge default_params(params) if self.respond_to? :default_params
|
98
|
+
options = {}
|
99
|
+
if self.respond_to? :params_lut
|
100
|
+
params.each do |key, value|
|
101
|
+
raise "Unknown parameter: #{key}" if !params_lut[key]
|
102
|
+
options[params_lut[key]] = value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
options
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|