[epiphany/wip/google-safe-browsing: 20/35] gsb-service: Delete long expired full hashes at every update
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/google-safe-browsing: 20/35] gsb-service: Delete long expired full hashes at every update
- Date: Sun, 24 Sep 2017 18:20:21 +0000 (UTC)
commit ca01537fda38325f2d3f038639c86805a4bf1d12
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date: Mon Sep 18 21:29:22 2017 +0300
gsb-service: Delete long expired full hashes at every update
lib/safe-browsing/ephy-gsb-service.c | 2 +
lib/safe-browsing/ephy-gsb-storage.c | 39 ++++++++++++++++++++++++++++++++++
lib/safe-browsing/ephy-gsb-storage.h | 1 +
3 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index 8cafc26..7201b5f 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -165,6 +165,8 @@ ephy_gsb_service_update_thread (GTask *task,
g_assert (EPHY_IS_GSB_SERVICE (self));
g_assert (ephy_gsb_storage_is_operable (self->storage));
+ ephy_gsb_storage_delete_old_full_hashes (self->storage);
+
threat_lists = ephy_gsb_storage_get_threat_lists (self->storage);
if (!threat_lists)
goto out;
diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c
index 2837505..6f27610 100644
--- a/lib/safe-browsing/ephy-gsb-storage.c
+++ b/lib/safe-browsing/ephy-gsb-storage.c
@@ -28,6 +28,8 @@
#include <glib/gstdio.h>
#include <string.h>
+#define EXPIRATION_THRESHOLD (8 * 60 * 60)
+
/* Keep this lower than 200 or else you'll get "too many SQL variables" error
* in ephy_gsb_storage_insert_batch(). SQLITE_MAX_VARIABLE_NUMBER is hardcoded
* in sqlite3 as 999.
@@ -1346,6 +1348,43 @@ out:
}
void
+ephy_gsb_storage_delete_old_full_hashes (EphyGSBStorage *self)
+{
+ EphySQLiteStatement *statement = NULL;
+ GError *error = NULL;
+ const char *sql;
+
+ g_assert (EPHY_IS_GSB_STORAGE (self));
+ g_assert (self->is_operable);
+
+ LOG ("Deleting full hashes expired for more than %d seconds", EXPIRATION_THRESHOLD);
+
+ sql = "DELETE FROM hash_full "
+ "WHERE expires_at <= (CAST(strftime('%s', 'now') AS INT)) - ?";
+ statement = ephy_sqlite_connection_create_statement (self->db, sql, &error);
+ if (error) {
+ g_warning ("Failed to create delete full hash statement: %s", error->message);
+ goto out;
+ }
+
+ ephy_sqlite_statement_bind_int64 (statement, 0, EXPIRATION_THRESHOLD, &error);
+ if (error) {
+ g_warning ("Failed to bind int64 in delete full hash statement: %s", error->message);
+ goto out;
+ }
+
+ ephy_sqlite_statement_step (statement, &error);
+ if (error)
+ g_warning ("Failed to execute delete full hash statement: %s", error->message);
+
+out:
+ if (statement)
+ g_object_unref (statement);
+ if (error)
+ g_error_free (error);
+}
+
+void
ephy_gsb_storage_update_hash_prefix_expiration (EphyGSBStorage *self,
GBytes *prefix,
gint64 duration)
diff --git a/lib/safe-browsing/ephy-gsb-storage.h b/lib/safe-browsing/ephy-gsb-storage.h
index c908ada..2d6854f 100644
--- a/lib/safe-browsing/ephy-gsb-storage.h
+++ b/lib/safe-browsing/ephy-gsb-storage.h
@@ -59,6 +59,7 @@ void ephy_gsb_storage_insert_full_hash (EphyGSBStorage
EphyGSBThreatList *list,
const guint8 *hash,
gint64 duration);
+void ephy_gsb_storage_delete_old_full_hashes (EphyGSBStorage *self);
void ephy_gsb_storage_update_hash_prefix_expiration (EphyGSBStorage *self,
GBytes *prefix,
gint64 duration);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]