Remove timeout event once we are calling the callback.
[kai/samba.git] / source4 / lib / ldb / ldb_tdb / ldb_tdb.h
index 05311346f4e659f2ec38ee9020b03304521788c0..c78a8172c72bd4625ffa38ca2e4270324a9819bf 100644 (file)
@@ -1,5 +1,8 @@
-
-#ifdef STANDALONE
+#if (_SAMBA_BUILD_ == 3)
+#include "tdb/include/tdb.h"
+#else
+#include "replace.h"
+#include "system/wait.h"
 #include "tdb.h"
 #endif
 
@@ -11,22 +14,43 @@ struct ltdb_private {
        
        /* a double is used for portability and ease of string
           handling. It has plenty of digits of precision */
-       double sequence_number;
+       unsigned long long sequence_number;
+
+       /* the low level tdb seqnum - used to avoid loading BASEINFO when
+          possible */
+       int tdb_seqnum;
 
-       struct {
-               struct ldb_message baseinfo;
-               struct ldb_message indexlist;
-               struct ldb_message attributes;
-               struct ldb_message subclasses;
+       struct ltdb_cache {
+               struct ldb_message *indexlist;
+               struct ldb_message *attributes;
 
                struct {
                        char *name;
                        int flags;
                } last_attribute;
-       } cache;
+       } *cache;
 
-       /* error if an internal ldb+tdb error */
-       const char *last_err_string;
+       int in_transaction;
+
+       bool check_base;
+};
+
+/*
+  the async local context
+  holds also internal search state during a full db search
+*/
+struct ltdb_context {
+       struct ldb_module *module;
+       struct ldb_request *req;
+
+       bool callback_failed;
+
+       /* search stuff */
+       const struct ldb_parse_tree *tree;
+       struct ldb_dn *base;
+       enum ldb_scope scope;
+       const char * const *attrs;
+       struct timed_event *timeout_event;
 };
 
 /* special record types */
@@ -34,39 +58,32 @@ struct ltdb_private {
 #define LTDB_INDEXLIST  "@INDEXLIST"
 #define LTDB_IDX        "@IDX"
 #define LTDB_IDXATTR    "@IDXATTR"
+#define LTDB_IDXONE     "@IDXONE"
 #define LTDB_BASEINFO   "@BASEINFO"
+#define LTDB_OPTIONS    "@OPTIONS"
 #define LTDB_ATTRIBUTES "@ATTRIBUTES"
-#define LTDB_SUBCLASSES "@SUBCLASSES"
 
 /* special attribute types */
 #define LTDB_SEQUENCE_NUMBER "sequenceNumber"
+#define LTDB_CHECK_BASE "checkBaseOnSearch"
+#define LTDB_MOD_TIMESTAMP "whenChanged"
 #define LTDB_OBJECTCLASS "objectClass"
 
-/* well known attribute flags */
-#define LTDB_FLAG_CASE_INSENSITIVE (1<<0)
-#define LTDB_FLAG_INTEGER          (1<<1)
-#define LTDB_FLAG_WILDCARD         (1<<2)
-#define LTDB_FLAG_OBJECTCLASS      (1<<3)
-#define LTDB_FLAG_HIDDEN           (1<<4)
-
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_cache.c  */
 
-void ltdb_cache_free(struct ldb_module *module);
+int ltdb_cache_reload(struct ldb_module *module);
 int ltdb_cache_load(struct ldb_module *module);
 int ltdb_increase_sequence_number(struct ldb_module *module);
-int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name);
+int ltdb_check_at_attributes_values(const struct ldb_val *value);
 
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_index.c  */
 
 struct ldb_parse_tree;
 
-int ltdb_search_indexed(struct ldb_module *module, 
-                       const char *base,
-                       enum ldb_scope scope,
-                       struct ldb_parse_tree *tree,
-                       const char * const attrs[], struct ldb_message ***res);
+int ltdb_search_indexed(struct ltdb_context *ctx);
 int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg);
 int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg);
+int ltdb_index_one(struct ldb_module *module, const struct ldb_message *msg, int add);
 int ltdb_reindex(struct ldb_module *module);
 
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_pack.c  */
@@ -85,34 +102,28 @@ int ltdb_unpack_data(struct ldb_module *module,
 int ltdb_has_wildcard(struct ldb_module *module, const char *attr_name, 
                      const struct ldb_val *val);
 void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
-int ltdb_search_dn1(struct ldb_module *module, const char *dn, struct ldb_message *msg);
-int ltdb_search_dn(struct ldb_module *module, char *dn,
-                  const char * const attrs[], struct ldb_message ***res);
-int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
+int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg);
+int ltdb_add_attr_results(struct ldb_module *module,
+                         TALLOC_CTX *mem_ctx, 
+                         struct ldb_message *msg,
                          const char * const attrs[], 
-                         int *count, 
+                         unsigned int *count, 
                          struct ldb_message ***res);
-int ltdb_search_free(struct ldb_module *module, struct ldb_message **msgs);
-int ltdb_search(struct ldb_module *module, const char *base,
-               enum ldb_scope scope, const char *expression,
-               const char * const attrs[], struct ldb_message ***res);
+int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs);
+int ltdb_search(struct ltdb_context *ctx);
 
 /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c  */
-struct TDB_DATA ltdb_key(struct ldb_module *module, const char *dn);
+int ltdb_lock_read(struct ldb_module *module);
+int ltdb_unlock_read(struct ldb_module *module);
+struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn);
 int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs);
-int ltdb_delete_noindex(struct ldb_module *module, const char *dn);
+int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn);
 int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg);
 
-/* The following definitions come from lib/ldb/ldb_tdb/ldb_match.c  */
-int ltdb_val_equal(struct ldb_module *module,
-                 const char *attr_name,
-                 const struct ldb_val *v1, const struct ldb_val *v2);
-int ltdb_message_match(struct ldb_module *module, 
-                     struct ldb_message *msg,
-                     struct ldb_parse_tree *tree,
-                     const char *base,
-                     enum ldb_scope scope);
-
 int ltdb_index_del_value(struct ldb_module *module, const char *dn, 
                         struct ldb_message_element *el, int v_idx);
 
+struct tdb_context *ltdb_wrap_open(TALLOC_CTX *mem_ctx,
+                                  const char *path, int hash_size, int tdb_flags,
+                                  int open_flags, mode_t mode,
+                                  struct ldb_context *ldb);