diff options
author | JP Rosevear <jpr@ximian.com> | 2003-11-19 04:02:06 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2003-11-19 04:02:06 +0800 |
commit | b44f4b40e239c4c481eef4ef94c10d8159e72ef2 (patch) | |
tree | 1ce2a93e6f531add200d31fa3a8ab2de77cf261d /e-util | |
parent | 45e03ba1dee9a53af1b0798a5b7149cf8000ca36 (diff) | |
download | gsoc2013-evolution-b44f4b40e239c4c481eef4ef94c10d8159e72ef2.tar.gz gsoc2013-evolution-b44f4b40e239c4c481eef4ef94c10d8159e72ef2.tar.zst gsoc2013-evolution-b44f4b40e239c4c481eef4ef94c10d8159e72ef2.zip |
remove db3 library, if you really want it, get it from e-d-s
2003-11-18 JP Rosevear <jpr@ximian.com>
* Makefile.am: remove db3 library, if you really want it, get it
from e-d-s
svn path=/trunk/; revision=23424
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/ChangeLog | 5 | ||||
-rw-r--r-- | e-util/Makefile.am | 16 | ||||
-rw-r--r-- | e-util/e-db3-utils.c | 184 | ||||
-rw-r--r-- | e-util/e-db3-utils.h | 29 | ||||
-rw-r--r-- | e-util/e-dbhash.c | 227 | ||||
-rw-r--r-- | e-util/e-dbhash.h | 45 |
6 files changed, 6 insertions, 500 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 727c5cb74d..32eb9600c0 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,8 @@ +2003-11-18 JP Rosevear <jpr@ximian.com> + + * Makefile.am: remove db3 library, if you really want it, get it + from e-d-s + 2003-11-14 JP Rosevear <jpr@ximian.com> * Makefile.am: don't build the e-source stuff anymore, its in diff --git a/e-util/Makefile.am b/e-util/Makefile.am index ab8f39a3a2..cfb512938e 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -1,6 +1,5 @@ eutilincludedir = $(privincludedir)/e-util econdincludedir = $(privincludedir)/e-conduit -edb3includedir = $(privincludedir)/e-db3util INCLUDES = \ -I$(top_srcdir) \ @@ -9,11 +8,10 @@ INCLUDES = \ -DG_LOG_DOMAIN=\"e-utils\" \ -DG_DISABLE_DEPRECATED \ -DGTK_DISABLE_DEPRECATED \ - $(DB3_CFLAGS) \ $(GNOME_PILOT_CFLAGS) \ $(E_UTIL_CFLAGS) -privlib_LTLIBRARIES = libeutil.la libedb3util.la libeconduit.la +privlib_LTLIBRARIES = libeutil.la libeconduit.la eutilinclude_HEADERS = \ e-account-list.h \ @@ -114,18 +112,6 @@ EXTRA_DIST = \ ChangeLog.pre-1-4 \ e-util-marshal.list -edb3include_HEADERS = \ - e-db3-utils.h \ - e-dbhash.h - -libedb3util_la_SOURCES = \ - $(edb3include_HEADERS) \ - e-db3-utils.c \ - e-dbhash.c - -libedb3util_la_LIBADD = \ - $(DB3_LDADD) - BUILT_SOURCES = $(MARSHAL_GENERATED) CLEANFILES = $(BUILT_SOURCES) diff --git a/e-util/e-db3-utils.c b/e-util/e-db3-utils.c deleted file mode 100644 index 3326f32a6e..0000000000 --- a/e-util/e-db3-utils.c +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- 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-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 deleted file mode 100644 index a574e59178..0000000000 --- a/e-util/e-db3-utils.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- 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 deleted file mode 100644 index 209798fbc5..0000000000 --- a/e-util/e-dbhash.c +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Author: - * JP Rosevear (jpr@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#include <config.h> - -#include "e-dbhash.h" - -#include <string.h> -#include <fcntl.h> -#include <db.h> -#include "md5-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 - -struct _EDbHashPrivate -{ - DB *db; -}; - -EDbHash * -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 */ - 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 (rv != 0) - return NULL; - } - - edbh = g_new (EDbHash, 1); - edbh->priv = g_new (EDbHashPrivate, 1); - edbh->priv->db = db; - - return edbh; -} - -static void -string_to_dbt(const char *str, DBT *dbt) -{ - memset (dbt, 0, sizeof (DBT)); - dbt->data = (void*)str; - dbt->size = strlen (str) + 1; -} - -static void -md5_to_dbt(const char str[16], DBT *dbt) -{ - memset (dbt, 0, sizeof (DBT)); - dbt->data = (void*)str; - dbt->size = 16; -} - -void -e_dbhash_add (EDbHash *edbh, const gchar *key, const gchar *data) -{ - DB *db; - DBT dkey; - DBT ddata; - guchar local_hash[16]; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - g_return_if_fail (edbh->priv->db != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (data != NULL); - - db = edbh->priv->db; - - /* Key dbt */ - string_to_dbt (key, &dkey); - - /* Data dbt */ - md5_get_digest (data, strlen (data), local_hash); - md5_to_dbt (local_hash, &ddata); - - /* Add to database */ - db->put (db, NULL, &dkey, &ddata, 0); -} - -void -e_dbhash_remove (EDbHash *edbh, const char *key) -{ - DB *db; - DBT dkey; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - g_return_if_fail (key != NULL); - - db = edbh->priv->db; - - /* Key dbt */ - string_to_dbt (key, &dkey); - - /* Remove from database */ - db->del (db, NULL, &dkey, 0); -} - -void -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); - g_return_if_fail (edbh->priv != NULL); - g_return_if_fail (func != NULL); - - db = edbh->priv->db; - - db_error = db->cursor (db, NULL, &dbc, 0); - - if (db_error != 0) { - return; - } - - memset(&dkey, 0, sizeof(DBT)); - memset(&ddata, 0, sizeof(DBT)); - db_error = dbc->c_get(dbc, &dkey, &ddata, DB_FIRST); - - while (db_error == 0) { - (*func) ((const char *)dkey.data, user_data); - - db_error = dbc->c_get(dbc, &dkey, &ddata, DB_NEXT); - } - dbc->c_close (dbc); -} - -EDbHashStatus -e_dbhash_compare (EDbHash *edbh, const char *key, const char *compare_data) -{ - DB *db; - DBT dkey; - DBT ddata; - guchar compare_hash[16]; - - g_return_val_if_fail (edbh != NULL, FALSE); - g_return_val_if_fail (edbh->priv != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (compare_hash != NULL, FALSE); - - db = edbh->priv->db; - - /* Key dbt */ - string_to_dbt (key, &dkey); - - /* Lookup in database */ - memset (&ddata, 0, sizeof (DBT)); - db->get (db, NULL, &dkey, &ddata, 0); - - /* Compare */ - if (ddata.data) { - md5_get_digest (compare_data, strlen (compare_data), compare_hash); - - if (memcmp (ddata.data, compare_hash, sizeof (guchar) * 16)) - return E_DBHASH_STATUS_DIFFERENT; - } else { - return E_DBHASH_STATUS_NOT_FOUND; - } - - return E_DBHASH_STATUS_SAME; -} - -void -e_dbhash_write (EDbHash *edbh) -{ - DB *db; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - - db = edbh->priv->db; - - /* Flush database to disk */ - db->sync (db, 0); -} - -void -e_dbhash_destroy (EDbHash *edbh) -{ - DB *db; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - - db = edbh->priv->db; - - /* Close datbase */ - db->close (db, 0); - - g_free (edbh->priv); - g_free (edbh); -} diff --git a/e-util/e-dbhash.h b/e-util/e-dbhash.h deleted file mode 100644 index 9772a60c41..0000000000 --- a/e-util/e-dbhash.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Writes hashes that go to/from disk in db form. Hash keys are strings - * - * Author: - * JP Rosevear (jpr@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#ifndef __E_DBHASH_H__ -#define __E_DBHASH_H__ - -#include <glib.h> - -typedef enum { - E_DBHASH_STATUS_SAME, - E_DBHASH_STATUS_DIFFERENT, - E_DBHASH_STATUS_NOT_FOUND, -} EDbHashStatus; - -typedef struct _EDbHash EDbHash; -typedef struct _EDbHashPrivate EDbHashPrivate; - -struct _EDbHash -{ - EDbHashPrivate *priv; -}; - -typedef void (*EDbHashFunc) (const char *key, gpointer user_data); - -EDbHash *e_dbhash_new (const char *filename); - -void e_dbhash_add (EDbHash *edbh, const char *key, const char *data); -void e_dbhash_remove (EDbHash *edbh, const char *key); - -EDbHashStatus e_dbhash_compare (EDbHash *edbh, const char *key, const char *compare_data); -void e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data); - -void e_dbhash_write (EDbHash *edbh); - -void e_dbhash_destroy (EDbHash *edbh); - -#endif /* ! __E_DBHASH_H__ */ - |