diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/dbwrap/dbwrap_ctdb.c | 66 |
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; } |