r26581: Make ldb_wait uniform, so that it is easy to remove it completely from modules
authorSimo Sorce <idra@samba.org>
Mon, 24 Dec 2007 07:38:37 +0000 (01:38 -0600)
committerStefan Metzmacher <metze@samba.org>
Mon, 24 Dec 2007 07:51:07 +0000 (01:51 -0600)
later on.
(This used to be commit f75ce8c20aa2b466e9ee86fdf1702b2ffda10ddf)

source4/lib/ldb/modules/asq.c
source4/lib/ldb/modules/paged_results.c
source4/lib/ldb/modules/paged_searches.c
source4/lib/ldb/modules/rdn_name.c
source4/lib/ldb/modules/sort.c

index c0d6a7c18c0c7ee1f601053eeb2505ee19529e78..b6a85941664044e4e5e65f046a0da85dbcfc0e32 100644 (file)
@@ -429,27 +429,26 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req)
        return asq_search_continue(h);
 }
 
-static int asq_wait_all(struct ldb_handle *handle)
+static int asq_wait(struct ldb_handle *handle, enum ldb_wait_type type)
 {
        int ret;
 
-       while (handle->state != LDB_ASYNC_DONE) {
-               ret = asq_search_continue(handle);
-               if (ret != LDB_SUCCESS) {
-                       return ret;
-               }
+       if (!handle || !handle->private_data) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       return handle->status;
-}
-
-static int asq_wait(struct ldb_handle *handle, enum ldb_wait_type type)
-{
        if (type == LDB_WAIT_ALL) {
-               return asq_wait_all(handle);
-       } else {
-               return asq_search_continue(handle);
+               while (handle->state != LDB_ASYNC_DONE) {
+                       ret = asq_search_continue(handle);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+
+               return handle->status;
        }
+
+       return asq_search_continue(handle);
 }
 
 static int asq_init(struct ldb_module *module)
index 61fce2125fbe07d8123fac48fd679cf87ecc699e..ee1bbe03353799cf4c6dd593c1342dabdda04ee1 100644 (file)
@@ -440,8 +440,7 @@ static int paged_results(struct ldb_handle *handle)
        return ret;
 }
 
-static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type)
-{
+static int paged_wait_once(struct ldb_handle *handle) {
        struct paged_context *ac;
        int ret;
     
@@ -471,28 +470,7 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type)
                return ret;
        }
 
-       if (type == LDB_WAIT_ALL) {
-               while (ac->store->req->handle->state != LDB_ASYNC_DONE) {
-                       ret = ldb_wait(ac->store->req->handle, type);
-                       if (ret != LDB_SUCCESS) {
-                               handle->state = LDB_ASYNC_DONE;
-                               handle->status = ret;
-                               return ret;
-                       }
-               }
-
-               ret = paged_results(handle);
-
-               /* we are done, if num_entries is zero free the storage
-                * as that mean we delivered the last batch */
-               if (ac->store->num_entries == 0) {
-                       talloc_free(ac->store);
-               }
-
-               return ret;
-       }
-
-       ret = ldb_wait(ac->store->req->handle, type);
+       ret = ldb_wait(ac->store->req->handle, LDB_WAIT_NONE);
        if (ret != LDB_SUCCESS) {
                handle->state = LDB_ASYNC_DONE;
                handle->status = ret;
@@ -516,6 +494,28 @@ static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type)
        return ret;
 }
 
+static int paged_wait(struct ldb_handle *handle, enum ldb_wait_type type)
+{
+       int ret;
+       if (!handle || !handle->private_data) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       if (type == LDB_WAIT_ALL) {
+               while (handle->state != LDB_ASYNC_DONE) {
+                       ret = paged_wait_once(handle);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+
+               return handle->status;
+       }
+
+       return paged_wait_once(handle);
+}
+
 static int paged_request_init(struct ldb_module *module)
 {
        struct private_data *data;
index 749858b49b3221ce8e48b647e3177588a284cd9b..fd580a3c4ac2ed038484791dbb5dba0fd579589a 100644 (file)
@@ -312,7 +312,7 @@ static int ps_continuation(struct ldb_handle *handle)
        return ldb_next_request(handle->module, ac->new_req);
 }
 
-static int ps_wait_none(struct ldb_handle *handle)
+static int ps_wait_once(struct ldb_handle *handle)
 {
        struct ps_context *ac;
        int ret;
@@ -365,27 +365,25 @@ done:
        return ret;
 }
 
-static int ps_wait_all(struct ldb_handle *handle)
+static int ps_wait(struct ldb_handle *handle, enum ldb_wait_type type)
 {
        int ret;
 
-       while (handle->state != LDB_ASYNC_DONE) {
-               ret = ps_wait_none(handle);
-               if (ret != LDB_SUCCESS) {
-                       return ret;
-               }
+       if (!handle || !handle->private_data) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       return handle->status;
-}
-
-static int ps_wait(struct ldb_handle *handle, enum ldb_wait_type type)
-{
        if (type == LDB_WAIT_ALL) {
-               return ps_wait_all(handle);
-       } else {
-               return ps_wait_none(handle);
+               while (handle->state != LDB_ASYNC_DONE) {
+                       ret = ps_wait_once(handle);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+
+               return handle->status;
        }
+       return ps_wait_once(handle);
 }
 
 static int check_supported_paged(struct ldb_context *ldb, void *context, 
index 4a95efe7d60bddd5d74d00530e548b69c76e5741..1a0ddbb3c462515b9571c829793935407dadcce1 100644 (file)
@@ -238,7 +238,7 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) {
        return ldb_request(h->module->ldb, ac->mod_req);
 }
 
-static int rename_wait(struct ldb_handle *handle)
+static int rdn_name_wait_once(struct ldb_handle *handle)
 {
        struct rename_context *ac;
        int ret;
@@ -304,27 +304,26 @@ done:
        return ret;
 }
 
-static int rename_wait_all(struct ldb_handle *handle) {
-
+static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type)
+{
        int ret;
-
-       while (handle->state != LDB_ASYNC_DONE) {
-               ret = rename_wait(handle);
-               if (ret != LDB_SUCCESS) {
-                       return ret;
-               }
+       if (!handle || !handle->private_data) {
+               return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       return handle->status;
-}
-
-static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type)
-{
        if (type == LDB_WAIT_ALL) {
-               return rename_wait_all(handle);
-       } else {
-               return rename_wait(handle);
+               while (handle->state != LDB_ASYNC_DONE) {
+                       ret = rdn_name_wait_once(handle);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+
+               return handle->status;
        }
+
+       return rdn_name_wait_once(handle);
 }
 
 static const struct ldb_module_ops rdn_name_ops = {
index b13dbe579bf3ba2ed72ba25f4b7e19cbae288c22..89b9a4fb19c69ae96dda928e356f57099c4ecee0 100644 (file)
@@ -373,7 +373,7 @@ static int server_sort_results(struct ldb_handle *handle)
        return LDB_SUCCESS;
 }
 
-static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type)
+static int server_sort_wait_once(struct ldb_handle *handle)
 {
        struct sort_context *ac;
        int ret;
@@ -384,7 +384,7 @@ static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type)
 
        ac = talloc_get_type(handle->private_data, struct sort_context);
 
-       ret = ldb_wait(ac->req->handle, type);
+       ret = ldb_wait(ac->req->handle, LDB_WAIT_NONE);
 
        if (ret != LDB_SUCCESS) {
                handle->status = ret;
@@ -405,6 +405,28 @@ static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type)
        return ret;
 }
 
+static int server_sort_wait(struct ldb_handle *handle, enum ldb_wait_type type)
+{
+       int ret;
+       if (!handle || !handle->private_data) {
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       if (type == LDB_WAIT_ALL) {
+               while (handle->state != LDB_ASYNC_DONE) {
+                       ret = server_sort_wait_once(handle);
+                       if (ret != LDB_SUCCESS) {
+                               return ret;
+                       }
+               }
+
+               return handle->status;
+       }
+
+       return server_sort_wait_once(handle);
+}
+
 static int server_sort_init(struct ldb_module *module)
 {
        struct ldb_request *req;