[epiphany/wip/google-safe-browsing: 31/57] 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: 31/57] gsb-service: Delete long expired full hashes at every update
- Date: Tue, 3 Oct 2017 16:46:57 +0000 (UTC)
commit a1f121325143ea3133bf7929a583dc7d2745068e
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 cb95618..3d483ea 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -167,6 +167,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 d985831..d3b2eee 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.
@@ -1339,6 +1341,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]