[epiphany/wip/sync: 1/3] sync: Add EphySyncPasswordsRecord



commit 1fce9d377e86d0985f14977d4b011e44c48cd32d
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Wed Apr 19 20:45:04 2017 +0300

    sync: Add EphySyncPasswordsRecord

 src/Makefile.am                       |    2 +
 src/sync/ephy-sync-passwords-record.c |  375 +++++++++++++++++++++++++++++++++
 src/sync/ephy-sync-passwords-record.h |   38 ++++
 3 files changed, 415 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 43d7c34..bfb12aa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -75,6 +75,8 @@ libephymain_la_SOURCES = \
        window-commands.h                       \
        sync/ephy-sync-crypto.c                 \
        sync/ephy-sync-crypto.h                 \
+       sync/ephy-sync-passwords-record.c       \
+       sync/ephy-sync-passwords-record.h       \
        sync/ephy-sync-secret.c                 \
        sync/ephy-sync-secret.h                 \
        sync/ephy-sync-service.c                \
diff --git a/src/sync/ephy-sync-passwords-record.c b/src/sync/ephy-sync-passwords-record.c
new file mode 100644
index 0000000..85adcd3
--- /dev/null
+++ b/src/sync/ephy-sync-passwords-record.c
@@ -0,0 +1,375 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2017 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ *  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-sync-passwords-record.h"
+
+#include "ephy-synchronizable.h"
+
+#include <json-glib/json-glib.h>
+
+struct _EphySyncPasswordsRecord {
+  GObject parent_instance;
+
+  /* EphySynchronizable specific fields. */
+  char     *id;
+  double    time_modified;
+  gboolean  is_uploaded;
+
+  /* Firefox Sync specific fields. */
+  char   *hostname;               /* Hostname that password is applicable at. */
+  char   *form_submit_url;        /* Submission URL (GET/POST URL set by form). */
+  char   *http_realm;             /* HTTP realm for which the login is valid. */
+  char   *username_field;         /* HTML field name of the username. */
+  char   *password_field;         /* HTML field name of the password. */
+  char   *username;               /* Uername to login in as. */
+  char   *password;               /* Password for the username. */
+  gint64  time_created;           /* UNIX timestamp, milliseconds. */
+  gint64  time_password_changed;  /* UNIX timestamp, milliseconds. */
+};
+
+static void json_serializable_iface_init (JsonSerializableIface *iface);
+static void ephy_synchronizable_iface_init (EphySynchronizableInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (EphySyncPasswordsRecord, ephy_sync_passwords_record, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE,
+                                                json_serializable_iface_init)
+                         G_IMPLEMENT_INTERFACE (EPHY_TYPE_SYNCHRONIZABLE,
+                                                ephy_synchronizable_iface_init))
+
+enum {
+  PROP_0,
+  PROP_HOSTNAME,
+  PROP_FORM_SUBMIT_URL,
+  PROP_HTTP_REALM,
+  PROP_USERNAME_FIELD,
+  PROP_PASSWORD_FIELD,
+  PROP_USERNAME,
+  PROP_PASSWORD,
+  PROP_TIME_CREATED,
+  PROP_TIME_PASSWORD_CHANGED,
+  LAST_PROP,
+  /* Interface properties. */
+  PROP_ID
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static const char *
+ephy_sync_passwords_record_synchronizable_get_id (EphySynchronizable *synchronizable)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (synchronizable);
+
+  return self->id;
+}
+
+static void
+ephy_sync_passwords_record_synchronizable_set_id (EphySynchronizable *synchronizable,
+                                                  const char         *id)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (synchronizable);
+
+  g_free (self->id);
+  self->id = g_strdup (id);
+}
+
+static double
+ephy_sync_passwords_record_synchronizable_get_time_modified (EphySynchronizable *synchronizable)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (synchronizable);
+
+  return self->time_modified;
+}
+
+static void
+ephy_sync_passwords_record_synchronizable_set_time_modified (EphySynchronizable *synchronizable,
+                                                             double              time_modified)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (synchronizable);
+
+  self->time_modified = time_modified;
+}
+
+static gboolean
+ephy_sync_passwords_record_synchronizable_is_uploaded (EphySynchronizable *synchronizable)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (synchronizable);
+
+  return self->is_uploaded;
+}
+
+static void
+ephy_sync_passwords_record_synchronizable_set_is_uploaded (EphySynchronizable *synchronizable,
+                                                           gboolean            is_uploaded)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (synchronizable);
+
+  self->is_uploaded = is_uploaded;
+}
+
+static JsonNode *
+ephy_sync_passwords_record_synchronizable_to_bso (EphySynchronizable  *synchronizable,
+                                                  SyncCryptoKeyBundle *bundle)
+{
+  return ephy_synchronizable_default_to_bso (synchronizable, bundle);
+}
+
+static void
+ephy_synchronizable_iface_init (EphySynchronizableInterface *iface)
+{
+  iface->get_id = ephy_sync_passwords_record_synchronizable_get_id;
+  iface->set_id = ephy_sync_passwords_record_synchronizable_set_id;
+  iface->get_time_modified = ephy_sync_passwords_record_synchronizable_get_time_modified;
+  iface->set_time_modified = ephy_sync_passwords_record_synchronizable_set_time_modified;
+  iface->is_uploaded = ephy_sync_passwords_record_synchronizable_is_uploaded;
+  iface->set_is_uploaded = ephy_sync_passwords_record_synchronizable_set_is_uploaded;
+  iface->to_bso = ephy_sync_passwords_record_synchronizable_to_bso;
+}
+
+static JsonNode *
+ephy_sync_passwords_record_serialize_property (JsonSerializable *serializable,
+                                               const char       *name,
+                                               const GValue     *value,
+                                               GParamSpec       *pspec)
+{
+  return json_serializable_default_serialize_property (serializable, name, value, pspec);
+}
+
+static gboolean
+ephy_sync_passwords_record_deserialize_property (JsonSerializable *serializable,
+                                                 const char       *name,
+                                                 GValue           *value,
+                                                 GParamSpec       *pspec,
+                                                 JsonNode         *node)
+{
+  return json_serializable_default_deserialize_property (serializable, name, value, pspec, node);
+}
+
+static void
+json_serializable_iface_init (JsonSerializableIface *iface)
+{
+  iface->serialize_property = ephy_sync_passwords_record_serialize_property;
+  iface->deserialize_property = ephy_sync_passwords_record_deserialize_property;
+}
+
+static void
+ephy_sync_passwords_record_set_property (GObject      *object,
+                                         guint          prop_id,
+                                         const GValue *value,
+                                         GParamSpec   *pspec)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (object);
+
+  switch (prop_id) {
+    case PROP_ID:
+      g_free (self->id);
+      self->id = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_HOSTNAME:
+      g_free (self->hostname);
+      self->hostname = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_FORM_SUBMIT_URL:
+      g_free (self->form_submit_url);
+      self->form_submit_url = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_HTTP_REALM:
+      g_free (self->http_realm);
+      self->http_realm = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_USERNAME_FIELD:
+      g_free (self->username_field);
+      self->username_field = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_PASSWORD_FIELD:
+      g_free (self->password_field);
+      self->password_field = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_USERNAME:
+      g_free (self->username);
+      self->username = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_PASSWORD:
+      g_free (self->password);
+      self->password = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_TIME_CREATED:
+      self->time_created = g_value_get_int64 (value);
+      break;
+    case PROP_TIME_PASSWORD_CHANGED:
+      self->time_password_changed = g_value_get_int64 (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
+}
+
+static void
+ephy_sync_passwords_record_get_property (GObject    *object,
+                                         guint       prop_id,
+                                         GValue     *value,
+                                         GParamSpec *pspec)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (object);
+
+  switch (prop_id) {
+    case PROP_ID:
+      g_value_set_string (value, self->id);
+      break;
+    case PROP_HOSTNAME:
+      g_value_set_string (value, self->hostname);
+      break;
+    case PROP_FORM_SUBMIT_URL:
+      g_value_set_string (value, self->form_submit_url);
+      break;
+    case PROP_HTTP_REALM:
+      g_value_set_string (value, self->http_realm);
+      break;
+    case PROP_USERNAME_FIELD:
+      g_value_set_string (value, self->username_field);
+      break;
+    case PROP_PASSWORD_FIELD:
+      g_value_set_string (value, self->password_field);
+      break;
+    case PROP_USERNAME:
+      g_value_set_string (value, self->username);
+      break;
+    case PROP_PASSWORD:
+      g_value_set_string (value, self->password);
+      break;
+    case PROP_TIME_CREATED:
+      g_value_set_int64 (value, self->time_created);
+      break;
+    case PROP_TIME_PASSWORD_CHANGED:
+      g_value_set_int64 (value, self->time_password_changed);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
+}
+
+static void
+ephy_sync_passwords_record_dispose (GObject *object)
+{
+  EphySyncPasswordsRecord *self = EPHY_SYNC_PASSWORDS_RECORD (object);
+
+  g_clear_pointer (&self->id, g_free);
+
+  G_OBJECT_CLASS (ephy_sync_passwords_record_parent_class)->dispose (object);
+}
+
+static void
+ephy_sync_passwords_record_class_init (EphySyncPasswordsRecordClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = ephy_sync_passwords_record_set_property;
+  object_class->get_property = ephy_sync_passwords_record_get_property;
+  object_class->dispose = ephy_sync_passwords_record_dispose;
+
+  obj_properties[PROP_HOSTNAME] =
+    g_param_spec_string ("hostname",
+                         "Hostname",
+                         "Hostname that password is applicable at",
+                         "Default hostname",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_FORM_SUBMIT_URL] =
+    g_param_spec_string ("formSubmitURL",
+                         "Form submit URL",
+                         "Submission URL set by form",
+                         "Default URL",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_HTTP_REALM] =
+    g_param_spec_string ("httpRealm",
+                         "HTTP realm",
+                         "HTTP realm for which the login is valid",
+                         "Default HTTP realm",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_USERNAME_FIELD] =
+    g_param_spec_string ("usernameField",
+                         "Username field",
+                         "HTML field name of the username",
+                         "Default username field",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_PASSWORD_FIELD] =
+    g_param_spec_string ("passwordField",
+                         "Password field",
+                         "HTML field name of the password",
+                         "Default password field",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_USERNAME] =
+    g_param_spec_string ("username",
+                         "Username",
+                         "Username to log in as",
+                         "Default username",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_PASSWORD] =
+    g_param_spec_string ("password",
+                         "Password",
+                         "Password for the username",
+                         "Default password",
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_TIME_CREATED] =
+    g_param_spec_int64 ("timeCreated",
+                        "Time created",
+                        "Time at which the password was created",
+                        0,
+                        G_MAXINT64,
+                        0,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+  obj_properties[PROP_TIME_PASSWORD_CHANGED] =
+    g_param_spec_int64 ("timePasswordChanged",
+                        "Time password changed",
+                        "Time at which the password was changed",
+                        0,
+                        G_MAXINT64,
+                        0,
+                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+  g_object_class_override_property (object_class, PROP_ID, "id");
+}
+
+static void
+ephy_sync_passwords_record_init (EphySyncPasswordsRecord *self)
+{
+}
+
+EphySyncPasswordsRecord *
+ephy_sync_passwords_record_new (const char *id,
+                                const char *hostname,
+                                const char *username_field,
+                                const char *password_field,
+                                const char *username,
+                                const char *password)
+{
+  return EPHY_SYNC_PASSWORDS_RECORD (g_object_new (EPHY_TYPE_SYNC_PASSWORDS_RECORD,
+                                                   "id", id,
+                                                   "hostname", hostname,
+                                                   "formSubmitURL", hostname,
+                                                   "httpRealm", hostname,
+                                                   "usernameField", username_field,
+                                                   "passwordField", password_field,
+                                                   "username", username,
+                                                   "password", password,
+                                                   "timeCreated", g_get_real_time () / 1000,
+                                                   "timePasswordChanged", g_get_real_time () / 1000,
+                                                   NULL));
+}
diff --git a/src/sync/ephy-sync-passwords-record.h b/src/sync/ephy-sync-passwords-record.h
new file mode 100644
index 0000000..2886c53
--- /dev/null
+++ b/src/sync/ephy-sync-passwords-record.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2017 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ *  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_SYNC_PASSWORDS_RECORD (ephy_sync_passwords_record_get_type ())
+
+G_DECLARE_FINAL_TYPE (EphySyncPasswordsRecord, ephy_sync_passwords_record, EPHY, SYNC_PASSWORDS_RECORD, 
GObject)
+
+EphySyncPasswordsRecord *ephy_sync_passwords_record_new (const char *id,
+                                                         const char *hostname,
+                                                         const char *username_field,
+                                                         const char *password_field,
+                                                         const char *username,
+                                                         const char *password);
+
+G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]