xmpp4r 0.3.2 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/{ChangeLog → CHANGELOG} +33 -0
  2. data/LICENSE +9 -9
  3. data/README.rdoc +110 -0
  4. data/README_ruby19.txt +43 -0
  5. data/Rakefile +235 -74
  6. data/data/doc/xmpp4r/examples/advanced/adventure/README +0 -1
  7. data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +1 -1
  8. data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +12 -12
  9. data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +10 -11
  10. data/data/doc/xmpp4r/examples/advanced/fileserve.rb +11 -11
  11. data/data/doc/xmpp4r/examples/advanced/getonline.rb +7 -7
  12. data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +3 -3
  13. data/data/doc/xmpp4r/examples/advanced/migrate.rb +21 -22
  14. data/data/doc/xmpp4r/examples/advanced/minimuc.rb +22 -22
  15. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/index.xsl +235 -0
  16. data/data/doc/xmpp4r/examples/advanced/pep-aggregator/pep-aggregator.rb +147 -0
  17. data/data/doc/xmpp4r/examples/advanced/recvfile.rb +0 -1
  18. data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +2 -3
  19. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +3 -3
  20. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +10 -10
  21. data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +2 -2
  22. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +12 -12
  23. data/data/doc/xmpp4r/examples/advanced/xmpping.rb +2 -3
  24. data/data/doc/xmpp4r/examples/basic/change_password.rb +3 -3
  25. data/data/doc/xmpp4r/examples/basic/client.rb +5 -3
  26. data/data/doc/xmpp4r/examples/basic/component.rb +1 -1
  27. data/data/doc/xmpp4r/examples/basic/{echo_threaded.rb → echo.rb} +8 -7
  28. data/data/doc/xmpp4r/examples/basic/jabbersend.rb +5 -5
  29. data/data/doc/xmpp4r/examples/basic/mass_sender.rb +11 -11
  30. data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +0 -1
  31. data/data/doc/xmpp4r/examples/basic/mucinfo.rb +3 -1
  32. data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +0 -1
  33. data/data/doc/xmpp4r/examples/basic/register.rb +21 -4
  34. data/data/doc/xmpp4r/examples/basic/roster.rb +7 -5
  35. data/data/doc/xmpp4r/examples/basic/rosterprint.rb +0 -0
  36. data/data/doc/xmpp4r/examples/basic/rosterrename.rb +2 -2
  37. data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +6 -7
  38. data/data/doc/xmpp4r/examples/basic/send_vcard.rb +3 -4
  39. data/data/doc/xmpp4r/examples/basic/tune_client.rb +56 -0
  40. data/data/doc/xmpp4r/examples/basic/tune_server.rb +58 -0
  41. data/data/doc/xmpp4r/examples/basic/versionbot.rb +1 -1
  42. data/lib/xmpp4r.rb +4 -4
  43. data/lib/xmpp4r/base64.rb +32 -0
  44. data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +10 -11
  45. data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +6 -8
  46. data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +3 -6
  47. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +0 -1
  48. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +8 -11
  49. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +4 -7
  50. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +7 -3
  51. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +10 -5
  52. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +14 -4
  53. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb.orig +62 -0
  54. data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +0 -1
  55. data/lib/xmpp4r/callbacks.rb +5 -5
  56. data/lib/xmpp4r/caps.rb +1 -0
  57. data/lib/xmpp4r/caps/c.rb +53 -0
  58. data/lib/xmpp4r/caps/helper/generator.rb +160 -0
  59. data/lib/xmpp4r/caps/helper/helper.rb +87 -0
  60. data/lib/xmpp4r/client.rb +111 -40
  61. data/lib/xmpp4r/command/iq/command.rb +1 -1
  62. data/lib/xmpp4r/component.rb +8 -8
  63. data/lib/xmpp4r/connection.rb +25 -9
  64. data/lib/xmpp4r/dataforms/x/data.rb +17 -5
  65. data/lib/xmpp4r/debuglog.rb +13 -5
  66. data/lib/xmpp4r/delay/x/delay.rb +1 -1
  67. data/lib/xmpp4r/discovery.rb +3 -2
  68. data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
  69. data/lib/xmpp4r/discovery/iq/discoinfo.rb +11 -12
  70. data/lib/xmpp4r/discovery/iq/discoitems.rb +12 -4
  71. data/lib/xmpp4r/{error.rb → errors.rb} +66 -10
  72. data/lib/xmpp4r/framework/base.rb +55 -0
  73. data/lib/xmpp4r/framework/bot.rb +148 -0
  74. data/lib/xmpp4r/httpbinding/client.rb +1 -1
  75. data/lib/xmpp4r/idgenerator.rb +1 -1
  76. data/lib/xmpp4r/iq.rb +34 -23
  77. data/lib/xmpp4r/jid.rb +2 -2
  78. data/lib/xmpp4r/message.rb +1 -1
  79. data/lib/xmpp4r/muc.rb +2 -0
  80. data/lib/xmpp4r/muc/helper/mucbrowser.rb +4 -19
  81. data/lib/xmpp4r/muc/helper/mucclient.rb +54 -23
  82. data/lib/xmpp4r/muc/helper/simplemucclient.rb +107 -1
  83. data/lib/xmpp4r/muc/iq/mucadmin.rb +23 -0
  84. data/lib/xmpp4r/muc/iq/mucadminitem.rb +20 -0
  85. data/lib/xmpp4r/muc/iq/mucowner.rb +5 -1
  86. data/lib/xmpp4r/muc/item.rb +143 -0
  87. data/lib/xmpp4r/muc/x/mucuserinvite.rb +2 -2
  88. data/lib/xmpp4r/muc/x/mucuseritem.rb +3 -117
  89. data/lib/xmpp4r/presence.rb +2 -1
  90. data/lib/xmpp4r/pubsub.rb +7 -0
  91. data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
  92. data/lib/xmpp4r/pubsub/{stanzas → children}/event.rb +13 -13
  93. data/lib/xmpp4r/pubsub/{stanzas → children}/item.rb +9 -1
  94. data/lib/xmpp4r/pubsub/{stanzas → children}/items.rb +10 -1
  95. data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
  96. data/lib/xmpp4r/pubsub/children/publish.rb +24 -0
  97. data/lib/xmpp4r/pubsub/{stanzas → children}/subscription.rb +16 -12
  98. data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
  99. data/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
  100. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +49 -93
  101. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +39 -36
  102. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +253 -162
  103. data/lib/xmpp4r/pubsub/iq/pubsub.rb +1 -1
  104. data/lib/xmpp4r/rexmladdons.rb +56 -28
  105. data/lib/xmpp4r/roster.rb +0 -1
  106. data/lib/xmpp4r/roster/helper/roster.rb +26 -15
  107. data/lib/xmpp4r/roster/iq/roster.rb +19 -19
  108. data/lib/xmpp4r/roster/x/roster.rb +10 -10
  109. data/lib/xmpp4r/rpc/helper/client.rb +17 -8
  110. data/lib/xmpp4r/rpc/helper/server.rb +1 -2
  111. data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +14 -4
  112. data/lib/xmpp4r/rpc/iq/rpc.rb +0 -1
  113. data/lib/xmpp4r/sasl.rb +27 -6
  114. data/lib/xmpp4r/stream.rb +39 -44
  115. data/lib/xmpp4r/streamparser.rb +4 -4
  116. data/lib/xmpp4r/tune.rb +2 -0
  117. data/lib/xmpp4r/tune/helper/helper.rb +58 -0
  118. data/lib/xmpp4r/tune/tune.rb +113 -0
  119. data/lib/xmpp4r/vcard.rb +0 -1
  120. data/lib/xmpp4r/vcard/helper/vcard.rb +1 -3
  121. data/lib/xmpp4r/vcard/iq/vcard.rb +14 -0
  122. data/lib/xmpp4r/version/iq/version.rb +0 -1
  123. data/lib/xmpp4r/x.rb +1 -1
  124. data/lib/xmpp4r/xhtml.rb +1 -0
  125. data/lib/xmpp4r/xhtml/html.rb +115 -0
  126. data/lib/xmpp4r/xmpp4r.rb +7 -5
  127. data/lib/xmpp4r/xmppelement.rb +21 -5
  128. data/lib/xmpp4r/xmppstanza.rb +6 -6
  129. data/setup.rb +4 -4
  130. data/test/bytestreams/tc_ibb.rb +2 -2
  131. data/test/bytestreams/tc_socks5bytestreams.rb +12 -2
  132. data/test/caps/tc_helper.rb +156 -0
  133. data/test/dataforms/tc_data.rb +0 -0
  134. data/test/delay/tc_xdelay.rb +2 -2
  135. data/test/discovery/tc_responder.rb +91 -0
  136. data/test/lib/assert_equal_xml.rb +14 -0
  137. data/test/lib/clienttester.rb +31 -24
  138. data/test/muc/tc_muc_mucclient.rb +249 -13
  139. data/test/muc/tc_muc_simplemucclient.rb +41 -2
  140. data/test/muc/tc_mucowner.rb +0 -0
  141. data/test/pubsub/tc_helper.rb +486 -51
  142. data/test/pubsub/tc_nodeconfig.rb +54 -0
  143. data/test/pubsub/tc_subscriptionconfig.rb +41 -0
  144. data/test/roster/tc_helper.rb +6 -7
  145. data/test/roster/tc_iqqueryroster.rb +16 -16
  146. data/test/roster/tc_xroster.rb +1 -1
  147. data/test/rpc/tc_helper.rb +15 -3
  148. data/test/tc_callbacks.rb +7 -7
  149. data/test/tc_class_names.rb +15 -6
  150. data/test/tc_client.rb +3 -3
  151. data/test/{tc_error.rb → tc_errors.rb} +54 -12
  152. data/test/tc_idgenerator.rb +0 -0
  153. data/test/tc_iq.rb +32 -29
  154. data/test/tc_iqquery.rb +2 -2
  155. data/test/tc_jid.rb +44 -42
  156. data/test/tc_message.rb +13 -12
  157. data/test/tc_presence.rb +25 -24
  158. data/test/tc_rexml.rb +81 -2
  159. data/test/tc_stream.rb +15 -13
  160. data/test/tc_streamComponent.rb +6 -5
  161. data/test/tc_streamError.rb +21 -15
  162. data/test/tc_streamSend.rb +9 -9
  163. data/test/tc_streamparser.rb +112 -0
  164. data/test/tc_xmppstanza.rb +19 -9
  165. data/test/ts_xmpp4r.rb +10 -1
  166. data/test/tune/tc_helper_recv.rb +84 -0
  167. data/test/tune/tc_helper_send.rb +74 -0
  168. data/test/tune/tc_tune.rb +79 -0
  169. data/test/vcard/tc_helper.rb +2 -2
  170. data/test/vcard/tc_iqvcard.rb +13 -3
  171. data/test/version/tc_helper.rb +2 -2
  172. data/test/version/tc_iqqueryversion.rb +10 -10
  173. data/test/xhtml/tc_html.rb +41 -0
  174. data/tools/gen_requires.bash +29 -8
  175. data/tools/xmpp4r-gemspec-test.rb +11 -0
  176. data/xmpp4r.gemspec +291 -0
  177. metadata +277 -218
  178. data/README +0 -28
  179. data/UPDATING +0 -40
  180. data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +0 -18
  181. data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +0 -192
  182. data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +0 -82
  183. data/lib/xmpp4r/authenticationfailure.rb +0 -13
  184. data/lib/xmpp4r/errorexception.rb +0 -32
  185. data/tools/doctoweb.bash +0 -30
@@ -22,9 +22,9 @@ if ARGV.length < 2
22
22
  end
23
23
 
24
24
  # Do the client stuff...
25
- myJID = JID::new(ARGV.shift)
25
+ myJID = JID.new(ARGV.shift)
26
26
  myPassword = ARGV.shift
27
- cl = Client::new(myJID)
27
+ cl = Client.new(myJID)
28
28
  cl.connect
29
29
  cl.auth(myPassword)
30
30
 
@@ -35,7 +35,7 @@ begin
35
35
  puts "Retrieving vCard information for #{cl.jid.strip}"
36
36
  vcard = vcard_helper.get
37
37
 
38
-
38
+
39
39
  # Inspect the command line for vCard fields to be changed
40
40
  ARGV.each { |arg|
41
41
  arg.scan(/^(.+?)=(.*)$/) { |field,text|
@@ -65,4 +65,3 @@ rescue Exception => e
65
65
  end
66
66
 
67
67
  cl.close
68
-
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift '../../../../../lib'
4
+
5
+ require 'xmpp4r'
6
+ require 'xmpp4r/roster'
7
+ require 'xmpp4r/discovery'
8
+ require 'xmpp4r/caps'
9
+ require 'xmpp4r/tune'
10
+
11
+
12
+ #
13
+ # Echo tunes received via XEP-0118 User Tune notifications
14
+ #
15
+ # See Jabber::UserTune::Helper for the gory details
16
+ #
17
+
18
+ if ARGV.length != 3
19
+ puts "Usage: ruby tune_client.rb <jid> <pw> <tune-playing-jid>"
20
+ exit 1
21
+ end
22
+
23
+ jid = ARGV[0]
24
+ pw = ARGV[1]
25
+ dj_jid = ARGV[2]
26
+
27
+ #Jabber::debug=true
28
+ cl = Jabber::Client.new(Jabber::JID.new(jid))
29
+ cl.connect
30
+ cl.auth(pw)
31
+
32
+ # PEP (XEP-0163 says we need:
33
+ # - a 'both' subscription to the dj
34
+ # - told the server that we support the '...tune+notify' feature
35
+ # before we can receive events
36
+ roster = Jabber::Roster::Helper.new(cl)
37
+ roster.add_subscription_request_callback(0, nil) do |item,pres|
38
+ roster.accept_subscription(pres.from)
39
+ end
40
+
41
+ caps = Jabber::Caps::Helper.new(cl,
42
+ [Jabber::Discovery::Identity.new('client', nil, 'pc')],
43
+ [Jabber::Discovery::Feature.new('http://jabber.org/protocol/tune+notify')]
44
+ )
45
+
46
+ t = Jabber::UserTune::Helper.new(cl, dj_jid)
47
+ t.add_usertune_callback do |tune|
48
+ puts "from:#{dj_jid} tune:#{tune.artist} plays #{tune.title}"
49
+ end
50
+
51
+ p = Jabber::Presence.new()
52
+ p.type = :subscribe
53
+ p.to = dj_jid
54
+ cl.send p
55
+
56
+ Thread.stop
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift '../../../../../lib'
4
+
5
+ require 'xmpp4r'
6
+ require 'xmpp4r/roster'
7
+ require 'xmpp4r/tune'
8
+ require 'rbosa'
9
+
10
+ #
11
+ # Send XEP-0118 User Tune events...
12
+ #
13
+ # See Jabber::UserTune::Helper for the gory details...
14
+ #
15
+ # NB needs rbosa library to access iTunes - only on MacOSX
16
+ #
17
+
18
+ if ARGV.length != 2:
19
+ puts "Usage: ruby tune_server.rb <jid> <pw>"
20
+ exit 1
21
+ end
22
+
23
+ jid=ARGV[0]
24
+ pw=ARGV[1]
25
+
26
+ Jabber::debug=true
27
+
28
+ cl = Jabber::Client.new(jid)
29
+ cl.connect
30
+ cl.auth(pw)
31
+
32
+ # Following XEP-0163 PEP we need to
33
+ # ensure we have a 'both' subscription to the Tune client
34
+ roster = Jabber::Roster::Helper.new(cl)
35
+ roster.add_subscription_request_callback do |item,pres|
36
+ roster.accept_subscription(pres.from)
37
+
38
+ reply = pres.answer
39
+ reply.type = :subscribe
40
+ cl.send(reply)
41
+ end
42
+
43
+ cl.send(Jabber::Presence.new.set_show(:chat))
44
+
45
+ t=Jabber::UserTune::Helper.new(cl, nil)
46
+
47
+ itunes=OSA.app('iTunes')
48
+
49
+ loop do
50
+ track = itunes.current_track
51
+
52
+ if track
53
+ puts "Now playing: #{track.name} by #{track.artist}"
54
+ t.now_playing(Jabber::UserTune::Tune.new(track.artist, track.name))
55
+ end
56
+
57
+ sleep 5
58
+ end
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  jid = Jabber::JID.new(ARGV[0])
25
25
 
26
- cl = Jabber::Client.new(jid, false)
26
+ cl = Jabber::Client.new(jid)
27
27
  cl.connect
28
28
  cl.auth(ARGV[1])
29
29
 
@@ -30,7 +30,7 @@
30
30
  #
31
31
  # This is not only useful for stanzas but all other XML processing, too:
32
32
  # * <tt><x/></tt> children elements of <tt><message/></tt> and <tt><presence/></tt> are converted to Jabber::X
33
- # * <tt><error/></tt> children elements of all three stanzas are converted to Jabber::Error
33
+ # * <tt><error/></tt> children elements of all three stanzas are converted to Jabber::ErrorResponse
34
34
  # * <tt><query/></tt> children elements of <tt><iq/></tt> are converted to Jabber::IqQuery
35
35
  # * <tt><vCard/></tt> children elements of <tt><iq/></tt> are converted to Jabber::IqVcard
36
36
  #
@@ -63,7 +63,7 @@
63
63
  #
64
64
  # Because it is built in an extensible way, it might be hard for newcomers to
65
65
  # understand where to look at documentation for a specific method. For example,
66
- # Client heritates from Connection, which itself heritates from Stream.
66
+ # Client inherits from Connection, which itself inherits from Stream.
67
67
  #
68
68
  # A newcomer should have a look at the <tt>Jabber::Client</tt> and
69
69
  # <tt>Jabber::Component</tt> classes, and their parent classes
@@ -73,7 +73,7 @@
73
73
  #
74
74
  # ==Non-basic features
75
75
  #
76
- # <tt>require 'xmpp4r'</tt> does only include basic functionality as
76
+ # <tt>require 'xmpp4r'</tt> only includes basic functionality for
77
77
  # Connections, Authentication, Stream processing, Callbacks, Stanza handling
78
78
  # and Debugging to keep the library's footprint small.
79
79
  #
@@ -100,7 +100,7 @@
100
100
  #
101
101
  # Helpers are intended to give more simplistic interfaces to various tasks
102
102
  # of Jabber clients at the cost of flexibility. But you won't need that
103
- # order of flexibility for the most things.
103
+ # level of flexibility in most cases.
104
104
  #
105
105
  # * Jabber::Roster::Helper: <tt>require 'xmpp4r/roster'</tt>
106
106
  # * Jabber::MUC::MUCBrowser, Jabber::MUC::MUCClient, Jabber::MUC::SimpleMUCClient: <tt>require 'xmpp4r/muc'</tt>
@@ -0,0 +1,32 @@
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
+ begin
6
+ require 'base64'
7
+ rescue LoadError
8
+ ##
9
+ # Ruby 1.9 has dropped the Base64 module,
10
+ # this is a replacement
11
+ #
12
+ # We could replace all call by Array#pack('m')
13
+ # and String#unpack('m'), but this module
14
+ # improves readability.
15
+ module Base64
16
+ ##
17
+ # Encode a String
18
+ # data:: [String] Binary
19
+ # result:: [String] Binary in Base64
20
+ def self.encode64(data)
21
+ [data].pack('m')
22
+ end
23
+
24
+ ##
25
+ # Decode a Base64-encoded String
26
+ # data64:: [String] Binary in Base64
27
+ # result:: [String] Binary
28
+ def self.decode64(data64)
29
+ data64.unpack('m').first
30
+ end
31
+ end
32
+ end
@@ -101,7 +101,7 @@ module Jabber
101
101
  length = @length - @bytes_read # Truncate it!
102
102
  end
103
103
  end
104
-
104
+
105
105
  buf = @file.read(length)
106
106
  @bytes_read += buf.size if buf
107
107
  buf
@@ -213,7 +213,7 @@ module Jabber
213
213
  else
214
214
  eanswer = iq.answer(false)
215
215
  eanswer.type = :error
216
- eanswer.add(Error.new('bad-request')).type = :cancel
216
+ eanswer.add(ErrorResponse.new('bad-request')).type = :cancel
217
217
  eanswer.error.add(REXML::Element.new('no-valid-streams')).add_namespace('http://jabber.org/protocol/si')
218
218
  @stream.send(eanswer)
219
219
 
@@ -228,7 +228,7 @@ module Jabber
228
228
  def decline(iq)
229
229
  answer = iq.answer(false)
230
230
  answer.type = :error
231
- error = answer.add(Error.new('forbidden', 'Offer declined'))
231
+ error = answer.add(ErrorResponse.new('forbidden', 'Offer declined'))
232
232
  error.type = :cancel
233
233
  @stream.send(answer)
234
234
  end
@@ -241,7 +241,7 @@ module Jabber
241
241
  # The result is a stream which you can configure, or nil
242
242
  # if the peer responded with an invalid stream-method.
243
243
  #
244
- # May raise an ErrorException
244
+ # May raise an ServerError
245
245
  # jid:: [JID] to send the file to
246
246
  # source:: File-transfer source, implementing the FileSource interface
247
247
  # desc:: [String] or [nil] Optional file description
@@ -259,7 +259,7 @@ module Jabber
259
259
  offered_methods[Bytestreams::IBB::NS_IBB] = nil
260
260
  end
261
261
 
262
- iq = Iq::new(:set, jid)
262
+ iq = Iq.new(:set, jid)
263
263
  iq.from = from
264
264
  si = iq.add(Bytestreams::IqSi.new(session_id, Bytestreams::PROFILE_FILETRANSFER, source.mime))
265
265
 
@@ -278,10 +278,10 @@ module Jabber
278
278
  begin
279
279
  stream_method = nil
280
280
  response = nil
281
- @stream.send_with_id(iq) { |r|
281
+ @stream.send_with_id(iq) do |r|
282
282
  response = r
283
283
  si = response.first_element('si')
284
- if response.type == :result and si and si.feature and si.feature.x
284
+ if si and si.feature and si.feature.x
285
285
  stream_method = si.feature.x.field('stream-method').values.first
286
286
 
287
287
  if si.file and si.file.range
@@ -293,9 +293,8 @@ module Jabber
293
293
  end
294
294
  end
295
295
  end
296
- true
297
- }
298
- rescue ErrorException => e
296
+ end
297
+ rescue ServerError => e
299
298
  if e.error.code == 403 # Declined
300
299
  return false
301
300
  else
@@ -310,7 +309,7 @@ module Jabber
310
309
  else # Target responded with a stream_method we didn't offer
311
310
  eanswer = response.answer
312
311
  eanswer.type = :error
313
- eanswer.add Error::new('bad-request')
312
+ eanswer.add ErrorResponse.new('bad-request')
314
313
  @stream.send(eanswer)
315
314
  nil
316
315
  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 'base64'
5
+ require 'xmpp4r/base64'
6
6
 
7
7
  module Jabber
8
8
  module Bytestreams
@@ -124,7 +124,7 @@ module Jabber
124
124
  # Close the stream
125
125
  #
126
126
  # Waits for acknowledge from peer,
127
- # may throw ErrorException
127
+ # may throw ServerError
128
128
  def close
129
129
  if active?
130
130
  flush
@@ -135,9 +135,7 @@ module Jabber
135
135
  close.add_namespace IBB::NS_IBB
136
136
  close.attributes['sid'] = @session_id
137
137
 
138
- @stream.send_with_id(iq) { |answer|
139
- answer.type == :result
140
- }
138
+ @stream.send_with_id(iq)
141
139
  end
142
140
  end
143
141
 
@@ -151,12 +149,12 @@ module Jabber
151
149
  msg = Message.new
152
150
  msg.from = @my_jid
153
151
  msg.to = @peer_jid
154
-
152
+
155
153
  data = msg.add REXML::Element.new('data')
156
154
  data.add_namespace NS_IBB
157
155
  data.attributes['sid'] = @session_id
158
156
  data.attributes['seq'] = @seq_send.to_s
159
- data.text = Base64::encode64 databuf
157
+ data.text = Base64::encode64(databuf)
160
158
 
161
159
  # TODO: Implement AMP correctly
162
160
  amp = msg.add REXML::Element.new('amp')
@@ -169,7 +167,7 @@ module Jabber
169
167
  match_resource.attributes['condition'] = 'match-resource'
170
168
  match_resource.attributes['value'] = 'exact'
171
169
  match_resource.attributes['action'] = 'error'
172
-
170
+
173
171
  @stream.send(msg)
174
172
 
175
173
  @seq_send += 1
@@ -14,21 +14,18 @@ module Jabber
14
14
  # Open the stream to the peer,
15
15
  # waits for successful result
16
16
  #
17
- # May throw ErrorException
17
+ # May throw ServerError
18
18
  def open
19
19
  iq = Iq.new(:set, @peer_jid)
20
20
  open = iq.add REXML::Element.new('open')
21
21
  open.add_namespace IBB::NS_IBB
22
22
  open.attributes['sid'] = @session_id
23
- open.attributes['block-size'] = @block_size
23
+ open.attributes['block-size'] = @block_size.to_s
24
24
 
25
- @stream.send_with_id(iq) { |answer|
26
- answer.type == :result
27
- }
25
+ @stream.send_with_id(iq)
28
26
 
29
27
  activate
30
28
  end
31
29
  end
32
30
  end
33
31
  end
34
-
@@ -45,4 +45,3 @@ module Jabber
45
45
  end
46
46
  end
47
47
  end
48
-
@@ -26,7 +26,7 @@ module Jabber
26
26
  #
27
27
  # default: nil, use the OS' default timeout
28
28
  attr_accessor :connect_timeout
29
-
29
+
30
30
  def initialize(stream, session_id, initiator_jid, target_jid)
31
31
  @stream = stream
32
32
  @session_id = session_id
@@ -95,19 +95,16 @@ module Jabber
95
95
  def self.query_streamhost(stream, streamhost, my_jid=nil)
96
96
  res = nil
97
97
 
98
- iq = Iq::new(:get, streamhost)
98
+ iq = Iq.new(:get, streamhost)
99
99
  iq.from = my_jid
100
100
  iq.add(IqQueryBytestreams.new)
101
101
  stream.send_with_id(iq) { |reply|
102
- if reply.type == :result
103
- reply.query.each_element { |e|
104
- if e.kind_of?(StreamHost)
105
- e.jid = reply.from # Help misconfigured proxys
106
- res = e
107
- end
108
- }
109
- end
110
- true
102
+ reply.query.each_element { |e|
103
+ if e.kind_of?(StreamHost)
104
+ e.jid = reply.from # Help misconfigured proxys
105
+ res = e
106
+ end
107
+ }
111
108
  }
112
109
 
113
110
  if res and res.jid and res.host and res.port
@@ -40,7 +40,7 @@ module Jabber
40
40
  # wait for an answer and
41
41
  # connect to the host the target chose.
42
42
  def open
43
- iq1 = Iq::new(:set, @target_jid)
43
+ iq1 = Iq.new(:set, @target_jid)
44
44
  iq1.from = @initiator_jid
45
45
  bs = iq1.add IqQueryBytestreams.new(@session_id)
46
46
  @streamhosts.each { |se|
@@ -49,12 +49,11 @@ module Jabber
49
49
 
50
50
  peer_used = nil
51
51
  @stream.send_with_id(iq1) { |response|
52
- if response.type == :result and response.query.kind_of?(IqQueryBytestreams)
52
+ if response.query.kind_of?(IqQueryBytestreams)
53
53
  peer_used = response.query.streamhost_used
54
54
  raise "No streamhost-used" unless peer_used
55
55
  raise "Invalid streamhost-used" unless peer_used.jid
56
56
  end
57
- true
58
57
  }
59
58
 
60
59
  @streamhost_used = nil
@@ -77,11 +76,9 @@ module Jabber
77
76
  @streamhost_cbs.process(@streamhost_used, :failure, e)
78
77
  raise e
79
78
  end
80
- iq2 = Iq::new(:set, @streamhost_used.jid)
79
+ iq2 = Iq.new(:set, @streamhost_used.jid)
81
80
  iq2.add(IqQueryBytestreams.new(@session_id)).activate = @target_jid.to_s
82
- @stream.send_with_id(iq2) { |reply|
83
- reply.type == :result
84
- }
81
+ @stream.send_with_id(iq2)
85
82
  end
86
83
  end
87
84
  end