#include "system/filesys.h"
#include "intl/lang_tdb.h"
#include "util_tdb.h"
+#include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_open.h"
-static TDB_CONTEXT *tdb;
+static struct db_context *db;
/* the currently selected language */
static char *current_lang;
return False;
}
- if (tdb_lockall(tdb) != 0) {
+ if (dbwrap_transaction_start(db) != 0) {
TALLOC_FREE(lines);
return False;
}
/* wipe the db */
- tdb_wipe_all(tdb);
+ dbwrap_wipe(db);
msgid = NULL;
all_string_sub(msgid, "\\n", "\n", 0);
all_string_sub(msgstr, "\\n", "\n", 0);
data = string_term_tdb_data(msgstr);
- tdb_store_bystring(tdb, msgid, data, 0);
+ dbwrap_store_bystring(db, msgid, data, 0);
msgid = NULL;
}
}
TALLOC_FREE(lines);
- tdb_unlockall(tdb);
+ dbwrap_transaction_commit(db);
return True;
}
char *msg_path = NULL;
struct stat st;
static int initialised;
- time_t loadtime;
+ int32_t loadtime;
bool result = False;
/* we only want to init once per process, unless given
if (initialised) {
/* we are re-initialising, free up any old init */
- if (tdb) {
- tdb_close(tdb);
- tdb = NULL;
- }
+ TALLOC_FREE(db);
SAFE_FREE(current_lang);
}
DEBUG(10, ("lang_tdb_init: loading %s\n", path));
- tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
- if (!tdb) {
- tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDONLY, 0);
- if (!tdb) {
+ db = db_s3open(NULL, path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
+ if (!db) {
+ db = db_s3open(NULL, path, 0, TDB_DEFAULT, O_RDONLY, 0);
+ if (!db) {
DEBUG(10, ("lang_tdb_init: %s: %s\n", path,
strerror(errno)));
goto done;
goto done;
}
- loadtime = tdb_fetch_int32(tdb, "/LOADTIME/");
-
- if (loadtime == -1 || loadtime < st.st_mtime) {
+ if (!NT_STATUS_IS_OK(dbwrap_fetch_int32(db, "/LOADTIME/", &loadtime))
+ || loadtime < st.st_mtime) {
load_msg(msg_path);
- tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL));
+ dbwrap_store_int32(db, "/LOADTIME/", (int)time(NULL));
}
current_lang = SMB_STRDUP(lang);
lang_tdb_init(NULL);
- if (!tdb) return msgid;
+ if (!db) return msgid;
/* Due to the way quotes in msgids are escaped in the msg file we
must replace " with \" before doing a lookup in the tdb. */
*q = 0;
- data = tdb_fetch_bystring(tdb, msgid_quoted);
+ if (!NT_STATUS_IS_OK(dbwrap_fetch_bystring(db, NULL, msgid_quoted,
+ &data))) {
+ free(msgid_quoted);
+ /* if the message isn't found then we still need to
+ return a pointer that can be freed. Pity. */
+ return talloc_strdup(db, msgid);
+ }
free(msgid_quoted);
-
- /* if the message isn't found then we still need to return a pointer
- that can be freed. Pity. */
- if (!data.dptr)
- return SMB_STRDUP(msgid);
-
return (const char *)data.dptr;
}
/* free up a string from lang_msg() */
void lang_msg_free(const char *msgstr)
{
- if (!tdb) return;
- free(discard_const_p(void, msgstr));
+ if (!db) return;
+ talloc_free(discard_const_p(void, msgstr));
}
/*