module Ldap.Client.Delete
( delete
, deleteEither
, deleteAsync
, deleteAsyncSTM
, Async
, wait
, waitSTM
) where
import Control.Concurrent.STM (STM, atomically)
import Data.List.NonEmpty (NonEmpty((:|)))
import qualified Ldap.Asn1.Type as Type
import Ldap.Client.Internal
delete :: Ldap -> Dn -> IO ()
delete :: Ldap -> Dn -> IO ()
delete Ldap
l Dn
dn =
forall e a. Exception e => Either e a -> IO a
raise forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ldap -> Dn -> IO (Either ResponseError ())
deleteEither Ldap
l Dn
dn
deleteEither :: Ldap -> Dn -> IO (Either ResponseError ())
deleteEither :: Ldap -> Dn -> IO (Either ResponseError ())
deleteEither Ldap
l Dn
dn =
forall a. Async a -> IO (Either ResponseError a)
wait forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ldap -> Dn -> IO (Async ())
deleteAsync Ldap
l Dn
dn
deleteAsync :: Ldap -> Dn -> IO (Async ())
deleteAsync :: Ldap -> Dn -> IO (Async ())
deleteAsync Ldap
l Dn
dn =
forall a. STM a -> IO a
atomically (Ldap -> Dn -> STM (Async ())
deleteAsyncSTM Ldap
l Dn
dn)
deleteAsyncSTM :: Ldap -> Dn -> STM (Async ())
deleteAsyncSTM :: Ldap -> Dn -> STM (Async ())
deleteAsyncSTM Ldap
l Dn
dn =
let req :: Request
req = Dn -> Request
deleteRequest Dn
dn in forall a.
Ldap
-> (Response -> Either ResponseError a) -> Request -> STM (Async a)
sendRequest Ldap
l (Request -> Response -> Either ResponseError ()
deleteResult Request
req) Request
req
deleteRequest :: Dn -> Request
deleteRequest :: Dn -> Request
deleteRequest (Dn Text
dn) =
LdapDn -> Request
Type.DeleteRequest (LdapString -> LdapDn
Type.LdapDn (Text -> LdapString
Type.LdapString Text
dn))
deleteResult :: Request -> Response -> Either ResponseError ()
deleteResult :: Request -> Response -> Either ResponseError ()
deleteResult Request
req (Type.DeleteResponse (Type.LdapResult ResultCode
code (Type.LdapDn (Type.LdapString Text
dn))
(Type.LdapString Text
msg) Maybe ReferralUris
_) :| [])
| ResultCode
Type.Success <- ResultCode
code = forall a b. b -> Either a b
Right ()
| Bool
otherwise = forall a b. a -> Either a b
Left (Request -> ResultCode -> Dn -> Text -> ResponseError
ResponseErrorCode Request
req ResultCode
code (Text -> Dn
Dn Text
dn) Text
msg)
deleteResult Request
req Response
res = forall a b. a -> Either a b
Left (Request -> Response -> ResponseError
ResponseInvalid Request
req Response
res)