From 0439f1c45e75771a6b0ad4bf7291c7feda179902 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 22 Feb 2009 00:18:05 +0100 Subject: [PATCH] Add dbwrap->parse_record Signed-off-by: Michael Adam (cherry picked from commit 68d4e25aad23b670e4ff735377de59ba396940cd) --- source/include/dbwrap.h | 4 ++++ source/lib/dbwrap.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/source/include/dbwrap.h b/source/include/dbwrap.h index 46833fabdce..3381d2d6666 100644 --- a/source/include/dbwrap.h +++ b/source/include/dbwrap.h @@ -45,6 +45,10 @@ struct db_context { int (*transaction_start)(struct db_context *db); int (*transaction_commit)(struct db_context *db); int (*transaction_cancel)(struct db_context *db); + int (*parse_record)(struct db_context *db, TDB_DATA key, + int (*parser)(TDB_DATA key, TDB_DATA data, + void *private_data), + void *private_data); void *private_data; bool persistent; }; diff --git a/source/lib/dbwrap.c b/source/lib/dbwrap.c index 73c2761a1b3..055f5549b60 100644 --- a/source/lib/dbwrap.c +++ b/source/lib/dbwrap.c @@ -42,6 +42,29 @@ static int dbwrap_fallback_fetch(struct db_context *db, TALLOC_CTX *mem_ctx, return 0; } +/* + * Fall back using fetch if no genuine parse operation is provided + */ + +static int dbwrap_fallback_parse_record(struct db_context *db, TDB_DATA key, + int (*parser)(TDB_DATA key, + TDB_DATA data, + void *private_data), + void *private_data) +{ + TDB_DATA data; + int res; + + res = db->fetch(db, talloc_tos(), key, &data); + if (res != 0) { + return res; + } + + res = parser(key, data, private_data); + TALLOC_FREE(data.dptr); + return res; +} + /** * open a database */ @@ -101,6 +124,9 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx, if ((result != NULL) && (result->fetch == NULL)) { result->fetch = dbwrap_fallback_fetch; } + if ((result != NULL) && (result->parse_record == NULL)) { + result->parse_record = dbwrap_fallback_parse_record; + } return result; } -- 2.11.4.GIT