/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Author: * JP Rosevear (jpr@helixcode.com) * * Copyright 2000, Helix Code, Inc. */ #include #include #include #ifdef HAVE_DB_185_H #include #else #ifdef HAVE_DB1_DB_H #include #else #include #endif #endif #include "md5-utils.h" #include "e-dbhash.h" struct _EDbHashPrivate { DB *db; }; EDbHash * e_dbhash_new (const char *filename) { EDbHash *edbh; DB *db; /* 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); if (db == NULL) 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) { dbt->data = (void*)str; dbt->size = strlen (str) + 1; } 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); string_to_dbt (local_hash, &ddata); /* Add to database */ db->put (db, &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, &dkey, 0); } void e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data) { DB *db; DBT dkey; DBT ddata; 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->seq(db, &dkey, &ddata, R_FIRST); while (db_error == 0) { (*func) ((const char *)dkey.data, user_data); db_error = db->seq(db, &dkey, &ddata, R_NEXT); } } 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, &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); g_free (edbh->priv); g_free (edbh); } option> FreeBSD GNOME current development ports (https://github.com/freebsd/freebsd-ports-gnome)
aboutsummaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* Update to 5.0.6.jkim2016-05-071-4/+4
* Remove ${PORTSDIR}/ from dependencies, categories r, s, t, and u.mat2016-04-013-5/+5
* Add missing items to the calligra-l10n ports plists.rakuco2016-03-292-0/+2
* Update to 5.0.5.jkim2016-02-161-4/+4
* Update Calligra to 2.9.11.rakuco2016-02-092-3/+2
* Update Calligra to 2.9.10.rakuco2015-12-223-26/+38
* Update to 5.0.4.jkim2015-12-181-4/+4
* Update to 5.0.3.jkim2015-11-041-4/+4
* Update to 5.0.2.jkim2015-09-242-6/+6
* Update LibreOffice to 5.0.1.jkim2015-09-021-4/+4
* Correct the pathname in user-instructions given by the port andmi2015-07-271-1/+1
* - Add NO_ARCHsunpoet2015-07-181-0/+1
* - Add NO_ARCHsunpoet2015-07-181-0/+1
* - Add NO_ARCHsunpoet2015-07-181-0/+1
* Update to 4.3.7.jkim2015-04-261-4/+4
* Make fonts repecting XDGbapt2015-03-224-18/+13
* Update KDE SC to 4.14.3alonso2015-03-122-2/+3
* - Update to 4.3.6.jkim2015-02-211-4/+4
* cleanup plistbapt2014-12-214-4/+0
* Update to 4.3.5.jkim2014-12-191-4/+4
* Update to 4.3.4.jkim2014-11-271-4/+4
* Cleanup plistantoine2014-11-122-5/+0
* Update to 4.3.3.jkim2014-11-011-4/+4
* Update to 1.8.0bapt2014-10-312-3/+3
* Update to 1.8.0bapt2014-10-312-3/+6
* KDE/FreeBSD team presents KDE SC 4.14.2 and KDE Workspace 4.11.13!makc2014-10-193-304/+86
* Update to 4.3.2.jkim2014-10-172-5/+4
* Update the default version of GCC in the Ports Collection from GCC 4.7.4gerald2014-09-113-2/+3
* Upgrade OpenEXR and ilmbase to 2.2.0.mandree2014-08-16