Merge remote-tracking branch 'matt/master'

Conflicts:
	lib/X11.rb
	lib/X11/auth.rb
	lib/X11/protocol.rb
This commit is contained in:
Richard Ramsden 2012-03-11 22:20:53 -07:00
commit 910924a36d
4 changed files with 22 additions and 7 deletions

View file

@ -6,3 +6,8 @@ require 'X11/auth'
require 'X11/display'
require 'X11/encode'
require 'X11/packet'
module X11
class X11Error < StandardError; end
class X11Exception < RuntimeException; end
end

View file

@ -52,14 +52,12 @@ module X11
# returns one entry from Xauthority file
def read
auth_info = []
auth_info << ADDRESS_TYPES[ @file.read(2).unpack('n').first ]
auth_info = [] << ADDRESS_TYPES[ @file.read(2).unpack('n').first ]
4.times do
length = @file.read(2).unpack('n').first
auth_info << @file.read(length)
end
AuthInfo[*auth_info]
end

View file

@ -1,4 +1,16 @@
module X11
class DisplayException < X11Exception; end
class ConnectionException < DisplayException; end
class AuthorizationException < ConnectionException
attr_reader :errorcode
def initialize msg, errcode=nil
super msg
@errorcode = errcode
end
end
class Display
# Open a connection to the specified display (numbered from 0) on the specified host
@ -42,13 +54,13 @@ private
len, major, minor, xlen = @socket.read(7).unpack("CSSS")
reason = @socket.read(xlen * 4)
reason = reason[0..len]
raise "Connection to server failed -- (version #{major}.#{minor}) #{reason}"
raise AuthorizationException.new "Connection to server failed -- (version #{major}.#{minor}) #{reason}", X11::Auth::FAILED
when X11::Auth::AUTHENTICATE
raise "Connection requires authentication"
raise AuthorizationException.new "Connection requires authentication", X11::Auth::AUTHENTICATE
when X11::Auth::SUCCESS
puts "CONNECTION SUCCESS"
else
raise "received unknown opcode #{type}"
raise AuthorizationException.new "Received unknown opcode #{type}"
end
end

View file

@ -7,7 +7,7 @@ module X11
when "\1\0\0\0"
"l".ord
else
raise "Cannot determine byte order"
raise ByteOrderError.new "Cannot determine byte order"
end
MAJOR = 11