module Gnome.Keyring.NetworkPassword
( NetworkPassword (..)
, NetworkPasswordLocation (..)
, findNetworkPassword
, setNetworkPassword
) where
import Control.Exception (bracket)
import Data.Text.Lazy (Text)
import Gnome.Keyring.ItemInfo.Internal (ItemID (..), ItemType (..))
import Gnome.Keyring.Item.Internal (GetItemIDCallback, peekItemID)
import Gnome.Keyring.Operation.Internal
import Gnome.Keyring.Types
import Foreign
import Foreign.C
import Gnome.Keyring.FFI
data NetworkPassword = NetworkPassword
{ networkPasswordKeyring :: KeyringName
, networkPasswordItemID :: ItemID
, networkPasswordLocation :: NetworkPasswordLocation
, networkPassword :: Text
}
deriving (Show, Eq)
data NetworkPasswordLocation = NetworkPasswordLocation
{ locationProtocol :: Maybe Text
, locationServer :: Maybe Text
, locationObject :: Maybe Text
, locationAuthType :: Maybe Text
, locationPort :: Word32
, locationUser :: Maybe Text
, locationDomain :: Maybe Text
}
deriving (Show, Eq)
findNetworkPassword :: NetworkPasswordLocation -> Operation [NetworkPassword]
findNetworkPassword loc = let
p1 = locationUser loc
p2 = locationDomain loc
p3 = locationServer loc
p4 = locationObject loc
p5 = locationProtocol loc
p6 = locationAuthType loc
p7 = locationPort loc
in operation
(find_network_password p1 p2 p3 p4 p5 p6 p7)
(find_network_password_sync p1 p2 p3 p4 p5 p6 p7)
find_network_password :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Word32 -> GetPasswordListCallback -> Ptr () -> DestroyNotifyPtr -> IO (CancellationKey)
find_network_password a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 =
withNullableText a1 $ \a1' ->
withNullableText a2 $ \a2' ->
withNullableText a3 $ \a3' ->
withNullableText a4 $ \a4' ->
withNullableText a5 $ \a5' ->
withNullableText a6 $ \a6' ->
let {a7' = fromIntegral a7} in
let {a8' = callbackToPtr a8} in
let {a9' = id a9} in
let {a10' = id a10} in
find_network_password'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
let {res' = CancellationKey res} in
return (res')
find_network_password_sync :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Word32 -> IO (Result, [NetworkPassword])
find_network_password_sync a1 a2 a3 a4 a5 a6 a7 =
withNullableText a1 $ \a1' ->
withNullableText a2 $ \a2' ->
withNullableText a3 $ \a3' ->
withNullableText a4 $ \a4' ->
withNullableText a5 $ \a5' ->
withNullableText a6 $ \a6' ->
let {a7' = fromIntegral a7} in
alloca $ \a8' ->
find_network_password_sync'_ a1' a2' a3' a4' a5' a6' a7' a8' >>= \res ->
stealPasswordList a8'>>= \a8'' ->
let {res' = result res} in
return (res', a8'')
setNetworkPassword :: Maybe KeyringName -> NetworkPasswordLocation ->
Text ->
Operation ItemID
setNetworkPassword k loc secret = let
p1 = locationUser loc
p2 = locationDomain loc
p3 = locationServer loc
p4 = locationObject loc
p5 = locationProtocol loc
p6 = locationAuthType loc
p7 = locationPort loc
in operation
(set_network_password k p1 p2 p3 p4 p5 p6 p7 secret)
(set_network_password_sync k p1 p2 p3 p4 p5 p6 p7 secret)
set_network_password :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Word32 -> Text -> GetItemIDCallback -> Ptr () -> DestroyNotifyPtr -> IO (CancellationKey)
set_network_password a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 =
withNullableText a1 $ \a1' ->
withNullableText a2 $ \a2' ->
withNullableText a3 $ \a3' ->
withNullableText a4 $ \a4' ->
withNullableText a5 $ \a5' ->
withNullableText a6 $ \a6' ->
withNullableText a7 $ \a7' ->
let {a8' = fromIntegral a8} in
withText a9 $ \a9' ->
let {a10' = callbackToPtr a10} in
let {a11' = id a11} in
let {a12' = id a12} in
set_network_password'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' a11' a12' >>= \res ->
let {res' = CancellationKey res} in
return (res')
set_network_password_sync :: Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Word32 -> Text -> IO (Result, ItemID)
set_network_password_sync a1 a2 a3 a4 a5 a6 a7 a8 a9 =
withNullableText a1 $ \a1' ->
withNullableText a2 $ \a2' ->
withNullableText a3 $ \a3' ->
withNullableText a4 $ \a4' ->
withNullableText a5 $ \a5' ->
withNullableText a6 $ \a6' ->
withNullableText a7 $ \a7' ->
let {a8' = fromIntegral a8} in
withText a9 $ \a9' ->
alloca $ \a10' ->
set_network_password_sync'_ a1' a2' a3' a4' a5' a6' a7' a8' a9' a10' >>= \res ->
peekItemID a10'>>= \a10'' ->
let {res' = result res} in
return (res', a10'')
peekPassword :: Ptr () -> IO NetworkPassword
peekPassword pwd = do
protocol <- peekNullableText =<< (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)}) pwd
server <- peekNullableText =<< (\ptr -> do {peekByteOff ptr 12 ::IO (Ptr CChar)}) pwd
object <- peekNullableText =<< (\ptr -> do {peekByteOff ptr 16 ::IO (Ptr CChar)}) pwd
authType <- peekNullableText =<< (\ptr -> do {peekByteOff ptr 20 ::IO (Ptr CChar)}) pwd
port <- fromIntegral `fmap` (\ptr -> do {peekByteOff ptr 24 ::IO CUInt}) pwd
user <- peekNullableText =<< (\ptr -> do {peekByteOff ptr 28 ::IO (Ptr CChar)}) pwd
domain <- peekNullableText =<< (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr CChar)}) pwd
let loc = NetworkPasswordLocation
{ locationProtocol = protocol
, locationServer = server
, locationObject = object
, locationAuthType = authType
, locationPort = port
, locationUser = user
, locationDomain = domain
}
keyring <- peekText =<< (\ptr -> do {peekByteOff ptr 0 ::IO (Ptr CChar)}) pwd
itemID <- (ItemID . fromIntegral) `fmap` (\ptr -> do {peekByteOff ptr 4 ::IO CUInt}) pwd
password <- peekText =<< (\ptr -> do {peekByteOff ptr 36 ::IO (Ptr CChar)}) pwd
return $ NetworkPassword keyring itemID loc password
stealPasswordList :: Ptr (Ptr ()) -> IO [NetworkPassword]
stealPasswordList ptr = bracket (peek ptr)
gnome_keyring_network_password_list_free
(mapGList peekPassword)
data GetPasswordListCallback = GetPasswordListCallback GetListCallbackPtr
instance Callback GetPasswordListCallback [NetworkPassword] where
callbackToPtr (GetPasswordListCallback x) = castFunPtr x
freeCallback (GetPasswordListCallback x) = freeHaskellFunPtr x
buildCallback = mkListCallback GetPasswordListCallback
peekPassword
foreign import ccall unsafe "Gnome/Keyring/NetworkPassword.chs.h gnome_keyring_find_network_password"
find_network_password'_ :: ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> (CUInt -> ((FunPtr (CInt -> ((Ptr ()) -> ((Ptr ()) -> (IO ()))))) -> ((Ptr ()) -> ((FunPtr ((Ptr ()) -> (IO ()))) -> (IO (Ptr ()))))))))))))
foreign import ccall safe "Gnome/Keyring/NetworkPassword.chs.h gnome_keyring_find_network_password_sync"
find_network_password_sync'_ :: ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> (CUInt -> ((Ptr (Ptr ())) -> (IO CInt)))))))))
foreign import ccall unsafe "Gnome/Keyring/NetworkPassword.chs.h gnome_keyring_set_network_password"
set_network_password'_ :: ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> (CUInt -> ((Ptr CChar) -> ((FunPtr (CInt -> (CUInt -> ((Ptr ()) -> (IO ()))))) -> ((Ptr ()) -> ((FunPtr ((Ptr ()) -> (IO ()))) -> (IO (Ptr ()))))))))))))))
foreign import ccall safe "Gnome/Keyring/NetworkPassword.chs.h gnome_keyring_set_network_password_sync"
set_network_password_sync'_ :: ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr CChar) -> (CUInt -> ((Ptr CChar) -> ((Ptr CUInt) -> (IO CInt)))))))))))
foreign import ccall unsafe "Gnome/Keyring/NetworkPassword.chs.h gnome_keyring_network_password_list_free"
gnome_keyring_network_password_list_free :: ((Ptr ()) -> (IO ()))