diff options
Diffstat (limited to 'e-util/e-dbhash.c')
-rw-r--r-- | e-util/e-dbhash.c | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/e-util/e-dbhash.c b/e-util/e-dbhash.c index e286500066..a61318e7ab 100644 --- a/e-util/e-dbhash.c +++ b/e-util/e-dbhash.c @@ -7,19 +7,19 @@ */ #include <config.h> + +#include "e-dbhash.h" + #include <string.h> #include <fcntl.h> -#ifdef HAVE_DB_185_H -#include <db_185.h> -#else -#ifdef HAVE_DB1_DB_H -#include <db1/db.h> -#else #include <db.h> -#endif -#endif #include "md5-utils.h" -#include "e-dbhash.h" + +#if DB_VERSION_MAJOR != 3 || \ + DB_VERSION_MINOR != 1 || \ + DB_VERSION_PATCH != 17 +#error Including wrong DB3. Need libdb 3.1.17. +#endif struct _EDbHashPrivate { @@ -31,20 +31,37 @@ e_dbhash_new (const char *filename) { EDbHash *edbh; DB *db; + int rv; + + int major, minor, patch; + + db_version (&major, &minor, &patch); + + if (major != 3 || + minor != 1 || + patch != 17) { + g_warning ("Wrong version of libdb."); + return NULL; + } /* Attempt to open the database */ - db = dbopen (filename, O_RDWR, 0666, DB_HASH, NULL); - if (db == NULL) { - db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); + rv = db_create (&db, NULL, 0); + if (rv != 0) { + return NULL; + } + + rv = db->open (db, filename, NULL, DB_HASH, 0, 0666); + if (rv != 0) { + rv = db->open (db, filename, NULL, DB_HASH, DB_CREATE, 0666); - if (db == NULL) + if (rv != 0) return NULL; } - + edbh = g_new (EDbHash, 1); edbh->priv = g_new (EDbHashPrivate, 1); edbh->priv->db = db; - + return edbh; } @@ -86,7 +103,7 @@ e_dbhash_add (EDbHash *edbh, const gchar *key, const gchar *data) md5_to_dbt (local_hash, &ddata); /* Add to database */ - db->put (db, &dkey, &ddata, 0); + db->put (db, NULL, &dkey, &ddata, 0); } void @@ -105,7 +122,7 @@ e_dbhash_remove (EDbHash *edbh, const char *key) string_to_dbt (key, &dkey); /* Remove from database */ - db->del (db, &dkey, 0); + db->del (db, NULL, &dkey, 0); } void @@ -114,6 +131,7 @@ e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data) DB *db; DBT dkey; DBT ddata; + DBC *dbc; int db_error = 0; g_return_if_fail (edbh != NULL); @@ -122,13 +140,20 @@ e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data) db = edbh->priv->db; - db_error = db->seq(db, &dkey, &ddata, R_FIRST); + db_error = db->cursor (db, NULL, &dbc, 0); + + if (db_error != 0) { + return; + } + + db_error = dbc->c_get(dbc, &dkey, &ddata, DB_FIRST); while (db_error == 0) { (*func) ((const char *)dkey.data, user_data); - db_error = db->seq(db, &dkey, &ddata, R_NEXT); + db_error = dbc->c_get(dbc, &dkey, &ddata, DB_NEXT); } + dbc->c_close (dbc); } EDbHashStatus @@ -151,7 +176,7 @@ e_dbhash_compare (EDbHash *edbh, const char *key, const char *compare_data) /* Lookup in database */ memset (&ddata, 0, sizeof (DBT)); - db->get (db, &dkey, &ddata, 0); + db->get (db, NULL, &dkey, &ddata, 0); /* Compare */ if (ddata.data) { @@ -191,10 +216,8 @@ e_dbhash_destroy (EDbHash *edbh) db = edbh->priv->db; /* Close datbase */ - db->close (db); + db->close (db, 0); g_free (edbh->priv); g_free (edbh); } - - |