xmpp4r 0.3.2 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/{ChangeLog → CHANGELOG} +33 -0
- data/LICENSE +9 -9
- data/README.rdoc +110 -0
- data/README_ruby19.txt +43 -0
- data/Rakefile +235 -74
- data/data/doc/xmpp4r/examples/advanced/adventure/README +0 -1
- data/data/doc/xmpp4r/examples/advanced/adventure/adventure.rb +1 -1
- data/data/doc/xmpp4r/examples/advanced/adventure/adventuremuc.rb +12 -12
- data/data/doc/xmpp4r/examples/advanced/adventure/world.rb +10 -11
- data/data/doc/xmpp4r/examples/advanced/fileserve.rb +11 -11
- data/data/doc/xmpp4r/examples/advanced/getonline.rb +7 -7
- data/data/doc/xmpp4r/examples/advanced/gtkmucclient.rb +3 -3
- data/data/doc/xmpp4r/examples/advanced/migrate.rb +21 -22
- data/data/doc/xmpp4r/examples/advanced/minimuc.rb +22 -22
- 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 +0 -1
- data/data/doc/xmpp4r/examples/advanced/rosterdiscovery.rb +2 -3
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr.rb +3 -3
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_jabber.rb +10 -10
- data/data/doc/xmpp4r/examples/advanced/shellmgr/shellmgr_test.rb +2 -2
- data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +12 -12
- data/data/doc/xmpp4r/examples/advanced/xmpping.rb +2 -3
- data/data/doc/xmpp4r/examples/basic/change_password.rb +3 -3
- data/data/doc/xmpp4r/examples/basic/client.rb +5 -3
- data/data/doc/xmpp4r/examples/basic/component.rb +1 -1
- data/data/doc/xmpp4r/examples/basic/{echo_threaded.rb → echo.rb} +8 -7
- data/data/doc/xmpp4r/examples/basic/jabbersend.rb +5 -5
- data/data/doc/xmpp4r/examples/basic/mass_sender.rb +11 -11
- data/data/doc/xmpp4r/examples/basic/muc_owner_config.rb +0 -1
- data/data/doc/xmpp4r/examples/basic/mucinfo.rb +3 -1
- data/data/doc/xmpp4r/examples/basic/mucsimplebot.rb +0 -1
- data/data/doc/xmpp4r/examples/basic/register.rb +21 -4
- data/data/doc/xmpp4r/examples/basic/roster.rb +7 -5
- data/data/doc/xmpp4r/examples/basic/rosterprint.rb +0 -0
- data/data/doc/xmpp4r/examples/basic/rosterrename.rb +2 -2
- data/data/doc/xmpp4r/examples/basic/rosterwatch.rb +6 -7
- data/data/doc/xmpp4r/examples/basic/send_vcard.rb +3 -4
- 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 +1 -1
- data/lib/xmpp4r.rb +4 -4
- data/lib/xmpp4r/base64.rb +32 -0
- data/lib/xmpp4r/bytestreams/helper/filetransfer.rb +10 -11
- data/lib/xmpp4r/bytestreams/helper/ibb/base.rb +6 -8
- data/lib/xmpp4r/bytestreams/helper/ibb/initiator.rb +3 -6
- data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +0 -1
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb +8 -11
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb +4 -7
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb +7 -3
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb +10 -5
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +14 -4
- data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb.orig +62 -0
- data/lib/xmpp4r/bytestreams/iq/bytestreams.rb +0 -1
- data/lib/xmpp4r/callbacks.rb +5 -5
- data/lib/xmpp4r/caps.rb +1 -0
- data/lib/xmpp4r/caps/c.rb +53 -0
- data/lib/xmpp4r/caps/helper/generator.rb +160 -0
- data/lib/xmpp4r/caps/helper/helper.rb +87 -0
- data/lib/xmpp4r/client.rb +111 -40
- data/lib/xmpp4r/command/iq/command.rb +1 -1
- data/lib/xmpp4r/component.rb +8 -8
- data/lib/xmpp4r/connection.rb +25 -9
- data/lib/xmpp4r/dataforms/x/data.rb +17 -5
- data/lib/xmpp4r/debuglog.rb +13 -5
- data/lib/xmpp4r/delay/x/delay.rb +1 -1
- data/lib/xmpp4r/discovery.rb +3 -2
- data/lib/xmpp4r/discovery/helper/responder.rb +165 -0
- data/lib/xmpp4r/discovery/iq/discoinfo.rb +11 -12
- data/lib/xmpp4r/discovery/iq/discoitems.rb +12 -4
- data/lib/xmpp4r/{error.rb → errors.rb} +66 -10
- data/lib/xmpp4r/framework/base.rb +55 -0
- data/lib/xmpp4r/framework/bot.rb +148 -0
- data/lib/xmpp4r/httpbinding/client.rb +1 -1
- data/lib/xmpp4r/idgenerator.rb +1 -1
- data/lib/xmpp4r/iq.rb +34 -23
- data/lib/xmpp4r/jid.rb +2 -2
- data/lib/xmpp4r/message.rb +1 -1
- data/lib/xmpp4r/muc.rb +2 -0
- data/lib/xmpp4r/muc/helper/mucbrowser.rb +4 -19
- data/lib/xmpp4r/muc/helper/mucclient.rb +54 -23
- data/lib/xmpp4r/muc/helper/simplemucclient.rb +107 -1
- 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 +5 -1
- data/lib/xmpp4r/muc/item.rb +143 -0
- data/lib/xmpp4r/muc/x/mucuserinvite.rb +2 -2
- data/lib/xmpp4r/muc/x/mucuseritem.rb +3 -117
- data/lib/xmpp4r/presence.rb +2 -1
- data/lib/xmpp4r/pubsub.rb +7 -0
- data/lib/xmpp4r/pubsub/children/configuration.rb +86 -0
- data/lib/xmpp4r/pubsub/{stanzas → children}/event.rb +13 -13
- data/lib/xmpp4r/pubsub/{stanzas → children}/item.rb +9 -1
- data/lib/xmpp4r/pubsub/{stanzas → children}/items.rb +10 -1
- data/lib/xmpp4r/pubsub/children/node_config.rb +48 -0
- data/lib/xmpp4r/pubsub/children/publish.rb +24 -0
- data/lib/xmpp4r/pubsub/{stanzas → children}/subscription.rb +16 -12
- data/lib/xmpp4r/pubsub/children/subscription_config.rb +67 -0
- data/lib/xmpp4r/pubsub/children/unsubscribe.rb +48 -0
- data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +49 -93
- data/lib/xmpp4r/pubsub/helper/nodehelper.rb +39 -36
- data/lib/xmpp4r/pubsub/helper/servicehelper.rb +253 -162
- data/lib/xmpp4r/pubsub/iq/pubsub.rb +1 -1
- data/lib/xmpp4r/rexmladdons.rb +56 -28
- data/lib/xmpp4r/roster.rb +0 -1
- data/lib/xmpp4r/roster/helper/roster.rb +26 -15
- data/lib/xmpp4r/roster/iq/roster.rb +19 -19
- data/lib/xmpp4r/roster/x/roster.rb +10 -10
- data/lib/xmpp4r/rpc/helper/client.rb +17 -8
- data/lib/xmpp4r/rpc/helper/server.rb +1 -2
- data/lib/xmpp4r/rpc/helper/xmlrpcaddons.rb +14 -4
- data/lib/xmpp4r/rpc/iq/rpc.rb +0 -1
- data/lib/xmpp4r/sasl.rb +27 -6
- data/lib/xmpp4r/stream.rb +39 -44
- data/lib/xmpp4r/streamparser.rb +4 -4
- 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 +0 -1
- data/lib/xmpp4r/vcard/helper/vcard.rb +1 -3
- data/lib/xmpp4r/vcard/iq/vcard.rb +14 -0
- data/lib/xmpp4r/version/iq/version.rb +0 -1
- data/lib/xmpp4r/x.rb +1 -1
- data/lib/xmpp4r/xhtml.rb +1 -0
- data/lib/xmpp4r/xhtml/html.rb +115 -0
- data/lib/xmpp4r/xmpp4r.rb +7 -5
- data/lib/xmpp4r/xmppelement.rb +21 -5
- data/lib/xmpp4r/xmppstanza.rb +6 -6
- data/setup.rb +4 -4
- data/test/bytestreams/tc_ibb.rb +2 -2
- data/test/bytestreams/tc_socks5bytestreams.rb +12 -2
- data/test/caps/tc_helper.rb +156 -0
- data/test/dataforms/tc_data.rb +0 -0
- data/test/delay/tc_xdelay.rb +2 -2
- data/test/discovery/tc_responder.rb +91 -0
- data/test/lib/assert_equal_xml.rb +14 -0
- data/test/lib/clienttester.rb +31 -24
- data/test/muc/tc_muc_mucclient.rb +249 -13
- data/test/muc/tc_muc_simplemucclient.rb +41 -2
- data/test/muc/tc_mucowner.rb +0 -0
- data/test/pubsub/tc_helper.rb +486 -51
- data/test/pubsub/tc_nodeconfig.rb +54 -0
- data/test/pubsub/tc_subscriptionconfig.rb +41 -0
- data/test/roster/tc_helper.rb +6 -7
- data/test/roster/tc_iqqueryroster.rb +16 -16
- data/test/roster/tc_xroster.rb +1 -1
- data/test/rpc/tc_helper.rb +15 -3
- data/test/tc_callbacks.rb +7 -7
- data/test/tc_class_names.rb +15 -6
- data/test/tc_client.rb +3 -3
- data/test/{tc_error.rb → tc_errors.rb} +54 -12
- data/test/tc_idgenerator.rb +0 -0
- data/test/tc_iq.rb +32 -29
- data/test/tc_iqquery.rb +2 -2
- data/test/tc_jid.rb +44 -42
- data/test/tc_message.rb +13 -12
- data/test/tc_presence.rb +25 -24
- data/test/tc_rexml.rb +81 -2
- data/test/tc_stream.rb +15 -13
- data/test/tc_streamComponent.rb +6 -5
- data/test/tc_streamError.rb +21 -15
- data/test/tc_streamSend.rb +9 -9
- data/test/tc_streamparser.rb +112 -0
- data/test/tc_xmppstanza.rb +19 -9
- data/test/ts_xmpp4r.rb +10 -1
- data/test/tune/tc_helper_recv.rb +84 -0
- data/test/tune/tc_helper_send.rb +74 -0
- data/test/tune/tc_tune.rb +79 -0
- data/test/vcard/tc_helper.rb +2 -2
- data/test/vcard/tc_iqvcard.rb +13 -3
- data/test/version/tc_helper.rb +2 -2
- data/test/version/tc_iqqueryversion.rb +10 -10
- data/test/xhtml/tc_html.rb +41 -0
- data/tools/gen_requires.bash +29 -8
- data/tools/xmpp4r-gemspec-test.rb +11 -0
- data/xmpp4r.gemspec +291 -0
- metadata +277 -218
- data/README +0 -28
- data/UPDATING +0 -40
- data/data/doc/xmpp4r/examples/buggy/jabber2jabber/jabber2jabber.rb +0 -18
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_cgi.rb +0 -192
- data/data/doc/xmpp4r/examples/buggy/miniedgarr_watch.rb +0 -82
- data/lib/xmpp4r/authenticationfailure.rb +0 -13
- data/lib/xmpp4r/errorexception.rb +0 -32
- data/tools/doctoweb.bash +0 -30
data/lib/xmpp4r/client.rb
CHANGED
@@ -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
|
30
|
-
super(
|
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
|
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
|
-
|
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
|
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
|
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)
|
149
|
+
send_with_id(iq) do |reply|
|
151
150
|
reported_jid = reply.first_element('jid')
|
152
|
-
if
|
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)
|
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
|
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
|
210
|
+
authset = Iq.new_authset_digest(@jid, @streamid.to_s, password)
|
181
211
|
else
|
182
|
-
authset = Iq
|
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
|
252
|
+
# This method may raise ServerError if the registration was
|
197
253
|
# not successful.
|
198
|
-
|
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
|
-
|
202
|
-
|
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)
|
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 (
|
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
|
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)
|
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
|
data/lib/xmpp4r/component.rb
CHANGED
@@ -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
|
27
|
-
super(
|
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
|
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
|
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
|
99
|
+
raise ComponentAuthenticationFailure.new, "Component authentication failed"
|
100
100
|
end
|
101
101
|
end
|
102
|
-
end
|
102
|
+
end
|
103
103
|
end
|
data/lib/xmpp4r/connection.rb
CHANGED
@@ -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
|
-
|
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
|
35
|
-
|
36
|
-
|
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 =
|
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
|
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
|
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
|
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
|
-
|
data/lib/xmpp4r/debuglog.rb
CHANGED
@@ -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
|
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
|
-
|
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
|