svn commit: samba r25629 - in branches/4.0-python: . source/lib/ldb/swig

jelmer at samba.org jelmer at samba.org
Sun Oct 14 14:24:28 GMT 2007


Author: jelmer
Date: 2007-10-14 14:24:27 +0000 (Sun, 14 Oct 2007)
New Revision: 25629

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25629

Log:
Wrap ldb_dn, rename 'ldb' to Ldb to comply with python standards, allowing connecting immediately using the constructor.
Modified:
   branches/4.0-python/
   branches/4.0-python/source/lib/ldb/swig/ldb.i


Changeset:

Property changes on: branches/4.0-python
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/4.0-python/source/lib/ldb/swig/ldb.i
===================================================================
--- branches/4.0-python/source/lib/ldb/swig/ldb.i	2007-10-14 13:28:01 UTC (rev 25628)
+++ branches/4.0-python/source/lib/ldb/swig/ldb.i	2007-10-14 14:24:27 UTC (rev 25629)
@@ -5,6 +5,7 @@
 
    Copyright (C) 2005,2006 Tim Potter <tpot at samba.org>
    Copyright (C) 2006 Simo Sorce <idra at samba.org>
+   Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
 
      ** NOTE! The following LGPL license applies to the ldb
      ** library. This does NOT imply that all of Samba is released
@@ -39,68 +40,19 @@
 #include <stdbool.h>
 #include "talloc.h"
 #include "ldb.h"
+#include "ldb_errors.h"
 
 typedef struct ldb_message ldb_msg;
 typedef struct ldb_message_element ldb_msg_element;
 typedef struct ldb_context ldb;
+typedef struct ldb_dn ldb_dn;
 
 %}
 
 %include "carrays.i"
-%include "exception.i"
 %include "typemaps.i"
+%include "exception.i"
 
-/*
- * Constants
- */
-
-#define LDB_SUCCESS				0
-#define LDB_ERR_OPERATIONS_ERROR		1
-#define LDB_ERR_PROTOCOL_ERROR			2
-#define LDB_ERR_TIME_LIMIT_EXCEEDED		3
-#define LDB_ERR_SIZE_LIMIT_EXCEEDED		4
-#define LDB_ERR_COMPARE_FALSE			5
-#define LDB_ERR_COMPARE_TRUE			6
-#define LDB_ERR_AUTH_METHOD_NOT_SUPPORTED	7
-#define LDB_ERR_STRONG_AUTH_REQUIRED		8
-/* 9 RESERVED */
-#define LDB_ERR_REFERRAL			10
-#define LDB_ERR_ADMIN_LIMIT_EXCEEDED		11
-#define LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION	12
-#define LDB_ERR_CONFIDENTIALITY_REQUIRED	13
-#define LDB_ERR_SASL_BIND_IN_PROGRESS		14
-#define LDB_ERR_NO_SUCH_ATTRIBUTE		16
-#define LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE	17
-#define LDB_ERR_INAPPROPRIATE_MATCHING		18
-#define LDB_ERR_CONSTRAINT_VIOLATION		19
-#define LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS	20
-#define LDB_ERR_INVALID_ATTRIBUTE_SYNTAX	21
-/* 22-31 unused */
-#define LDB_ERR_NO_SUCH_OBJECT			32
-#define LDB_ERR_ALIAS_PROBLEM			33
-#define LDB_ERR_INVALID_DN_SYNTAX		34
-/* 35 RESERVED */
-#define LDB_ERR_ALIAS_DEREFERENCING_PROBLEM	36
-/* 37-47 unused */
-#define LDB_ERR_INAPPROPRIATE_AUTHENTICATION	48
-#define LDB_ERR_INVALID_CREDENTIALS		49
-#define LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS	50
-#define LDB_ERR_BUSY				51
-#define LDB_ERR_UNAVAILABLE			52
-#define LDB_ERR_UNWILLING_TO_PERFORM		53
-#define LDB_ERR_LOOP_DETECT			54
-/* 55-63 unused */
-#define LDB_ERR_NAMING_VIOLATION		64
-#define LDB_ERR_OBJECT_CLASS_VIOLATION		65
-#define LDB_ERR_NOT_ALLOWED_ON_NON_LEAF		66
-#define LDB_ERR_NOT_ALLOWED_ON_RDN		67
-#define LDB_ERR_ENTRY_ALREADY_EXISTS		68
-#define LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED	69
-/* 70 RESERVED FOR CLDAP */
-#define LDB_ERR_AFFECTS_MULTIPLE_DSAS		71
-/* 72-79 unused */
-#define LDB_ERR_OTHER				80
-
 enum ldb_scope {LDB_SCOPE_DEFAULT=-1, 
 		LDB_SCOPE_BASE=0, 
 		LDB_SCOPE_ONELEVEL=1,
@@ -123,12 +75,6 @@
  * Wrap a small bit of talloc
  */
 
-/* Use talloc_init() to create a parameter to pass to ldb_init().  Don't
-   forget to free it using talloc_free() afterwards. */
-
-TALLOC_CTX *talloc_init(char *name);
-int talloc_free(TALLOC_CTX *ptr);
-
 /*
  * Wrap struct ldb_val
  */
@@ -175,9 +121,25 @@
 } ldb_msg_element;
 
 /*
- * Wrap struct ldb_message
+ * Wrap struct ldb_dn
  */
 
+typedef struct ldb_dn {
+    %extend {
+        ldb_dn(ldb *ldb, const char *str)
+        {
+            ldb_dn *ret = ldb_dn_new(NULL, ldb, str);
+            if (ret == NULL)
+                SWIG_exception(SWIG_ValueError, "unable to parse dn string");
+fail:
+            return ret;
+        }
+        bool validate();
+        const char *get_casefold();
+        const char *get_linearized();
+    }
+} ldb_dn;
+
 %array_functions(struct ldb_message_element, ldb_message_element_array);
 
 %apply ldb_msg_element **OUTPUT { ldb_msg_element **return_el };
@@ -198,6 +160,10 @@
 
 %array_functions(struct ldb_message *, ldb_message_ptr_array);
 
+/* FIXME: Convert ldb_result to 3-tuple:
+   (msgs, refs, controls)
+ */
+
 struct ldb_result {
 	unsigned int count;
 	ldb_msg **msgs;
@@ -209,42 +175,43 @@
  * Wrap ldb functions 
  */
 
-/* Initialisation */
-
-int ldb_global_init(void);
-struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx);
-
 /* Error handling */
 
 const char *ldb_errstring(struct ldb_context *ldb);
 const char *ldb_strerror(int ldb_err);
 
+%rename(Ldb) ldb;
 /* Top-level ldb operations */
-
 typedef struct ldb_context {
     %extend {
-        new();
-        int connect(const char *url, unsigned int flags = 0, const char *options[] = NULL);
-        int search(struct ldb_dn *base = NULL, enum ldb_scope scope = LDB_SCOPE_DEFAULT, const char *expression = NULL, const char * const *attrs = NULL, struct ldb_result **OUT);
+        ldb(const char *url, unsigned int flags = 0, 
+            const char *options[] = NULL)
+        {
+            ldb *ldb = ldb_init(NULL);
+            int ret = ldb_connect(ldb, url, flags, options);
+            if (ret != LDB_SUCCESS) {
+                SWIG_exception(SWIG_ValueError, ldb_errstring(ldb));
+            }
+            return ldb;
+
+fail:
+            return NULL;
+        }
+        ~ldb() { talloc_free($self); }
+        int search(struct ldb_dn *base = NULL, 
+                   enum ldb_scope scope = LDB_SCOPE_DEFAULT, 
+                   const char *expression = NULL, 
+                   const char * const *attrs = NULL, 
+                   struct ldb_result **OUT);
         int delete(struct ldb_dn *dn);
         int rename(struct ldb_dn *olddn, struct ldb_dn *newdn);
         int add(ldb_msg *message);
+        ldb_dn *get_config_basedn();
+        ldb_dn *get_root_basedn();
+        ldb_dn *get_schema_basedn();
+        ldb_dn *get_default_basedn();
     }
 } ldb;
 
-/* Ldb message operations */
-
-ldb_msg *ldb_msg_new(void *mem_ctx);
-
-int ldb_msg_sanity_check(struct ldb_context *ldb, const struct ldb_message *msg);
-
-/* DN operations */
-
-/* struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn); */
-
-/* char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *dn); */
-
 %nodefault ldb_message;
 %nodefault ldb;
-%newobject ldb_msg_new;
-%rename(ldb_context) Ldb;



More information about the samba-cvs mailing list