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
@@ -33,6 +33,14 @@ module Jabber
33
33
  @create = XMLRPC::Create.new
34
34
  end
35
35
 
36
+ ##
37
+ # automatically trys to find a method
38
+ # thanx to eric cestari :)
39
+ def method_missing(methodname, *args)
40
+ send("call", methodname,*args)
41
+ end
42
+
43
+
36
44
  def call(method, *args)
37
45
  ok, param = call2(method, *args)
38
46
  if ok
@@ -75,14 +83,11 @@ module Jabber
75
83
  rpcquery.typed_add(xmlrpc)
76
84
 
77
85
  result = nil
78
- @stream.send_with_id(iq) { |iqreply|
79
- if iqreply.type == :result and iqreply.query.kind_of?(IqQueryRPC)
86
+ @stream.send_with_id(iq) do |iqreply|
87
+ if iqreply.query.kind_of?(IqQueryRPC)
80
88
  result = iqreply.query.to_s
81
- true
82
- else
83
- false
84
89
  end
85
- }
90
+ end
86
91
 
87
92
  result
88
93
  end
@@ -91,7 +96,12 @@ module Jabber
91
96
 
92
97
  def gen_multicall(methods=[])
93
98
  ok, params = call2("system.multicall",
94
- methods.collect { |m| {'methodName' => m[0], 'params' => m[1..-1]} }
99
+ methods.collect { |m|
100
+ {
101
+ 'methodName' => m[0],
102
+ 'params' => m[1..-1]
103
+ }
104
+ }
95
105
  )
96
106
 
97
107
  if ok
@@ -111,4 +121,3 @@ module Jabber
111
121
  end
112
122
  end # Helpers
113
123
  end # Jabber
114
-
@@ -64,7 +64,7 @@ module Jabber
64
64
  def handle_rpc_requests(rpcdata)
65
65
  resp = process(rpcdata.to_s)
66
66
  if resp == nil or resp.size <= 0
67
- raise Jabber::Error.new(:forbidden)
67
+ raise Jabber::ErrorResponse.new(:forbidden)
68
68
  else
69
69
  return resp
70
70
  end
@@ -72,4 +72,3 @@ module Jabber
72
72
  end # RPCServer
73
73
  end # Helpers
74
74
  end # Jabber
75
-
@@ -6,6 +6,11 @@ require "xmlrpc/utils" # ParserWriterChooseMixin
6
6
 
7
7
  module XMLRPC
8
8
  class Create
9
+
10
+ # Avoids warnings
11
+ remove_method(:methodCall)
12
+ remove_method(:methodResponse)
13
+
9
14
  ##
10
15
  # create a Method Call
11
16
  # name:: [String] name of the method
@@ -38,11 +43,16 @@ module XMLRPC
38
43
  def methodResponse(is_ret, *params)
39
44
 
40
45
  if is_ret
41
- resp = params.collect do |param|
42
- @writer.ele("param", conv2value(param))
43
- end
46
+ begin
47
+ resp = params.collect do |param|
48
+ @writer.ele("param", conv2value(param))
49
+ end
44
50
 
45
- resp = [@writer.ele("params", *resp)]
51
+ resp = [@writer.ele("params", *resp)]
52
+ rescue Exception => e
53
+ error = XMLRPC::FaultException.new(XMLRPC::BasicServer::ERR_UNCAUGHT_EXCEPTION, "Uncaught exception '#{e.message}' serialising params into response")
54
+ resp = @writer.ele("fault", conv2value(error.to_h))
55
+ end
46
56
  else
47
57
  if params.size != 1 or params[0] === XMLRPC::FaultException
48
58
  raise ArgumentError, "no valid fault-structure given"
@@ -21,4 +21,3 @@ module Jabber
21
21
  end
22
22
  end
23
23
  end
24
-
@@ -2,8 +2,8 @@
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'
6
5
  require 'digest/md5'
6
+ require 'xmpp4r/base64'
7
7
 
8
8
  module Jabber
9
9
  ##
@@ -16,12 +16,14 @@ module Jabber
16
16
 
17
17
  ##
18
18
  # Factory function to obtain a SASL helper for the specified mechanism
19
- def SASL::new(stream, mechanism)
19
+ def SASL.new(stream, mechanism)
20
20
  case mechanism
21
21
  when 'DIGEST-MD5'
22
22
  DigestMD5.new(stream)
23
23
  when 'PLAIN'
24
24
  Plain.new(stream)
25
+ when 'ANONYMOUS'
26
+ Anonymous.new(stream)
25
27
  else
26
28
  raise "Unknown SASL mechanism: #{mechanism}"
27
29
  end
@@ -63,7 +65,26 @@ module Jabber
63
65
  end
64
66
  true
65
67
  }
66
-
68
+
69
+ raise error if error
70
+ end
71
+ end
72
+
73
+ ##
74
+ # SASL Anonymous authentication helper
75
+ class Anonymous < Base
76
+ ##
77
+ # Authenticate by sending nothing with the ANONYMOUS token
78
+ def auth(password)
79
+ auth_text = "#{@stream.jid.node}"
80
+ error = nil
81
+ @stream.send(generate_auth('ANONYMOUS', Base64::encode64(auth_text).gsub(/\s/, ''))) { |reply|
82
+ if reply.name != 'success'
83
+ error = reply.first_element(nil).name
84
+ end
85
+ true
86
+ }
87
+
67
88
  raise error if error
68
89
  end
69
90
  end
@@ -175,7 +196,7 @@ module Jabber
175
196
  end
176
197
  true
177
198
  }
178
-
199
+
179
200
  return if success_already
180
201
  raise error if error
181
202
 
@@ -188,7 +209,7 @@ module Jabber
188
209
  end
189
210
  true
190
211
  }
191
-
212
+
192
213
  raise error if error
193
214
  end
194
215
 
@@ -200,7 +221,7 @@ module Jabber
200
221
  ##
201
222
  # Function from RFC2831
202
223
  def hh(s); Digest::MD5.hexdigest(s); end
203
-
224
+
204
225
  ##
205
226
  # Calculate the value for the response field
206
227
  def response_value(username, realm, digest_uri, passwd, nonce, cnonce, qop)
@@ -10,7 +10,6 @@ require 'xmpp4r/streamparser'
10
10
  require 'xmpp4r/presence'
11
11
  require 'xmpp4r/message'
12
12
  require 'xmpp4r/iq'
13
- require 'xmpp4r/errorexception'
14
13
  require 'xmpp4r/debuglog'
15
14
  require 'xmpp4r/idgenerator'
16
15
 
@@ -37,19 +36,15 @@ module Jabber
37
36
  attr_reader :status
38
37
 
39
38
  ##
40
- # Create a new stream
41
- # (just initializes)
42
- def initialize(threaded = true)
43
- unless threaded
44
- raise "Non-threaded mode was removed from XMPP4R."
45
- end
39
+ # Initialize a new stream
40
+ def initialize
46
41
  @fd = nil
47
42
  @status = DISCONNECTED
48
- @xmlcbs = CallbackList::new
49
- @stanzacbs = CallbackList::new
50
- @messagecbs = CallbackList::new
51
- @iqcbs = CallbackList::new
52
- @presencecbs = CallbackList::new
43
+ @xmlcbs = CallbackList.new
44
+ @stanzacbs = CallbackList.new
45
+ @messagecbs = CallbackList.new
46
+ @iqcbs = CallbackList.new
47
+ @presencecbs = CallbackList.new
53
48
  @send_lock = Mutex.new
54
49
  @last_send = Time.now
55
50
  @exception_block = nil
@@ -90,10 +85,7 @@ module Jabber
90
85
  @exception_block.call(e, self, :start)
91
86
  end
92
87
  else
93
- if Jabber::debug
94
- puts "Exception caught in Parser thread! (#{e.class})"
95
- puts e.backtrace
96
- end
88
+ Jabber::debuglog "Exception caught in Parser thread! (#{e.class})\n#{e.backtrace.join("\n")}"
97
89
  close!
98
90
  raise
99
91
  end
@@ -109,7 +101,7 @@ module Jabber
109
101
  end
110
102
 
111
103
  ##
112
- # Mounts a block to handle exceptions if they occur during the
104
+ # Mounts a block to handle exceptions if they occur during the
113
105
  # poll send. This will likely be the first indication that
114
106
  # the socket dropped in a Jabber Session.
115
107
  #
@@ -136,9 +128,8 @@ module Jabber
136
128
  @exception_block.call(e, self, :parser)
137
129
  end
138
130
  else
139
- puts "Stream#parse_failure was called by XML parser. Dumping " +
140
- "backtrace...\n" + e.exception + "\n"
141
- puts e.backtrace
131
+ Jabber::debuglog "Stream#parse_failure was called by XML parser. Dumping " +
132
+ "backtrace...\n" + e.exception + "\n#{e.backtrace.join("\n")}"
142
133
  close
143
134
  raise
144
135
  end
@@ -174,7 +165,7 @@ module Jabber
174
165
  end
175
166
 
176
167
  ##
177
- # Processes a received REXML::Element and executes
168
+ # Processes a received REXML::Element and executes
178
169
  # registered thread blocks and filters against it.
179
170
  #
180
171
  # element:: [REXML::Element] The received element
@@ -201,7 +192,7 @@ module Jabber
201
192
 
202
193
  unless element.attributes['version'] # isn't XMPP compliant, so
203
194
  Jabber::debuglog("FEATURES: server not XMPP compliant, will not wait for features")
204
- @features_sem.run # don't wait for <stream:features/>
195
+ @features_sem.run # don't wait for <stream:features/>
205
196
  end
206
197
  when 'features'
207
198
  stanza = element
@@ -335,10 +326,7 @@ module Jabber
335
326
  @exception_block.call(e, self, :sending)
336
327
  end
337
328
  else
338
- if Jabber::debug
339
- puts "Exception caught while sending! (#{e.class})"
340
- puts e.backtrace
341
- end
329
+ Jabber::debuglog "Exception caught while sending! (#{e.class})\n#{e.backtrace.join("\n")}"
342
330
  close!
343
331
  raise
344
332
  end
@@ -359,10 +347,14 @@ module Jabber
359
347
  # The block will be called once: when receiving a stanza with the
360
348
  # same Jabber::XMPPStanza#id. There is no need to return true to
361
349
  # complete this! Instead the return value of the block will be
362
- # returned.
350
+ # returned. This is a direct result of unique request/response
351
+ # stanza identification via the id attribute.
352
+ #
353
+ # The block may be omitted. Then, the result will be the response
354
+ # stanza.
363
355
  #
364
356
  # Be aware that if a stanza with <tt>type='error'</tt> is received
365
- # the function does not yield but raises an ErrorException with
357
+ # the function does not yield but raises an ServerError with
366
358
  # the corresponding error element.
367
359
  #
368
360
  # Please see Stream#send for some implementational details.
@@ -379,11 +371,14 @@ module Jabber
379
371
  send(xml) do |received|
380
372
  if received.kind_of? XMPPStanza and received.id == xml.id
381
373
  if received.type == :error
382
- error = (received.error ? received.error : Error.new)
374
+ error = (received.error ? received.error : ErrorResponse.new)
383
375
  true
384
- else
376
+ elsif block_given?
385
377
  res = yield(received)
386
378
  true
379
+ else
380
+ res = received
381
+ true
387
382
  end
388
383
  else
389
384
  false
@@ -391,7 +386,7 @@ module Jabber
391
386
  end
392
387
 
393
388
  unless error.nil?
394
- raise ErrorException.new(error)
389
+ raise ServerError.new(error)
395
390
  end
396
391
 
397
392
  res
@@ -399,9 +394,9 @@ module Jabber
399
394
 
400
395
  ##
401
396
  # Adds a callback block to process received XML messages
402
- #
397
+ #
403
398
  # priority:: [Integer] The callback's priority, the higher, the sooner
404
- # ref:: [String] The callback's reference
399
+ # ref:: [String] The callback's reference
405
400
  # &block:: [Block] The optional block
406
401
  def add_xml_callback(priority = 0, ref = nil, &block)
407
402
  @xmlcbs.add(priority, ref, block)
@@ -417,9 +412,9 @@ module Jabber
417
412
 
418
413
  ##
419
414
  # Adds a callback block to process received Messages
420
- #
415
+ #
421
416
  # priority:: [Integer] The callback's priority, the higher, the sooner
422
- # ref:: [String] The callback's reference
417
+ # ref:: [String] The callback's reference
423
418
  # &block:: [Block] The optional block
424
419
  def add_message_callback(priority = 0, ref = nil, &block)
425
420
  @messagecbs.add(priority, ref, block)
@@ -435,9 +430,9 @@ module Jabber
435
430
 
436
431
  ##
437
432
  # Adds a callback block to process received Stanzas
438
- #
433
+ #
439
434
  # priority:: [Integer] The callback's priority, the higher, the sooner
440
- # ref:: [String] The callback's reference
435
+ # ref:: [String] The callback's reference
441
436
  # &block:: [Block] The optional block
442
437
  def add_stanza_callback(priority = 0, ref = nil, &block)
443
438
  @stanzacbs.add(priority, ref, block)
@@ -450,12 +445,12 @@ module Jabber
450
445
  def delete_stanza_callback(ref)
451
446
  @stanzacbs.delete(ref)
452
447
  end
453
-
448
+
454
449
  ##
455
- # Adds a callback block to process received Presences
456
- #
450
+ # Adds a callback block to process received Presences
451
+ #
457
452
  # priority:: [Integer] The callback's priority, the higher, the sooner
458
- # ref:: [String] The callback's reference
453
+ # ref:: [String] The callback's reference
459
454
  # &block:: [Block] The optional block
460
455
  def add_presence_callback(priority = 0, ref = nil, &block)
461
456
  @presencecbs.add(priority, ref, block)
@@ -468,12 +463,12 @@ module Jabber
468
463
  def delete_presence_callback(ref)
469
464
  @presencecbs.delete(ref)
470
465
  end
471
-
466
+
472
467
  ##
473
468
  # Adds a callback block to process received Iqs
474
- #
469
+ #
475
470
  # priority:: [Integer] The callback's priority, the higher, the sooner
476
- # ref:: [String] The callback's reference
471
+ # ref:: [String] The callback's reference
477
472
  # &block:: [Block] The optional block
478
473
  def add_iq_callback(priority = 0, ref = nil, &block)
479
474
  @iqcbs.add(priority, ref, block)
@@ -36,10 +36,10 @@ module Jabber
36
36
  def parse
37
37
  @started = false
38
38
  begin
39
- parser = REXML::Parsers::SAX2Parser.new @stream
39
+ parser = REXML::Parsers::SAX2Parser.new @stream
40
40
 
41
41
  parser.listen( :start_element ) do |uri, localname, qname, attributes|
42
- e = REXML::Element::new(qname)
42
+ e = REXML::Element.new(qname)
43
43
  e.add_attributes attributes
44
44
  @current = @current.nil? ? e : @current.add_element(e)
45
45
 
@@ -61,11 +61,11 @@ module Jabber
61
61
  end
62
62
 
63
63
  parser.listen( :characters ) do | text |
64
- @current.text = @current.text.to_s + text if @current
64
+ @current.add(REXML::Text.new(text.to_s, @current.whitespace, nil, true)) if @current
65
65
  end
66
66
 
67
67
  parser.listen( :cdata ) do | text |
68
- raise "Not implemented !"
68
+ @current.add(REXML::CData.new(text)) if @current
69
69
  end
70
70
 
71
71
  parser.parse
@@ -0,0 +1,2 @@
1
+ require 'xmpp4r/tune/tune'
2
+ require 'xmpp4r/tune/helper/helper'
@@ -0,0 +1,58 @@
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'
6
+ require 'xmpp4r/pubsub'
7
+ require 'xmpp4r/tune/tune'
8
+
9
+ module Jabber
10
+ module UserTune
11
+ ##
12
+ # A Helper for XEP-0118 User Tune
13
+ #
14
+ # Use this helper to send user tunes, or receive them from a
15
+ # specified jid. Described at http://www.xmpp.org/extensions/xep-0118.html
16
+ #
17
+ # For example:
18
+ # <pre>
19
+ # h = UserTune::Helper( @client, 'radio1@hug.hellomatty.com' )
20
+ # h.add_usertune_callback do |tune|
21
+ # puts "Now playing: #{tune.title} by #{tune.artist}"
22
+ # end
23
+ # </pre>
24
+ #
25
+ # Also see the examples provided.
26
+ class Helper < PubSub::ServiceHelper
27
+ ##
28
+ # Send out the tune currently playing.
29
+ #
30
+ # track:: [Jabber::UserTune::Tune] the tune currently playing
31
+ def now_playing(track)
32
+ item = Jabber::PubSub::Item.new()
33
+ item.add(track)
34
+
35
+ publish_item_to(NS_USERTUNE, item)
36
+ end
37
+
38
+ ##
39
+ # Use this method to indicate that you have stopped playing
40
+ # a tune.
41
+ def stop_playing
42
+ now_playing(Jabber::UserTune::Tune.new())
43
+ end
44
+
45
+ ##
46
+ # Add a callback that will be invoked when a tune is received
47
+ # from the jid specified when you constructed the Helper.
48
+ def add_usertune_callback(prio = 200, ref = nil, &block)
49
+ add_event_callback(prio, ref) do |event|
50
+ tune = event.first_element('items/item/tune')
51
+ if tune
52
+ block.call(tune)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end