Skip to content

Commit

Permalink
Clean up a few things, and use a closure for TLS instead of two methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
rakaur committed Oct 4, 2010
1 parent 8673985 commit e84b9ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
10 changes: 5 additions & 5 deletions lib/kintara.rb
Expand Up @@ -133,8 +133,8 @@ def initialize
end

# Set up the SSL stuff
certfile = Kintara.config[:listen][:certificate]
keyfile = Kintara.config[:listen][:private_key]
certfile = @@config[:listen][:certificate]
keyfile = @@config[:listen][:private_key]

begin
cert = OpenSSL::X509::Certificate.new(File.read(certfile))
Expand All @@ -143,12 +143,12 @@ def initialize
puts "#{ME}: configuration error: #{e}"
abort
else
ctx = OpenSSL::SSL::SSLContext.new

ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
ctx = OpenSSL::SSL::SSLContext.new
ctx.cert = cert
ctx.key = pkey

ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE

@@ssl_context = ctx
end

Expand Down
44 changes: 25 additions & 19 deletions lib/kintara/client.rb
Expand Up @@ -105,7 +105,6 @@ def set_default_handlers
@eventq.handle(:stanza_ready) { |xml| process_stanza(xml) }

@eventq.handle(:new_stream) { |xml| initialize_new_stream(xml) }
@eventq.handle(:start_tls) { really_start_tls }
end

def initialize_parser
Expand Down Expand Up @@ -174,10 +173,14 @@ def parse
#
def dead=(bool)
if bool
# Try to flush the sendq first. This is for errors and such.
write unless @sendq.empty?

debug("client for #@host is dead")
@dead = true

@socket.close
@socket = nil
@dead = true
@state = []
end
end
Expand All @@ -190,9 +193,6 @@ def error(defined_condition)

@sendq << err

# Force it to send now
write

self.dead = true
end

Expand Down Expand Up @@ -283,26 +283,26 @@ def start_tls(xml)
# the TLS handshake. The event loop breaks it otherwise. Hack :/
write

@eventq.post(:start_tls)
end
@eventq.post(:tls_callback)

def really_start_tls
begin
@eventq.handle(:tls_callback) do
socket = OpenSSL::SSL::SSLSocket.new(@socket, Kintara.ssl_context)
socket.accept
rescue Exception => e
debug("TLS error: #{e}")

fai = XML.new_element('failure', 'urn:ietf:params:xml:ns:xmpp-tls')
@sendq << fai
begin
socket.accept
rescue Exception => e
debug("TLS error: #{e}")

self.dead = true
fai = XML.new_element('failure',
'urn:ietf:params:xml:ns:xmpp-tls')
@sendq << fai

return
self.dead = true
else
@socket = socket
@state << :tls
end
end

@socket = socket
@state << :tls
end

######
Expand Down Expand Up @@ -373,6 +373,12 @@ def write
end
rescue Errno::EAGAIN
retry
rescue Exception => e
debug("write error on #@host: #{e}")
debug("client from #@host disconnected")
@sendq = []
self.dead = true
return
end
end
end
Expand Down

0 comments on commit e84b9ed

Please sign in to comment.