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
@@ -3,9 +3,7 @@
3
3
  # Website::http://home.gna.org/xmpp4r/
4
4
 
5
5
  require 'resolv'
6
-
7
6
  require 'xmpp4r/connection'
8
- require 'xmpp4r/authenticationfailure'
9
7
  require 'xmpp4r/sasl'
10
8
 
11
9
  module Jabber
@@ -26,8 +24,8 @@ module Jabber
26
24
  # Create a new Client.
27
25
  #
28
26
  # Remember to *always* put a resource in your JID unless the server can do SASL.
29
- def initialize(jid, threaded = true)
30
- super(threaded)
27
+ def initialize(jid)
28
+ super()
31
29
  @jid = (jid.kind_of?(JID) ? jid : JID.new(jid.to_s))
32
30
  end
33
31
 
@@ -39,6 +37,7 @@ module Jabber
39
37
  # be resolved. If none works, fallback is connecting to the domain part
40
38
  # of the jid.
41
39
  # host:: [String] Optional c2s host, will be extracted from jid if nil
40
+ # use_ssl:: [Boolean] Optional. Use (old, deprecated) SSL when connecting.
42
41
  # return:: self
43
42
  def connect(host = nil, port = 5222)
44
43
  if host.nil?
@@ -46,7 +45,7 @@ module Jabber
46
45
  srv = []
47
46
  Resolv::DNS.open { |dns|
48
47
  # If ruby version is too old and SRV is unknown, this will raise a NameError
49
- # which is catched below
48
+ # which is caught below
50
49
  Jabber::debuglog("RESOLVING:\n_xmpp-client._tcp.#{@jid.domain} (SRV)")
51
50
  srv = dns.getresources("_xmpp-client._tcp.#{@jid.domain}", Resolv::DNS::Resource::IN::SRV)
52
51
  }
@@ -58,16 +57,16 @@ module Jabber
58
57
  connect(record.target.to_s, record.port)
59
58
  # Success
60
59
  return self
61
- rescue SocketError
60
+ rescue SocketError, Errno::ECONNREFUSED
62
61
  # Try next SRV record
63
62
  end
64
63
  }
65
64
  rescue NameError
66
- $stderr.puts "Resolv::DNS does not support SRV records. Please upgrade to ruby-1.8.3 or later!"
65
+ Jabber::debuglog "Resolv::DNS does not support SRV records. Please upgrade to ruby-1.8.3 or later!"
67
66
  end
68
67
  # Fallback to normal connect method
69
68
  end
70
-
69
+
71
70
  super(host.nil? ? jid.domain : host, port)
72
71
  self
73
72
  end
@@ -96,7 +95,7 @@ module Jabber
96
95
  ##
97
96
  # Authenticate with the server
98
97
  #
99
- # Throws AuthenticationFailure
98
+ # Throws ClientAuthenticationFailure
100
99
  #
101
100
  # Authentication mechanisms are used in the following preference:
102
101
  # * SASL DIGEST-MD5
@@ -114,7 +113,7 @@ module Jabber
114
113
  end
115
114
  rescue
116
115
  Jabber::debuglog("#{$!.class}: #{$!}\n#{$!.backtrace.join("\n")}")
117
- raise AuthenticationFailure.new, $!.to_s
116
+ raise ClientAuthenticationFailure.new, $!.to_s
118
117
  end
119
118
  end
120
119
 
@@ -147,14 +146,12 @@ module Jabber
147
146
  resource.text = jid.resource
148
147
  end
149
148
 
150
- send_with_id(iq) { |reply|
149
+ send_with_id(iq) do |reply|
151
150
  reported_jid = reply.first_element('jid')
152
- if reply.type == :result and reported_jid and reported_jid.text
151
+ if reported_jid and reported_jid.text
153
152
  @jid = JID.new(reported_jid.text)
154
153
  end
155
-
156
- true
157
- }
154
+ end
158
155
  end
159
156
 
160
157
  # Session starting
@@ -163,44 +160,127 @@ module Jabber
163
160
  session = iq.add REXML::Element.new('session')
164
161
  session.add_namespace @stream_features['session']
165
162
 
166
- send_with_id(iq) { true }
163
+ send_with_id(iq)
164
+ end
165
+ end
166
+
167
+ ##
168
+ # See Client#auth_anonymous_sasl
169
+ def auth_anonymous
170
+ auth_anonymous_sasl
171
+ end
172
+
173
+
174
+ ##
175
+ # Shortcut for anonymous connection to server
176
+ #
177
+ # Throws ClientAuthenticationFailure
178
+ def auth_anonymous_sasl
179
+ if self.supports_anonymous?
180
+ begin
181
+ auth_sasl SASL.new(self, 'ANONYMOUS'), ""
182
+ rescue
183
+ Jabber::debuglog("#{$!.class}: #{$!}\n#{$!.backtrace.join("\n")}")
184
+ raise ClientAuthenticationFailure, $!.to_s
185
+ end
186
+ else
187
+ raise ClientAuthenticationFailure, 'Anonymous authentication unsupported'
167
188
  end
168
189
  end
169
190
 
191
+ ##
192
+ # Reports whether or not anonymous authentication is reported
193
+ # by the client.
194
+ #
195
+ # Returns true or false
196
+ def supports_anonymous?
197
+ @stream_mechanisms.include? 'ANONYMOUS'
198
+ end
199
+
170
200
  ##
171
201
  # Send auth with given password and wait for result
172
202
  # (non-SASL)
173
203
  #
174
- # Throws ErrorException
204
+ # Throws ServerError
175
205
  # password:: [String] the password
176
206
  # digest:: [Boolean] use Digest authentication
177
207
  def auth_nonsasl(password, digest=true)
178
208
  authset = nil
179
209
  if digest
180
- authset = Iq::new_authset_digest(@jid, @streamid.to_s, password)
210
+ authset = Iq.new_authset_digest(@jid, @streamid.to_s, password)
181
211
  else
182
- authset = Iq::new_authset(@jid, password)
183
- end
184
- send_with_id(authset) do |r|
185
- true
212
+ authset = Iq.new_authset(@jid, password)
186
213
  end
214
+ send_with_id(authset)
187
215
  $defout.flush
188
216
 
189
217
  true
190
218
  end
191
219
 
220
+ ##
221
+ # Get instructions and available fields for registration
222
+ # return:: [instructions, fields] Where instructions is a String and fields is an Array of Strings
223
+ def register_info
224
+ instructions = nil
225
+ fields = []
226
+
227
+ reg = Iq.new_registerget
228
+ reg.to = jid.domain
229
+ send_with_id(reg) do |answer|
230
+ if answer.query
231
+ answer.query.each_element { |e|
232
+ if e.namespace == 'jabber:iq:register'
233
+ if e.name == 'instructions'
234
+ instructions = e.text.strip
235
+ else
236
+ fields << e.name
237
+ end
238
+ end
239
+ }
240
+ end
241
+
242
+ true
243
+ end
244
+
245
+ [instructions, fields]
246
+ end
247
+
192
248
  ##
193
249
  # Register a new user account
194
250
  # (may be used instead of Client#auth)
195
251
  #
196
- # This method may raise ErrorException if the registration was
252
+ # This method may raise ServerError if the registration was
197
253
  # not successful.
198
- def register(password)
254
+ #
255
+ # password:: String
256
+ # fields:: {String=>String} additional registration information
257
+ #
258
+ # XEP-0077 Defines the following fields for registration information:
259
+ # http://www.xmpp.org/extensions/xep-0077.html
260
+ #
261
+ # 'username' => 'Account name associated with the user'
262
+ # 'nick' => 'Familiar name of the user'
263
+ # 'password' => 'Password or secret for the user'
264
+ # 'name' => 'Full name of the user'
265
+ # 'first' => 'First name or given name of the user'
266
+ # 'last' => 'Last name, surname, or family name of the user'
267
+ # 'email' => 'Email address of the user'
268
+ # 'address' => 'Street portion of a physical or mailing address'
269
+ # 'city' => 'Locality portion of a physical or mailing address'
270
+ # 'state' => 'Region portion of a physical or mailing address'
271
+ # 'zip' => 'Postal code portion of a physical or mailing address'
272
+ # 'phone' => 'Telephone number of the user'
273
+ # 'url' => 'URL to web page describing the user'
274
+ # 'date' => 'Some date (e.g., birth date, hire date, sign-up date)'
275
+ #
276
+ def register(password, fields={})
199
277
  reg = Iq.new_register(jid.node, password)
200
278
  reg.to = jid.domain
201
- send_with_id(reg) { |answer|
202
- true
279
+ fields.each { |name,value|
280
+ reg.query.add(REXML::Element.new(name)).text = value
203
281
  }
282
+
283
+ send_with_id(reg)
204
284
  end
205
285
 
206
286
  ##
@@ -212,10 +292,7 @@ module Jabber
212
292
  reg = Iq.new_register
213
293
  reg.to = jid.domain
214
294
  reg.query.add(REXML::Element.new('remove'))
215
- send_with_id(reg) { |answer|
216
- p answer.to_s
217
- true
218
- }
295
+ send_with_id(reg)
219
296
  end
220
297
 
221
298
  ##
@@ -224,23 +301,17 @@ module Jabber
224
301
  # Threading is suggested, as this code waits
225
302
  # for an answer.
226
303
  #
227
- # Raises an exception upon error response (ErrorException from
304
+ # Raises an exception upon error response (ServerError from
228
305
  # Stream#send_with_id).
229
306
  # new_password:: [String] New password
230
307
  def password=(new_password)
231
- iq = Iq::new_query(:set, @jid.domain)
308
+ iq = Iq.new_query(:set, @jid.domain)
232
309
  iq.query.add_namespace('jabber:iq:register')
233
310
  iq.query.add(REXML::Element.new('username')).text = @jid.node
234
311
  iq.query.add(REXML::Element.new('password')).text = new_password
235
312
 
236
313
  err = nil
237
- send_with_id(iq) { |answer|
238
- if answer.type == :result
239
- true
240
- else
241
- false
242
- end
243
- }
314
+ send_with_id(iq)
244
315
  end
245
- end
316
+ end
246
317
  end
@@ -1,7 +1,7 @@
1
1
  require 'xmpp4r/iq'
2
2
 
3
3
  module Jabber
4
-
4
+
5
5
  module Command
6
6
 
7
7
  ##
@@ -23,12 +23,12 @@ module Jabber
23
23
 
24
24
  # Create a new Component
25
25
  # jid:: [JID]
26
- def initialize(jid, server_address=nil, server_port=5347, threaded = true)
27
- super(threaded)
26
+ def initialize(jid, server_address=nil, server_port=5347)
27
+ super()
28
28
  @jid = (jid.kind_of?(JID) ? jid : JID.new(jid.to_s))
29
29
 
30
30
  if server_address
31
- $stderr.puts "Passing server and port to Jabber::Component::new is " +
31
+ $stderr.puts "Passing server and port to Jabber::Component.new is " +
32
32
  "obsolete and will vanish in some later XMPP4R release. " +
33
33
  "Please use these arguments when calling " +
34
34
  "Jabber::Client#connect"
@@ -36,7 +36,7 @@ module Jabber
36
36
  @server_port = server_port
37
37
  end
38
38
  end
39
-
39
+
40
40
  # Connect to the server
41
41
  # (chaining-friendly)
42
42
  # server:: [String] Hostname
@@ -80,8 +80,8 @@ module Jabber
80
80
  ##
81
81
  # Send auth with given secret and wait for result
82
82
  #
83
- # Throws AuthenticationFailure
84
- # secret:: [String] the shared secret
83
+ # Throws ComponentAuthenticationFailure
84
+ # secret:: [String] the shared secret
85
85
  def auth(secret)
86
86
  hash = Digest::SHA1::hexdigest(@streamid.to_s + secret)
87
87
  authenticated = false
@@ -96,8 +96,8 @@ module Jabber
96
96
  end
97
97
  }
98
98
  unless authenticated
99
- raise AuthenticationFailure.new, "Component authentication failed"
99
+ raise ComponentAuthenticationFailure.new, "Component authentication failed"
100
100
  end
101
101
  end
102
- end
102
+ end
103
103
  end
@@ -2,9 +2,11 @@
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 'openssl'
5
+ begin
6
+ require 'openssl'
7
+ rescue LoadError
8
+ end
6
9
  require 'xmpp4r/stream'
7
- require 'xmpp4r/errorexception'
8
10
 
9
11
  module Jabber
10
12
  ##
@@ -30,19 +32,23 @@ module Jabber
30
32
  # Optional callback for verification of SSL peer
31
33
  attr_accessor :ssl_verifycb
32
34
 
35
+ #whether to use the old and deprecated SSL protocol
36
+ #Defaults to false
37
+ attr_accessor :use_ssl
38
+
33
39
  ##
34
- # Create a new connection to the given host and port, using threaded mode
35
- # or not.
36
- def initialize(threaded = true)
37
- super(threaded)
40
+ # Create a new connection to the given host and port
41
+ def initialize
42
+ super()
38
43
  @host = nil
39
44
  @port = nil
40
- @allow_tls = true
45
+ @allow_tls = defined? OpenSSL
41
46
  @tls = false
42
47
  @ssl_capath = nil
43
48
  @ssl_verifycb = nil
44
49
  @features_timeout = 10
45
50
  @keepalive_interval = 60
51
+ @use_ssl = false
46
52
  end
47
53
 
48
54
  ##
@@ -58,6 +64,16 @@ module Jabber
58
64
 
59
65
  Jabber::debuglog("CONNECTING:\n#{@host}:#{@port}")
60
66
  @socket = TCPSocket.new(@host, @port)
67
+
68
+ # We want to use the old and deprecated SSL protocol (usually on port 5223)
69
+ if @use_ssl
70
+ ssl = OpenSSL::SSL::SSLSocket.new(@socket)
71
+ ssl.connect # start SSL session
72
+ ssl.sync_close = true
73
+ Jabber::debuglog("SSL connection established.")
74
+ @socket = ssl
75
+ end
76
+
61
77
  start
62
78
 
63
79
  accept_features
@@ -115,7 +131,7 @@ module Jabber
115
131
  true
116
132
  }
117
133
  if reply.name != 'proceed'
118
- raise ErrorException(reply.first_element('error'))
134
+ raise ServerError(reply.first_element('error'))
119
135
  end
120
136
  # Don't be interrupted
121
137
  stop
@@ -124,7 +140,7 @@ module Jabber
124
140
  error = nil
125
141
 
126
142
  # Context/user set-able stuff
127
- ctx = OpenSSL::SSL::SSLContext.new('TLSv1')
143
+ ctx = OpenSSL::SSL::SSLContext.new
128
144
  if @ssl_capath
129
145
  ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
130
146
  ctx.ca_path = @ssl_capath
@@ -28,10 +28,11 @@ module Jabber
28
28
  nil
29
29
  end
30
30
 
31
- def fields
31
+ def fields(including_hidden=false)
32
32
  fields = []
33
33
  each_element do |xe|
34
- if xe.kind_of?(XDataField) and xe.type != :hidden and xe.type != :fixed
34
+ if xe.kind_of?(XDataField) and (including_hidden or
35
+ (xe.type != :hidden and xe.type != :fixed))
35
36
  fields << xe
36
37
  end
37
38
  end
@@ -90,9 +91,9 @@ module Jabber
90
91
  each_element('instructions') do |xe|
91
92
  fields << xe
92
93
  end
93
- fields
94
+ fields
94
95
  end
95
-
96
+
96
97
  ##
97
98
  # Add Data Form instructions
98
99
  # i:: [String]
@@ -251,6 +252,18 @@ module Jabber
251
252
  }
252
253
  end
253
254
 
255
+ ##
256
+ # Get the first value
257
+ def value
258
+ values.first
259
+ end
260
+
261
+ ##
262
+ # Remove all and set one value
263
+ def value=(val)
264
+ self.values = [val]
265
+ end
266
+
254
267
  ##
255
268
  # Get the options (in a Data Form with type='form')
256
269
  def options
@@ -282,4 +295,3 @@ module Jabber
282
295
  end
283
296
  end
284
297
  end
285
-
@@ -2,7 +2,17 @@
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 'logger'
6
+
5
7
  module Jabber
8
+ def Jabber::logger
9
+ @@logger ||= Logger.new($stderr)
10
+ end
11
+
12
+ def Jabber::logger=(logger)
13
+ @@logger = logger
14
+ end
15
+
6
16
  # Is debugging mode enabled ?
7
17
  @@debug = false
8
18
 
@@ -21,14 +31,12 @@ module Jabber
21
31
  def Jabber::debug
22
32
  @@debug
23
33
  end
24
-
34
+
25
35
  # Outputs a string only if debugging mode is enabled. If the string includes
26
- # several lines, 4 spaces are added at the begginning of each line but the
36
+ # several lines, 4 spaces are added at the beginning of each line but the
27
37
  # first one. Time is prepended to the string.
28
38
  def Jabber::debuglog(string)
29
39
  return if not @@debug
30
- s = string.chomp.gsub("\n", "\n ")
31
- t = Time::new.strftime('%H:%M:%S')
32
- puts "#{t} #{s}"
40
+ logger.debug string.chomp.gsub("\n", "\n ")
33
41
  end
34
42
  end