I've now translated the C code below into Haskell. Unfortunately, when I run hugs, it
bombs
with the following message.
/usr/local/share/hugs/lib/exts/IOExts.hs
/usr/local/share/hugs/lib/exts/Foreign.hs
/home/dom/haskelldirect/hdirect-0.16/hugs-lib/PointerPrim.hs
/usr/local/share/hugs/lib/exts/Weak.hs
/home/dom/haskelldirect/hdirect-0.16/hugs-lib/Pointer.lhs
/home/dom/haskelldirect/hdirect-0.16/hugs-lib/AddrBits.hs
/home/dom/haskelldirect/hdirect-0.16/hugs-lib/HDirect.lhs
LDAPType.hs
Ldap.hs
main.hs
Main> main
Unexpected signal
Presumably, when I call the ldap interface, it suspends the process until the
directory replies at which
point it gets woken up with a signal. But I'm not sure why hugs is picking this up.
Here's the C code which I have checked works.
/* get a handle to an LDAP connection */
if ( (ld = ldap_init( MY_HOST, MY_PORT )) == NULL ) {
perror( "ldap_init" );
return( 1 );
}
/* authenticate to the directory as nobody */
if ( ldap_simple_bind_s( ld, NULL, NULL ) != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_simple_bind_s" );
ldap_unbind( ld );
return( 1 );
}
Here's the Haskell.
module Main(main) where
import Prelude
import Ldap
import Addr
main =
do x <- ldap_init "wssun16" 389
if x == Nothing
then putStrLn "Failure"
else let Just z = x in
do (ld,y) <- ldap_simple_bind_s z "" ""
if y == 0
then putStrLn "Success"
else putStrLn "Failure"
The marshalling code for ldap_simple_bind_s is
ldap_simple_bind_s ld who passwd =
do
who <- marshallString who
passwd <- marshallString passwd
ld <- marshallLDAP ld
o_ldap_simple_bind_s <- prim_Ldap_ldap_simple_bind_s ld who passwd
freeString who
freeString passwd
ld <- doThenFree free readLDAP ld
return (ld, o_ldap_simple_bind_s)
primitive prim_Ldap_ldap_simple_bind_s :: Addr -> Addr -> Addr -> IO Int32
Dominic.
[EMAIL PROTECTED] on 30/03/2000 18:05:00
To: Dominic Steinitz
cc: erik
bcc:
Subject: RE: Help with HaskellDirect
ok, great - I have added support to HDirect now so
that the manual intervention you had to make for
the LDAP type is no longer required.
Let me know how you get on.
--sigbjorn
> -----Original Message-----
> From: Steinitz, Dominic J
> [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 29, 2000 19:32
> To: Sigbjorn Finne
> Cc: erik
> Subject: RE: Help with HaskellDirect
>
>
> This seems to work. I have
>
> [dom@lhrtba8fd85 ldap]$ more LDAPType.idl
> [deriving("Eq")]interface LDAP {};
>
>
> and in ldap.hs I have commented out the generated LDAP Haskell type
> along with all the marshallers that work over it. Hugs now
> accepts this and
> I get "Success" presumably because all the interface is doing
> is allocating
> some memory to store the parameters in.
>
> I'll add some more interesting functions like ldap_bind and
> see if I can make
> contact with the directory.
>
> Thanks, Dominic
>
>
>
>
> [EMAIL PROTECTED] on 30/03/2000 00:25:00
> To: Dominic Steinitz
> cc: erik
> bcc:
> Subject: RE: Help with HaskellDirect
>
>
> Hmm..I think there's room for improvement here on
> the HDirect side to support this automatically.
>
> "ldap.h" defines the abstract type LDAP as
>
> typedef struct ldap LDAP;
>
> HDirect supports abstract types via empty interface decls,
> e.g., to make 'gdImage' an abstract type in examples/gd/gd.idl,
> the following decl is given:
>
> [deriving("Eq"), finaliser("gdFreeImage")]
> interface gdImage {};
>
> This generates the type
>
> data GdImage = GdImage ForeignObj
> ...
>
> which wraps up (gdImage*) pointers in Haskell.
>
> That's what you want to do for LDAP, but since the defn of
> it is buried inside a header file, you can't change it.
>
> Here's what I suggest you do:
>
> * generate ldap.hs as before
> * comment out the generated LDAP Haskell type along with
> all the marshallers that work over it.
> * create a one-line IDL file containing
>
> interface LDAP{};
>
> * call it LDAPType.idl and compile it with HDirect (remembering
> to use the -fhs-to-c option)
>
> * Add an import of 'LDAPType' to LDAP.hs
>
> Notice that HDirect version 0.16 had a bug to do with the
> marshalling of pointers to empty struct types, so if the generated
> code in LDAP.hs simply isn't type correct, let me know.
>
> --sigbjorn
>
>
> > -----Original Message-----
> > From: Steinitz, Dominic J
> > [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, March 29, 2000 13:36
> > To: erik
> > Cc: Sigbjorn Finne
> > Subject: RE: Help with HaskellDirect
> >
> >
> > Erik,
> >
> > I don't think it's the IDL that's causing this to get
> > generated. Here it is:
> >
> > [dom@lhrtba8fd85 ldap]$ more ldap.idl
> > stub_include "ldap.h";
> > #include "ldap.h"
> >
> > // To avoid requiring that users have a modified cpp binary
> installed
> > // which lets you automatically convert #defines to const
> > decls, here are
> > // the ones we're interested in:
> >
> > const unsigned int lDAP_SUCCESS = LDAP_SUCCESS;
> >
> >
> > and here's the ASF:
> >
> > [dom@lhrtba8fd85 ldap]$ more ldap.asf
> > //
> > // ASF for LDAP library.
> > //
> >
> > ldap_init: [unique]
> > ldap_init.defhost : [in,string]
> > ldap_init.defport : [in]
> >
> >
> > I think it's caused by the following declaration in ldap.h:
> >
> > typedef struct ldap LDAP; /* opaque connection
> > handle */
> >
> > ldap is not defined anywhere else so you can't see inside it.
> > The C example code maninpulates pointers
> > to it and of course you can test for equality of pointers.
> >
> > Dominic.
> >
> >
> >
> >
> >
> >
> > [EMAIL PROTECTED] on 29/03/2000 20:35:00
> > To: Dominic Steinitz
> > cc: sof
> > bcc:
> > Subject: RE: Help with HaskellDirect
> >
> > Hi Dominic,
> >
> > > HaskellDirect generates the following interface for ldap_init.
> > >
> > > data LDAP = Ldap
> >
> > Is this really the code generated for LDAP? In that case your
> > function can
> > either return bottom, or the single non-trivial value Ldap.
> >
> > I am not sure wether the H/Direct generated code checks your
> > null-pointers
> > for you in this case; but Sigbjorn is the person to know that.
> >
> > I am quite curious to see the IDL.
> >
> > Erik
> >
> >
> >
> >
>
>