summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-07-29 15:12:39 +0200
committerMichael Adam <obnox@samba.org>2009-07-29 16:26:28 +0200
commitfac81b375099e32f8124ae3cba631bb5fe36b1cb (patch)
tree611e59ecfeb1c4f558edf478655d03b0566b59ae /source3
parenta86e163c1be3485698a238508101c205a47bc937 (diff)
downloadsamba-fac81b375099e32f8124ae3cba631bb5fe36b1cb.tar.gz
samba-fac81b375099e32f8124ae3cba631bb5fe36b1cb.tar.bz2
samba-fac81b375099e32f8124ae3cba631bb5fe36b1cb.zip
s3:dbwrap: export logic of dbwrap_change_int32_atomic into an action function
to prepare for adding a transaction wrapper to dbwrap_change_int32_atomic() Michael
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap_util.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/source3/lib/dbwrap_util.c b/source3/lib/dbwrap_util.c
index ace480eaa4..ca0658579a 100644
--- a/source3/lib/dbwrap_util.c
+++ b/source3/lib/dbwrap_util.c
@@ -190,30 +190,40 @@ NTSTATUS dbwrap_trans_change_uint32_atomic(struct db_context *db,
* return old value in *oldval.
* store *oldval + change_val to db.
*/
-NTSTATUS dbwrap_change_int32_atomic(struct db_context *db, const char *keystr,
- int32_t *oldval, int32_t change_val)
+
+struct dbwrap_change_int32_atomic_context {
+ const char *keystr;
+ int32_t *oldval;
+ int32_t change_val;
+};
+
+static NTSTATUS dbwrap_change_int32_atomic_action(struct db_context *db,
+ void *private_data)
{
struct db_record *rec;
int32_t val = -1;
TDB_DATA data;
NTSTATUS ret;
+ struct dbwrap_change_int32_atomic_context *state;
- rec = db->fetch_locked(db, NULL, string_term_tdb_data(keystr));
+ state = (struct dbwrap_change_int32_atomic_context *)private_data;
+
+ rec = db->fetch_locked(db, NULL, string_term_tdb_data(state->keystr));
if (!rec) {
return NT_STATUS_UNSUCCESSFUL;
}
if (rec->value.dptr == NULL) {
- val = *oldval;
+ val = *(state->oldval);
} else if (rec->value.dsize == sizeof(val)) {
val = IVAL(rec->value.dptr, 0);
- *oldval = val;
+ *(state->oldval) = val;
} else {
ret = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- val += change_val;
+ val += state->change_val;
data.dsize = sizeof(val);
data.dptr = (uint8 *)&val;
@@ -225,6 +235,21 @@ done:
return ret;
}
+NTSTATUS dbwrap_change_int32_atomic(struct db_context *db, const char *keystr,
+ int32_t *oldval, int32_t change_val)
+{
+ NTSTATUS ret;
+ struct dbwrap_change_int32_atomic_context state;
+
+ state.keystr = keystr;
+ state.oldval = oldval;
+ state.change_val = change_val;
+
+ ret = dbwrap_change_int32_atomic_action(db, &state);
+
+ return ret;
+}
+
struct dbwrap_store_context {
TDB_DATA *key;
TDB_DATA *dbuf;