xmpp4r 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/ChangeLog +12 -0
  2. data/Rakefile +2 -4
  3. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +6 -6
  4. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +3 -3
  5. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +5 -5
  6. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +17 -4
  7. data/data/doc/xmpp4r/examples/advanced/xmppingrc.sample +5 -0
  8. data/data/doc/xmpp4r/examples/basic/echo_threaded.rb +6 -2
  9. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +13 -0
  10. data/lib/xmpp4r.rb +0 -6
  11. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +6 -7
  12. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +5 -6
  13. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +3 -5
  14. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +1 -1
  15. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +10 -8
  16. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +3 -5
  17. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +11 -17
  18. data/lib/xmpp4r/bytestreams/iq/si.rb +13 -32
  19. data/lib/xmpp4r/callbacks.rb +124 -0
  20. data/lib/xmpp4r/client.rb +2 -5
  21. data/lib/xmpp4r/command/helper/responder.rb +53 -0
  22. data/lib/xmpp4r/command/iq/command.rb +154 -0
  23. data/lib/xmpp4r/connection.rb +49 -12
  24. data/lib/xmpp4r/dataforms/x/data.rb +66 -29
  25. data/lib/xmpp4r/delay/x/delay.rb +2 -3
  26. data/lib/xmpp4r/discovery/iq/discoinfo.rb +20 -33
  27. data/lib/xmpp4r/discovery/iq/discoitems.rb +5 -28
  28. data/lib/xmpp4r/error.rb +5 -10
  29. data/lib/xmpp4r/feature_negotiation/iq/feature.rb +2 -20
  30. data/lib/xmpp4r/httpbinding.rb +5 -0
  31. data/lib/xmpp4r/httpbinding/client.rb +285 -0
  32. data/lib/xmpp4r/iq.rb +22 -41
  33. data/lib/xmpp4r/message.rb +8 -38
  34. data/lib/xmpp4r/muc.rb +2 -0
  35. data/lib/xmpp4r/muc/helper/mucclient.rb +50 -1
  36. data/lib/xmpp4r/muc/helper/simplemucclient.rb +2 -2
  37. data/lib/xmpp4r/muc/iq/mucowner.rb +11 -0
  38. data/lib/xmpp4r/muc/x/muc.rb +2 -30
  39. data/lib/xmpp4r/muc/x/mucuserinvite.rb +4 -2
  40. data/lib/xmpp4r/muc/x/mucuseritem.rb +4 -2
  41. data/lib/xmpp4r/presence.rb +7 -35
  42. data/lib/xmpp4r/pubsub.rb +1 -0
  43. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +174 -0
  44. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +153 -0
  45. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +326 -0
  46. data/lib/xmpp4r/pubsub/iq/pubsub.rb +19 -0
  47. data/lib/xmpp4r/pubsub/stanzas/event.rb +49 -0
  48. data/lib/xmpp4r/pubsub/stanzas/item.rb +27 -0
  49. data/lib/xmpp4r/pubsub/stanzas/items.rb +35 -0
  50. data/lib/xmpp4r/pubsub/stanzas/subscription.rb +58 -0
  51. data/lib/xmpp4r/query.rb +4 -32
  52. data/lib/xmpp4r/rexmladdons.rb +7 -772
  53. data/lib/xmpp4r/roster/helper/roster.rb +29 -50
  54. data/lib/xmpp4r/roster/iq/roster.rb +6 -35
  55. data/lib/xmpp4r/roster/x/roster.rb +13 -30
  56. data/lib/xmpp4r/rpc.rb +2 -0
  57. data/lib/xmpp4r/rpc/helper/client.rb +114 -0
  58. data/lib/xmpp4r/rpc/helper/server.rb +75 -0
  59. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +57 -0
  60. data/lib/xmpp4r/rpc/iq/rpc.rb +24 -0
  61. data/lib/xmpp4r/sasl.rb +1 -1
  62. data/lib/xmpp4r/semaphore.rb +38 -0
  63. data/lib/xmpp4r/stream.rb +104 -165
  64. data/lib/xmpp4r/streamparser.rb +2 -2
  65. data/lib/xmpp4r/vcard/iq/vcard.rb +5 -12
  66. data/lib/xmpp4r/version/helper/responder.rb +2 -1
  67. data/lib/xmpp4r/version/iq/version.rb +6 -18
  68. data/lib/xmpp4r/x.rb +20 -26
  69. data/lib/xmpp4r/xmpp4r.rb +1 -1
  70. data/lib/xmpp4r/xmppelement.rb +152 -0
  71. data/lib/xmpp4r/{xmlstanza.rb → xmppstanza.rb} +17 -29
  72. data/setup.rb +1 -0
  73. data/test/bytestreams/tc_ibb.rb +8 -8
  74. data/test/dataforms/tc_data.rb +81 -0
  75. data/test/lib/clienttester.rb +20 -17
  76. data/test/muc/tc_muc_mucclient.rb +48 -23
  77. data/test/muc/tc_muc_simplemucclient.rb +7 -4
  78. data/test/muc/tc_mucowner.rb +50 -0
  79. data/test/pubsub/tc_helper.rb +227 -0
  80. data/test/roster/tc_helper.rb +181 -55
  81. data/test/roster/tc_iqqueryroster.rb +33 -0
  82. data/test/roster/tc_xroster.rb +6 -3
  83. data/test/rpc/tc_helper.rb +84 -0
  84. data/test/tc_callbacks.rb +2 -1
  85. data/test/tc_class_names.rb +9 -1
  86. data/test/tc_error.rb +1 -0
  87. data/test/tc_iq.rb +13 -12
  88. data/test/tc_message.rb +1 -0
  89. data/test/tc_presence.rb +1 -0
  90. data/test/tc_rexml.rb +1 -1
  91. data/test/tc_stream.rb +147 -102
  92. data/test/tc_streamComponent.rb +94 -0
  93. data/test/tc_streamError.rb +67 -29
  94. data/test/tc_streamSend.rb +1 -1
  95. data/test/tc_xmppstanza.rb +125 -0
  96. data/test/ts_xmpp4r.rb +37 -28
  97. data/test/version/tc_helper.rb +14 -0
  98. data/test/version/tc_iqqueryversion.rb +4 -3
  99. metadata +163 -123
  100. data/data/doc/xmpp4r/examples/basic/echo_nonthreaded.rb +0 -32
  101. data/lib/callbacks.rb +0 -122
  102. data/test/tc_streamThreaded.rb +0 -168
  103. data/test/tc_xmlstanza.rb +0 -76
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'tempfile'
6
+ require 'test/unit'
7
+ require 'socket'
8
+ require 'xmpp4r/component'
9
+ require 'xmpp4r/bytestreams'
10
+ require 'xmpp4r/semaphore'
11
+ require 'xmpp4r'
12
+ include Jabber
13
+
14
+ class StreamComponentTest < Test::Unit::TestCase
15
+ @@SOCKET_PORT = 65224
16
+
17
+ def setup
18
+ servlisten = TCPServer.new(@@SOCKET_PORT)
19
+ serverwait = Semaphore.new
20
+ Thread.new do
21
+ Thread.current.abort_on_exception = true
22
+ serversock = servlisten.accept
23
+ servlisten.close
24
+ serversock.sync = true
25
+ @server = Stream.new(true)
26
+ @server.add_xml_callback do |xml|
27
+ if xml.prefix == 'stream' and xml.name == 'stream'
28
+ @server.send('<stream:stream xmlns="jabber:component:accept">')
29
+ true
30
+ else
31
+ false
32
+ end
33
+ end
34
+ @server.start(serversock)
35
+
36
+ serverwait.run
37
+ end
38
+
39
+ @stream = Component::new('test')
40
+ @stream.connect('localhost', @@SOCKET_PORT)
41
+
42
+ serverwait.wait
43
+ end
44
+
45
+ def teardown
46
+ @stream.close
47
+ @server.close
48
+ end
49
+
50
+ def test_process
51
+ stanzas = 0
52
+ message_lock = Semaphore.new
53
+ iq_lock = Semaphore.new
54
+ presence_lock = Semaphore.new
55
+
56
+ @stream.add_message_callback { |msg|
57
+ assert_kind_of(Message, msg)
58
+ stanzas += 1
59
+ message_lock.run
60
+ }
61
+ @stream.add_iq_callback { |iq|
62
+ assert_kind_of(Iq, iq)
63
+ stanzas += 1
64
+ iq_lock.run
65
+ }
66
+ @stream.add_presence_callback { |pres|
67
+ assert_kind_of(Presence, pres)
68
+ stanzas += 1
69
+ presence_lock.run
70
+ }
71
+
72
+ @server.send('<message/>')
73
+ @server.send('<iq/>')
74
+ @server.send('<presence/>')
75
+
76
+ message_lock.wait
77
+ iq_lock.wait
78
+ presence_lock.wait
79
+
80
+ assert_equal(3, stanzas)
81
+ end
82
+
83
+ def test_outgoing
84
+ received_wait = Semaphore.new
85
+
86
+ @server.add_message_callback { |msg|
87
+ assert_kind_of(Message, msg)
88
+ received_wait.run
89
+ }
90
+
91
+ @stream.send(Message.new)
92
+ received_wait.wait
93
+ end
94
+ end
@@ -8,18 +8,48 @@ require 'xmpp4r/client'
8
8
  include Jabber
9
9
 
10
10
  class ConnectionErrorTest < Test::Unit::TestCase
11
+ @@SOCKET_PORT = 65225
12
+
13
+ def setup
14
+ servlisten = TCPServer.new(@@SOCKET_PORT)
15
+ serverwait = Semaphore.new
16
+ @server = nil
17
+ Thread.new do
18
+ Thread.current.abort_on_exception = true
19
+ @server = servlisten.accept
20
+ servlisten.close
21
+ @server.sync = true
22
+
23
+ serverwait.run
24
+ end
25
+
26
+ @conn = TCPSocket::new('localhost', @@SOCKET_PORT)
27
+
28
+ serverwait.wait
29
+ end
30
+
31
+ def teardown
32
+ @conn.close if not @conn.closed?
33
+ @server.close if not @conn.closed?
34
+ end
35
+
11
36
  def test_connectionError_start_withexcblock
12
- @conn, @server = IO.pipe
13
- @stream = Stream::new(false)
37
+ @stream = Stream::new
14
38
  error = false
15
39
  @stream.on_exception do |e, o, w|
16
- assert_equal(RuntimeError, e.class)
40
+ # strange exception, it's caused by REXML, actually
41
+ assert_equal(NameError, e.class)
17
42
  assert_equal(Jabber::Stream, o.class)
18
43
  assert_equal(:start, w)
19
44
  error = true
20
45
  end
21
46
  assert(!error)
22
- @stream.start(nil)
47
+ begin
48
+ # wrong port on purpose
49
+ conn = TCPSocket::new('localhost', 1)
50
+ rescue
51
+ end
52
+ @stream.start(conn)
23
53
  sleep 0.2
24
54
  assert(error)
25
55
  @server.close
@@ -27,8 +57,7 @@ class ConnectionErrorTest < Test::Unit::TestCase
27
57
  end
28
58
 
29
59
  def test_connectionError_parse_withexcblock
30
- @conn, @server = IO.pipe
31
- @stream = Stream::new(false)
60
+ @stream = Stream::new
32
61
  error = false
33
62
  @stream.start(@conn)
34
63
  @stream.on_exception do |e, o, w|
@@ -40,9 +69,7 @@ class ConnectionErrorTest < Test::Unit::TestCase
40
69
  @server.puts('<stream:stream>')
41
70
  @server.flush
42
71
  assert(!error)
43
- assert_raise(Errno::EPIPE) {
44
- @server.puts('</blop>')
45
- }
72
+ @server.puts('</blop>')
46
73
  @server.flush
47
74
  sleep 0.2
48
75
  assert(error)
@@ -51,37 +78,48 @@ class ConnectionErrorTest < Test::Unit::TestCase
51
78
  end
52
79
 
53
80
  def test_connectionError_send_withexcblock
54
- @conn, @server = IO.pipe
55
- @stream = Stream::new(false)
56
- error = false
81
+ @stream = Stream::new
82
+ error = 0
57
83
  @stream.start(@conn)
58
- @stream.on_exception do |e, o, w|
59
- assert_equal(IOError, e.class)
60
- assert_equal(Jabber::Stream, o.class)
61
- assert_equal(:sending, w)
62
- error = true
84
+ @stream.on_exception do |exc, o, w|
85
+ case w
86
+ when :sending
87
+ assert_equal(IOError, exc.class)
88
+ assert_equal(Jabber::Stream, o.class)
89
+ when :disconnected
90
+ assert_equal(nil, exc)
91
+ assert_equal(Jabber::Stream, o.class)
92
+ else
93
+ assert(false)
94
+ end
95
+ error += 1
63
96
  end
64
97
  @server.puts('<stream:stream>')
65
98
  @server.flush
66
- assert(!error)
67
- @stream.send('</test>')
68
- sleep 0.2
69
- assert(error)
99
+ assert_equal(0, error)
70
100
  @server.close
101
+ sleep 0.1
102
+ assert_equal(1, error)
103
+ @stream.send('</test>')
104
+ sleep 0.1
105
+ @stream.send('</test>')
106
+ sleep 0.1
107
+ assert_equal(3, error)
71
108
  @stream.close
72
109
  end
73
110
 
74
111
  def test_connectionError_send_withoutexcblock
75
- @conn, @server = IO.pipe
76
- @stream = Stream::new(false)
112
+ @stream = Stream::new
77
113
  @stream.start(@conn)
78
114
  @server.puts('<stream:stream>')
79
115
  @server.flush
80
- assert_raise(IOError) { @stream.send('</test>') }
81
- @server.close
82
- @stream.close
116
+ assert_raise(Errno::EPIPE) do
117
+ @server.close
118
+ sleep 0.1
119
+ @stream.send('</test>')
120
+ sleep 0.1
121
+ @stream.send('</test>')
122
+ sleep 0.1
123
+ end
83
124
  end
84
-
85
-
86
-
87
125
  end
@@ -17,7 +17,7 @@ class StreamSendTest < Test::Unit::TestCase
17
17
  @servlisten = UNIXServer::new(@tmpfilepath)
18
18
  thServer = Thread.new { @server = @servlisten.accept }
19
19
  @iostream = UNIXSocket::new(@tmpfilepath)
20
- @stream = Stream::new(false)
20
+ @stream = Stream::new
21
21
  @stream.start(@iostream)
22
22
 
23
23
  thServer.join
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift '../lib'
4
+
5
+ require 'test/unit'
6
+ require 'socket'
7
+ require 'xmpp4r/rexmladdons'
8
+ require 'xmpp4r/xmppstanza'
9
+ require 'xmpp4r/iq'
10
+ require 'xmpp4r/feature_negotiation'
11
+ require 'xmpp4r/dataforms'
12
+ include Jabber
13
+
14
+ class XMPPStanzaTest < Test::Unit::TestCase
15
+
16
+ ##
17
+ # Hack: XMPPStanza derives from XMPPElement
18
+ # which enforces element classes to be named at declaration time
19
+ class MyXMPPStanza < XMPPStanza
20
+ name_xmlns 'stanza', 'http://home.gna.org/xmpp4r'
21
+ end
22
+
23
+ class MyStanza < XMPPStanza
24
+ end
25
+
26
+ def test_from
27
+ x = MyXMPPStanza::new
28
+ assert_equal(nil, x.from)
29
+ assert_equal(x, x.set_from("blop"))
30
+ assert_equal("blop", x.from.to_s)
31
+ x.from = "tada"
32
+ assert_equal("tada", x.from.to_s)
33
+ end
34
+
35
+ def test_to
36
+ x = MyXMPPStanza::new
37
+ assert_equal(nil, x.to)
38
+ assert_equal(x, x.set_to("blop"))
39
+ assert_equal("blop", x.to.to_s)
40
+ x.to = "tada"
41
+ assert_equal("tada", x.to.to_s)
42
+ end
43
+
44
+ def test_id
45
+ x = MyXMPPStanza::new
46
+ assert_equal(nil, x.id)
47
+ assert_equal(x, x.set_id("blop"))
48
+ assert_equal("blop", x.id)
49
+ x.id = "tada"
50
+ assert_equal("tada", x.id)
51
+ end
52
+
53
+ def test_type
54
+ x = MyXMPPStanza::new
55
+ assert_equal(nil, x.type)
56
+ assert_equal(x, x.set_type("blop"))
57
+ assert_equal("blop", x.type)
58
+ x.type = "tada"
59
+ assert_equal("tada", x.type)
60
+ end
61
+
62
+ def test_import
63
+ x = MyXMPPStanza::new
64
+ x.id = "heya"
65
+ q = x.add_element("query")
66
+ q.add_namespace("about:blank")
67
+ q.add_element("b").text = "I am b"
68
+ q.add_text("I am text")
69
+ q.add_element("a").add_attribute("href", "http://home.gna.org/xmpp4r/")
70
+ x.add_text("yow")
71
+ x.add_element("query")
72
+
73
+ assert_raise(RuntimeError) { iq = Iq.import(x) }
74
+ x.name = 'iq'
75
+ iq = Iq.import(x)
76
+
77
+ assert_equal(x.id, iq.id)
78
+ assert_equal(q.to_s, iq.query.to_s)
79
+ assert_equal(x.to_s, iq.to_s)
80
+ assert_equal(q.namespace, iq.queryns)
81
+ end
82
+
83
+ def test_import2
84
+ feature = FeatureNegotiation::IqFeature.new
85
+ xdata = feature.add(Dataforms::XData.new(:form))
86
+ field = xdata.add(Dataforms::XDataField.new('stream-method', :list_single))
87
+
88
+ feature2 = FeatureNegotiation::IqFeature.new.import(feature)
89
+ assert_equal(field.var, feature2.x.fields.first.var)
90
+ assert_equal(field.type, feature2.x.fields.first.type)
91
+ end
92
+
93
+ def test_error
94
+ x = MyXMPPStanza::new
95
+ assert_equal(nil, x.error)
96
+ x.typed_add(REXML::Element.new('error'))
97
+ assert_equal('<error/>', x.error.to_s)
98
+ assert_equal(Error, x.error.class)
99
+ end
100
+
101
+ def test_clone_and_dup
102
+ x = MyXMPPStanza::new
103
+ x.attributes['xyz'] = '123'
104
+ x.text = 'abc'
105
+
106
+ assert_equal(x.attributes['xyz'], '123')
107
+ assert_equal(x.text, 'abc')
108
+
109
+ x2 = x.clone
110
+ assert_kind_of(MyXMPPStanza, x2)
111
+ assert_equal('123', x2.attributes['xyz'])
112
+ assert_nil(x2.text)
113
+
114
+ x3 = x.dup
115
+ assert_kind_of(MyXMPPStanza, x3)
116
+ assert_equal('123', x3.attributes['xyz'])
117
+ assert_equal('abc', x3.text)
118
+ end
119
+
120
+ def test_raise
121
+ assert_raises(NoNameXmlnsRegistered) {
122
+ XMPPStanza.name_xmlns_for_class(MyStanza)
123
+ }
124
+ end
125
+ end
@@ -1,35 +1,44 @@
1
1
  #!/usr/bin/ruby -w
2
2
 
3
-
4
3
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
4
  $:.unshift File.join(File.dirname(__FILE__), '..', 'test')
6
5
  $:.unshift File.join(File.dirname(__FILE__), 'lib')
7
6
  $:.unshift File.join(File.dirname(__FILE__), 'test')
8
7
 
9
- require 'tc_streamThreaded'
10
- require 'bytestreams/tc_ibb'
11
- require 'bytestreams/tc_socks5bytestreams'
12
- require 'delay/tc_xdelay'
13
- require 'muc/tc_muc_simplemucclient'
14
- require 'muc/tc_muc_mucclient'
15
- require 'tc_error'
16
- require 'tc_stream'
17
- require 'tc_idgenerator'
18
- require 'tc_iqquery'
19
- #require 'tc_streamError'
20
- require 'tc_presence'
21
- require 'vcard/tc_iqvcard'
22
- require 'roster/tc_iqqueryroster'
23
- require 'roster/tc_xroster'
24
- #require 'roster/tc_helper'
25
- require 'version/tc_iqqueryversion'
26
- require 'version/tc_helper'
27
- require 'tc_streamSend'
28
- require 'tc_jid'
29
- require 'tc_iq'
30
- require 'tc_client'
31
- require 'tc_callbacks'
32
- require 'tc_xmlstanza'
33
- require 'tc_message'
34
- require 'tc_class_names'
35
- require 'tc_rexml'
8
+ # This is allowed here, to make sure it's enabled in all test.
9
+ Thread::abort_on_exception = true
10
+
11
+ require 'xmpp4r'
12
+ require 'find'
13
+
14
+ # List files' basenames, not full path!
15
+ # EXCLUDED_FILES = [ 'tc_muc_simplemucclient.rb' ]
16
+ EXCLUDED_FILES = []
17
+
18
+ tc_files = []
19
+ tc_subdirs = []
20
+ Find.find(File.dirname(__FILE__)) do |f|
21
+ if File::directory?(f)
22
+ if f == '.'
23
+ # do nothing
24
+ elsif File::basename(f) != '.svn'
25
+ tc_subdirs << f
26
+ Find.prune
27
+ end
28
+ elsif File::basename(f) =~ /^tc.*\.rb$/
29
+ tc_files << f
30
+ end
31
+ end
32
+
33
+ tc_subdirs.each do |dir|
34
+ Find.find(dir) do |f|
35
+ if File::file?(f) and File::basename(f) =~ /^tc.*\.rb$/
36
+ tc_files << f
37
+ end
38
+ end
39
+ end
40
+
41
+ tc_files.each do |f|
42
+ next if EXCLUDED_FILES.include?(File::basename(f))
43
+ require f
44
+ end
@@ -7,6 +7,7 @@ require File::dirname(__FILE__) + '/../lib/clienttester'
7
7
 
8
8
  require 'xmpp4r'
9
9
  require 'xmpp4r/version/helper/responder'
10
+ require 'xmpp4r/version/helper/simpleresponder'
10
11
  include Jabber
11
12
 
12
13
  class Version::HelperTest < Test::Unit::TestCase
@@ -43,4 +44,17 @@ class Version::HelperTest < Test::Unit::TestCase
43
44
  }
44
45
  assert_equal(1, calls)
45
46
  end
47
+
48
+ def test_simple
49
+ h = Version::SimpleResponder.new(@client, 'Test program', '1.0', 'Ruby Test::Unit')
50
+
51
+ # Send a query
52
+ @server.send("<iq type='get'><query xmlns='jabber:iq:version'/></iq>") { |reply|
53
+ assert_equal('Test program', reply.query.iname)
54
+ assert_equal('1.0', reply.query.version)
55
+ assert_equal('Ruby Test::Unit', reply.query.os)
56
+ true
57
+ }
58
+
59
+ end
46
60
  end