diff options
author | Christopher James Lahey <clahey@ximian.com> | 2001-06-01 09:02:12 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-06-01 09:02:12 +0800 |
commit | 8f183d269e13e528442def98657e040b3728597d (patch) | |
tree | b6de7454fd22221b7e49bf7b8a408424fb8af6b5 | |
parent | 9d1e57701a113ad29c920cfa26b9966115570f08 (diff) | |
download | gsoc2013-evolution-8f183d269e13e528442def98657e040b3728597d.tar.gz gsoc2013-evolution-8f183d269e13e528442def98657e040b3728597d.tar.zst gsoc2013-evolution-8f183d269e13e528442def98657e040b3728597d.zip |
Included information about db3.
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* README: Included information about db3.
* acconfig.h: Added HAVE_DB_H and HAVE_DB3_DB_H.
* configure.in: Added various checks for db3 libraries and
includes. Of note are the new configure options
--with-db3-includes=PREFIX and --with-db3-libs=PREFIX to specify
the location for your db3 library.
From addressbook/ChangeLog:
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* backend/pas/Makefile.am (INCLUDES): Added db3 cflags.
* backend/pas/pas-backend-file.c: Updated this to use db3.
From e-util/ChangeLog:
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* Makefile.am (INCLUDES): Added db3 cflags.
* e-dbhash.c: Made this use db3.
* e-db3-utils.c, e-db3-utils.h: New files with some helper
functions.
From wombat/ChangeLog:
2001-05-31 Christopher James Lahey <clahey@ximian.com>
* Makefile.am (wombat_LDADD): Added db3 libs.
svn path=/trunk/; revision=10077
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | README | 9 | ||||
-rw-r--r-- | acconfig.h | 3 | ||||
-rw-r--r-- | addressbook/ChangeLog | 6 | ||||
-rw-r--r-- | addressbook/backend/pas/Makefile.am | 1 | ||||
-rw-r--r-- | addressbook/backend/pas/pas-backend-file.c | 258 | ||||
-rw-r--r-- | configure.in | 156 | ||||
-rw-r--r-- | e-util/ChangeLog | 9 | ||||
-rw-r--r-- | e-util/Makefile.am | 4 | ||||
-rw-r--r-- | e-util/e-db3-utils.c | 185 | ||||
-rw-r--r-- | e-util/e-db3-utils.h | 29 | ||||
-rw-r--r-- | e-util/e-dbhash.c | 69 | ||||
-rw-r--r-- | wombat/ChangeLog | 4 | ||||
-rw-r--r-- | wombat/Makefile.am | 8 |
14 files changed, 627 insertions, 125 deletions
@@ -1,5 +1,16 @@ 2001-05-31 Christopher James Lahey <clahey@ximian.com> + * README: Included information about db3. + + * acconfig.h: Added HAVE_DB_H and HAVE_DB3_DB_H. + + * configure.in: Added various checks for db3 libraries and + includes. Of note are the new configure options + --with-db3-includes=PREFIX and --with-db3-libs=PREFIX to specify + the location for your db3 library. + +2001-05-31 Christopher James Lahey <clahey@ximian.com> + * configure.in (GTKHTML_DATADIR): Use --moddatadir to derive this. 2001-05-30 Dan Winship <danw@ximian.com> @@ -140,6 +140,15 @@ and -devel packages for each library. - gtkhtml - later than 0.9.3 + - Berkeley's libdb - 3.1.17 + + db3 is available from www.sleepycat.com. Make sure to get 3.1.17, + it isn't the newest version. + + *** Note that db3 installs by default in /usr/local/BerkeleyDB.3.1 + *** so you may need to specify evolution to look in this directory + *** for it. We will add a check for this directory later. + If you want support for PalmPilot syncing (currently experimental so please back up your pilot) you will also need to do the following: diff --git a/acconfig.h b/acconfig.h index 4b6a2c2d6f..63f8f69d2a 100644 --- a/acconfig.h +++ b/acconfig.h @@ -24,6 +24,9 @@ #undef USE_FLOCK #undef ENABLE_NNTP +#undef HAVE_DB_H +#undef HAVE_DB3_DB_H + /* Sub-version identification string. */ #undef SUB_VERSION diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index 6c47e2f67d..b12a636bb6 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,9 @@ +2001-05-31 Christopher James Lahey <clahey@ximian.com> + + * backend/pas/Makefile.am (INCLUDES): Added db3 cflags. + + * backend/pas/pas-backend-file.c: Updated this to use db3. + 2001-05-31 Federico Mena Quintero <federico@ximian.com> * gui/widgets/e-addressbook-view.h (EAddressbookView): Added diff --git a/addressbook/backend/pas/Makefile.am b/addressbook/backend/pas/Makefile.am index 5ed8753a39..6d239689bf 100644 --- a/addressbook/backend/pas/Makefile.am +++ b/addressbook/backend/pas/Makefile.am @@ -13,6 +13,7 @@ $(CORBA_SOURCE): $(idls) $(ORBIT_IDL) -I $(srcdir) $(srcdir)/../idl/addressbook.idl $(idl_flags) INCLUDES = \ + $(DB3_CFLAGS) \ -DGNOMELOCALEDIR=\""$(localedir)"\" \ -DG_LOG_DOMAIN=\"wombat-pas\" \ -I$(top_srcdir) \ diff --git a/addressbook/backend/pas/pas-backend-file.c b/addressbook/backend/pas/pas-backend-file.c index d5bf2c6410..0c0cd5c7db 100644 --- a/addressbook/backend/pas/pas-backend-file.c +++ b/addressbook/backend/pas/pas-backend-file.c @@ -13,14 +13,14 @@ #include <unistd.h> #include <fcntl.h> #include <time.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 + +#include <e-util/e-db3-utils.h> + +#if DB_VERSION_MAJOR != 3 || \ + DB_VERSION_MINOR != 1 || \ + DB_VERSION_PATCH != 17 +#error Including wrong DB3. Need libdb 3.1.17. #endif #include <gtk/gtksignal.h> @@ -32,6 +32,7 @@ #include <ebook/e-card-simple.h> #include <e-util/e-sexp.h> #include <e-util/e-dbhash.h> +#include <e-util/e-db3-utils.h> #include "pas-book.h" #include "pas-card-cursor.h" @@ -476,22 +477,32 @@ pas_backend_file_search (PASBackendFile *bf, { int db_error = 0; GList *cards = NULL; - gint card_count = 0, card_threshold = 20, card_threshold_max = 200; + gint card_count = 0, card_threshold = 20, card_threshold_max = 1000; DB *db = bf->priv->file_db; + DBC *dbc; DBT id_dbt, vcard_dbt; int i, file_version_name_len; int esexp_error; PASBackendFileBookView *view = (PASBackendFileBookView *)cnstview; + gboolean search_needed; if (!bf->priv->loaded) return; - pas_book_view_notify_status_message (view->book_view, "Searching..."); + search_needed = TRUE; + + if ( ! strcmp (view->search, "(contains \"x-evolution-any-field\" \"\")")) + search_needed = FALSE; + + if (search_needed) + pas_book_view_notify_status_message (view->book_view, "Searching..."); + else + pas_book_view_notify_status_message (view->book_view, "Loading..."); if (view->search_sexp) e_sexp_unref(view->search_sexp); view->search_sexp = e_sexp_new(); - + for(i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) { if (symbols[i].type == 1) { e_sexp_add_ifunction(view->search_sexp, 0, symbols[i].name, @@ -505,8 +516,6 @@ pas_backend_file_search (PASBackendFile *bf, e_sexp_input_text(view->search_sexp, view->search, strlen(view->search)); esexp_error = e_sexp_parse(view->search_sexp); - file_version_name_len = strlen (PAS_BACKEND_FILE_VERSION_NAME); - if (esexp_error == -1) { /* need a different error message here. */ pas_book_view_notify_complete (view->book_view); @@ -514,43 +523,56 @@ pas_backend_file_search (PASBackendFile *bf, return; } - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_FIRST); + file_version_name_len = strlen (PAS_BACKEND_FILE_VERSION_NAME); + + db_error = db->cursor (db, NULL, &dbc, 0); + + memset (&id_dbt, 0, sizeof (id_dbt)); + memset (&vcard_dbt, 0, sizeof (vcard_dbt)); + + if (db_error != 0) { + g_warning ("pas_backend_file_search: error building list\n"); + } else { + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_FIRST); + + while (db_error == 0) { - while (db_error == 0) { + /* don't include the version in the list of cards */ + if (id_dbt.size != file_version_name_len+1 + || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { + char *vcard_string = vcard_dbt.data; - /* don't include the version in the list of cards */ - if (id_dbt.size != file_version_name_len+1 - || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { - char *vcard_string = vcard_dbt.data; + /* check if the vcard matches the search sexp */ + if ((!search_needed) || vcard_matches_search (view, vcard_string)) { + cards = g_list_prepend (cards, g_strdup (vcard_string)); + } - /* check if the vcard matches the search sexp */ - if (vcard_matches_search (view, vcard_string)) { - cards = g_list_prepend (cards, g_strdup (vcard_string)); - ++card_count; + card_count ++; - /* If we've accumulated a number of matches, pass them off to the client. */ - if (card_count > card_threshold) { + /* If we've accumulated a number of checks, pass them off to the client. */ + if (card_count >= card_threshold) { + cards = g_list_reverse (cards); pas_book_view_notify_add (view->book_view, cards); - /* Clean up the handed-off data. */ + /* Clean up the handed-off data. */ g_list_foreach (cards, (GFunc)g_free, NULL); g_list_free (cards); cards = NULL; card_count = 0; - /* Yeah, this scheme is over-complicated. But I like it. */ - if (card_threshold <= card_threshold_max) { + /* Yeah, this scheme is over-complicated. But I like it. */ + if (card_threshold < card_threshold_max) { card_threshold = MIN (2*card_threshold, card_threshold_max); } } - } + + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_NEXT); } - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_NEXT); - } + dbc->c_close (dbc); - if (db_error == -1) { - g_warning ("pas_backend_file_search: error building list\n"); + if (db_error != DB_NOTFOUND) { + g_warning ("pas_backend_file_search: error building list\n"); + } } if (card_count) @@ -575,7 +597,7 @@ pas_backend_file_changes_foreach_key (const char *key, gpointer user_data) int db_error = 0; string_to_dbt (key, &id_dbt); - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); + db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (db_error == 1) { char *id = id_dbt.data; @@ -595,6 +617,7 @@ pas_backend_file_changes (PASBackendFile *bf, EDbHash *ehash; GList *i, *v; DB *db = bf->priv->file_db; + DBC *dbc; PASBackendFileBookView *view = (PASBackendFileBookView *)cnstview; PASBackendFileChangeContext *ctx = cnstview->change_context; @@ -606,32 +629,39 @@ pas_backend_file_changes (PASBackendFile *bf, ehash = e_dbhash_new (filename); g_free (filename); - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_FIRST); - - while (db_error == 0) { - - /* don't include the version in the list of cards */ - if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 - || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { - char *id = id_dbt.data; - char *vcard_string = vcard_dbt.data; - - /* check what type of change has occurred, if any */ - switch (e_dbhash_compare (ehash, id, vcard_string)) { - case E_DBHASH_STATUS_SAME: - break; - case E_DBHASH_STATUS_NOT_FOUND: - ctx->add_cards = g_list_append (ctx->add_cards, strdup(vcard_string)); - ctx->add_ids = g_list_append (ctx->add_ids, strdup(id)); - break; - case E_DBHASH_STATUS_DIFFERENT: - ctx->mod_cards = g_list_append (ctx->mod_cards, strdup(vcard_string)); - ctx->mod_ids = g_list_append (ctx->mod_ids, strdup(id)); - break; + db_error = db->cursor (db, NULL, &dbc, 0); + + if (db_error != 0) { + g_warning ("pas_backend_file_changes: error building list\n"); + } else { + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_FIRST); + + while (db_error == 0) { + + /* don't include the version in the list of cards */ + if (id_dbt.size != strlen(PAS_BACKEND_FILE_VERSION_NAME) + 1 + || strcmp (id_dbt.data, PAS_BACKEND_FILE_VERSION_NAME)) { + char *id = id_dbt.data; + char *vcard_string = vcard_dbt.data; + + /* check what type of change has occurred, if any */ + switch (e_dbhash_compare (ehash, id, vcard_string)) { + case E_DBHASH_STATUS_SAME: + break; + case E_DBHASH_STATUS_NOT_FOUND: + ctx->add_cards = g_list_append (ctx->add_cards, strdup(vcard_string)); + ctx->add_ids = g_list_append (ctx->add_ids, strdup(id)); + break; + case E_DBHASH_STATUS_DIFFERENT: + ctx->mod_cards = g_list_append (ctx->mod_cards, strdup(vcard_string)); + ctx->mod_ids = g_list_append (ctx->mod_ids, strdup(id)); + break; + } } + + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_NEXT); } - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_NEXT); + dbc->c_close (dbc); } e_dbhash_foreach_key (ehash, (EDbHashFunc)pas_backend_file_changes_foreach_key, view->change_context); @@ -650,13 +680,13 @@ pas_backend_file_changes (PASBackendFile *bf, for (i = ctx->del_ids; i != NULL; i = i->next){ char *id = i->data; e_dbhash_remove (ehash, id); - } + } e_dbhash_write (ehash); e_dbhash_destroy (ehash); /* Send the changes */ - if (db_error == -1) { + if (db_error != DB_NOTFOUND) { g_warning ("pas_backend_file_changes: error building list\n"); } else { if (ctx->add_cards != NULL) @@ -698,7 +728,7 @@ do_create(PASBackend *backend, string_to_dbt (vcard, &vcard_dbt); - db_error = db->put (db, &id_dbt, &vcard_dbt, 0); + db_error = db->put (db, NULL, &id_dbt, &vcard_dbt, 0); if (0 == db_error) { db_error = db->sync (db, 0); @@ -776,7 +806,7 @@ pas_backend_file_process_remove_card (PASBackend *backend, string_to_dbt (req->id, &id_dbt); - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); + db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (0 != db_error) { pas_book_respond_remove ( book, @@ -785,7 +815,7 @@ pas_backend_file_process_remove_card (PASBackend *backend, return; } - db_error = db->del (db, &id_dbt, 0); + db_error = db->del (db, NULL, &id_dbt, 0); if (0 != db_error) { pas_book_respond_remove ( book, @@ -837,7 +867,7 @@ pas_backend_file_process_modify_card (PASBackend *backend, string_to_dbt (id, &id_dbt); /* get the old ecard - the one that's presently in the db */ - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); + db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (0 != db_error) { pas_book_respond_modify ( book, @@ -849,7 +879,7 @@ pas_backend_file_process_modify_card (PASBackend *backend, string_to_dbt (req->vcard, &vcard_dbt); - db_error = db->put (db, &id_dbt, &vcard_dbt, 0); + db_error = db->put (db, NULL, &id_dbt, &vcard_dbt, 0); if (0 == db_error) { db_error = db->sync (db, 0); @@ -901,12 +931,19 @@ pas_backend_file_build_all_cards_list(PASBackend *backend, { PASBackendFile *bf = PAS_BACKEND_FILE (backend); DB *db = bf->priv->file_db; + DBC *dbc; int db_error; DBT id_dbt, vcard_dbt; cursor_data->elements = NULL; - - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_FIRST); + + db_error = db->cursor (db, NULL, &dbc, 0); + + if (db_error != 0) { + g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); + } + + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_FIRST); while (db_error == 0) { @@ -919,11 +956,11 @@ pas_backend_file_build_all_cards_list(PASBackend *backend, } - db_error = db->seq(db, &id_dbt, &vcard_dbt, R_NEXT); + db_error = dbc->c_get(dbc, &id_dbt, &vcard_dbt, DB_NEXT); } - if (db_error == -1) { + if (db_error != DB_NOTFOUND) { g_warning ("pas_backend_file_build_all_cards_list: error building list\n"); } else { @@ -1254,7 +1291,7 @@ pas_backend_file_get_vcard (PASBook *book, const char *id) string_to_dbt (id, &id_dbt); - db_error = db->get (db, &id_dbt, &vcard_dbt, 0); + db_error = db->get (db, NULL, &id_dbt, &vcard_dbt, 0); if (db_error == 0) { /* success */ return g_strdup (vcard_dbt.data); @@ -1281,7 +1318,7 @@ pas_backend_file_upgrade_db (PASBackendFile *bf, char *old_version) string_to_dbt (PAS_BACKEND_FILE_VERSION_NAME, &version_name_dbt); string_to_dbt (PAS_BACKEND_FILE_VERSION, &version_dbt); - db_error = db->put (db, &version_name_dbt, &version_dbt, 0); + db_error = db->put (db, NULL, &version_name_dbt, &version_dbt, 0); if (db_error == 0) return TRUE; else @@ -1305,7 +1342,7 @@ pas_backend_file_maybe_upgrade_db (PASBackendFile *bf) string_to_dbt (PAS_BACKEND_FILE_VERSION_NAME, &version_name_dbt); - db_error = db->get (db, &version_name_dbt, &version_dbt, 0); + db_error = db->get (db, NULL, &version_name_dbt, &version_dbt, 0); if (db_error == 0) { /* success */ version = g_strdup (version_dbt.data); @@ -1323,6 +1360,7 @@ pas_backend_file_maybe_upgrade_db (PASBackendFile *bf) return ret_val; } + #define INITIAL_VCARD "BEGIN:VCARD\n\ X-EVOLUTION-FILE-AS:Ximian, Inc.\n\ LABEL;WORK;QUOTED-PRINTABLE:401 Park Drive 3 West=0ABoston, MA 02215=0AUSA\n\ @@ -1340,26 +1378,53 @@ pas_backend_file_load_uri (PASBackend *backend, { PASBackendFile *bf = PAS_BACKEND_FILE (backend); char *filename; - gboolean writable = FALSE; + gboolean writable = FALSE; GList *l; + int db_error; + DB *db; + int major, minor, patch; g_assert (bf->priv->loaded == FALSE); + db_version (&major, &minor, &patch); + + if (major != 3 || + minor != 1 || + patch != 17) { + g_warning ("Wrong version of libdb."); + return FALSE; + } + filename = pas_backend_file_extract_path_from_uri (uri); - bf->priv->file_db = dbopen (filename, O_RDWR, 0666, DB_HASH, NULL); - if (bf->priv->file_db) { - writable = TRUE; + db_error = e_db3_utils_maybe_recover (filename); + if (db_error != 0) + return FALSE; + + db_error = db_create (&db, NULL, 0); + if (db_error != 0) + return FALSE; + + db_error = db->open (db, filename, NULL, DB_HASH, 0, 0666); + + if (db_error == DB_OLD_VERSION) { + db_error = e_db3_utils_upgrade_format (filename); + + if (db_error != 0) + return FALSE; + + db_error = db->open (db, filename, NULL, DB_HASH, 0, 0666); } - else { - /* try to open the file read-only */ - bf->priv->file_db = dbopen (filename, O_RDONLY, 0666, DB_HASH, NULL); - if (!bf->priv->file_db) { - /* lastly, try and create the file */ - bf->priv->file_db = dbopen (filename, O_RDWR | O_CREAT, 0666, DB_HASH, NULL); + if (db_error == 0) { + writable = TRUE; + } else { + db_error = db->open (db, filename, NULL, DB_HASH, DB_RDONLY, 0666); + + if (db_error != 0) { + db_error = db->open (db, filename, NULL, DB_HASH, DB_CREATE, 0666); - if (bf->priv->file_db) { + if (db_error == 0) { char *create_initial_file; char *dir; @@ -1382,15 +1447,24 @@ pas_backend_file_load_uri (PASBackend *backend, g_free (filename); - if (bf->priv->file_db != NULL) { - if (pas_backend_file_maybe_upgrade_db (bf)) - bf->priv->loaded = TRUE; - /* XXX what if we fail to upgrade it? */ - - g_free(bf->priv->uri); - bf->priv->uri = g_strdup (uri); - } else + if (db_error != 0) { return FALSE; + } + + bf->priv->writable = writable; + bf->priv->file_db = db; + + if (pas_backend_file_maybe_upgrade_db (bf)) + bf->priv->loaded = TRUE; + else { + db->close (db, 0); + bf->priv->file_db = NULL; + bf->priv->writable = FALSE; + return FALSE; + } + + g_free(bf->priv->uri); + bf->priv->uri = g_strdup (uri); /* report the writable status of the book to all its clients */ for (l = bf->priv->clients; l; l = g_list_next (l)) { @@ -1399,8 +1473,6 @@ pas_backend_file_load_uri (PASBackend *backend, pas_book_report_writable (book, writable); } - bf->priv->writable = writable; - return TRUE; } diff --git a/configure.in b/configure.in index 3304686ff0..652af381b2 100644 --- a/configure.in +++ b/configure.in @@ -206,12 +206,158 @@ fi dnl ************************************************** dnl * pas-backend-file stuff. -dnl * check for db_185.h. if it's there, we use it. -dnl * otherwise, we use db.h (since it'll be 185). -dnl * Except on RH7.0, which puts db in yet another place +dnl * check for version 3.1.17 of db.h. First check +dnl * in db.h, then in db3/db.h (For Red Hat Linux +dnl * 7.0). dnl ************************************************** -AC_CHECK_HEADERS(db_185.h) -AC_CHECK_HEADERS(db1/db.h) + +AC_ARG_WITH(db3-includes, [ --with-db3-includes=PREFIX Location of db3 includes.], + with_db3_includes="$withval") + +DB3_CFLAGS= + +AC_CACHE_CHECK([for libdb3 version 3.1.17], ac_cv_db3_version_check, +[ + CPPFLAGS_save="$CPPFLAGS" + if test "x${with_db3_includes}" != "x"; then + CPPFLAGS="-I$with_db3_includes $CPPFLAGS" + fi + + AC_TRY_COMPILE([ + #include <db.h> + ],[ + #if DB_VERSION_MAJOR != 3 || \ + DB_VERSION_MINOR != 1 || \ + DB_VERSION_PATCH != 17 + #error + #endif + ], ac_cv_db3_version_check=yes, ac_cv_db3_version_check=no) + + CPPFLAGS="$CPPFLAGS_save" +]) + +if test $ac_cv_db3_version_check = yes; then + AC_DEFINE(HAVE_DB_H) + if test "x${with_db3_includes}" != "x"; then + DB3_CFLAGS="-I$with_db3_includes" + fi +else + AC_CACHE_CHECK([for libdb3 version 3.1.17 in db3/db.h], ac_cv_db3_db3_db_h_version_check, + [ + CPPFLAGS_save="$CPPFLAGS" + if test "x${with_db3_includes}" != "x"; then + CPPFLAGS="-I$with_db3_includes $CPPFLAGS" + fi + + AC_TRY_COMPILE([ + #include <db3/db.h> + ],[ + #if DB_VERSION_MAJOR != 3 || \ + DB_VERSION_MINOR != 1 || \ + DB_VERSION_PATCH != 17 + #error + #endif + ], ac_cv_db3_db3_db_h_version_check=yes, ac_cv_db3_db3_db_h_version_check=no) + + CPPFLAGS="$CPPFLAGS_save" + ]) + if test $ac_cv_db3_db3_db_h_version_check = yes; then + AC_DEFINE(HAVE_DB3_DB_H) + if test "x${with_db3_includes}" != "x"; then + DB3_CFLAGS="-I$with_db3_includes" + fi + else + AC_ERROR(You must have libdb3 version 3.1.17 installed to compile evolution) + fi +fi + +AC_SUBST(DB3_CFLAGS) + + +AC_ARG_WITH(db3-libs, [ --with-db3-libs=PREFIX Location of db3 libs.], + with_db3_libs="$withval", with_db3_libs="/usr/lib/") + +DB3_LDADD= + +if test $ac_cv_db3_version_check = yes; then + HAVE_DB3_DB_H_INTERNAL=0 +else + HAVE_DB3_DB_H_INTERNAL=1 +fi + +AC_CACHE_CHECK([for -ldb 3.1.17], ac_cv_db3_lib_check, +[ + LIBS_save="$LIBS" + LIBS="$with_db3_libs/libdb.a $LIBS" + CPPFLAGS_save="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $DB3_CFLAGS" + + AC_TRY_RUN([ +#if $HAVE_DB3_DB_H_INTERNAL +#include <db3/db.h> +#else +#include <db.h> +#endif +int +main (void) +{ + int major, minor, patch; + db_version (&major, &minor, &patch); + if (major == 3 && + minor == 1 && + patch == 17) + return 0; + else + return 1; +} +], ac_cv_db3_lib_check=yes, ac_cv_db3_lib_check=no) + + LIBS="$LIBS_save" + CPPFLAGS="$CPPFLAGS_save" +]) + +if test $ac_cv_db3_lib_check = yes; then + DB3_LDADD="$with_db3_libs/libdb.a" +else + AC_CACHE_CHECK([for -ldb3 3.1.17], ac_cv_db3_lib_db3_check, + [ + LIBS_save="$LIBS" + LIBS="$with_db3_libs/libdb3.a $LIBS" + CPPFLAGS_save="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $DB3_CFLAGS" + + AC_TRY_RUN([ +#if $HAVE_DB3_DB_H_INTERNAL +#include <db3/db.h> +#else +#include <db.h> +#endif +int +main (void) +{ + int major, minor, patch; + db_version (&major, &minor, &patch); + if (major == 3 && + minor == 1 && + patch == 17) + return 0; + else + return 1; +} +], ac_cv_db3_lib_db3_check=yes, ac_cv_db3_lib_db3_check=no) + + LIBS="$LIBS_save" + CPPFLAGS="$CPPFLAGS_save" + ]) + + if test $ac_cv_db3_lib_db3_check = yes; then + DB3_LDADD="$with_db3_libs/libdb3.a" + else + AC_ERROR(Didn't find libdb 3.1.17 libraries. You must have libdb version 3.1.17 installed to compile evolution) + fi +fi + +AC_SUBST(DB3_LDADD) dnl ************************************************** dnl * ldap related stuff. diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 8f350ea0f5..0084885485 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,12 @@ +2001-05-31 Christopher James Lahey <clahey@ximian.com> + + * Makefile.am (INCLUDES): Added db3 cflags. + + * e-dbhash.c: Made this use db3. + + * e-db3-utils.c, e-db3-utils.h: New files with some helper + functions. + 2001-05-27 Dan Winship <danw@ximian.com> * e-gui-utils.c: Remove e_pixmaps_update (moved to libeshell) so diff --git a/e-util/Makefile.am b/e-util/Makefile.am index 822c766f43..4b901acd30 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = . ename imagesdir = $(datadir)/images/evolution INCLUDES = \ + $(DB3_CFLAGS) \ -I$(top_srcdir) \ $(GNOME_INCLUDEDIR) \ $(EXTRA_GNOME_CFLAGS) \ @@ -44,6 +45,8 @@ libeutil_la_SOURCES = \ e-time-utils.h \ e-url.c \ e-url.h \ + e-db3-utils.c \ + e-db3-utils.h \ e-dbhash.c \ e-dbhash.h \ md5-utils.c \ @@ -52,6 +55,7 @@ libeutil_la_SOURCES = \ libeutil_la_LIBADD = $(GAL_LIBS) libeutil_static_la_SOURCES = $(libeutil_la_SOURCES) +libeutil_static_la_LIBADD = $(libeutil_la_LIBADD) libeutil_static_la_LDFLAGS = --all-static pilot_sources = \ diff --git a/e-util/e-db3-utils.c b/e-util/e-db3-utils.c new file mode 100644 index 0000000000..c1da265453 --- /dev/null +++ b/e-util/e-db3-utils.c @@ -0,0 +1,185 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ + +#include "config.h" + +#include "e-db3-utils.h" + +#include <db.h> + +#include <errno.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <libgnome/gnome-defs.h> +#include <libgnome/gnome-util.h> + +#if DB_VERSION_MAJOR != 3 || \ + DB_VERSION_MINOR != 1 || \ + DB_VERSION_PATCH != 17 +#error Including wrong DB3. Need libdb 3.1.17. +#endif + +static char * +get_check_filename (const char *filename) +{ + return g_strdup_printf ("%s-upgrading", filename); +} + +static char * +get_copy_filename (const char *filename) +{ + return g_strdup_printf ("%s-copy", filename); +} + +static int +cp_file (const char *src, const char *dest) +{ + int i; + int o; + char buffer[1024]; + int length; + int place; + + i = open (src, O_RDONLY); + if (i == -1) + return -1; + o = creat (dest, S_IREAD | S_IWRITE); + if (o == -1) { + close (i); + return -1; + } + while (1) { + length = read (i, &buffer, sizeof (buffer)); + + if (length == 0) + break; + + if (length == -1) { + if (errno == EINTR) + continue; + else { + close (i); + close (o); + unlink (dest); + return -1; + } + } + + place = 0; + while (length != 0) { + int count; + count = write (o, buffer + place, length); + if (count == -1) { + if (errno == EINTR) + continue; + else { + close (i); + close (o); + unlink (dest); + return -1; + } + } + + length -= count; + place += count; + } + } + if (close (i)) + return -1; + if (close (o)) + return -1; + return 0; +} + +static int +touch_file (const char *file) +{ + int o; + o = creat (file, S_IREAD | S_IWRITE); + if (o == -1) + return -1; + + if (close (o) == -1) + return -1; + + return 0; +} + +static int +resume_upgrade (const char *filename, const char *copy_filename, const char *check_filename) +{ + DB *db; + int ret_val; + + ret_val = db_create (&db, NULL, 0); + + if (ret_val == 0) + ret_val = cp_file (copy_filename, filename); + + if (ret_val == 0) + ret_val = db->upgrade (db, filename, 0); + + if (ret_val == 0) + ret_val = unlink (check_filename); + if (ret_val == 0) + ret_val = unlink (copy_filename); + + db->close (db, 0); + + return ret_val; +} + +int +e_db3_utils_maybe_recover (const char *filename) +{ + int ret_val = 0; + char *copy_filename; + char *check_filename; + + copy_filename = get_copy_filename (filename); + check_filename = get_check_filename (filename); + + if (g_file_exists (check_filename)) { + ret_val = resume_upgrade(filename, copy_filename, check_filename); + } else if (g_file_exists (copy_filename)) { + unlink (copy_filename); + } + + g_free (copy_filename); + g_free (check_filename); + return ret_val; +} + +int +e_db3_utils_upgrade_format (const char *filename) +{ + char *copy_filename; + char *check_filename; + DB *db; + int ret_val; + + ret_val = db_create (&db, NULL, 0); + if (ret_val != 0) + return ret_val; + + copy_filename = get_copy_filename (filename); + check_filename = get_check_filename (filename); + + ret_val = cp_file (filename, copy_filename); + + if (ret_val == 0) + ret_val = touch_file (check_filename); + if (ret_val == 0) + ret_val = db->upgrade (db, filename, 0); + if (ret_val == 0) + ret_val = unlink (check_filename); + + if (ret_val == 0) + ret_val = unlink (copy_filename); + + db->close (db, 0); + + g_free (check_filename); + g_free (copy_filename); + return ret_val; +} diff --git a/e-util/e-db3-utils.h b/e-util/e-db3-utils.h new file mode 100644 index 0000000000..a574e59178 --- /dev/null +++ b/e-util/e-db3-utils.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * db3 utils. + * + * Author: + * Chris Lahey <clahey@ximian.com> + * + * Copyright 2001, Ximian, Inc. + */ + +#ifndef __E_DB3_UTILS_H__ +#define __E_DB3_UTILS_H__ + +#include <glib.h> + +#ifdef __cplusplus +extern "C" { +#pragma } +#endif /* __cplusplus */ + +int e_db3_utils_maybe_recover (const char *filename); +int e_db3_utils_upgrade_format (const char *filename); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ! __E_DB3_UTILS_H__ */ + 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); } - - diff --git a/wombat/ChangeLog b/wombat/ChangeLog index fda6fc5e00..f146e26b2f 100644 --- a/wombat/ChangeLog +++ b/wombat/ChangeLog @@ -1,3 +1,7 @@ +2001-05-31 Christopher James Lahey <clahey@ximian.com> + + * Makefile.am (wombat_LDADD): Added db3 libs. + 2001-04-03 Dietmar Maurer <dietmar@ximian.com> * wombat-moniker.c (wombat_lookup_db): fix ref. counting problem diff --git a/wombat/Makefile.am b/wombat/Makefile.am index 0d0919613b..be6fb7fce8 100644 --- a/wombat/Makefile.am +++ b/wombat/Makefile.am @@ -22,8 +22,6 @@ wombat_SOURCES = \ wombat.c wombat_LDADD = \ - $(EXTRA_GNOME_LIBS) \ - $(BONOBO_VFS_GNOME_LIBS) \ $(top_builddir)/addressbook/backend/pas/libpas.a \ $(top_builddir)/addressbook/backend/ebook/libebook.la \ $(top_builddir)/e-util/ename/libename.la \ @@ -32,7 +30,10 @@ wombat_LDADD = \ $(top_builddir)/libical/src/libical/libical.la \ $(top_builddir)/libversit/libversit.la \ $(top_builddir)/e-util/libeutil.la \ - $(LDAP_LIBS) + $(LDAP_LIBS) \ + $(DB3_LDADD) \ + $(EXTRA_GNOME_LIBS) \ + $(BONOBO_VFS_GNOME_LIBS) oafdir = $(datadir)/oaf @@ -54,4 +55,3 @@ wombat.pure: wombat $(PLINK) $(wombat_LDFLAGS) $(wombat_OBJECTS) $(wombat_LDADD) $(LIBS) endif - |