em-xmpp 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em-xmpp/connection.rb +8 -2
- data/lib/em-xmpp/connector.rb +2 -2
- data/lib/em-xmpp/context.rb +62 -9
- data/lib/em-xmpp/entity.rb +54 -0
- data/lib/em-xmpp/jid.rb +10 -2
- data/lib/em-xmpp/namespaces.rb +1 -1
- data/lib/em-xmpp/version.rb +1 -1
- metadata +9 -8
data/lib/em-xmpp/connection.rb
CHANGED
@@ -3,8 +3,10 @@ require 'em-xmpp/namespaces'
|
|
3
3
|
require 'em-xmpp/connector'
|
4
4
|
require 'em-xmpp/handler'
|
5
5
|
require 'em-xmpp/jid'
|
6
|
+
require 'em-xmpp/entity'
|
6
7
|
require 'em-xmpp/cert_store'
|
7
8
|
require 'eventmachine'
|
9
|
+
require 'fiber'
|
8
10
|
|
9
11
|
module EM::Xmpp
|
10
12
|
class Connection < EM::Connection
|
@@ -34,7 +36,7 @@ module EM::Xmpp
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def stanza_end(node)
|
37
|
-
@handler.handle(node)
|
39
|
+
Fiber.new { @handler.handle(node) }.resume
|
38
40
|
end
|
39
41
|
|
40
42
|
def unhandled_stanza(node)
|
@@ -42,7 +44,11 @@ module EM::Xmpp
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def jid_received(jid)
|
45
|
-
@jid =
|
47
|
+
@jid = entity jid
|
48
|
+
end
|
49
|
+
|
50
|
+
def entity(jid)
|
51
|
+
Entity.new(self, jid)
|
46
52
|
end
|
47
53
|
|
48
54
|
def negotiation_finished
|
data/lib/em-xmpp/connector.rb
CHANGED
@@ -144,7 +144,7 @@ module EM::Xmpp
|
|
144
144
|
node.add_namespace_definition pfx, href
|
145
145
|
end
|
146
146
|
|
147
|
-
puts "starting: #{name}, stack:#{@stack.size}" if $DEBUG
|
147
|
+
# puts "starting: #{name}, stack:#{@stack.size}" if $DEBUG
|
148
148
|
case @stack.size
|
149
149
|
when 0 #the streaming tag starts
|
150
150
|
stream_support(node)
|
@@ -160,7 +160,7 @@ module EM::Xmpp
|
|
160
160
|
|
161
161
|
def xml_end_element(name)
|
162
162
|
node = @stack.pop
|
163
|
-
puts "ending: #{name}, stack:#{@stack.size}" if $DEBUG
|
163
|
+
#puts "ending: #{name}, stack:#{@stack.size}" if $DEBUG
|
164
164
|
|
165
165
|
case @stack.size
|
166
166
|
when 0 #i.e., the stream support ends
|
data/lib/em-xmpp/context.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'em-xmpp/jid'
|
3
|
+
require 'em-xmpp/entity'
|
3
4
|
require 'em-xmpp/namespaces'
|
4
5
|
require 'time'
|
5
6
|
require 'ostruct'
|
@@ -83,10 +84,10 @@ module EM::Xmpp
|
|
83
84
|
end
|
84
85
|
end
|
85
86
|
def to
|
86
|
-
read_attr(stanza, 'to'){|j|
|
87
|
+
read_attr(stanza, 'to'){|j| @connection.entity(j)}
|
87
88
|
end
|
88
89
|
def from
|
89
|
-
read_attr(stanza, 'from'){|j|
|
90
|
+
read_attr(stanza, 'from'){|j| @connection.entity(j)}
|
90
91
|
end
|
91
92
|
def error?
|
92
93
|
type == 'error'
|
@@ -236,16 +237,50 @@ module EM::Xmpp
|
|
236
237
|
|
237
238
|
module Discoinfos
|
238
239
|
include Discoveries
|
240
|
+
Identity = Struct.new(:name, :category, :type)
|
241
|
+
Feature = Struct.new(:var)
|
239
242
|
def query_node
|
240
243
|
xpath('//xmlns:query',{'xmlns' => DiscoverInfos}).first
|
241
244
|
end
|
245
|
+
def identities
|
246
|
+
n = query_node
|
247
|
+
if n
|
248
|
+
n.xpath('xmlns:identity',{'xmlns' => DiscoverInfos}).map do |x|
|
249
|
+
cat = read_attr(x, 'category')
|
250
|
+
type = read_attr(x, 'type')
|
251
|
+
name = read_attr(x, 'name')
|
252
|
+
Identity.new name, cat, type
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
def features
|
257
|
+
n = query_node
|
258
|
+
if n
|
259
|
+
n.xpath('xmlns:feature',{'xmlns' => DiscoverInfos}).map do |x|
|
260
|
+
var = read_attr(x, 'var')
|
261
|
+
Feature.new var
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
242
265
|
end
|
243
266
|
|
244
267
|
module Discoitems
|
245
268
|
include Discoveries
|
269
|
+
Item = Struct.new(:entity, :node, :name)
|
246
270
|
def query_node
|
247
271
|
xpath('//xmlns:query',{'xmlns' => DiscoverItems}).first
|
248
272
|
end
|
273
|
+
def item_nodes
|
274
|
+
xpath('//xmlns:item',{'xmlns' => DiscoverItems})
|
275
|
+
end
|
276
|
+
def items
|
277
|
+
item_nodes.map do |n|
|
278
|
+
entity = read_attr(n, 'jid'){|x| @connection.entity(x)}
|
279
|
+
node = read_attr(n, 'node')
|
280
|
+
name = read_attr(n, 'name')
|
281
|
+
Item.new(entity, node, name)
|
282
|
+
end
|
283
|
+
end
|
249
284
|
end
|
250
285
|
|
251
286
|
module Command
|
@@ -266,13 +301,31 @@ module EM::Xmpp
|
|
266
301
|
end
|
267
302
|
|
268
303
|
module Dataforms
|
269
|
-
|
270
|
-
|
304
|
+
Form = Struct.new(:type, :fields)
|
305
|
+
Field = Struct.new(:var, :type, :values) do
|
306
|
+
def value
|
307
|
+
values.first
|
308
|
+
end
|
271
309
|
end
|
272
310
|
|
273
|
-
def
|
274
|
-
|
275
|
-
|
311
|
+
def x_form_nodes
|
312
|
+
xpath('//xmlns:x',{'xmlns' => Namespaces::DataForms})
|
313
|
+
end
|
314
|
+
|
315
|
+
def x_forms
|
316
|
+
x_form_nodes.map do |form|
|
317
|
+
form_type = read_attr(form, 'type')
|
318
|
+
field_nodes = form.xpath('xmlns:field',{'xmlns' => Namespaces::DataForms})
|
319
|
+
fields = field_nodes.map do |field|
|
320
|
+
var = read_attr(field, 'var')
|
321
|
+
type = read_attr(field, 'type')
|
322
|
+
value_nodes = field.xpath('xmlns:value',{'xmlns' => Namespaces::DataForms})
|
323
|
+
values = value_nodes.map(&:content)
|
324
|
+
|
325
|
+
Field.new(var,type,values)
|
326
|
+
end
|
327
|
+
Form.new form_type, fields
|
328
|
+
end
|
276
329
|
end
|
277
330
|
end
|
278
331
|
|
@@ -309,7 +362,7 @@ module EM::Xmpp
|
|
309
362
|
|
310
363
|
def new_subscription(n)
|
311
364
|
type = read_attr(n,'subscription')
|
312
|
-
jid = read_attr(n,'jid') {|x|
|
365
|
+
jid = read_attr(n,'jid') {|x| @connection.entity x}
|
313
366
|
name = read_attr(n,'name')
|
314
367
|
groups = n.xpath('xmlns:group', 'xmlns' => EM::Xmpp::Namespaces::Roster).map{|n| n.content}
|
315
368
|
Subscription.new(type, jid, name, groups)
|
@@ -498,7 +551,7 @@ worried}.freeze
|
|
498
551
|
def jid
|
499
552
|
n = item_node
|
500
553
|
jid_str = read_attr(n, 'jid') if n
|
501
|
-
|
554
|
+
@connection.entity jid_str if jid_str
|
502
555
|
end
|
503
556
|
|
504
557
|
def affiliation
|
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
require 'em-xmpp/jid'
|
3
|
+
require 'em-xmpp/namespaces'
|
4
|
+
require 'fiber'
|
5
|
+
|
6
|
+
module EM::Xmpp
|
7
|
+
class Entity
|
8
|
+
attr_reader :jid, :connection
|
9
|
+
|
10
|
+
def initialize(connection, jid)
|
11
|
+
@connection = connection
|
12
|
+
@jid = JID.parse jid.to_s
|
13
|
+
yield self if block_given?
|
14
|
+
end
|
15
|
+
|
16
|
+
def domain
|
17
|
+
Entity.new(connection, jid.domain)
|
18
|
+
end
|
19
|
+
|
20
|
+
def bare
|
21
|
+
Entity.new(connection, jid.bare)
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
jid.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
#TODO: subscribe, unsubscribe, say, pub, sub, etc.
|
29
|
+
|
30
|
+
def discover_infos(node=nil)
|
31
|
+
f = Fiber.current
|
32
|
+
hash = {'xmlns' => Namespaces::DiscoverInfos}
|
33
|
+
hash['node'] = node if node
|
34
|
+
iq = connection.iq_stanza('to'=>jid) do |xml|
|
35
|
+
xml.query(hash)
|
36
|
+
end
|
37
|
+
connection.send_stanza(iq) do |ctx|
|
38
|
+
f.resume ctx
|
39
|
+
end
|
40
|
+
Fiber.yield
|
41
|
+
end
|
42
|
+
|
43
|
+
def discover_items(node=nil)
|
44
|
+
f = Fiber.current
|
45
|
+
iq = connection.iq_stanza('to'=>jid.to_s) do |xml|
|
46
|
+
xml.query('xmlns' => Namespaces::DiscoverItems)
|
47
|
+
end
|
48
|
+
connection.send_stanza(iq) do |ctx|
|
49
|
+
f.resume ctx
|
50
|
+
end
|
51
|
+
Fiber.yield
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/em-xmpp/jid.rb
CHANGED
@@ -13,11 +13,19 @@ module EM::Xmpp
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def bare
|
16
|
-
|
16
|
+
if node
|
17
|
+
[node,domain].map(&:to_s).join('@')
|
18
|
+
else
|
19
|
+
domain
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def full
|
20
|
-
|
24
|
+
if resource
|
25
|
+
[bare,resource].map(&:to_s).join('/')
|
26
|
+
else
|
27
|
+
bare
|
28
|
+
end
|
21
29
|
end
|
22
30
|
|
23
31
|
def to_s
|
data/lib/em-xmpp/namespaces.rb
CHANGED
@@ -20,7 +20,7 @@ module EM::Xmpp
|
|
20
20
|
#XMPP item discovery
|
21
21
|
DiscoverItems = "http://jabber.org/protocol/disco#items"
|
22
22
|
#XMPP info discovery
|
23
|
-
DiscoverInfos = "http://jabber.org/protocol/disco#
|
23
|
+
DiscoverInfos = "http://jabber.org/protocol/disco#info"
|
24
24
|
#Jabber Roster
|
25
25
|
Roster = 'jabber:iq:roster'
|
26
26
|
#XMPP commands
|
data/lib/em-xmpp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-xmpp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &2160859240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2160859240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &2160889280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2160889280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-sasl
|
38
|
-
requirement: &
|
38
|
+
requirement: &2160888860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2160888860
|
47
47
|
description: XMPP client for event machine
|
48
48
|
email:
|
49
49
|
- crapooze@gmail.com
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/em-xmpp/connection.rb
|
63
63
|
- lib/em-xmpp/connector.rb
|
64
64
|
- lib/em-xmpp/context.rb
|
65
|
+
- lib/em-xmpp/entity.rb
|
65
66
|
- lib/em-xmpp/handler.rb
|
66
67
|
- lib/em-xmpp/jid.rb
|
67
68
|
- lib/em-xmpp/namespaces.rb
|