summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-11-12 12:13:39 +0100
committerMichael Adam <obnox@samba.org>2012-11-29 18:03:59 +0100
commit93219f92bb4294f0d7be7ba91f6a2e312336469d (patch)
tree8b341fa571d21a9a11597176112d29f2c2964ba2 /source3
parent850d5de96702b8c4bd8a285b4bd44a15350dfca8 (diff)
downloadsamba-93219f92bb4294f0d7be7ba91f6a2e312336469d.tar.gz
samba-93219f92bb4294f0d7be7ba91f6a2e312336469d.tar.bz2
samba-93219f92bb4294f0d7be7ba91f6a2e312336469d.zip
s3: Factor out parse_newest_in_marshall_buffer from pull_newest_from_marshall_buffer
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap/dbwrap_ctdb.c66
1 files changed, 51 insertions, 15 deletions
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 642053875f..a971d21d2e 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -432,11 +432,11 @@ static int db_ctdb_transaction_start(struct db_context *db)
return 0;
}
-static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
- TDB_DATA key,
- struct ctdb_ltdb_header *pheader,
- TALLOC_CTX *mem_ctx,
- TDB_DATA *pdata)
+static bool parse_newest_in_marshall_buffer(
+ struct ctdb_marshall_buffer *buf, TDB_DATA key,
+ void (*parser)(TDB_DATA key, struct ctdb_ltdb_header *header,
+ TDB_DATA data, void *private_data),
+ void *private_data)
{
struct ctdb_rec_data *rec = NULL;
struct ctdb_ltdb_header *h = NULL;
@@ -477,19 +477,55 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
return false;
}
- if (pdata != NULL) {
- data.dptr = (uint8_t *)talloc_memdup(mem_ctx, data.dptr,
- data.dsize);
- if ((data.dsize != 0) && (data.dptr == NULL)) {
- return false;
- }
- *pdata = data;
- }
+ parser(key, h, data, private_data);
+
+ return true;
+}
+
+struct pull_newest_from_marshall_buffer_state {
+ struct ctdb_ltdb_header *pheader;
+ TALLOC_CTX *mem_ctx;
+ TDB_DATA *pdata;
+};
+
+static void pull_newest_from_marshall_buffer_parser(
+ TDB_DATA key, struct ctdb_ltdb_header *header,
+ TDB_DATA data, void *private_data)
+{
+ struct pull_newest_from_marshall_buffer_state *state =
+ (struct pull_newest_from_marshall_buffer_state *)private_data;
- if (pheader != NULL) {
- *pheader = *h;
+ if (state->pheader != NULL) {
+ memcpy(state->pheader, header, sizeof(*state->pheader));
}
+ if (state->pdata != NULL) {
+ state->pdata->dsize = data.dsize;
+ state->pdata->dptr = (uint8_t *)talloc_memdup(
+ state->mem_ctx, data.dptr, data.dsize);
+ }
+}
+
+static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
+ TDB_DATA key,
+ struct ctdb_ltdb_header *pheader,
+ TALLOC_CTX *mem_ctx,
+ TDB_DATA *pdata)
+{
+ struct pull_newest_from_marshall_buffer_state state;
+
+ state.pheader = pheader;
+ state.mem_ctx = mem_ctx;
+ state.pdata = pdata;
+ if (!parse_newest_in_marshall_buffer(
+ buf, key, pull_newest_from_marshall_buffer_parser,
+ &state)) {
+ return false;
+ }
+ if ((pdata != NULL) && (pdata->dsize != 0) && (pdata->dptr == NULL)) {
+ /* ENOMEM */
+ return false;
+ }
return true;
}