summaryrefslogtreecommitdiff
path: root/ruby/lib/qpid/framer.rb
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2009-01-20 21:26:28 +0000
committerTed Ross <tross@apache.org>2009-01-20 21:26:28 +0000
commit861692abf515cf136e86e70446d005e7849a0f87 (patch)
tree10025e3499876dbdae8697f2dda4c68b4ec55933 /ruby/lib/qpid/framer.rb
parent15488eba1c867bac8b6db1f7ad870b277c4fa748 (diff)
downloadqpid-python-861692abf515cf136e86e70446d005e7849a0f87.tar.gz
QPID-1602 SASL Authentication, Authorization, and Security Layer for Ruby Client.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@736111 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'ruby/lib/qpid/framer.rb')
-rw-r--r--ruby/lib/qpid/framer.rb35
1 files changed, 25 insertions, 10 deletions
diff --git a/ruby/lib/qpid/framer.rb b/ruby/lib/qpid/framer.rb
index 2a565a69a8..abac221f00 100644
--- a/ruby/lib/qpid/framer.rb
+++ b/ruby/lib/qpid/framer.rb
@@ -19,6 +19,7 @@
require 'monitor'
require 'logger'
+require 'sasl'
module Qpid
@@ -109,21 +110,31 @@ module Qpid
def initialize(sock)
@sock = sock
@sock.extend(MonitorMixin)
- @buf = ""
+ @tx_buf = ""
+ @rx_buf = ""
+ @security_layer_tx = nil
+ @security_layer_rx = nil
+ @maxbufsize = 65535
end
attr_reader :sock
+ attr_accessor :security_layer_tx, :security_layer_rx
def aborted? ; false ; end
def write(buf)
- @buf += buf
+ @tx_buf += buf
end
def flush
@sock.synchronize do
- _write(@buf)
- @buf = ""
+ if @security_layer_tx
+ cipher_buf = Sasl.encode(@security_layer_tx, @tx_buf)
+ _write(cipher_buf)
+ else
+ _write(@tx_buf)
+ end
+ @tx_buf = ""
frm.debug("FLUSHED") if frm
end
end
@@ -139,12 +150,14 @@ module Qpid
end
def read(n)
- data = ""
- while data.size < n
+ while @rx_buf.size < n
begin
- s = @sock.read(n - data.size)
+ s = @sock.recv(@maxbufsize)
+ if @security_layer_rx
+ s = Sasl.decode(@security_layer_rx, s)
+ end
rescue IOError => e
- raise e if data != ""
+ raise e if @rx_buf != ""
@sock.close unless @sock.closed?
raise Closed
end
@@ -153,9 +166,11 @@ module Qpid
@sock.close unless @sock.closed?
raise Closed
end
- data += s
- raw.debug("RECV #{n}/#{data.size} #{s.inspect}") if raw
+ @rx_buf += s
+ raw.debug("RECV #{n}/#{@rx_buf.size} #{s.inspect}") if raw
end
+ data = @rx_buf[0, n]
+ @rx_buf = @rx_buf[n, @rx_buf.size - n]
return data
end