xmpp4r 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +12 -0
- data/Rakefile +2 -4
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +6 -6
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +3 -3
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +5 -5
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +17 -4
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +5 -0
- data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +6 -2
- data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +13 -0
- data/lib/xmpp4r.rb +0 -6
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +6 -7
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +5 -6
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +3 -5
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +1 -1
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +10 -8
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +3 -5
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +11 -17
- data/lib/xmpp4r/bytestreams/iq/si.rb +13 -32
- data/lib/xmpp4r/callbacks.rb +124 -0
- data/lib/xmpp4r/client.rb +2 -5
- data/lib/xmpp4r/command/helper/responder.rb +53 -0
- data/lib/xmpp4r/command/iq/command.rb +154 -0
- data/lib/xmpp4r/connection.rb +49 -12
- data/lib/xmpp4r/dataforms/x/data.rb +66 -29
- data/lib/xmpp4r/delay/x/delay.rb +2 -3
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +20 -33
- data/lib/xmpp4r/discovery/iq/discoitems.rb +5 -28
- data/lib/xmpp4r/error.rb +5 -10
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +2 -20
- data/lib/xmpp4r/httpbinding.rb +5 -0
- data/lib/xmpp4r/httpbinding/client.rb +285 -0
- data/lib/xmpp4r/iq.rb +22 -41
- data/lib/xmpp4r/message.rb +8 -38
- data/lib/xmpp4r/muc.rb +2 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +50 -1
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +2 -2
- data/lib/xmpp4r/muc/iq/mucowner.rb +11 -0
- data/lib/xmpp4r/muc/x/muc.rb +2 -30
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +4 -2
- data/lib/xmpp4r/muc/x/mucuseritem.rb +4 -2
- data/lib/xmpp4r/presence.rb +7 -35
- data/lib/xmpp4r/pubsub.rb +1 -0
- data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +174 -0
- data/lib/xmpp4r/pubsub/helper/nodehelper.rb +153 -0
- data/lib/xmpp4r/pubsub/helper/servicehelper.rb +326 -0
- data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
- data/lib/xmpp4r/pubsub/stanzas/event.rb +49 -0
- data/lib/xmpp4r/pubsub/stanzas/item.rb +27 -0
- data/lib/xmpp4r/pubsub/stanzas/items.rb +35 -0
- data/lib/xmpp4r/pubsub/stanzas/subscription.rb +58 -0
- data/lib/xmpp4r/query.rb +4 -32
- data/lib/xmpp4r/rexmladdons.rb +7 -772
- data/lib/xmpp4r/roster/helper/roster.rb +29 -50
- data/lib/xmpp4r/roster/iq/roster.rb +6 -35
- data/lib/xmpp4r/roster/x/roster.rb +13 -30
- data/lib/xmpp4r/rpc.rb +2 -0
- data/lib/xmpp4r/rpc/helper/client.rb +114 -0
- data/lib/xmpp4r/rpc/helper/server.rb +75 -0
- data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +57 -0
- data/lib/xmpp4r/rpc/iq/rpc.rb +24 -0
- data/lib/xmpp4r/sasl.rb +1 -1
- data/lib/xmpp4r/semaphore.rb +38 -0
- data/lib/xmpp4r/stream.rb +104 -165
- data/lib/xmpp4r/streamparser.rb +2 -2
- data/lib/xmpp4r/vcard/iq/vcard.rb +5 -12
- data/lib/xmpp4r/version/helper/responder.rb +2 -1
- data/lib/xmpp4r/version/iq/version.rb +6 -18
- data/lib/xmpp4r/x.rb +20 -26
- data/lib/xmpp4r/xmpp4r.rb +1 -1
- data/lib/xmpp4r/xmppelement.rb +152 -0
- data/lib/xmpp4r/{xmlstanza.rb → xmppstanza.rb} +17 -29
- data/setup.rb +1 -0
- data/test/bytestreams/tc_ibb.rb +8 -8
- data/test/dataforms/tc_data.rb +81 -0
- data/test/lib/clienttester.rb +20 -17
- data/test/muc/tc_muc_mucclient.rb +48 -23
- data/test/muc/tc_muc_simplemucclient.rb +7 -4
- data/test/muc/tc_mucowner.rb +50 -0
- data/test/pubsub/tc_helper.rb +227 -0
- data/test/roster/tc_helper.rb +181 -55
- data/test/roster/tc_iqqueryroster.rb +33 -0
- data/test/roster/tc_xroster.rb +6 -3
- data/test/rpc/tc_helper.rb +84 -0
- data/test/tc_callbacks.rb +2 -1
- data/test/tc_class_names.rb +9 -1
- data/test/tc_error.rb +1 -0
- data/test/tc_iq.rb +13 -12
- data/test/tc_message.rb +1 -0
- data/test/tc_presence.rb +1 -0
- data/test/tc_rexml.rb +1 -1
- data/test/tc_stream.rb +147 -102
- data/test/tc_streamComponent.rb +94 -0
- data/test/tc_streamError.rb +67 -29
- data/test/tc_streamSend.rb +1 -1
- data/test/tc_xmppstanza.rb +125 -0
- data/test/ts_xmpp4r.rb +37 -28
- data/test/version/tc_helper.rb +14 -0
- data/test/version/tc_iqqueryversion.rb +4 -3
- metadata +163 -123
- data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +0 -32
- data/lib/callbacks.rb +0 -122
- data/test/tc_streamThreaded.rb +0 -168
- data/test/tc_xmlstanza.rb +0 -76
data/lib/xmpp4r/streamparser.rb
CHANGED
@@ -10,7 +10,7 @@ module Jabber
|
|
10
10
|
|
11
11
|
##
|
12
12
|
# The StreamParser uses REXML to parse the incoming XML stream
|
13
|
-
# of the Jabber protocol and fires
|
13
|
+
# of the Jabber protocol and fires XMPPStanza at the Connection
|
14
14
|
# instance.
|
15
15
|
#
|
16
16
|
class StreamParser
|
@@ -21,7 +21,7 @@ module Jabber
|
|
21
21
|
# Constructs a parser for the supplied stream (socket input)
|
22
22
|
#
|
23
23
|
# stream:: [IO] Socket input stream
|
24
|
-
# listener:: [Object.receive(
|
24
|
+
# listener:: [Object.receive(XMPPStanza)] The listener (usually a Jabber::Protocol::Connection instance)
|
25
25
|
#
|
26
26
|
def initialize(stream, listener)
|
27
27
|
@stream = stream
|
@@ -10,13 +10,15 @@ module Jabber
|
|
10
10
|
# vCard container for User Information
|
11
11
|
# (can be specified by users themselves, mostly kept on servers)
|
12
12
|
# (JEP 0054)
|
13
|
-
class IqVcard <
|
13
|
+
class IqVcard < XMPPElement
|
14
|
+
name_xmlns 'vCard', 'vcard-temp'
|
15
|
+
force_xmlns true
|
16
|
+
|
14
17
|
##
|
15
18
|
# Initialize a <vCard/> element
|
16
19
|
# fields:: [Hash] Initialize with keys as XPath element names and values for element texts
|
17
20
|
def initialize(fields=nil)
|
18
|
-
super(
|
19
|
-
add_namespace('vcard-temp')
|
21
|
+
super()
|
20
22
|
|
21
23
|
unless fields.nil?
|
22
24
|
fields.each { |name,value|
|
@@ -25,13 +27,6 @@ module Jabber
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
##
|
29
|
-
# element:: [REXML::Element] to import
|
30
|
-
# result:: [IqVcard] with all attributes and children copied from element
|
31
|
-
def IqVcard.import(element)
|
32
|
-
IqVcard::new.import(element)
|
33
|
-
end
|
34
|
-
|
35
30
|
##
|
36
31
|
# Get an elements/fields text
|
37
32
|
#
|
@@ -95,8 +90,6 @@ module Jabber
|
|
95
90
|
}
|
96
91
|
res
|
97
92
|
end
|
98
|
-
|
99
|
-
Iq.add_elementclass('vCard', IqVcard)
|
100
93
|
end
|
101
94
|
end
|
102
95
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
|
3
3
|
# Website::http://home.gna.org/xmpp4r/
|
4
4
|
|
5
|
-
require 'callbacks'
|
5
|
+
require 'xmpp4r/callbacks'
|
6
6
|
require 'xmpp4r/version/iq/version'
|
7
7
|
|
8
8
|
module Jabber
|
@@ -57,6 +57,7 @@ module Jabber
|
|
57
57
|
answer.query.set_iname(name).set_version(version).set_os(os)
|
58
58
|
|
59
59
|
@stream.send(answer)
|
60
|
+
true
|
60
61
|
}
|
61
62
|
@versioncbs.process(iq, replyblock)
|
62
63
|
else
|
@@ -13,25 +13,15 @@ module Jabber
|
|
13
13
|
# Notice that according to JEP 0092 only the <os/> element can be omitted,
|
14
14
|
# <name/> (iname) and <version/> must be present
|
15
15
|
class IqQueryVersion < IqQuery
|
16
|
+
name_xmlns 'query', 'jabber:iq:version'
|
17
|
+
|
16
18
|
##
|
17
19
|
# Create a new <query xmlns='jabber:iq:version'/> element
|
18
|
-
def initialize(iname=
|
20
|
+
def initialize(iname=nil, version=nil, os=nil)
|
19
21
|
super()
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
set_os(os)
|
24
|
-
end
|
25
|
-
|
26
|
-
##
|
27
|
-
# Import an element,
|
28
|
-
# deletes <name/>, <version/> and <os/> elements first
|
29
|
-
# xe:: [REXML::Element]
|
30
|
-
def import(xe)
|
31
|
-
delete_element('name')
|
32
|
-
delete_element('version')
|
33
|
-
delete_element('os')
|
34
|
-
super
|
22
|
+
set_iname(iname) if iname
|
23
|
+
set_version(version) if version
|
24
|
+
set_os(os) if os
|
35
25
|
end
|
36
26
|
|
37
27
|
##
|
@@ -111,8 +101,6 @@ module Jabber
|
|
111
101
|
self
|
112
102
|
end
|
113
103
|
end
|
114
|
-
|
115
|
-
IqQuery.add_namespaceclass('jabber:iq:version', IqQueryVersion)
|
116
104
|
end
|
117
105
|
end
|
118
106
|
|
data/lib/xmpp4r/x.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
|
3
3
|
# Website::http://home.gna.org/xmpp4r/
|
4
4
|
|
5
|
-
require 'xmpp4r/
|
5
|
+
require 'xmpp4r/xmppelement'
|
6
6
|
|
7
7
|
module Jabber
|
8
8
|
##
|
@@ -10,34 +10,28 @@ module Jabber
|
|
10
10
|
#
|
11
11
|
# These elements may occur as "attachments"
|
12
12
|
# in [Message] and [Presence] stanzas
|
13
|
-
class X <
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# Initialize a <x/> element
|
18
|
-
#
|
19
|
-
# Does nothing more than setting the element's name to 'x'
|
20
|
-
def initialize
|
21
|
-
super("x")
|
22
|
-
end
|
13
|
+
class X < XMPPElement
|
14
|
+
name_xmlns 'x'
|
15
|
+
force_xmlns true
|
16
|
+
end
|
23
17
|
|
18
|
+
module XParent
|
24
19
|
##
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
# Get the first <x/> element in this stanza, or nil if none found.
|
21
|
+
# wanted_xmlns:: [String] Optional, find the first <x/> element having this xmlns,
|
22
|
+
# wanted_xmlns can also be a derivate of XMPPElement from which the namespace will be taken
|
23
|
+
# result:: [REXML::Element] or nil
|
24
|
+
def x(wanted_xmlns=nil)
|
25
|
+
if wanted_xmlns.kind_of? Class and wanted_xmlns.ancestors.include? XMPPElement
|
26
|
+
wanted_xmlns = wanted_xmlns.new.namespace
|
32
27
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@@namespace_classes[ns] = xclass
|
28
|
+
|
29
|
+
each_element('x') { |x|
|
30
|
+
if wanted_xmlns.nil? or wanted_xmlns == x.namespace
|
31
|
+
return x
|
32
|
+
end
|
33
|
+
}
|
34
|
+
nil
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
data/lib/xmpp4r/xmpp4r.rb
CHANGED
@@ -0,0 +1,152 @@
|
|
1
|
+
# =XMPP4R - XMPP Library for Ruby
|
2
|
+
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
|
3
|
+
# Website::http://home.gna.org/xmpp4r/
|
4
|
+
|
5
|
+
require 'xmpp4r/rexmladdons'
|
6
|
+
|
7
|
+
module Jabber
|
8
|
+
class NoNameXmlnsRegistered < RuntimeError
|
9
|
+
def initialize(klass)
|
10
|
+
super "Class #{klass} has not set name and xmlns"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# This class represents an XML element and provides functionality
|
16
|
+
# for automatic casting of XML element classes according to their
|
17
|
+
# element name and namespace.
|
18
|
+
#
|
19
|
+
# Deriving classes must met these criteria:
|
20
|
+
# * The element name and namespace must be specified by calling
|
21
|
+
# the name_xmlns class method
|
22
|
+
# * The class constructor must be callable with no mandatory parameter
|
23
|
+
class XMPPElement < REXML::Element
|
24
|
+
@@name_xmlns_classes = {}
|
25
|
+
@@force_xmlns = false
|
26
|
+
|
27
|
+
##
|
28
|
+
# Specify XML element name and xmlns for a deriving class,
|
29
|
+
# this pair and the class will be added to a global pool
|
30
|
+
#
|
31
|
+
# If the namespace is nil the class is a "wildcard class"
|
32
|
+
# matching elements with any xmlns if no other class with
|
33
|
+
# that namespace was defined
|
34
|
+
def self.name_xmlns(name, xmlns=nil)
|
35
|
+
@@name_xmlns_classes[[name, xmlns]] = self
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Set whether this element is always built with an xmlns attribute
|
40
|
+
def self.force_xmlns(force)
|
41
|
+
@@force_xmlns = force
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Whether this element is always built with an xmlns attribute
|
46
|
+
def self.force_xmlns?
|
47
|
+
@@force_xmlns
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Find the name and namespace for a given class.
|
52
|
+
# This class must have registered these two values
|
53
|
+
# by calling name_xmlns at definition time.
|
54
|
+
#
|
55
|
+
# Raises an exception if none was found
|
56
|
+
# klass:: [Class]
|
57
|
+
# result:: [String, String] name and namespace
|
58
|
+
def self.name_xmlns_for_class(klass)
|
59
|
+
klass.ancestors.each do |klass1|
|
60
|
+
@@name_xmlns_classes.each do |name_xmlns,k|
|
61
|
+
if klass1 == k
|
62
|
+
return name_xmlns
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
raise NoNameXmlnsRegistered.new(klass)
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Find a class for given name and namespace
|
72
|
+
# name:: [String]
|
73
|
+
# xmlns:: [String]
|
74
|
+
# result:: A descendant of XMPPElement or REXML::Element
|
75
|
+
def self.class_for_name_xmlns(name, xmlns)
|
76
|
+
if @@name_xmlns_classes.has_key? [name, xmlns]
|
77
|
+
@@name_xmlns_classes[[name, xmlns]]
|
78
|
+
elsif @@name_xmlns_classes.has_key? [name, nil]
|
79
|
+
@@name_xmlns_classes[[name, nil]]
|
80
|
+
else
|
81
|
+
REXML::Element
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Import another REXML::Element descendant to:
|
87
|
+
# * Either an element class that registered with
|
88
|
+
# name and xmlns before
|
89
|
+
# * Or if none was found to the class itself
|
90
|
+
# (you may call this class method on a deriving class)
|
91
|
+
def self.import(element)
|
92
|
+
klass = class_for_name_xmlns(element.name, element.namespace)
|
93
|
+
if klass != self and klass.ancestors.include?(self)
|
94
|
+
klass.new.import(element)
|
95
|
+
else
|
96
|
+
self.new.import(element)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# Initialize this element, which will then be initialized
|
102
|
+
# with the name registered with name_xmlns.
|
103
|
+
def initialize(*arg)
|
104
|
+
if arg.empty?
|
105
|
+
name, xmlns = self.class::name_xmlns_for_class(self.class)
|
106
|
+
super(name)
|
107
|
+
if self.class::force_xmlns?
|
108
|
+
add_namespace(xmlns)
|
109
|
+
end
|
110
|
+
else
|
111
|
+
super
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Add a child element which will be imported according to the
|
117
|
+
# child's name and xmlns
|
118
|
+
# element:: [REXML::Element] Child
|
119
|
+
# result:: [REXML::Element or descendant of XMPPElement] New child
|
120
|
+
def typed_add(element)
|
121
|
+
if element.kind_of? REXML::Element
|
122
|
+
element_ns = (element.namespace.to_s == '') ? namespace : element.namespace
|
123
|
+
|
124
|
+
klass = XMPPElement::class_for_name_xmlns(element.name, element_ns)
|
125
|
+
if klass != element.class
|
126
|
+
element = klass.import(element)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
super(element)
|
131
|
+
end
|
132
|
+
|
133
|
+
def parent=(new_parent)
|
134
|
+
if parent and parent.namespace('') == namespace('') and attributes['xmlns'].nil?
|
135
|
+
add_namespace parent.namespace('')
|
136
|
+
end
|
137
|
+
|
138
|
+
super
|
139
|
+
|
140
|
+
if new_parent and new_parent.namespace('') == namespace('')
|
141
|
+
delete_namespace
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def clone
|
146
|
+
cloned = self.class.new
|
147
|
+
cloned.add_attributes self.attributes.clone
|
148
|
+
cloned.context = @context
|
149
|
+
cloned
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -2,18 +2,19 @@
|
|
2
2
|
# License:: Ruby's license (see the LICENSE file) or GNU GPL, at your option.
|
3
3
|
# Website::http://home.gna.org/xmpp4r/
|
4
4
|
|
5
|
-
require 'xmpp4r/
|
5
|
+
require 'xmpp4r/xmppelement'
|
6
6
|
require 'xmpp4r/error'
|
7
|
+
require 'xmpp4r/jid'
|
7
8
|
|
8
9
|
module Jabber
|
9
10
|
##
|
10
11
|
# root class of all Jabber XML elements
|
11
|
-
class
|
12
|
+
class XMPPStanza < XMPPElement
|
12
13
|
##
|
13
14
|
# Compose a response by doing the following:
|
14
|
-
# * Create a new
|
15
|
+
# * Create a new XMPPStanza of the same subclass
|
15
16
|
# with the same element-name
|
16
|
-
# * Import
|
17
|
+
# * Import xmppstanza if import is true
|
17
18
|
# * Swap 'to' and 'from'
|
18
19
|
# * Copy 'id'
|
19
20
|
# * Does not take care about the type
|
@@ -23,33 +24,20 @@ module Jabber
|
|
23
24
|
# another error on the other side, which could be leading to a
|
24
25
|
# ping-pong effect quickly!
|
25
26
|
#
|
26
|
-
#
|
27
|
+
# xmppstanza:: [XMPPStanza] source
|
27
28
|
# import:: [true or false] Copy attributes and children of source
|
28
|
-
# result:: [
|
29
|
-
def
|
30
|
-
x =
|
29
|
+
# result:: [XMPPStanza] answer stanza
|
30
|
+
def XMPPStanza.answer(xmppstanza, import=true)
|
31
|
+
x = xmppstanza.class::new
|
31
32
|
if import
|
32
|
-
x.import(
|
33
|
+
x.import(xmppstanza)
|
33
34
|
end
|
34
|
-
x.from =
|
35
|
-
x.to =
|
36
|
-
x.id =
|
35
|
+
x.from = xmppstanza.to
|
36
|
+
x.to = xmppstanza.from
|
37
|
+
x.id = xmppstanza.id
|
37
38
|
x
|
38
39
|
end
|
39
40
|
|
40
|
-
##
|
41
|
-
# Add a sub-element
|
42
|
-
#
|
43
|
-
# Will be converted to [Error] if named "error"
|
44
|
-
# element:: [REXML::Element] to add
|
45
|
-
def typed_add(element)
|
46
|
-
if element.kind_of?(REXML::Element) && (element.name == 'error')
|
47
|
-
super(Error::import(element))
|
48
|
-
else
|
49
|
-
super(element)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
41
|
##
|
54
42
|
# Return the first <tt><error/></tt> child
|
55
43
|
def error
|
@@ -57,11 +45,11 @@ module Jabber
|
|
57
45
|
end
|
58
46
|
|
59
47
|
##
|
60
|
-
# Compose a response of this
|
61
|
-
# (see
|
62
|
-
# result:: [
|
48
|
+
# Compose a response of this XMPPStanza
|
49
|
+
# (see XMPPStanza.answer)
|
50
|
+
# result:: [XMPPStanza] New constructed stanza
|
63
51
|
def answer(import=true)
|
64
|
-
|
52
|
+
XMPPStanza.answer(self, import)
|
65
53
|
end
|
66
54
|
|
67
55
|
##
|
data/setup.rb
CHANGED
data/test/bytestreams/tc_ibb.rb
CHANGED
@@ -7,6 +7,7 @@ require File::dirname(__FILE__) + '/../lib/clienttester'
|
|
7
7
|
|
8
8
|
require 'xmpp4r'
|
9
9
|
require 'xmpp4r/bytestreams'
|
10
|
+
require 'xmpp4r/semaphore'
|
10
11
|
include Jabber
|
11
12
|
|
12
13
|
class IBBTest < Test::Unit::TestCase
|
@@ -71,10 +72,9 @@ class IBBTest < Test::Unit::TestCase
|
|
71
72
|
|
72
73
|
def test_ibb_pingpong
|
73
74
|
ignored_stanzas = 0
|
74
|
-
wait =
|
75
|
-
wait.
|
76
|
-
@server.
|
77
|
-
@server.add_iq_callback { ignored_stanzas += 1; wait.unlock }
|
75
|
+
wait = Semaphore.new
|
76
|
+
@server.add_message_callback { ignored_stanzas += 1; wait.run }
|
77
|
+
@server.add_iq_callback { ignored_stanzas += 1; wait.run }
|
78
78
|
|
79
79
|
|
80
80
|
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
@@ -96,7 +96,7 @@ class IBBTest < Test::Unit::TestCase
|
|
96
96
|
@client.send("<iq from='1@a.com/1' type='set'>
|
97
97
|
<close xmlns='http://jabber.org/protocol/ibb' sid='another session id'/>
|
98
98
|
</iq>")
|
99
|
-
wait.
|
99
|
+
wait.wait
|
100
100
|
assert_equal(1, ignored_stanzas)
|
101
101
|
|
102
102
|
|
@@ -107,12 +107,12 @@ class IBBTest < Test::Unit::TestCase
|
|
107
107
|
@client.send("<message from='1@a.com/1' type='error'>
|
108
108
|
<data xmlns='http://jabber.org/protocol/ibb' sid='another session id' seq='0'/>
|
109
109
|
</message>")
|
110
|
-
wait.
|
110
|
+
wait.wait
|
111
111
|
assert_equal(2, ignored_stanzas)
|
112
112
|
@client.send("<iq from='1@a.com/1' type='set'>
|
113
113
|
<close xmlns='http://jabber.org/protocol/ibb' sid='another session id'/>
|
114
114
|
</iq>")
|
115
|
-
wait.
|
115
|
+
wait.wait
|
116
116
|
assert_equal(3, ignored_stanzas)
|
117
117
|
|
118
118
|
|
@@ -133,7 +133,7 @@ class IBBTest < Test::Unit::TestCase
|
|
133
133
|
|
134
134
|
assert_equal(3, ignored_stanzas)
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
def test_ibb_error
|
138
138
|
target = Bytestreams::IBBTarget.new(@server, '1', nil, '1@a.com/1')
|
139
139
|
initiator = Bytestreams::IBBInitiator.new(@client, '1', nil, '1@a.com/1')
|