adddir ./Graphics adddir ./Graphics/X11 addfile ./Graphics/X11/Xauth.hsc hunk ./Graphics/X11/Xauth.hsc 1 +module Graphics.X11.Xauth + (Xauth(..), Family, familyLocal, familyWild, familyNetname, + familyKrb5Principal, familyLocalHost, getAuthByAddr) where + +#include + +import Foreign +import Foreign.C +import Control.Monad (liftM2, zipWithM_) + +data Xauth = Xauth { xauthName, xauthData :: [CChar] } deriving (Show, Read) + +type Family = CUShort + +familyLocal, familyWild, familyNetname, familyKrb5Principal, familyLocalHost :: Family +familyLocal = #{const FamilyLocal} +familyWild = #{const FamilyWild} +familyNetname = #{const FamilyNetname} +familyKrb5Principal = #{const FamilyKrb5Principal} +familyLocalHost = #{const FamilyLocalHost} + +foreign import ccall "X11/Xauth.h XauGetAuthByAddr" + xauGetAuthByAddr :: Family -> CUShort -> Ptr CChar -> CUShort -> Ptr CChar + -> CInt -> Ptr CChar -> IO (Ptr Xauth) + +foreign import ccall "X11/Xauth.h XauDisposeAuth" + xauDisposeAuth :: Ptr Xauth -> IO () + +getAuthByAddr :: Family -> [CChar] -> [CChar] -> [CChar] -> IO (Maybe Xauth) +getAuthByAddr family address number atype + = withArray address $ \addr_p -> withArray number $ \num_p -> + withArray atype $ \atype_p -> do + res <- xauGetAuthByAddr family (slength address) addr_p (slength number) + num_p (slength atype) atype_p + if res == nullPtr + then return Nothing + else do + name_p <- #{peek Xauth, name} res + name_len <- #{peek Xauth, name_length} res :: IO CUShort + data_p <- #{peek Xauth, data} res + data_len <- #{peek Xauth, data_length} res :: IO CUShort + x <- if or [nullPtr == name_p, nullPtr == data_p, data_len <= 0, name_len <= 0] + then return $ Nothing + else + liftM2 ((Just .) . Xauth) + (peekArray (fromIntegral name_len) name_p) + (peekArray (fromIntegral data_len) data_p) + xauDisposeAuth res + return x + where slength x = fromIntegral $ length x addfile ./LICENSE hunk ./LICENSE 1 +Copyright (c) 2008 Spencer Janssen + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the author nor the names of his contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. addfile ./Setup.hs hunk ./Setup.hs 1 +module Main (main) where + +import Distribution.Simple + +main :: IO () +main = defaultMain addfile ./Xauth.cabal hunk ./Xauth.cabal 1 +name: Xauth +version: 0.1 +license: BSD3 +license-file: LICENSE +copyright: Spencer Janssen +maintainer: Spencer Janssen +category: Graphics +synopsis: A binding to the X11 authentication library +description: A Haskell binding to the X11 authentication library. +exposed-modules: + Graphics.X11.Xauth +extensions: ForeignFunctionInterface, CPP +extra-libraries: + "Xau" +build-depends: base +build-type: Simple hunk ./Graphics/X11/Xauth.hsc 2 - (Xauth(..), Family, familyLocal, familyWild, familyNetname, + (Xauth(..), familyLocal, familyWild, familyNetname, hunk ./Graphics/X11/Xauth.hsc 13 -type Family = CUShort - -familyLocal, familyWild, familyNetname, familyKrb5Principal, familyLocalHost :: Family +familyLocal, familyWild, familyNetname, familyKrb5Principal, familyLocalHost :: CUShort hunk ./Graphics/X11/Xauth.hsc 21 - xauGetAuthByAddr :: Family -> CUShort -> Ptr CChar -> CUShort -> Ptr CChar + xauGetAuthByAddr :: CUShort -> CUShort -> Ptr CChar -> CUShort -> Ptr CChar hunk ./Graphics/X11/Xauth.hsc 27 -getAuthByAddr :: Family -> [CChar] -> [CChar] -> [CChar] -> IO (Maybe Xauth) +getAuthByAddr :: CUShort -> [CChar] -> [CChar] -> [CChar] -> IO (Maybe Xauth) hunk ./Xauth.cabal 13 -extra-libraries: - "Xau" hunk ./Xauth.cabal 15 +pkgconfig-depends: xau