ldb-hs: Import work on Haskell bindings for LDB

Jelmer Vernooij jelmer at samba.org
Sun May 11 23:19:01 GMT 2008


Mon Nov 28 16:21:35 CET 2005  Jelmer Vernooij <jelmer at samba.org>
  * Import work on Haskell bindings for LDB

    A ./LDB.chs
    A ./Makefile
    A ./test.hs

Mon Nov 28 16:21:35 CET 2005  Jelmer Vernooij <jelmer at samba.org>
  * Import work on Haskell bindings for LDB
diff -rN -u old-ldb-hs/LDB.chs new-ldb-hs/LDB.chs
--- old-ldb-hs/LDB.chs	1970-01-01 01:00:00.000000000 +0100
+++ new-ldb-hs/LDB.chs	2008-05-12 01:19:01.000000000 +0200
@@ -0,0 +1,121 @@
+{-
+	Haskell bindings for LDB
+
+	Copyright (C) Jelmer Vernooij 2005
+
+     ** NOTE! The following LGPL license applies to the ldb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+	 
+   	This library is free software; you can redistribute it and/or
+	modify it under the terms of the GNU Lesser General Public
+   	License as published by the Free Software Foundation; either
+   	version 2 of the License, or (at your option) any later version.
+
+   	This library is distributed in the hope that it will be useful,
+   	but WITHOUT ANY WARRANTY; without even the implied warranty of
+   	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   	Lesser General Public License for more details.
+
+   	You should have received a copy of the GNU Lesser General Public
+   	License along with this library; if not, write to the Free Software
+   	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+-}
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "../include/ldb.h"
+
+module LDB (Element, Message, Context, connect, search, add, modify, delete,
+			rename, parseDn)
+where
+
+import Foreign
+import Foreign.Ptr
+import Foreign.C.String
+import Foreign.C.Types
+import Monad
+
+{#context lib = "ldb"#}
+{#context prefix = "ldb"#}
+
+{#enum ldb_changetype as Changetype {underscoreToCase}#}
+{#enum ldb_scope as Scope {underscoreToCase}#}
+{#enum ldb_debug_level as DebugLevel {underscoreToCase}#}
+
+-- Only used internally
+{#pointer *ldb_message as LMessage newtype#}
+{#pointer *ldb_dn as LDn newtype#}
+
+{#pointer *ldb_context as Context newtype#}
+
+data Element = Element {
+	name :: String,
+	value :: [String],
+	flags :: Int
+}
+
+data Message = Message {
+	dn :: Dn,
+	elements :: [Element]
+}
+
+-- Convert from LMessage to Message
+fromLMessage :: LMessage -> Message
+fromLMessage = undefined -- FIXME
+
+toLMessage :: Message -> LMessage
+toLMessage = undefined -- FIXME
+
+data Dn = EmptyDn
+		| Child String String Dn
+		| Special String
+
+fromLDn :: LDn -> Dn
+fromLDn = undefined -- FIXME
+
+toLDn :: Dn -> LDn
+toLDn = undefined -- FIXME
+
+ldbException :: String
+ldbException = "An LDB error occurred"
+
+connect :: String -> [String] -> IO Context
+connect url opts = do
+	ctx <- {#call unsafe ldb_init#} nullPtr
+	mem <- newCString url
+	{#call unsafe ldb_connect#} ctx mem 0 undefined
+	free mem
+	return ctx
+
+search :: Context -> Dn -> Scope -> String -> [String] -> IO [Message]
+search ctx dn sc expr attrs = do
+	mem <- newCString expr
+	{#call unsafe ldb_search#} ctx (toLDn dn) sc mem []
+	free mem
+	return [] -- FIXME
+
+add :: Context -> Message -> IO ()
+add ctx msg = do
+	{#call unsafe ldb_add#} ctx $ toLMessage msg
+	return ()
+
+modify :: Context -> Message -> IO ()
+modify ctx msg = do
+	{#call unsafe ldb_modify#} ctx $ toLMessage msg
+	return ()
+
+delete :: Context -> Dn -> IO ()
+delete ctx dn = do
+	{#call unsafe ldb_delete#} ctx $ toLDn dn
+	return ()
+
+rename :: Context -> Dn -> Dn -> IO ()
+rename ctx od nd = do
+	{#call unsafe ldb_rename#} ctx (toLDn od) (toLDn nd)
+	return ()
+
+parseDn :: String -> LDn
+parseDn s = do
+	return $ {#call ldb_dn_explode#} nullPtr $ withCString s
diff -rN -u old-ldb-hs/Makefile new-ldb-hs/Makefile
--- old-ldb-hs/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ new-ldb-hs/Makefile	2008-05-12 01:19:01.000000000 +0200
@@ -0,0 +1,18 @@
+HC ?= ghc
+HCFLAGS += -fglasgow-exts 
+C2HS = c2hs
+C2HSFLAGS = -l
+
+all: LDB.hs
+
+%.o: %.hs
+	$(HC) $(HCFLAGS) -L. $<
+
+test: test.o LDB.o
+	$(HC) $(HCFLAGS) -L. $^
+	
+clean:
+	rm -f LDB.hs LDB.chi LDB.h *.hi *.o
+
+%.hs: %.chs
+	$(C2HS) $(C2HSFLAGS) $<
diff -rN -u old-ldb-hs/test.hs new-ldb-hs/test.hs
--- old-ldb-hs/test.hs	1970-01-01 01:00:00.000000000 +0100
+++ new-ldb-hs/test.hs	2008-05-12 01:19:01.000000000 +0200
@@ -0,0 +1,6 @@
+module Main 
+where 
+import LDB
+
+main :: IO ()
+main = putStr "bla"




More information about the samba-cvs mailing list