now that the db_ctdb_marshall_loop_next_key has been factored out.
Reviewed-by: Michael Adam <obnox@samba.org>
-/*
- loop over a marshalling buffer
-
- - pass r==NULL to start
- - loop the number of times indicated by m->count
-*/
-static struct ctdb_rec_data *db_ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
- uint32_t *reqid,
- struct ctdb_ltdb_header *header,
- TDB_DATA *key, TDB_DATA *data)
+static bool db_ctdb_marshall_buf_parse(
+ struct ctdb_rec_data *r, uint32_t *reqid,
+ struct ctdb_ltdb_header **header, TDB_DATA *data)
- r = db_ctdb_marshall_loop_next_key(m, r, key);
- if (r == NULL) {
- return NULL;
+ if (r->datalen < sizeof(struct ctdb_ltdb_header)) {
+ return false;
- if (reqid != NULL) {
- *reqid = r->reqid;
- }
- if (data != NULL) {
- data->dptr = &r->data[r->keylen];
- data->dsize = r->datalen;
- if (header != NULL) {
- data->dptr += sizeof(*header);
- data->dsize -= sizeof(*header);
- }
- }
+ data->dptr = &r->data[r->keylen] + sizeof(struct ctdb_ltdb_header);
+ data->dsize = r->datalen - sizeof(struct ctdb_ltdb_header);
- if (header != NULL) {
- if (r->datalen < sizeof(*header)) {
- return NULL;
- }
- *header = *(struct ctdb_ltdb_header *)&r->data[r->keylen];
- }
+ *header = (struct ctdb_ltdb_header *)&r->data[r->keylen];
TDB_DATA *pdata)
{
struct ctdb_rec_data *rec = NULL;
TDB_DATA *pdata)
{
struct ctdb_rec_data *rec = NULL;
- struct ctdb_ltdb_header h;
- bool found = false;
+ struct ctdb_ltdb_header *h = NULL;
- ZERO_STRUCT(h);
- ZERO_STRUCT(data);
-
/*
* Walk the list of records written during this
* transaction. If we want to read one we have already
/*
* Walk the list of records written during this
* transaction. If we want to read one we have already
*/
for (i=0; i<buf->count; i++) {
*/
for (i=0; i<buf->count; i++) {
- struct ctdb_ltdb_header hdr;
-
- ZERO_STRUCT(hdr);
- rec = db_ctdb_marshall_loop_next(buf, rec, &reqid, &hdr, &tkey,
- &tdata);
+ rec = db_ctdb_marshall_loop_next_key(buf, rec, &tkey);
if (rec == NULL) {
return false;
}
if (rec == NULL) {
return false;
}
- if (tdb_data_equal(key, tkey)) {
- found = true;
- data = tdata;
- h = hdr;
+ if (!tdb_data_equal(key, tkey)) {
+ continue;
+ }
+
+ if (!db_ctdb_marshall_buf_parse(rec, &reqid, &h, &data)) {
+ return false;