mirror of
https://github.com/vidarh/ruby-x11
synced 2025-01-13 20:01:22 +01:00
Merge remote-tracking branch 'matt/master'
Conflicts: lib/X11.rb lib/X11/auth.rb lib/X11/protocol.rb
This commit is contained in:
commit
910924a36d
4 changed files with 22 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue