File: Result.hsc

package info (click to toggle)
ldap-haskell 0.6.10-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 148 kB
  • sloc: haskell: 83; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,681 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{- -*- Mode: haskell; -*-
Haskell LDAP Interface
Copyright (C) 2005 John Goerzen <jgoerzen@complete.org>

This code is under a 3-clause BSD license; see COPYING for details.
-}

{- |
   Module     : LDAP.Result
   Copyright  : Copyright (C) 2005 John Goerzen
   License    : BSD

   Maintainer : John Goerzen,
   Maintainer : jgoerzen\@complete.org
   Stability  : provisional
   Portability: portable

LDAP Result Processing

Written by John Goerzen, jgoerzen\@complete.org
-}

module LDAP.Result (LDAPMessage, CLDAPMessage,
                    ldap_1result
                   ) where

import LDAP.Utils
import LDAP.Types
import Foreign
#if (__GLASGOW_HASKELL__>=705)
import Foreign.C.Types(CInt(..))
#endif

#include <ldap.h>

data CLDAPMessage
type LDAPMessage = ForeignPtr CLDAPMessage

{- | Get 1 result from an operation. -}
ldap_1result :: LDAP -> LDAPInt -> IO (LDAPMessage)
ldap_1result ld msgid =
    withLDAPPtr ld (\cld ->
    alloca (f cld)
    )
    where f cld (ptr::Ptr (Ptr CLDAPMessage)) =
              do checkLEn1 "ldap_1result" ld $
                         ldap_result cld msgid 0 nullPtr ptr
                 fromldmptr "ldap_1result" (peek ptr)

fromldmptr :: String -> IO (Ptr CLDAPMessage) -> IO LDAPMessage
fromldmptr caller action =
    do ptr <- action
       if ptr == nullPtr
          then fail (caller ++ ": got null LDAPMessage pointer")
          else newForeignPtr ldap_msgfree_call ptr

foreign import ccall unsafe "ldap.h ldap_result"
  ldap_result :: LDAPPtr -> LDAPInt -> LDAPInt -> Ptr () -> Ptr (Ptr CLDAPMessage) -> IO LDAPInt

foreign import ccall unsafe "ldap.h &ldap_msgfree"
  ldap_msgfree_call :: FunPtr (Ptr CLDAPMessage -> IO ())