Skip to content

Commit

Permalink
Merge pull request xmpp4r#1 from coderhs/master
Browse files Browse the repository at this point in the history
Merging the BOSH service updates
  • Loading branch information
coderhs committed Sep 30, 2013
2 parents 2dc321a + 2c11966 commit 73d6338
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ coverage/*
rdoc/*
tools/*.png
*~
*#
*#
21 changes: 21 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
mad-p-xmpp4r 0.6.3 (02/03/2013)
===============================
* Removed unnecessary dependency on pry.

mad-p-xmpp4r 0.6.2 (26/02/2013)
===============================
* Merge pull request #1 from Strech/patch-1
* Non-bosh connection flushes correctly
* Elaborated debug messages in HTTPBinding::Client

mad-p-xmpp4r 0.6.1 (21/02/2013)
===============================
* Modified to work with BOSH with HTTPBinding::Client
- Support stream restart with urn:xmpp:xbosh way.
- Removed unnecessary wait until authenticated.
- Added Semaphore to wait for auth and bind response.
- Hook to setup SSL flags (certificate, etc.)
- Adjusted HTTP::Net read_timeout according to http_wait.
- Proxy handling.
- Respect poll/request BOSH parameters to avoid overactivity.

XMPP4R 0.5 (15/06/2009)
=======================
* Many bugs fixed and tests cleanups (better Ruby 1.9 support, in
Expand Down
26 changes: 13 additions & 13 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rake'
require "rake/clean"
require 'rake/testtask'
require 'rake/rdoctask'
require 'rdoc/task'

$:.unshift 'lib'
require "xmpp4r"
Expand All @@ -10,18 +10,18 @@ require "xmpp4r"
# OPTIONS
##############################################################################

PKG_NAME = 'xmpp4r'
PKG_NAME = 'mad-p-xmpp4r'
PKG_VERSION = Jabber::XMPP4R_VERSION
AUTHORS = ['Lucas Nussbaum', 'Stephan Maka', 'Glenn Rempe']
EMAIL = "[email protected]"
HOMEPAGE = "http://home.gna.org/xmpp4r/"
SUMMARY = "XMPP4R is an XMPP/Jabber library for Ruby."
AUTHORS = ['Lucas Nussbaum', 'Stephan Maka', 'Glenn Rempe', 'Kaoru Maeda']
EMAIL = "[email protected]"
HOMEPAGE = "https://github.com/mad-p/xmpp4r"
SUMMARY = "This is a fork from XMPP4R (https://github.com/ln/xmpp4r), fixing BOSH"

# These are the common rdoc options that are shared between generation of
# rdoc files using BOTH 'rake rdoc' and the installation by users of a
# RubyGem version which builds rdoc's along with its installation. Any
# rdoc options that are ONLY for developers running 'rake rdoc' should be
# added in the 'Rake::RDocTask' block below.
# added in the 'RDoc::Task' block below.
RDOC_OPTIONS = [
"--quiet",
"--title", SUMMARY,
Expand All @@ -35,7 +35,7 @@ RDOC_OPTIONS = [
RDOC_FILES = (%w( README.rdoc README_ruby19.txt CHANGELOG LICENSE COPYING )).sort

# The full file list used for rdocs, tarballs, gems, and for generating the xmpp4r.gemspec.
PKG_FILES = (%w( Rakefile setup.rb xmpp4r.gemspec ) + RDOC_FILES + Dir["{lib,test,data,tools}/**/*"]).sort
PKG_FILES = (%w( Rakefile setup.rb mad-p-xmpp4r.gemspec ) + RDOC_FILES + Dir["{lib,test,data,tools}/**/*"]).sort

##############################################################################
# DEFAULT TASK
Expand All @@ -61,7 +61,7 @@ end

# RDOC
#######
Rake::RDocTask.new do |rd|
RDoc::Task.new do |rd|

# which dir should rdoc files be installed in?
rd.rdoc_dir = 'rdoc'
Expand Down Expand Up @@ -134,7 +134,7 @@ end
CLEAN.include ["*.gem", "pkg", "rdoc", "coverage", "tools/*.png"]

begin
require 'rake/gempackagetask'
require 'rubygems/package_task'

spec = Gem::Specification.new do |s|
s.name = PKG_NAME
Expand All @@ -156,7 +156,7 @@ begin
s.required_ruby_version = ">= 1.8.4"
end

Rake::GemPackageTask.new(spec) do |pkg|
Gem::PackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
pkg.need_tar = true
pkg.need_zip = true
Expand All @@ -182,14 +182,14 @@ begin
# Thanks to the Merb project for this code.
desc "Update Github Gemspec"
task :update_gemspec do
skip_fields = %w(new_platform original_platform date)
skip_fields = %w(new_platform original_platform date cache_dir cache_file loaded)

result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
result << "# RUN : 'rake gem:update_gemspec'\n\n"
result << "Gem::Specification.new do |s|\n"
spec.instance_variables.sort.each do |ivar|
value = spec.instance_variable_get(ivar)
name = ivar.split("@").last
name = ivar.to_s.split("@").last
next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
if name == "dependencies"
value.each do |d|
Expand Down
22 changes: 18 additions & 4 deletions lib/xmpp4r/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Client < Connection
def initialize(jid)
super()
@jid = (jid.kind_of?(JID) ? jid : JID.new(jid.to_s))
@authenticated = false
end

##
Expand Down Expand Up @@ -113,6 +114,7 @@ def auth(password)
else
auth_nonsasl(password)
end
@authenticated = true
rescue
Jabber::debuglog("#{$!.class}: #{$!}\n#{$!.backtrace.join("\n")}")
raise ClientAuthenticationFailure.new, $!.to_s
Expand All @@ -133,6 +135,7 @@ def bind(desired_resource=nil)
end

jid = nil
semaphore = Semaphore.new
send_with_id(iq) do |reply|
reply_bind = reply.first_element('bind')
if reply_bind
Expand All @@ -141,7 +144,9 @@ def bind(desired_resource=nil)
jid = JID.new(reported_jid.text)
end
end
semaphore.run
end
semaphore.wait
jid
end

Expand Down Expand Up @@ -171,13 +176,13 @@ def auth_sasl(sasl, password)
sasl.auth(password)

# Restart stream after SASL auth
stop
start
restart
# And wait for features - again
@features_sem.wait

# Resource binding (RFC3920 - 7)
if @stream_features.has_key? 'bind'
Jabber::debuglog("**********Handling bind")
@jid = bind(@jid.resource)
end

Expand All @@ -187,10 +192,19 @@ def auth_sasl(sasl, password)
session = iq.add REXML::Element.new('session')
session.add_namespace @stream_features['session']

send_with_id(iq)
semaphore = Semaphore.new
send_with_id(iq) {
semaphore.run
}
semaphore.wait
end
end

def restart
stop
start
end

##
# See Client#auth_anonymous_sasl
def auth_anonymous
Expand Down Expand Up @@ -239,7 +253,7 @@ def auth_nonsasl(password, digest=true)
authset = Iq.new_authset(@jid, password)
end
send_with_id(authset)
$defout.flush
$>.flush

true
end
Expand Down
Loading

0 comments on commit 73d6338

Please sign in to comment.