gmcmillan-xmpp4r 0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +91 -0
- data/COPYING +340 -0
- data/LICENSE +59 -0
- data/README.rdoc +122 -0
- data/README_ruby19.txt +43 -0
- data/Rakefile +258 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/README +56 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +23 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +136 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/cube.xml +15 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/tower.xml +69 -0
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +424 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.conf +11 -0
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +346 -0
- data/data/doc/xmpp4r/examples/advanced/getonline.rb +56 -0
- data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +315 -0
- data/data/doc/xmpp4r/examples/advanced/migrate.rb +88 -0
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +266 -0
- data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
- data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
- data/data/doc/xmpp4r/examples/advanced/recvfile.rb +85 -0
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +129 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.conf +10 -0
- data/data/doc/xmpp4r/examples/advanced/sendfile.rb +72 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +51 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +43 -0
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +10 -0
- data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +109 -0
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +146 -0
- data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +14 -0
- data/data/doc/xmpp4r/examples/basic/change_password.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/client.rb +70 -0
- data/data/doc/xmpp4r/examples/basic/component.rb +11 -0
- data/data/doc/xmpp4r/examples/basic/echo.rb +37 -0
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +68 -0
- data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +12 -0
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +41 -0
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +82 -0
- data/data/doc/xmpp4r/examples/basic/register.rb +42 -0
- data/data/doc/xmpp4r/examples/basic/remove_registration.rb +18 -0
- data/data/doc/xmpp4r/examples/basic/roster.rb +44 -0
- data/data/doc/xmpp4r/examples/basic/rosterprint.rb +50 -0
- data/data/doc/xmpp4r/examples/basic/rosterrename.rb +34 -0
- data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +171 -0
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +67 -0
- data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
- data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
- data/data/doc/xmpp4r/examples/basic/versionbot.rb +75 -0
- data/lib/xmpp4r.rb +118 -0
- data/lib/xmpp4r/base64.rb +32 -0
- data/lib/xmpp4r/bytestreams.rb +15 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +321 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +257 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +31 -0
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +54 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +153 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +86 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +198 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +65 -0
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +82 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +170 -0
- data/lib/xmpp4r/bytestreams/iq/si.rb +206 -0
- data/lib/xmpp4r/callbacks.rb +133 -0
- data/lib/xmpp4r/caps.rb +1 -0
- data/lib/xmpp4r/caps/c.rb +67 -0
- data/lib/xmpp4r/caps/helper/generator.rb +160 -0
- data/lib/xmpp4r/caps/helper/helper.rb +84 -0
- data/lib/xmpp4r/client.rb +345 -0
- data/lib/xmpp4r/command/helper/responder.rb +53 -0
- data/lib/xmpp4r/command/iq/command.rb +154 -0
- data/lib/xmpp4r/component.rb +103 -0
- data/lib/xmpp4r/connection.rb +231 -0
- data/lib/xmpp4r/dataforms.rb +5 -0
- data/lib/xmpp4r/dataforms/x/data.rb +297 -0
- data/lib/xmpp4r/debuglog.rb +63 -0
- data/lib/xmpp4r/delay.rb +5 -0
- data/lib/xmpp4r/delay/x/delay.rb +99 -0
- data/lib/xmpp4r/discovery.rb +8 -0
- data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
- data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +211 -0
- data/lib/xmpp4r/discovery/iq/discoitems.rb +147 -0
- data/lib/xmpp4r/entity_time.rb +6 -0
- data/lib/xmpp4r/entity_time/iq.rb +45 -0
- data/lib/xmpp4r/entity_time/responder.rb +57 -0
- data/lib/xmpp4r/errors.rb +284 -0
- data/lib/xmpp4r/feature_negotiation.rb +5 -0
- data/lib/xmpp4r/feature_negotiation/iq/feature.rb +28 -0
- data/lib/xmpp4r/framework/base.rb +55 -0
- data/lib/xmpp4r/framework/bot.rb +148 -0
- data/lib/xmpp4r/httpbinding.rb +5 -0
- data/lib/xmpp4r/httpbinding/client.rb +275 -0
- data/lib/xmpp4r/idgenerator.rb +37 -0
- data/lib/xmpp4r/iq.rb +221 -0
- data/lib/xmpp4r/jid.rb +167 -0
- data/lib/xmpp4r/last.rb +2 -0
- data/lib/xmpp4r/last/helper/helper.rb +37 -0
- data/lib/xmpp4r/last/iq/last.rb +67 -0
- data/lib/xmpp4r/location.rb +2 -0
- data/lib/xmpp4r/location/helper/helper.rb +56 -0
- data/lib/xmpp4r/location/location.rb +179 -0
- data/lib/xmpp4r/message.rb +226 -0
- data/lib/xmpp4r/muc.rb +14 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +92 -0
- data/lib/xmpp4r/muc/helper/mucclient.rb +469 -0
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +332 -0
- data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
- data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
- data/lib/xmpp4r/muc/iq/mucowner.rb +15 -0
- data/lib/xmpp4r/muc/item.rb +143 -0
- data/lib/xmpp4r/muc/x/muc.rb +70 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +60 -0
- data/lib/xmpp4r/muc/x/mucuseritem.rb +36 -0
- data/lib/xmpp4r/presence.rb +232 -0
- data/lib/xmpp4r/pubsub.rb +8 -0
- data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
- data/lib/xmpp4r/pubsub/children/event.rb +49 -0
- data/lib/xmpp4r/pubsub/children/item.rb +35 -0
- data/lib/xmpp4r/pubsub/children/items.rb +53 -0
- data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
- data/lib/xmpp4r/pubsub/children/publish.rb +38 -0
- data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
- data/lib/xmpp4r/pubsub/children/subscription.rb +62 -0
- data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
- data/lib/xmpp4r/pubsub/children/unsubscribe.rb +63 -0
- data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +129 -0
- data/lib/xmpp4r/pubsub/helper/nodehelper.rb +156 -0
- data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
- data/lib/xmpp4r/pubsub/helper/servicehelper.rb +490 -0
- data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
- data/lib/xmpp4r/query.rb +15 -0
- data/lib/xmpp4r/reliable.rb +168 -0
- data/lib/xmpp4r/rexmladdons.rb +197 -0
- data/lib/xmpp4r/roster.rb +7 -0
- data/lib/xmpp4r/roster/helper/roster.rb +532 -0
- data/lib/xmpp4r/roster/iq/roster.rb +215 -0
- data/lib/xmpp4r/roster/x/roster.rb +138 -0
- data/lib/xmpp4r/rpc.rb +2 -0
- data/lib/xmpp4r/rpc/helper/client.rb +123 -0
- data/lib/xmpp4r/rpc/helper/server.rb +74 -0
- data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +67 -0
- data/lib/xmpp4r/rpc/iq/rpc.rb +23 -0
- data/lib/xmpp4r/sasl.rb +259 -0
- data/lib/xmpp4r/semaphore.rb +38 -0
- data/lib/xmpp4r/stream.rb +611 -0
- data/lib/xmpp4r/streamparser.rb +66 -0
- data/lib/xmpp4r/test/listener_mocker.rb +118 -0
- data/lib/xmpp4r/tune.rb +2 -0
- data/lib/xmpp4r/tune/helper/helper.rb +58 -0
- data/lib/xmpp4r/tune/tune.rb +113 -0
- data/lib/xmpp4r/vcard.rb +6 -0
- data/lib/xmpp4r/vcard/helper/vcard.rb +84 -0
- data/lib/xmpp4r/vcard/iq/vcard.rb +109 -0
- data/lib/xmpp4r/version.rb +7 -0
- data/lib/xmpp4r/version/helper/responder.rb +72 -0
- data/lib/xmpp4r/version/helper/simpleresponder.rb +44 -0
- data/lib/xmpp4r/version/iq/version.rb +105 -0
- data/lib/xmpp4r/x.rb +37 -0
- data/lib/xmpp4r/xhtml.rb +1 -0
- data/lib/xmpp4r/xhtml/html.rb +115 -0
- data/lib/xmpp4r/xmpp4r.rb +20 -0
- data/lib/xmpp4r/xmppelement.rb +168 -0
- data/lib/xmpp4r/xmppstanza.rb +162 -0
- data/setup.rb +1586 -0
- data/test/bytestreams/tc_ibb.rb +188 -0
- data/test/bytestreams/tc_socks5bytestreams.rb +114 -0
- data/test/caps/tc_helper.rb +158 -0
- data/test/dataforms/tc_data.rb +81 -0
- data/test/delay/tc_xdelay.rb +51 -0
- data/test/discovery/tc_responder.rb +91 -0
- data/test/entity_time/tc_responder.rb +65 -0
- data/test/last/tc_helper.rb +75 -0
- data/test/lib/assert_equal_xml.rb +14 -0
- data/test/lib/clienttester.rb +149 -0
- data/test/muc/tc_muc_mucclient.rb +834 -0
- data/test/muc/tc_muc_simplemucclient.rb +114 -0
- data/test/muc/tc_mucowner.rb +50 -0
- data/test/pubsub/tc_helper.rb +785 -0
- data/test/pubsub/tc_nodeconfig.rb +61 -0
- data/test/pubsub/tc_subscriptionconfig.rb +41 -0
- data/test/roster/tc_helper.rb +523 -0
- data/test/roster/tc_iqqueryroster.rb +173 -0
- data/test/roster/tc_xroster.rb +73 -0
- data/test/rpc/tc_helper.rb +96 -0
- data/test/tc_callbacks.rb +129 -0
- data/test/tc_class_names.rb +146 -0
- data/test/tc_client.rb +30 -0
- data/test/tc_errors.rb +146 -0
- data/test/tc_idgenerator.rb +30 -0
- data/test/tc_iq.rb +113 -0
- data/test/tc_iqquery.rb +31 -0
- data/test/tc_jid.rb +204 -0
- data/test/tc_presence.rb +150 -0
- data/test/tc_rexml.rb +139 -0
- data/test/tc_stream.rb +193 -0
- data/test/tc_streamComponent.rb +105 -0
- data/test/tc_streamError.rb +129 -0
- data/test/tc_streamSend.rb +59 -0
- data/test/tc_streamparser.rb +137 -0
- data/test/tc_xmppstanza.rb +135 -0
- data/test/ts_xmpp4r.rb +44 -0
- data/test/tune/tc_helper_recv.rb +82 -0
- data/test/tune/tc_helper_send.rb +74 -0
- data/test/tune/tc_tune.rb +79 -0
- data/test/vcard/tc_helper.rb +49 -0
- data/test/vcard/tc_iqvcard.rb +62 -0
- data/test/version/tc_helper.rb +60 -0
- data/test/version/tc_iqqueryversion.rb +97 -0
- data/test/xhtml/tc_html.rb +41 -0
- data/tools/gen_requires.bash +31 -0
- data/tools/xmpp4r-gemspec-test.rb +11 -0
- data/xmpp4r.gemspec +249 -0
- metadata +299 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
7
|
+
|
8
|
+
require 'xmpp4r'
|
9
|
+
require 'xmpp4r/pubsub/children/node_config'
|
10
|
+
require 'xmpp4r/dataforms'
|
11
|
+
include Jabber
|
12
|
+
|
13
|
+
# Jabber.debug = true
|
14
|
+
|
15
|
+
class PubSub::NodeConfigTest < Test::Unit::TestCase
|
16
|
+
include ClientTester
|
17
|
+
|
18
|
+
def test_create()
|
19
|
+
config = PubSub::NodeConfig.new()
|
20
|
+
assert_nil(config.form)
|
21
|
+
assert_nil(config.node)
|
22
|
+
assert_equal({}, config.options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_create_with_options
|
26
|
+
options = {'pubsub#access_model'=>'open'}
|
27
|
+
|
28
|
+
config = PubSub::NodeConfig.new(nil, options)
|
29
|
+
assert_kind_of(Jabber::Dataforms::XData, config.form)
|
30
|
+
assert_equal(options, config.options)
|
31
|
+
assert_equal(:submit, config.form.type)
|
32
|
+
assert_equal('http://jabber.org/protocol/pubsub#node_config', config.form.field('FORM_TYPE').values.first)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_create_with_options_and_node
|
36
|
+
node = 'mynode'
|
37
|
+
options = {'pubsub#access_model'=>'open'}
|
38
|
+
|
39
|
+
config = PubSub::NodeConfig.new(node, options)
|
40
|
+
assert_equal(node, config.node)
|
41
|
+
assert_kind_of(Jabber::Dataforms::XData, config.form)
|
42
|
+
assert_equal(options, config.options)
|
43
|
+
assert_equal(:submit, config.form.type)
|
44
|
+
assert_equal('http://jabber.org/protocol/pubsub#node_config', config.form.field('FORM_TYPE').values.first)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_set_options
|
48
|
+
options = {'pubsub#access_model'=>'open'}
|
49
|
+
config = PubSub::NodeConfig.new()
|
50
|
+
config.options = options
|
51
|
+
assert_kind_of(Jabber::Dataforms::XData, config.form)
|
52
|
+
assert_equal(options, config.options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_create_with_array_in_options
|
56
|
+
options = {'pubsub#collection'=>['parent1','parent2']}
|
57
|
+
config = PubSub::OwnerNodeConfig.new(nil, options)
|
58
|
+
|
59
|
+
assert_equal(options, config.options)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
7
|
+
|
8
|
+
require 'xmpp4r'
|
9
|
+
require 'xmpp4r/pubsub/children/subscription_config'
|
10
|
+
require 'xmpp4r/dataforms'
|
11
|
+
include Jabber
|
12
|
+
|
13
|
+
# Jabber.debug = true
|
14
|
+
|
15
|
+
class PubSub::SubscriptionConfigTest < Test::Unit::TestCase
|
16
|
+
include ClientTester
|
17
|
+
|
18
|
+
def test_create()
|
19
|
+
config = PubSub::SubscriptionConfig.new()
|
20
|
+
assert_nil(config.form)
|
21
|
+
assert_nil(config.node)
|
22
|
+
assert_equal({}, config.options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_create_with_options
|
26
|
+
node = 'mynode'
|
27
|
+
jid = 'test@test.com'
|
28
|
+
options = {'pubsub#access_model'=>'open'}
|
29
|
+
subid = '004-yyy'
|
30
|
+
|
31
|
+
config = PubSub::SubscriptionConfig.new(node, jid, options, subid)
|
32
|
+
assert_equal(node, config.node)
|
33
|
+
assert_equal(subid, config.subid)
|
34
|
+
assert_kind_of(Jabber::JID, config.jid)
|
35
|
+
assert_equal(Jabber::JID.new(jid), config.jid)
|
36
|
+
assert_kind_of(Jabber::Dataforms::XData, config.form)
|
37
|
+
assert_equal(options, config.options)
|
38
|
+
assert_equal(:submit, config.form.type)
|
39
|
+
assert_equal('http://jabber.org/protocol/pubsub#subscribe_options', config.form.field('FORM_TYPE').values.first)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,523 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File::dirname(__FILE__) + '/../../lib'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require File::dirname(__FILE__) + '/../lib/clienttester'
|
7
|
+
|
8
|
+
require 'xmpp4r'
|
9
|
+
require 'xmpp4r/roster/helper/roster'
|
10
|
+
require 'xmpp4r/semaphore'
|
11
|
+
include Jabber
|
12
|
+
|
13
|
+
class Roster::HelperTest < Test::Unit::TestCase
|
14
|
+
include ClientTester
|
15
|
+
|
16
|
+
def test_simple
|
17
|
+
state { |iq|
|
18
|
+
assert_kind_of(Iq, iq)
|
19
|
+
assert_equal(:get, iq.type)
|
20
|
+
assert_nil(iq.to)
|
21
|
+
assert_equal('jabber:iq:roster', iq.queryns)
|
22
|
+
|
23
|
+
send("<iq type='result'><query xmlns='jabber:iq:version'/></iq>")
|
24
|
+
send("<iq type='result' id='#{iq.id}'>
|
25
|
+
<query xmlns='jabber:iq:roster'>
|
26
|
+
<item jid='a@b.c' subscription='both'/>
|
27
|
+
<item jid='b@b.c' name='b guy' subscription='from' ask='subscribe'/>
|
28
|
+
<item jid='123@xyz' name='123' subscription='to'/>
|
29
|
+
</query>
|
30
|
+
</iq>")
|
31
|
+
}
|
32
|
+
|
33
|
+
query_waiter = Semaphore.new
|
34
|
+
h = Roster::Helper.new(@client, false)
|
35
|
+
h.add_query_callback { |iq|
|
36
|
+
query_waiter.run
|
37
|
+
}
|
38
|
+
h.get_roster
|
39
|
+
wait_state
|
40
|
+
query_waiter.wait
|
41
|
+
|
42
|
+
assert_equal([nil], h.groups)
|
43
|
+
jids = h.find_by_group(nil).collect { |item| item.jid }.sort
|
44
|
+
assert_equal([JID.new('123@xyz'), JID.new('a@b.c'), JID.new('b@b.c')], jids)
|
45
|
+
assert_equal(1, h.find('123@xyz/res').size)
|
46
|
+
|
47
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
48
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
49
|
+
assert_nil(h['a@b.c'].iname)
|
50
|
+
assert_equal(:both, h['a@b.c'].subscription)
|
51
|
+
assert_nil(h['a@b.c'].ask)
|
52
|
+
|
53
|
+
assert_kind_of(Roster::Helper::RosterItem, h[JID.new('b@b.c')])
|
54
|
+
assert_equal(JID.new('b@b.c'), h['b@b.c'].jid)
|
55
|
+
assert_equal('b guy', h['b@b.c'].iname)
|
56
|
+
assert_equal(:from, h['b@b.c'].subscription)
|
57
|
+
assert_equal(:subscribe, h['b@b.c'].ask)
|
58
|
+
|
59
|
+
assert_kind_of(Roster::Helper::RosterItem, h['123@xyz'])
|
60
|
+
assert_equal(JID.new('123@xyz'), h['123@xyz'].jid)
|
61
|
+
assert_equal('123', h['123@xyz'].iname)
|
62
|
+
assert_equal(:to, h['123@xyz'].subscription)
|
63
|
+
assert_nil(h['123@xyz'].ask)
|
64
|
+
|
65
|
+
assert_nil(h['c@b.c'])
|
66
|
+
assert_nil(h[JID.new('c@b.c')])
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_rosterpush
|
70
|
+
state { |iq|
|
71
|
+
send("<iq type='result' id='#{iq.id}'>
|
72
|
+
<query xmlns='jabber:iq:roster'>
|
73
|
+
</query>
|
74
|
+
</iq>")
|
75
|
+
}
|
76
|
+
|
77
|
+
query_waiter = Semaphore.new
|
78
|
+
h = Roster::Helper.new(@client, false)
|
79
|
+
h.add_query_callback { |iq| query_waiter.run }
|
80
|
+
h.get_roster
|
81
|
+
wait_state
|
82
|
+
query_waiter.wait
|
83
|
+
|
84
|
+
assert_equal([], h.groups)
|
85
|
+
assert_nil(h['a@b.c'])
|
86
|
+
|
87
|
+
send("<iq type='set'>
|
88
|
+
<query xmlns='jabber:iq:roster'>
|
89
|
+
<item jid='a@b.c'/>
|
90
|
+
</query>
|
91
|
+
</iq>")
|
92
|
+
query_waiter.wait
|
93
|
+
|
94
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
95
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
96
|
+
assert_nil(h['a@b.c'].iname)
|
97
|
+
assert_nil(h['a@b.c'].subscription)
|
98
|
+
assert_nil(h['a@b.c'].ask)
|
99
|
+
|
100
|
+
send("<iq type='set'>
|
101
|
+
<query xmlns='jabber:iq:roster'>
|
102
|
+
<item jid='a@b.c' subscription='from' name='ABC' ask='subscribe'/>
|
103
|
+
</query>
|
104
|
+
</iq>")
|
105
|
+
query_waiter.wait
|
106
|
+
|
107
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
108
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
109
|
+
assert_equal('ABC', h['a@b.c'].iname)
|
110
|
+
assert_equal(:from, h['a@b.c'].subscription)
|
111
|
+
assert_equal(:subscribe, h['a@b.c'].ask)
|
112
|
+
|
113
|
+
send("<iq type='set'>
|
114
|
+
<query xmlns='jabber:iq:roster'>
|
115
|
+
<item jid='a@b.c'/>
|
116
|
+
</query>
|
117
|
+
</iq>")
|
118
|
+
query_waiter.wait
|
119
|
+
|
120
|
+
assert_kind_of(Roster::Helper::RosterItem, h['a@b.c'])
|
121
|
+
assert_equal(JID.new('a@b.c'), h['a@b.c'].jid)
|
122
|
+
assert_nil(h['a@b.c'].iname)
|
123
|
+
assert_nil(h['a@b.c'].subscription)
|
124
|
+
assert_nil(h['a@b.c'].ask)
|
125
|
+
|
126
|
+
send("<iq type='set'>
|
127
|
+
<query xmlns='jabber:iq:roster'>
|
128
|
+
<item jid='a@b.c' subscription='remove'/>
|
129
|
+
</query>
|
130
|
+
</iq>")
|
131
|
+
query_waiter.wait
|
132
|
+
|
133
|
+
assert_nil(h['a@b.c'])
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_presence
|
137
|
+
state { |iq|
|
138
|
+
send("<iq type='result' id='#{iq.id}'>
|
139
|
+
<query xmlns='jabber:iq:roster'>
|
140
|
+
<item jid='a@b.c' subscription='both'/>
|
141
|
+
</query>
|
142
|
+
</iq>")
|
143
|
+
}
|
144
|
+
|
145
|
+
query_waiter = Semaphore.new
|
146
|
+
presence_waiter = Semaphore.new
|
147
|
+
h = Roster::Helper.new(@client, false)
|
148
|
+
h.add_query_callback { |iq|
|
149
|
+
query_waiter.run
|
150
|
+
}
|
151
|
+
cb_item, cb_op, cb_p = nil, nil, nil
|
152
|
+
h.add_presence_callback { |item,oldpres,pres|
|
153
|
+
# HACK:
|
154
|
+
# if two stanzas are expected for one sent stanza,
|
155
|
+
# race conditions may appear here
|
156
|
+
Thread.pass
|
157
|
+
|
158
|
+
cb_item, cb_op, cb_p = item, oldpres, pres
|
159
|
+
presence_waiter.run
|
160
|
+
}
|
161
|
+
h.get_roster
|
162
|
+
wait_state
|
163
|
+
query_waiter.wait
|
164
|
+
|
165
|
+
assert_equal(false, h['a@b.c'].online?)
|
166
|
+
presences = 0
|
167
|
+
h['a@b.c'].each_presence { presences += 1 }
|
168
|
+
assert_equal(0, presences)
|
169
|
+
|
170
|
+
send("<presence from='a@b.c/r'/>")
|
171
|
+
presence_waiter.wait
|
172
|
+
|
173
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
174
|
+
assert_nil(cb_op)
|
175
|
+
assert_kind_of(Presence, cb_p)
|
176
|
+
assert_nil(cb_p.type)
|
177
|
+
assert_equal(true, h['a@b.c'].online?)
|
178
|
+
presences = 0
|
179
|
+
h['a@b.c'].each_presence { presences += 1 }
|
180
|
+
assert_equal(1, presences)
|
181
|
+
|
182
|
+
send("<presence from='a@b.c/r2'/>")
|
183
|
+
presence_waiter.wait
|
184
|
+
|
185
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
186
|
+
assert_nil(cb_op)
|
187
|
+
assert_kind_of(Presence, cb_p)
|
188
|
+
assert_nil(cb_p.type)
|
189
|
+
assert_equal(true, h['a@b.c'].online?)
|
190
|
+
presences = 0
|
191
|
+
h['a@b.c'].each_presence { presences += 1 }
|
192
|
+
assert_equal(2, presences)
|
193
|
+
|
194
|
+
send("<presence from='a@b.c/r'/>")
|
195
|
+
presence_waiter.wait
|
196
|
+
|
197
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
198
|
+
assert_kind_of(Presence, cb_op)
|
199
|
+
assert_nil(cb_op.type)
|
200
|
+
assert_kind_of(Presence, cb_p)
|
201
|
+
assert_nil(cb_p.type)
|
202
|
+
assert_equal(true, h['a@b.c'].online?)
|
203
|
+
presences = 0
|
204
|
+
h['a@b.c'].each_presence { presences += 1 }
|
205
|
+
assert_equal(2, presences)
|
206
|
+
|
207
|
+
send("<presence from='a@b.c/r' type='error'/>")
|
208
|
+
presence_waiter.wait
|
209
|
+
|
210
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
211
|
+
assert_kind_of(Presence, cb_op)
|
212
|
+
assert_nil(cb_op.type)
|
213
|
+
assert_kind_of(Presence, cb_p)
|
214
|
+
assert_equal(:error, cb_p.type)
|
215
|
+
assert_equal(true, h['a@b.c'].online?)
|
216
|
+
presences = 0
|
217
|
+
h['a@b.c'].each_presence { presences += 1 }
|
218
|
+
assert_equal(2, presences)
|
219
|
+
|
220
|
+
send("<presence from='a@b.c/r2' type='unavailable'/>")
|
221
|
+
presence_waiter.wait
|
222
|
+
|
223
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
224
|
+
assert_kind_of(Presence, cb_op)
|
225
|
+
assert_nil(cb_op.type)
|
226
|
+
assert_kind_of(Presence, cb_p)
|
227
|
+
assert_equal(:unavailable, cb_p.type)
|
228
|
+
assert_equal(false, h['a@b.c'].online?)
|
229
|
+
presences = 0
|
230
|
+
h['a@b.c'].each_presence { presences += 1 }
|
231
|
+
assert_equal(2, presences)
|
232
|
+
|
233
|
+
send("<presence from='a@b.c/r'/>")
|
234
|
+
presence_waiter.wait
|
235
|
+
|
236
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
237
|
+
assert_kind_of(Presence, cb_op)
|
238
|
+
assert_equal(:error, cb_op.type)
|
239
|
+
assert_kind_of(Presence, cb_p)
|
240
|
+
assert_nil(cb_p.type)
|
241
|
+
assert_equal(true, h['a@b.c'].online?)
|
242
|
+
presences = 0
|
243
|
+
h['a@b.c'].each_presence { presences += 1 }
|
244
|
+
assert_equal(1, presences)
|
245
|
+
|
246
|
+
send("<presence from='a@b.c/r2'/>")
|
247
|
+
presence_waiter.wait
|
248
|
+
|
249
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
250
|
+
assert_nil(cb_op)
|
251
|
+
assert_kind_of(Presence, cb_p)
|
252
|
+
assert_nil(cb_p.type)
|
253
|
+
assert_equal(true, h['a@b.c'].online?)
|
254
|
+
presences = 0
|
255
|
+
h['a@b.c'].each_presence { presences += 1 }
|
256
|
+
assert_equal(2, presences)
|
257
|
+
|
258
|
+
send("<presence from='a@b.c' type='error'/>")
|
259
|
+
2.times {
|
260
|
+
presence_waiter.wait
|
261
|
+
|
262
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
263
|
+
assert_kind_of(Presence, cb_op)
|
264
|
+
assert_kind_of(Presence, cb_p)
|
265
|
+
assert_equal(:error, cb_p.type)
|
266
|
+
}
|
267
|
+
assert_equal(false, h['a@b.c'].online?)
|
268
|
+
presences = 0
|
269
|
+
h['a@b.c'].each_presence { presences += 1 }
|
270
|
+
assert_equal(1, presences)
|
271
|
+
|
272
|
+
send("<presence from='a@b.c/r'/>")
|
273
|
+
presence_waiter.wait
|
274
|
+
|
275
|
+
assert_kind_of(Roster::Helper::RosterItem, cb_item)
|
276
|
+
assert_nil(cb_op)
|
277
|
+
assert_kind_of(Presence, cb_p)
|
278
|
+
assert_nil(cb_p.type)
|
279
|
+
assert_equal(true, h['a@b.c'].online?)
|
280
|
+
presences = 0
|
281
|
+
h['a@b.c'].each_presence { presences += 1 }
|
282
|
+
assert_equal(1, presences)
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_subscribe
|
286
|
+
state { |iq|
|
287
|
+
send("<iq type='result' id='#{iq.id}'>
|
288
|
+
<query xmlns='jabber:iq:roster'/>
|
289
|
+
</iq>")
|
290
|
+
}
|
291
|
+
|
292
|
+
query_waiter = Semaphore.new
|
293
|
+
h = Roster::Helper.new(@client, false)
|
294
|
+
h.add_query_callback { |iq| query_waiter.run }
|
295
|
+
h.get_roster
|
296
|
+
wait_state
|
297
|
+
query_waiter.wait
|
298
|
+
|
299
|
+
state { |iq|
|
300
|
+
assert_kind_of(Iq, iq)
|
301
|
+
assert_equal('jabber:iq:roster', iq.queryns)
|
302
|
+
assert_equal(JID.new('contact@example.org'), iq.query.first_element('item').jid)
|
303
|
+
assert_equal('MyContact', iq.query.first_element('item').iname)
|
304
|
+
send("<iq type='set'>
|
305
|
+
<query xmlns='jabber:iq:roster'>
|
306
|
+
<item jid='contact@example.org' subscription='none' name='MyContact'/>
|
307
|
+
</query>
|
308
|
+
</iq>
|
309
|
+
<iq type='result' id='#{iq.id}'/>")
|
310
|
+
}
|
311
|
+
state { |pres|
|
312
|
+
assert_kind_of(Presence, pres)
|
313
|
+
assert_equal(:subscribe, pres.type)
|
314
|
+
assert_equal(JID.new('contact@example.org'), pres.to)
|
315
|
+
Thread.pass
|
316
|
+
}
|
317
|
+
h.add('contact@example.org', 'MyContact', true)
|
318
|
+
wait_state
|
319
|
+
query_waiter.wait
|
320
|
+
wait_state
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_accept_subscription
|
324
|
+
state { |iq|
|
325
|
+
send("<iq type='result' id='#{iq.id}'>
|
326
|
+
<query xmlns='jabber:iq:roster'/>
|
327
|
+
</iq>")
|
328
|
+
}
|
329
|
+
|
330
|
+
query_waiter = Semaphore.new
|
331
|
+
h = Roster::Helper.new(@client, false)
|
332
|
+
h.add_query_callback { |iq| query_waiter.run }
|
333
|
+
h.get_roster
|
334
|
+
wait_state
|
335
|
+
query_waiter.wait
|
336
|
+
|
337
|
+
state { |pres|
|
338
|
+
assert_kind_of(Presence, pres)
|
339
|
+
assert_equal(:subscribed, pres.type)
|
340
|
+
}
|
341
|
+
state { |iq|
|
342
|
+
assert_kind_of(Iq, iq)
|
343
|
+
assert_equal(:set, iq.type)
|
344
|
+
send("<iq type='result' id='#{iq.id}'/>")
|
345
|
+
}
|
346
|
+
|
347
|
+
cb_lock = Semaphore.new
|
348
|
+
h.add_subscription_request_callback { |item,pres|
|
349
|
+
assert_nil(item)
|
350
|
+
assert_kind_of(Presence, pres)
|
351
|
+
h.accept_subscription(pres.from)
|
352
|
+
cb_lock.run
|
353
|
+
}
|
354
|
+
send("<presence type='subscribe' from='contact@example.org' to='user@example.com'/>")
|
355
|
+
skip_state
|
356
|
+
wait_state
|
357
|
+
cb_lock.wait
|
358
|
+
|
359
|
+
state { |pres|
|
360
|
+
assert_kind_of(Presence, pres)
|
361
|
+
assert_equal(:subscribed, pres.type)
|
362
|
+
assert_equal(JID.new('contact@example.org'), pres.to)
|
363
|
+
}
|
364
|
+
wait_state
|
365
|
+
end
|
366
|
+
|
367
|
+
def test_decline_subscription
|
368
|
+
query_waiter = Semaphore.new
|
369
|
+
|
370
|
+
state { |iq|
|
371
|
+
send("<iq type='result' id='#{iq.id}'>
|
372
|
+
<query xmlns='jabber:iq:roster'/>
|
373
|
+
</iq>")
|
374
|
+
}
|
375
|
+
|
376
|
+
h = Roster::Helper.new(@client, false)
|
377
|
+
h.add_query_callback { |iq| query_waiter.run }
|
378
|
+
h.get_roster
|
379
|
+
|
380
|
+
wait_state
|
381
|
+
query_waiter.wait
|
382
|
+
|
383
|
+
state { |pres|
|
384
|
+
assert_kind_of(Presence, pres)
|
385
|
+
assert_equal(:unsubscribed, pres.type)
|
386
|
+
assert_equal(JID.new('contact@example.org'), pres.to)
|
387
|
+
}
|
388
|
+
cb_lock = Semaphore.new
|
389
|
+
h.add_subscription_request_callback { |item,pres|
|
390
|
+
assert_nil(item)
|
391
|
+
assert_kind_of(Presence, pres)
|
392
|
+
h.decline_subscription(pres.from)
|
393
|
+
|
394
|
+
cb_lock.run
|
395
|
+
}
|
396
|
+
|
397
|
+
send("<presence type='subscribe' from='contact@example.org' to='user@example.com'/>")
|
398
|
+
wait_state
|
399
|
+
cb_lock.wait
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_groupset
|
403
|
+
state { |iq|
|
404
|
+
send("<iq type='result'>
|
405
|
+
<query xmlns='jabber:iq:roster'>
|
406
|
+
<item jid='test@test' subscription='both'>
|
407
|
+
<group>One</group>
|
408
|
+
<group>Two</group>
|
409
|
+
</item>
|
410
|
+
</query>
|
411
|
+
</iq>")
|
412
|
+
}
|
413
|
+
|
414
|
+
query_waiter = Semaphore.new
|
415
|
+
h = Roster::Helper.new(@client, false)
|
416
|
+
h.add_query_callback { query_waiter.run }
|
417
|
+
h.get_roster
|
418
|
+
wait_state
|
419
|
+
query_waiter.wait
|
420
|
+
|
421
|
+
assert_equal(1, h.items.size)
|
422
|
+
assert_equal(%w(One Two).sort, h['test@test'].groups.sort)
|
423
|
+
|
424
|
+
state { |iq|
|
425
|
+
send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>")
|
426
|
+
}
|
427
|
+
h['test@test'].groups = %w(One Two Three)
|
428
|
+
h['test@test'].send
|
429
|
+
wait_state
|
430
|
+
query_waiter.wait
|
431
|
+
assert_equal(%w(One Two Three).sort, h['test@test'].groups.sort)
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_nameset
|
435
|
+
state { |iq|
|
436
|
+
send("<iq type='result'>
|
437
|
+
<query xmlns='jabber:iq:roster'>
|
438
|
+
<item jid='test@test' subscription='both'/>
|
439
|
+
</query>
|
440
|
+
</iq>")
|
441
|
+
}
|
442
|
+
|
443
|
+
query_waiter = Semaphore.new
|
444
|
+
h = Roster::Helper.new(@client, false)
|
445
|
+
h.add_query_callback { query_waiter.run }
|
446
|
+
h.get_roster
|
447
|
+
wait_state
|
448
|
+
query_waiter.wait
|
449
|
+
|
450
|
+
assert_equal(1, h.items.size)
|
451
|
+
assert_nil(h['test@test'].iname)
|
452
|
+
|
453
|
+
state { |iq|
|
454
|
+
send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>")
|
455
|
+
}
|
456
|
+
h['test@test'].iname = 'Unknown'
|
457
|
+
h['test@test'].send
|
458
|
+
wait_state
|
459
|
+
query_waiter.wait
|
460
|
+
assert_equal('Unknown', h['test@test'].iname)
|
461
|
+
|
462
|
+
state { |iq|
|
463
|
+
send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>")
|
464
|
+
}
|
465
|
+
h['test@test'].iname = 'Known'
|
466
|
+
h['test@test'].send
|
467
|
+
wait_state
|
468
|
+
query_waiter.wait
|
469
|
+
assert_equal('Known', h['test@test'].iname)
|
470
|
+
|
471
|
+
state { |iq|
|
472
|
+
send("<iq type='result' id='#{iq.id}'>#{iq.query}</iq>")
|
473
|
+
}
|
474
|
+
h['test@test'].iname = nil
|
475
|
+
h['test@test'].send
|
476
|
+
wait_state
|
477
|
+
query_waiter.wait
|
478
|
+
assert_nil(h['test@test'].iname)
|
479
|
+
end
|
480
|
+
|
481
|
+
def test_update_callback
|
482
|
+
update_args = nil
|
483
|
+
update_waiter = Semaphore.new
|
484
|
+
|
485
|
+
h = Roster::Helper.new(@client, false)
|
486
|
+
h.add_update_callback { |*a|
|
487
|
+
update_args = a
|
488
|
+
update_waiter.run
|
489
|
+
}
|
490
|
+
h.get_roster
|
491
|
+
|
492
|
+
send("<iq type='set'>
|
493
|
+
<query xmlns='jabber:iq:roster'>
|
494
|
+
<item jid='foo@bar' name='Foo'/>
|
495
|
+
</query>
|
496
|
+
</iq>")
|
497
|
+
update_waiter.wait
|
498
|
+
assert_nil(update_args[0])
|
499
|
+
assert_equal(JID.new('foo@bar'), update_args[1].jid)
|
500
|
+
assert_equal('Foo', update_args[1].iname)
|
501
|
+
|
502
|
+
send("<iq type='set'>
|
503
|
+
<query xmlns='jabber:iq:roster'>
|
504
|
+
<item jid='foo@bar'/>
|
505
|
+
</query>
|
506
|
+
</iq>")
|
507
|
+
update_waiter.wait
|
508
|
+
assert_equal(JID.new('foo@bar'), update_args[0].jid)
|
509
|
+
assert_equal('Foo', update_args[0].iname)
|
510
|
+
assert_equal(JID.new('foo@bar'), update_args[1].jid)
|
511
|
+
assert_nil(update_args[1].iname)
|
512
|
+
|
513
|
+
send("<iq type='set'>
|
514
|
+
<query xmlns='jabber:iq:roster'>
|
515
|
+
<item jid='foo@bar' subscription='remove'/>
|
516
|
+
</query>
|
517
|
+
</iq>")
|
518
|
+
update_waiter.wait
|
519
|
+
assert_equal(JID.new('foo@bar'), update_args[0].jid)
|
520
|
+
assert_nil(update_args[0].iname)
|
521
|
+
assert_nil(update_args[1])
|
522
|
+
end
|
523
|
+
end
|