s3:smbd: convert notify db to use dbwrap wrapper functions
authorMichael Adam <obnox@samba.org>
Wed, 24 Aug 2011 23:35:16 +0000 (01:35 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 11 Oct 2011 12:17:57 +0000 (14:17 +0200)
Avoid direct use of the db_record and db_context structs.

source3/smbd/notify_internal.c

index 2dd8557a87a73e8ce55994ba2a69f24d9791456b..4f2749e17d0000815224fd6b1d8f9a2ed68cf8ac 100644 (file)
@@ -119,8 +119,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
        notify->messaging_ctx = messaging_ctx;
        notify->list = NULL;
        notify->array = NULL;
-       notify->seqnum = notify->db_recursive->get_seqnum(
-               notify->db_recursive);
+       notify->seqnum = dbwrap_get_seqnum(notify->db_recursive);
        notify->key = string_term_tdb_data(NOTIFY_KEY);
 
        talloc_set_destructor(notify, notify_destructor);
@@ -172,8 +171,7 @@ bool notify_internal_parent_init(TALLOC_CTX *mem_ctx)
 */
 static NTSTATUS notify_fetch_locked(struct notify_context *notify, struct db_record **rec)
 {
-       *rec = notify->db_recursive->fetch_locked(notify->db_recursive,
-                                                 notify, notify->key);
+       *rec = dbwrap_fetch_locked(notify->db_recursive, notify, notify->key);
        if (*rec == NULL) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
@@ -190,7 +188,7 @@ static NTSTATUS notify_load(struct notify_context *notify, struct db_record *rec
        NTSTATUS status;
        int seqnum;
 
-       seqnum = notify->db_recursive->get_seqnum(notify->db_recursive);
+       seqnum = dbwrap_get_seqnum(notify->db_recursive);
 
        if (seqnum == notify->seqnum && notify->array != NULL) {
                return NT_STATUS_OK;
@@ -203,12 +201,13 @@ static NTSTATUS notify_load(struct notify_context *notify, struct db_record *rec
        NT_STATUS_HAVE_NO_MEMORY(notify->array);
 
        if (!rec) {
-               if (notify->db_recursive->fetch(notify->db_recursive, notify,
-                                               notify->key, &dbuf) != 0) {
+               status = dbwrap_fetch(notify->db_recursive, notify,
+                                     notify->key, &dbuf);
+               if (!NT_STATUS_IS_OK(status)) {
                        return NT_STATUS_INTERNAL_DB_CORRUPTION;
                }
        } else {
-               dbuf = rec->value;
+               dbuf = dbwrap_record_get_value(rec);
        }
 
        blob.data = (uint8 *)dbuf.dptr;
@@ -228,7 +227,7 @@ static NTSTATUS notify_load(struct notify_context *notify, struct db_record *rec
 
                        ZERO_STRUCTP(notify->array);
                        if (rec != NULL) {
-                               rec->delete_rec(rec);
+                               dbwrap_record_delete(rec);
                        }
 
                } else {
@@ -274,7 +273,7 @@ static NTSTATUS notify_save(struct notify_context *notify, struct db_record *rec
 
        /* we might just be able to delete the record */
        if (notify->array->num_depths == 0) {
-               return rec->delete_rec(rec);
+               return dbwrap_record_delete(rec);
        }
 
        tmp_ctx = talloc_new(notify);
@@ -295,7 +294,7 @@ static NTSTATUS notify_save(struct notify_context *notify, struct db_record *rec
        dbuf.dptr = blob.data;
        dbuf.dsize = blob.length;
 
-       status = rec->store(rec, dbuf, TDB_REPLACE);
+       status = dbwrap_record_store(rec, dbuf, TDB_REPLACE);
        talloc_free(tmp_ctx);
 
        return status;
@@ -412,6 +411,7 @@ static void notify_add_onelevel(struct notify_context *notify,
        struct db_record *rec;
        DATA_BLOB blob;
        TDB_DATA dbuf;
+       TDB_DATA value;
        enum ndr_err_code ndr_err;
        NTSTATUS status;
 
@@ -420,9 +420,9 @@ static void notify_add_onelevel(struct notify_context *notify,
                return;
        }
 
-       rec = notify->db_onelevel->fetch_locked(
-               notify->db_onelevel, talloc_tos(),
-               make_tdb_data((uint8_t *)&e->dir_id, sizeof(e->dir_id)));
+       rec = dbwrap_fetch_locked(notify->db_onelevel, talloc_tos(),
+                                 make_tdb_data((uint8_t *)&e->dir_id,
+                                  sizeof(e->dir_id)));
        if (rec == NULL) {
                DEBUG(10, ("notify_add_onelevel: fetch_locked for %s failed"
                           "\n", file_id_string_tos(&e->dir_id)));
@@ -430,8 +430,9 @@ static void notify_add_onelevel(struct notify_context *notify,
                return;
        }
 
-       blob.data = (uint8_t *)rec->value.dptr;
-       blob.length = rec->value.dsize;
+       value = dbwrap_record_get_value(rec);
+       blob.data = (uint8_t *)value.dptr;
+       blob.length = value.dsize;
 
        if (blob.length > 0) {
                ndr_err = ndr_pull_struct_blob(&blob, array, array,
@@ -477,7 +478,7 @@ static void notify_add_onelevel(struct notify_context *notify,
        dbuf.dptr = blob.data;
        dbuf.dsize = blob.length;
 
-       status = rec->store(rec, dbuf, TDB_REPLACE);
+       status = dbwrap_record_store(rec, dbuf, TDB_REPLACE);
        TALLOC_FREE(array);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("notify_add_onelevel: store failed: %s\n",
@@ -585,6 +586,7 @@ NTSTATUS notify_remove_onelevel(struct notify_context *notify,
        struct db_record *rec;
        DATA_BLOB blob;
        TDB_DATA dbuf;
+       TDB_DATA value;
        enum ndr_err_code ndr_err;
        NTSTATUS status;
        int i;
@@ -598,7 +600,7 @@ NTSTATUS notify_remove_onelevel(struct notify_context *notify,
                return NT_STATUS_NO_MEMORY;
        }
 
-       rec = notify->db_onelevel->fetch_locked(
+       rec = dbwrap_fetch_locked(
                notify->db_onelevel, array,
                make_tdb_data((const uint8_t *)fid, sizeof(*fid)));
        if (rec == NULL) {
@@ -608,8 +610,9 @@ NTSTATUS notify_remove_onelevel(struct notify_context *notify,
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
 
-       blob.data = (uint8_t *)rec->value.dptr;
-       blob.length = rec->value.dsize;
+       value = dbwrap_record_get_value(rec);
+       blob.data = (uint8_t *)value.dptr;
+       blob.length = value.dsize;
 
        if (blob.length > 0) {
                ndr_err = ndr_pull_struct_blob(&blob, array, array,
@@ -643,7 +646,7 @@ NTSTATUS notify_remove_onelevel(struct notify_context *notify,
        array->num_entries -= 1;
 
        if (array->num_entries == 0) {
-               rec->delete_rec(rec);
+               dbwrap_record_delete(rec);
                TALLOC_FREE(array);
                return NT_STATUS_OK;
        }
@@ -665,7 +668,7 @@ NTSTATUS notify_remove_onelevel(struct notify_context *notify,
        dbuf.dptr = blob.data;
        dbuf.dsize = blob.length;
 
-       status = rec->store(rec, dbuf, TDB_REPLACE);
+       status = dbwrap_record_store(rec, dbuf, TDB_REPLACE);
        TALLOC_FREE(array);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("notify_add_onelevel: store failed: %s\n",
@@ -831,6 +834,7 @@ void notify_onelevel(struct notify_context *notify, uint32_t action,
        DATA_BLOB blob;
        bool have_dead_entries = false;
        int i;
+       NTSTATUS status;
 
        if (notify == NULL) {
                return;
@@ -841,10 +845,10 @@ void notify_onelevel(struct notify_context *notify, uint32_t action,
                return;
        }
 
-       if (notify->db_onelevel->fetch(
-                   notify->db_onelevel, array,
-                   make_tdb_data((uint8_t *)&fid, sizeof(fid)),
-                   &dbuf) != 0) {
+       status = dbwrap_fetch(notify->db_onelevel, array,
+                             make_tdb_data((uint8_t *)&fid, sizeof(fid)),
+                             &dbuf);
+       if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(array);
                return;
        }
@@ -872,8 +876,6 @@ void notify_onelevel(struct notify_context *notify, uint32_t action,
                struct notify_entry *e = &array->entries[i];
 
                if ((e->filter & filter) != 0) {
-                       NTSTATUS status;
-
                        status = notify_send(notify, e, name, action);
                        if (NT_STATUS_EQUAL(
                                    status, NT_STATUS_INVALID_HANDLE)) {