[epiphany/wip/google-safe-browsing: 15/57] safe-browsing: Add stub service and storage objects
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/google-safe-browsing: 15/57] safe-browsing: Add stub service and storage objects
- Date: Tue, 3 Oct 2017 16:45:37 +0000 (UTC)
commit db785bb030e801d2716a306179f74c75c3003d52
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date: Fri Sep 8 17:38:56 2017 +0300
safe-browsing: Add stub service and storage objects
embed/ephy-embed-shell.c | 27 +++++++
embed/ephy-embed-shell.h | 2 +
lib/ephy-profile-utils.h | 2 +
lib/meson.build | 5 +-
lib/safe-browsing/ephy-gsb-service.c | 135 ++++++++++++++++++++++++++++++++++
lib/safe-browsing/ephy-gsb-service.h | 33 ++++++++
lib/safe-browsing/ephy-gsb-storage.c | 126 +++++++++++++++++++++++++++++++
lib/safe-browsing/ephy-gsb-storage.h | 33 ++++++++
8 files changed, 362 insertions(+), 1 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 29f8f1b..47541de 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -57,6 +57,7 @@
typedef struct {
WebKitWebContext *web_context;
EphyHistoryService *global_history_service;
+ EphyGSBService *global_gsb_service;
EphyEncodings *encodings;
GtkPageSetup *page_setup;
GtkPrintSettings *print_settings;
@@ -168,6 +169,7 @@ ephy_embed_shell_dispose (GObject *object)
g_clear_object (&priv->page_setup);
g_clear_object (&priv->print_settings);
g_clear_object (&priv->global_history_service);
+ g_clear_object (&priv->global_gsb_service);
g_clear_object (&priv->about_handler);
g_clear_object (&priv->user_content);
g_clear_object (&priv->downloads_manager);
@@ -575,6 +577,31 @@ ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell)
return priv->global_history_service;
}
+/**
+ * ephy_embed_shell_get_global_gsb_service:
+ * @shell: the #EphyEmbedShell
+ *
+ * Return value: (transfer none): the global #EphyGSBService
+ **/
+EphyGSBService *
+ephy_embed_shell_get_global_gsb_service (EphyEmbedShell *shell)
+{
+ EphyEmbedShellPrivate *priv = ephy_embed_shell_get_instance_private (shell);
+
+ g_return_val_if_fail (EPHY_IS_EMBED_SHELL (shell), NULL);
+
+ if (priv->global_gsb_service == NULL) {
+ char *filename;
+
+ filename = g_build_filename (ephy_dot_dir (), EPHY_GSB_FILE, NULL);
+ priv->global_gsb_service = ephy_gsb_service_new (filename);
+
+ g_free (filename);
+ }
+
+ return priv->global_gsb_service;
+}
+
static void
snapshot_saved_cb (EphySnapshotService *service,
const char *url,
diff --git a/embed/ephy-embed-shell.h b/embed/ephy-embed-shell.h
index 6d9b2d0..44d6cc7 100644
--- a/embed/ephy-embed-shell.h
+++ b/embed/ephy-embed-shell.h
@@ -26,6 +26,7 @@
#include "ephy-downloads-manager.h"
#include "ephy-encodings.h"
+#include "ephy-gsb-service.h"
#include "ephy-history-service.h"
#include "ephy-permissions-manager.h"
#include "ephy-search-engine-manager.h"
@@ -58,6 +59,7 @@ EphyEmbedShell *ephy_embed_shell_get_default (void);
WebKitWebContext *ephy_embed_shell_get_web_context (EphyEmbedShell *shell);
EphyHistoryService
*ephy_embed_shell_get_global_history_service (EphyEmbedShell *shell);
+EphyGSBService *ephy_embed_shell_get_global_gsb_service (EphyEmbedShell *shell);
EphyEncodings *ephy_embed_shell_get_encodings (EphyEmbedShell *shell);
void ephy_embed_shell_restored_window (EphyEmbedShell *shell);
void ephy_embed_shell_set_page_setup (EphyEmbedShell *shell,
diff --git a/lib/ephy-profile-utils.h b/lib/ephy-profile-utils.h
index 54d6487..6f310e1 100644
--- a/lib/ephy-profile-utils.h
+++ b/lib/ephy-profile-utils.h
@@ -32,6 +32,8 @@ G_BEGIN_DECLS
#define EPHY_BOOKMARKS_FILE "bookmarks.gvdb"
#define EPHY_HISTORY_FILE "ephy-history.db"
+/* Threat list database for Google Safe Browsing. */
+#define EPHY_GSB_FILE "gsb-threats.db"
int ephy_profile_utils_get_migration_version (void);
int ephy_profile_utils_get_migration_version_for_profile_dir (const char *profile_directory);
diff --git a/lib/meson.build b/lib/meson.build
index e992db7..fdb5d75 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -48,6 +48,8 @@ libephymisc_sources = [
'history/ephy-history-service-urls-table.c',
'history/ephy-history-service-visits-table.c',
'history/ephy-history-types.c',
+ 'safe-browsing/ephy-gsb-service.c',
+ 'safe-browsing/ephy-gsb-storage.c',
enums
]
@@ -74,7 +76,8 @@ libephymisc_includes = include_directories(
'..',
'contrib',
'contrib/gvdb',
- 'history'
+ 'history',
+ 'safe-browsing'
)
libephymisc = shared_library('ephymisc',
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
new file mode 100644
index 0000000..dda2add
--- /dev/null
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -0,0 +1,135 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Gabriel Ivascu <gabrielivascu gnome org>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "ephy-gsb-service.h"
+
+#include "ephy-debug.h"
+#include "ephy-gsb-storage.h"
+
+struct _EphyGSBService {
+ GObject parent_instance;
+
+ EphyGSBStorage *storage;
+};
+
+G_DEFINE_TYPE (EphyGSBService, ephy_gsb_service, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_GSB_STORAGE,
+ LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static void
+ephy_gsb_service_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyGSBService *self = EPHY_GSB_SERVICE (object);
+
+ switch (prop_id) {
+ case PROP_GSB_STORAGE:
+ if (self->storage)
+ g_object_unref (self->storage);
+ self->storage = g_value_dup_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_gsb_service_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyGSBService *self = EPHY_GSB_SERVICE (object);
+
+ switch (prop_id) {
+ case PROP_GSB_STORAGE:
+ g_value_set_object (value, self->storage);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_gsb_service_dispose (GObject *object)
+{
+ EphyGSBService *self = EPHY_GSB_SERVICE (object);
+
+ g_clear_object (&self->storage);
+
+ G_OBJECT_CLASS (ephy_gsb_service_parent_class)->dispose (object);
+}
+
+static void
+ephy_gsb_service_constructed (GObject *object)
+{
+ EphyGSBService *self = EPHY_GSB_SERVICE (object);
+
+ G_OBJECT_CLASS (ephy_gsb_service_parent_class)->constructed (object);
+
+ /* TODO: Perform an initial database update if necessary. */
+}
+
+static void
+ephy_gsb_service_init (EphyGSBService *self)
+{
+}
+
+static void
+ephy_gsb_service_class_init (EphyGSBServiceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = ephy_gsb_service_set_property;
+ object_class->get_property = ephy_gsb_service_get_property;
+ object_class->constructed = ephy_gsb_service_constructed;
+ object_class->dispose = ephy_gsb_service_dispose;
+
+ obj_properties[PROP_GSB_STORAGE] =
+ g_param_spec_object ("gsb-storage",
+ "GSB filename",
+ "Handler object for the Google Safe Browsing database",
+ EPHY_TYPE_GSB_STORAGE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+}
+
+EphyGSBService *
+ephy_gsb_service_new (const char *db_path)
+{
+ EphyGSBService *service;
+ EphyGSBStorage *storage;
+
+ storage = ephy_gsb_storage_new (db_path);
+ service = g_object_new (EPHY_TYPE_GSB_SERVICE, "gsb-storage", storage, NULL);
+ g_object_unref (storage);
+
+ return service;
+}
diff --git a/lib/safe-browsing/ephy-gsb-service.h b/lib/safe-browsing/ephy-gsb-service.h
new file mode 100644
index 0000000..bcb4072
--- /dev/null
+++ b/lib/safe-browsing/ephy-gsb-service.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Gabriel Ivascu <gabrielivascu gnome org>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_GSB_SERVICE (ephy_gsb_service_get_type ())
+
+G_DECLARE_FINAL_TYPE (EphyGSBService, ephy_gsb_service, EPHY, GSB_SERVICE, GObject)
+
+EphyGSBService *ephy_gsb_service_new (const char *db_path);
+
+G_END_DECLS
diff --git a/lib/safe-browsing/ephy-gsb-storage.c b/lib/safe-browsing/ephy-gsb-storage.c
new file mode 100644
index 0000000..fbfc992
--- /dev/null
+++ b/lib/safe-browsing/ephy-gsb-storage.c
@@ -0,0 +1,126 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Gabriel Ivascu <gabrielivascu gnome org>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "ephy-gsb-storage.h"
+
+#include "ephy-debug.h"
+
+struct _EphyGSBStorage {
+ GObject parent_instance;
+
+ char *db_path;
+};
+
+G_DEFINE_TYPE (EphyGSBStorage, ephy_gsb_storage, G_TYPE_OBJECT);
+
+enum {
+ PROP_0,
+ PROP_DB_PATH,
+ LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static void
+ephy_gsb_storage_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyGSBStorage *self = EPHY_GSB_STORAGE (object);
+
+ switch (prop_id) {
+ case PROP_DB_PATH:
+ g_free (self->db_path);
+ self->db_path = g_strdup (g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_gsb_storage_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyGSBStorage *self = EPHY_GSB_STORAGE (object);
+
+ switch (prop_id) {
+ case PROP_DB_PATH:
+ g_value_set_string (value, self->db_path);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_gsb_storage_finalize (GObject *object)
+{
+ EphyGSBStorage *self = EPHY_GSB_STORAGE (object);
+
+ g_free (self->db_path);
+
+ G_OBJECT_CLASS (ephy_gsb_storage_parent_class)->finalize (object);
+}
+
+static void
+ephy_gsb_storage_constructed (GObject *object)
+{
+ EphyGSBStorage *self = EPHY_GSB_STORAGE (object);
+
+ G_OBJECT_CLASS (ephy_gsb_storage_parent_class)->constructed (object);
+
+ /* TODO: Check database existence/integrity. */
+}
+
+static void
+ephy_gsb_storage_init (EphyGSBStorage *self)
+{
+}
+
+static void
+ephy_gsb_storage_class_init (EphyGSBStorageClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = ephy_gsb_storage_set_property;
+ object_class->get_property = ephy_gsb_storage_get_property;
+ object_class->constructed = ephy_gsb_storage_constructed;
+ object_class->finalize = ephy_gsb_storage_finalize;
+
+ obj_properties[PROP_DB_PATH] =
+ g_param_spec_string ("db-path",
+ "Database path",
+ "The path of the SQLite file holding the lists of unsafe web resources",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+}
+
+EphyGSBStorage *
+ephy_gsb_storage_new (const char *db_path)
+{
+ return g_object_new (EPHY_TYPE_GSB_STORAGE, "db-path", db_path, NULL);
+}
diff --git a/lib/safe-browsing/ephy-gsb-storage.h b/lib/safe-browsing/ephy-gsb-storage.h
new file mode 100644
index 0000000..7a92313
--- /dev/null
+++ b/lib/safe-browsing/ephy-gsb-storage.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Gabriel Ivascu <gabrielivascu gnome org>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Epiphany is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_GSB_STORAGE (ephy_gsb_storage_get_type ())
+
+G_DECLARE_FINAL_TYPE (EphyGSBStorage, ephy_gsb_storage, EPHY, GSB_STORAGE, GObject)
+
+EphyGSBStorage *ephy_gsb_storage_new (const char *db_path);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]