~jmillikin/+junk/gsasl

« back to all changes in this revision

Viewing changes to Network/Protocol/SASL/GSASL.chs

  • Committer: John Millikin
  • Date: 2009-06-28 04:34:27 UTC
  • Revision ID: jmillikin@gmail.com-20090628043427-62g3o64v5e29934a
Add functions for managing the lifetimes of sessions and contexts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        
33
33
        -- * Context procedures
34
34
        ,mkContext
 
35
        ,freeContext
 
36
        ,withContext
35
37
        ,clientMechanisms
36
38
        ,serverMechanisms
37
39
        ,clientSupportP
50
52
        -- * Session procedures
51
53
        ,clientStart
52
54
        ,serverStart
 
55
        ,freeSession
 
56
        ,withSession
53
57
        ,step
54
58
        ,step64
55
59
        ,encode
133
137
        id `Ptr ContextPtr'
134
138
        } -> `()' checkRC* #}
135
139
 
136
 
{- -- TODO: make this automatic in mkContext
137
 
{#fun gsasl_done {
 
140
freeContext :: Context -> IO ()
 
141
freeContext ctxt = do
 
142
        hook <- callbackHookGet (rawContext ctxt)
 
143
        freeStablePtr . castPtrToStablePtr $ hook
 
144
        gsasl_done ctxt
 
145
 
 
146
{#fun gsasl_done  {
138
147
        rawContext `Context'
139
148
        } -> `()' #}
140
 
-}
 
149
 
 
150
withContext :: (Context -> IO a) -> IO a
 
151
withContext = bracket mkContext freeContext
141
152
 
142
153
clientMechanisms :: Context -> IO [String]
143
154
clientMechanisms ctxt =
191
202
mkCallbackWrapper :: CallbackComputation -> (FunPtr CallbackComputationPtr -> IO a) -> IO a
192
203
mkCallbackWrapper comp block = bracket
193
204
        (callbackWrapper $ mkCallbackWrapper' comp)
194
 
        --(freeHaskellFunPtr)
 
205
        --(freeHaskellFunPtr) -- TODO
195
206
        (\_ -> return ())
196
207
        (block)
197
208
 
285
296
        ,id `Ptr SessionPtr'
286
297
        } -> `()' checkRC* #}
287
298
 
 
299
freeSession :: Session -> IO ()
 
300
freeSession session = do
 
301
        hook <- sessionHookGet (rawSession session)
 
302
        freeStablePtr . castPtrToStablePtr $ hook
 
303
        gsasl_finish session
 
304
 
 
305
{#fun gsasl_finish {
 
306
         rawSession `Session'
 
307
        } -> `()' #}
 
308
 
 
309
withSession :: IO Session -> (Session -> IO a) -> IO a
 
310
withSession getSession = bracket getSession freeSession
 
311
 
288
312
step :: Session -> String -> IO (String, ReturnCode)
289
313
step s input =
290
314
        withCStringLen input $ \(cInput, cInputLen) -> do
313
337
gsasl_step64 :: SessionPtr -> CString -> Ptr CString -> IO CInt
314
338
gsasl_step64 = {#call gsasl_step64 as gsasl_step64' #}
315
339
 
316
 
{- -- TODO: make this automatic in client/serverStart
317
 
{#fun gsasl_finish as finish {
318
 
         rawSession `Session'
319
 
        } -> `()' #}
320
 
-}
321
 
 
322
340
encode :: Session -> String -> IO String
323
341
encode = encodeDecodeImpl {#call gsasl_encode #}
324
342