SkypeR 0.0.8 → 0.0.9

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.
@@ -14,7 +14,8 @@ module SkypeR
14
14
  class Identifier < Yaparc::AbstractParser
15
15
  def initialize
16
16
  @parser = lambda do
17
- Yaparc::Tokenize.new(Yaparc::Ident.new)
17
+ # Yaparc::Tokenize.new(Yaparc::Ident.new)
18
+ Yaparc::Regex.new(/\A[0-9a-zA-Z_]+/)
18
19
  end
19
20
  end
20
21
  end
@@ -50,7 +51,7 @@ module SkypeR
50
51
  class CommandID < Yaparc::AbstractParser
51
52
  def initialize
52
53
  @parser = lambda do
53
- Yaparc::Tokenize.new(Yaparc::Regex.new(/#[A-Z0-9]+/))
54
+ Yaparc::Tokenize.new(Yaparc::Regex.new(/\A#[A-Z0-9]+/))
54
55
  # Yaparc::Token.new(Yaparc::Regex.new(/#[A-Z0-9]+/))
55
56
  end
56
57
  end
@@ -60,8 +61,16 @@ module SkypeR
60
61
  class ChatID < Yaparc::AbstractParser
61
62
  def initialize
62
63
  @parser = lambda do
63
- Yaparc::Tokenize.new(Yaparc::Regex.new(/#[A-Za-z]*\/\$[A-Za-z]*;[0-9]*/))
64
- # Yaparc::Token.new(Yaparc::Regex.new(/#[A-Za-z]*\/\$[A-Za-z]*;[0-9]*/))
64
+ # #tk3adapter/$akimichi_tatsukawa;309cfdf0927d827b
65
+ Yaparc::Seq.new(Yaparc::Literal.new('#'),
66
+ Identifier.new,
67
+ Yaparc::Literal.new('/$'),
68
+ Identifier.new,
69
+ Yaparc::Literal.new(';'),
70
+ Yaparc::Regex.new(/\A\w+/)) do |_,sender,_,receiver,_,identifier|
71
+ "##{sender}/$#{receiver};#{identifier}"
72
+ # Yaparc::Tokenize.new(Yaparc::Regex.new(/#[A-Za-z]*\/\$[A-Za-z]*;[0-9]*/))
73
+ end
65
74
  end
66
75
  end
67
76
  end
@@ -6,7 +6,7 @@ require "logger"
6
6
 
7
7
 
8
8
  =begin
9
- (insert-image-file "~/develop/ruby/skyper/docs/parser.png")
9
+
10
10
  =end
11
11
 
12
12
  module SkypeR
@@ -46,10 +46,12 @@ module SkypeR
46
46
  def initialize
47
47
  @parser = lambda do
48
48
  Yaparc::Seq.new(Yaparc::Symbol.new("USER"),
49
- Yaparc::Identifier.new,
50
- SkypeR::Parser::UserProperty.new,
51
- AnyValue.new) do |_,identifier,property, value|
52
- {:identifier => identifier, :property => property, :value => value}
49
+ Yaparc::Identifier.new,
50
+ SkypeR::Parser::UserProperty.new,
51
+ AnyValue.new) do |_,identifier,property, value|
52
+ #{:identifier => identifier, :property => property, :value => value}
53
+ SkypeR::Object::User.new(Hash[:handle => identifier, :"#{property}" => value])
54
+
53
55
  end
54
56
  end
55
57
  end
@@ -99,15 +101,15 @@ module SkypeR
99
101
  def initialize
100
102
  @parser = lambda do
101
103
  Yaparc::Seq.new(Yaparc::Symbol.new("CHAT"),
102
- ChatID.new,
103
- Yaparc::Symbol.new("CHATMESSAGES"),
104
- Yaparc::Many.new(
105
- Yaparc::Seq.new(Yaparc::Symbol.new(','),
106
- Target.new) do |_, target|
107
- target
108
- end
109
- )
110
- )
104
+ SkypeR::Parser::ChatID.new,
105
+ Yaparc::Symbol.new("CHATMESSAGES"),
106
+ Yaparc::Many.new(
107
+ Yaparc::Seq.new(Yaparc::Symbol.new(','),
108
+ Target.new) do |_, target|
109
+ target
110
+ end
111
+ )
112
+ )
111
113
  end
112
114
  end
113
115
  end
@@ -258,20 +260,44 @@ module SkypeR
258
260
 
259
261
  # <chat_create_response> := CHAT <chat_id> STATUS <value>
260
262
  class ChatCreateResponse < ResponseBase
261
- def initialize
263
+ attr_accessor :chat_object
264
+
265
+ def initialize(chat_object)
266
+ @chat_object = chat_object
262
267
  @parser = lambda do
263
268
  Yaparc::Seq.new(
269
+ CommandID.new,
264
270
  Yaparc::Symbol.new("CHAT"),
265
- CallId.new,
271
+ SkypeR::Parser::ChatID.new,
266
272
  Yaparc::Symbol.new("STATUS"),
267
273
  AnyValue.new
268
- ) do |_,call_id,_,value|
269
- {:call_id => call_id, :value => value}
274
+ ) do |command_id,_,chat_id,_,status|
275
+ @chat_object.name = chat_id
276
+ @chat_object.status = status
277
+ @chat_object
278
+ #SkypeR::Object::Chat.new(Hash[:name => chat_id, :status => status]
270
279
  end
271
280
  end
272
281
  end
273
282
  end
274
283
 
275
284
 
285
+ # <chat_message_response> := CHATMESSAGE <id> STATUS SENDING
286
+ class ChatMessageResponse < ResponseBase
287
+ def initialize
288
+ @parser = lambda do
289
+ Yaparc::Seq.new(
290
+ Yaparc::Symbol.new("CHATMESSAGE"),
291
+ CallId.new,
292
+ Yaparc::Symbol.new("STATUS"),
293
+ Yaparc::Symbol.new("SENDING")
294
+ ) do |_,call_id,_,_|
295
+ #{:call_id => call_id}
296
+ SkypeR::Object::ChatMessage.new(Hash[:from_handle => call_id, :status => :sending])
297
+ end
298
+ end
299
+ end
300
+ end
301
+
276
302
  end # of Parser
277
303
  end # of Skyper
@@ -1,5 +1,4 @@
1
1
  require 'rubygems'
2
- #require 'uuidtools.rb'
3
2
  require 'uuidtools'
4
3
  require 'rbus.rb'
5
4
  require 'thread.rb'
@@ -10,6 +9,12 @@ module SkypeR
10
9
  module Service
11
10
  class Application
12
11
  def initialize(name, protocol_num = 5)
12
+ unless ENV["DBUS_SESSION_BUS_ADDRESS"]
13
+ output = `dbus-launch --auto-syntax`
14
+ dbus_session_bus_address, dummy, dbus_session_bus_pid = output.split("\n")
15
+ ENV["DBUS_SESSION_BUS_ADDRESS"] = dbus_session_bus_address.match(/\ADBUS_SESSION_BUS_ADDRESS='(.*)';\Z/)[1]
16
+ ENV["DBUS_SESSION_BUS_PID"] = dbus_session_bus_pid.match(/\ADBUS_SESSION_BUS_PID=(.*)*;\Z/)[1]
17
+ end
13
18
  remote_bus = ::RBus.session_bus
14
19
  service_name = 'com.Skype.API'
15
20
  object_path = "/com/Skype"
@@ -19,30 +24,39 @@ module SkypeR
19
24
  @invoked_commands = Hash.new
20
25
  end
21
26
 
27
+
28
+ def execute(command, timeout = 60)
29
+
30
+ end
31
+
22
32
  def invoke(command, timeout = 60)
23
33
  begin
24
34
  ::Timeout.timeout(timeout) {
25
35
  authenticate
26
- @invoked_commands[command.command_id] = command.statement
27
- @api_object.Invoke("##{command.command_id} #{command.statement}")
36
+ case result = parse(command)
37
+ when Yaparc::Result::OK
38
+ response_parser = result.value[:response_parser]
39
+ generated_object = result.value[:generated_object]
40
+ @invoked_commands[command.command_id] = command.statement
41
+ response_statement = @api_object.Invoke("##{command.command_id} #{command.statement}")
42
+ # response_parser.parse(response_statement)
43
+ when Yaparc::Result::Fail
44
+ raise SkypeR::Exception::ParseError
45
+ else
46
+ raise SkypeR::Exception::UnknownError
47
+ end
28
48
  }
49
+ rescue SkypeR::Exception::ParseError
50
+ puts "Parse Error: '#{command.statement}'"
51
+ []
29
52
  rescue ::Timeout::Error
30
53
  puts "Connection timeout. Please try again."
31
54
  end
32
55
  end
33
56
 
34
57
 
35
- def parse(message)
36
- case message
37
- when CommandMessage
38
- command_parser = SkypeR::Parser::CommandStatement.new
39
- command_parser.parse(message.statement)
40
- when ResponseMessage
41
- response_parser = SkypeR::Parser::ResponseCommandStatement.new
42
- response_parser.parse(message.statement)
43
- else
44
- raise
45
- end
58
+ def parse(command_message)
59
+ command_message.parse
46
60
  end
47
61
 
48
62
  def validate(command)
@@ -80,9 +94,17 @@ module SkypeR
80
94
 
81
95
  def initialize(statement)
82
96
  @statement = statement
83
- @command_id = UUID.timestamp_create.to_i
97
+ # UUID.mac_address = nil
98
+ # @command_id = UUID.timestamp_create.to_i
99
+ @command_id = UUID.random_create.to_i
84
100
  end
85
- end # of Command
101
+
102
+ def parse
103
+ command_parser = SkypeR::Parser::CommandStatement.new
104
+ command_parser.parse(@statement)
105
+ end
106
+
107
+ end # of CommandMessage
86
108
 
87
109
 
88
110
  class ResponseMessage < MessageBase
@@ -91,6 +113,12 @@ module SkypeR
91
113
  @statement = statement
92
114
  @response_instance = response_instance
93
115
  end
116
+
117
+ def parse
118
+ response_parser = SkypeR::Parser::ResponseCommandStatement.new
119
+ response_parser.parse(@statement)
120
+ end
121
+
94
122
  end # Response
95
123
 
96
124
  # class Result < Response
@@ -0,0 +1,127 @@
1
+ require 'rubygems'
2
+ require 'uuidtools'
3
+ require 'rbus.rb'
4
+ require 'thread.rb'
5
+ require 'timeout.rb'
6
+
7
+
8
+ module SkypeR
9
+ module Service
10
+ class Application
11
+ def initialize(name, protocol_num = 5)
12
+ unless ENV["DBUS_SESSION_BUS_ADDRESS"]
13
+ output = `dbus-launch --auto-syntax`
14
+ dbus_session_bus_address, dummy, dbus_session_bus_pid = output.split("\n")
15
+ ENV["DBUS_SESSION_BUS_ADDRESS"] = dbus_session_bus_address.match(/\ADBUS_SESSION_BUS_ADDRESS='(.*)';\Z/)[1]
16
+ ENV["DBUS_SESSION_BUS_PID"] = dbus_session_bus_pid.match(/\ADBUS_SESSION_BUS_PID=(.*)*;\Z/)[1]
17
+ end
18
+ remote_bus = ::RBus.session_bus
19
+ service_name = 'com.Skype.API'
20
+ object_path = "/com/Skype"
21
+ @api_object = remote_bus.get_object(service_name, object_path)
22
+ @api_object.interface!(service_name)
23
+ @application_name = name
24
+ @invoked_commands = Hash.new
25
+ end
26
+
27
+
28
+ def execute(command, timeout = 60)
29
+
30
+ end
31
+
32
+ def invoke(command, timeout = 60)
33
+ begin
34
+ ::Timeout.timeout(timeout) {
35
+ authenticate
36
+ case result = parse(command)
37
+ when Yaparc::Result::OK
38
+ response_parser = result.value[:response_parser]
39
+ generated_object = result.value[:generated_object]
40
+ @invoked_commands[command.command_id] = command.statement
41
+ response_statement = @api_object.Invoke("##{command.command_id} #{command.statement}")
42
+ response_parser.parse(response_statement)
43
+ when Yaparc::Result::Fail
44
+ raise SkypeR::Exception::ParseError
45
+ else
46
+ raise SkypeR::Exception::UnknownError
47
+ end
48
+ }
49
+ rescue ::Timeout::Error
50
+ puts "Connection timeout. Please try again."
51
+ end
52
+ end
53
+
54
+
55
+ def parse(command_message)
56
+ command_message.parse
57
+ end
58
+
59
+ def validate(command)
60
+ case result = parse(command)
61
+ when Yaparc::Result::OK
62
+ true
63
+ when Yaparc::Result::Fail
64
+ false
65
+ else
66
+ raise
67
+ end
68
+ end
69
+
70
+ private
71
+ def authenticate(protocol_num = 5)
72
+ result = nil
73
+ query = Thread.start do
74
+ name_command = SkypeR::Service::CommandMessage.new("NAME #{@application_name}")
75
+ result = @api_object.Invoke(name_command.statement)
76
+ puts result
77
+ protocol_command = SkypeR::Service::CommandMessage.new("PROTOCOL #{protocol_num}")
78
+ result = @api_object.Invoke(protocol_command.statement)
79
+ puts result
80
+ end
81
+ query.join
82
+ end
83
+ end # of Application
84
+
85
+
86
+ class MessageBase
87
+ attr_accessor :statement, :command_id
88
+ end
89
+
90
+ class CommandMessage < MessageBase
91
+
92
+ def initialize(statement)
93
+ @statement = statement
94
+ # UUID.mac_address = nil
95
+ # @command_id = UUID.timestamp_create.to_i
96
+ @command_id = UUID.random_create.to_i
97
+ end
98
+
99
+ def parse
100
+ command_parser = SkypeR::Parser::CommandStatement.new
101
+ command_parser.parse(@statement)
102
+ end
103
+
104
+ end # of CommandMessage
105
+
106
+
107
+ class ResponseMessage < MessageBase
108
+ attr_accessor :statement, :response_instance
109
+ def initialize(statement, response_instance)
110
+ @statement = statement
111
+ @response_instance = response_instance
112
+ end
113
+
114
+ def parse
115
+ response_parser = SkypeR::Parser::ResponseCommandStatement.new
116
+ response_parser.parse(@statement)
117
+ end
118
+
119
+ end # Response
120
+
121
+ # class Result < Response
122
+ # end
123
+
124
+ # class Error < Response
125
+ # end
126
+ end
127
+ end
@@ -0,0 +1,181 @@
1
+ # author: Péter Kiss, Akimichi TATSUKAWA
2
+
3
+ require 'rubygems'
4
+ require 'uuidtools'
5
+ #require 'rbus.rb'
6
+ require 'thread.rb'
7
+ require 'timeout.rb'
8
+ #require 'dbus'
9
+
10
+
11
+
12
+ module SkypeR
13
+ #{{Szinkron kommunikációnál ennyi sec-t várunk a DBUS-válaszra
14
+ TIMEOUT = 15
15
+ #}}
16
+ module Service
17
+ class Application
18
+ #async [] pufferek
19
+ attr_accessor :missed_chats,:missed_messages,:connstatus
20
+
21
+ def initialize(name, protocol_num = 5)
22
+
23
+ @missed_chats = []
24
+ @missed_messages = []
25
+ @missed_chats_puff = []
26
+ @connstatus = []
27
+ @global_res = []
28
+
29
+ # remote_bus = ::RBus.session_bus
30
+ # service_dbus = remote_bus.service('org.freedesktop.DBus')
31
+ remote_bus = ::DBus.session_bus
32
+ service_dbus = remote_bus_dbus.request_service("com.Skype.API.Client")
33
+
34
+ #és elkérjük a skype service-t
35
+ skype_service_name = 'com.Skype.API'
36
+ object_path = '/com/Skype'
37
+ @api_object = remote_bus.get_object(skype_service_name, object_path)
38
+
39
+ #Notify-k kezelése
40
+ #
41
+ # << %Gő%@ ezen hív minket befelé
42
+ @api_object.connect!(:Notify, :member => 'Notify', :type => 'method_call', :path => '/com/Skype/Client', :interface => 'com.Skype.API.Client') {|s|
43
+ my_arr = s.split()
44
+ # puts s
45
+ if my_arr.size == 2 and not ((my_arr[0] =~ /#/) == 0)
46
+ #Státusz üzenet. köszönjük
47
+ var,value = my_arr
48
+ #instance_eval("puts 'Status changed #{var}->#{value}' if defined?(@#{var.downcase}) and @#{var.downcase} != '#{value}'")
49
+ # instance_eval("@#{var.downcase}='#{value}'")
50
+ @connstatus_last = value
51
+ Thread.exclusive(){ @connstatus << value if @connstatus_last != value} if var == 'CONNSTATUS'
52
+ return ['']
53
+ else
54
+ #hogyha nekünk érkezett vmi id-vel válasz, akkor tároljuk csak le.
55
+ if( (my_arr[0] =~ /#/) == 0)
56
+ Thread.exclusive(){@global_res << s}
57
+ else
58
+ s.gsub(/CHAT\s([^\s]*)\sACTIVITY_TIMESTAMP\s([0-9]*)/){
59
+ chat_id,ts,ts = $1,$2,$3
60
+ Thread.exclusive(){ @missed_chats_puff << chat_id }
61
+ print 'iC'
62
+ return ['']
63
+ }
64
+ s.gsub(/CHATMESSAGE\s([0-9]+)\sSTATUS\sRECEIVED/){
65
+ msg_id = $1
66
+ Thread.exclusive(){
67
+ @missed_chats << @missed_chats_puff.delete_at(0)
68
+ @missed_messages << msg_id
69
+ }
70
+ print 'im'
71
+ return ['']
72
+ }
73
+
74
+ #ezek a kliensen történ%Gő%@ egyéb események hatására érkez%Gő%@ infók, amit nem kezelünk (még)
75
+ puts s
76
+ #return ['']
77
+ end
78
+ end
79
+ return ['']
80
+ }
81
+ # >> mi ezen kommunikálunk kifelé
82
+ @api_object.interface!(skype_service_name)
83
+ @application_name = name
84
+ # @invoked_commands = Hash.new
85
+ end
86
+ # ez itt egy dbus-os service publikálás és hívás.
87
+ # mivel sikerült m%Gű%@ködésre bírni az RBus-szal ezért erre nincs szükség.
88
+ def init_callback
89
+ STDOUT.sync = true
90
+ remote_bus_dbus = ::DBus.session_bus
91
+ my_service = remote_bus_dbus.request_service("com.Skype.API.Client")
92
+ exported_obj = Test.new('/com/Skype/Client')
93
+ my_service.export(exported_obj)
94
+ Thread.new do
95
+ begin
96
+ main = DBus::Main.new
97
+ main << remote_bus_dbus
98
+ main.run
99
+ rescue Exception => e
100
+ puts e.message
101
+ puts "Backtrace:"
102
+ e.backtrace.each {|line| puts line }
103
+ end
104
+ end
105
+ ms = remote_bus_dbus.service('com.Skype.API.Client')
106
+ o = ms.object('/com/Skype/Client')
107
+ o.introspect
108
+ o.default_iface = 'com.Skype.API.Client'
109
+ o.Notify 'szevasz'
110
+ end
111
+
112
+ # segéd fv. biztonságosan ránéz az aktuális üzenetre és true,ha nekünk jött
113
+ def not_for_us_thread_safe_sync command_id
114
+ Thread.exclusive(){
115
+ @res == nil or (@res.split[0] != "##{command_id}")
116
+ }
117
+ end
118
+
119
+ # segéd fv. biztonságosan ránéz az aktuális üzenetre és true,ha nekünk jött
120
+ def not_for_us_thread_safe_async command_id
121
+ Thread.exclusive(){
122
+ @global_res.empty? or !@global_res.select{|s| s.split[0] == "##{command_id}"}
123
+ }
124
+ end
125
+
126
+ #asynchron message handleing to avoid skype for hang
127
+ def invoke(command, timeout = TIMEOUT)
128
+ @global_res = []
129
+ begin
130
+ ::Timeout.timeout(timeout) {
131
+
132
+ authenticate
133
+
134
+ command_string = "##{command.command_id} #{command.statement}"
135
+ #puts command_string
136
+ @api_object.Invoke(command_string){|async_result|
137
+ @res = nil
138
+
139
+ while @res == nil do
140
+ Thread.pass
141
+ @res = async_result.dup
142
+ end
143
+ }
144
+ # megvárjuk, amíg jön valami értelmes.
145
+ # az "" is értelmes, lásd lentebb
146
+ while not_for_us_thread_safe_sync(command.command_id) do
147
+ break if @res == ""
148
+ Thread.pass
149
+ end
150
+ return @res if @res != ""
151
+ }
152
+ # "" -> ide akkor jutunk, ha asszinkron
153
+ # visszahívásra várunk ezért most várjuk, hogy
154
+ # megérkezzék az adat.
155
+ while not_for_us_thread_safe_async(command.command_id) do
156
+ #had játszadozzon üzenetküldéssel a skype, ha akar, mégiscsak ez egy asszinkron üzenet..
157
+ sleep(1)
158
+
159
+ Thread.pass
160
+ end
161
+ Thread.exclusive(){
162
+ @res = @global_res.select{|s| s.split[0] == "##{command.command_id}"}.shift.dup
163
+ }
164
+ return @res
165
+ rescue ::Timeout::Error
166
+ print 't' if DEBUG == true
167
+ end
168
+ end
169
+
170
+ def authenticate(protocol_num = 5)
171
+ result = nil
172
+ name_command = SkypeR::Service::CommandMessage.new("NAME #{@application_name}")
173
+ result = @api_object.Invoke(name_command.statement)
174
+ puts result unless result =~ /PROTOCOL|OK/
175
+ protocol_command = SkypeR::Service::CommandMessage.new("PROTOCOL #{protocol_num}")
176
+ result = @api_object.Invoke(protocol_command.statement)
177
+ puts result unless result =~ /PROTOCOL|OK/
178
+ end
179
+ end # of Application
180
+ end
181
+ end