[epiphany/wip/ephy-sync] bookmark: Add ephy_bookmark_from_bso() function
- From: Gabriel - Cristian Ivascu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/ephy-sync] bookmark: Add ephy_bookmark_from_bso() function
- Date: Mon, 8 Aug 2016 18:23:23 +0000 (UTC)
commit d2544648ade84347e4cccfc3c253c1aaf783aa86
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Mon Aug 8 21:10:40 2016 +0300
bookmark: Add ephy_bookmark_from_bso() function
src/ephy-bookmark.c | 67 +++++++++++++++++++++++++++++++++++++++++------
src/ephy-bookmark.h | 4 +++
src/ephy-sync-crypto.c | 4 +-
src/ephy-sync-crypto.h | 4 +-
4 files changed, 66 insertions(+), 13 deletions(-)
---
diff --git a/src/ephy-bookmark.c b/src/ephy-bookmark.c
index 34ee26e..2baf426 100644
--- a/src/ephy-bookmark.c
+++ b/src/ephy-bookmark.c
@@ -23,7 +23,6 @@
#include "ephy-sync-crypto.h"
#include "ephy-sync-utils.h"
-#include <json-glib/json-glib.h>
#include <string.h>
struct _EphyBookmark {
@@ -319,20 +318,23 @@ ephy_bookmark_get_title (EphyBookmark *bookmark)
return bookmark->title;
}
-const char *
-ephy_bookmark_get_id (EphyBookmark *self)
+void
+ephy_bookmark_set_id (EphyBookmark *self,
+ const char *id)
{
- g_return_val_if_fail (EPHY_IS_BOOKMARK (self), NULL);
+ g_return_if_fail (EPHY_IS_BOOKMARK (self));
+ g_return_if_fail (id != NULL);
- return self->id;
+ g_free (self->id);
+ self->id = g_strdup (id);
}
-double
-ephy_bookmark_get_modified (EphyBookmark *self)
+const char *
+ephy_bookmark_get_id (EphyBookmark *self)
{
- g_return_val_if_fail (EPHY_IS_BOOKMARK (self), -1);
+ g_return_val_if_fail (EPHY_IS_BOOKMARK (self), NULL);
- return self->modified;
+ return self->id;
}
void
@@ -344,6 +346,14 @@ ephy_bookmark_set_modified (EphyBookmark *self,
self->modified = modified;
}
+double
+ephy_bookmark_get_modified (EphyBookmark *self)
+{
+ g_return_val_if_fail (EPHY_IS_BOOKMARK (self), -1);
+
+ return self->modified;
+}
+
void
ephy_bookmark_add_tag (EphyBookmark *self,
const char *tag)
@@ -472,3 +482,42 @@ ephy_bookmark_to_bso (EphyBookmark *self)
return bso;
}
+
+EphyBookmark *
+ephy_bookmark_from_bso (JsonObject *bso)
+{
+ EphySyncService *service;
+ EphyBookmark *bookmark = NULL;
+ GObject *object;
+ GError *error = NULL;
+ guint8 *sync_key;
+ guint8 *decoded;
+ gsize decoded_len;
+ char *decrypted;
+
+ g_return_val_if_fail (bso != NULL, NULL);
+
+ service = ephy_shell_get_global_sync_service (ephy_shell_get_default ());
+ sync_key = ephy_sync_crypto_decode_hex (ephy_sync_service_get_token (service, TOKEN_KB));
+ decoded = ephy_sync_crypto_base64_urlsafe_decode (json_object_get_string_member (bso, "payload"),
+ &decoded_len);
+ decrypted = (char *) ephy_sync_crypto_aes_256 (AES_256_MODE_DECRYPT, sync_key,
+ decoded, decoded_len, NULL);
+ object = json_gobject_from_data (EPHY_TYPE_BOOKMARK, decrypted, -1, &error);
+
+ if (object == NULL) {
+ g_warning ("Failed to create GObject from data: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ bookmark = EPHY_BOOKMARK (object);
+ ephy_bookmark_set_id (bookmark, json_object_get_string_member (bso, "id"));
+ ephy_bookmark_set_modified (bookmark, json_object_get_double_member (bso, "modified"));
+
+out:
+ g_free (decoded);
+ g_free (decrypted);
+
+ return bookmark;
+}
diff --git a/src/ephy-bookmark.h b/src/ephy-bookmark.h
index 502b563..c76dffe 100644
--- a/src/ephy-bookmark.h
+++ b/src/ephy-bookmark.h
@@ -19,6 +19,7 @@
#define _EPHY_BOOKMARK_H
#include <glib-object.h>
+#include <json-glib/json-glib.h>
G_BEGIN_DECLS
@@ -42,6 +43,8 @@ void ephy_bookmark_set_title (EphyBookmark *self,
const char *title);
const char *ephy_bookmark_get_title (EphyBookmark *self);
+void ephy_bookmark_set_id (EphyBookmark *self,
+ const char *id);
const char *ephy_bookmark_get_id (EphyBookmark *self);
void ephy_bookmark_set_modified (EphyBookmark *self,
@@ -62,6 +65,7 @@ int ephy_bookmark_tags_compare (const char *tag1,
const char *tag2);
char *ephy_bookmark_to_bso (EphyBookmark *self);
+EphyBookmark *ephy_bookmark_from_bso (JsonObject *bso);
G_END_DECLS
diff --git a/src/ephy-sync-crypto.c b/src/ephy-sync-crypto.c
index 947a69e..c6e5cdb 100644
--- a/src/ephy-sync-crypto.c
+++ b/src/ephy-sync-crypto.c
@@ -1000,8 +1000,8 @@ ephy_sync_crypto_base64_urlsafe_encode (guint8 *data,
}
guint8 *
-ephy_sync_crypto_base64_urlsafe_decode (gchar *text,
- gsize *out_length)
+ephy_sync_crypto_base64_urlsafe_decode (const gchar *text,
+ gsize *out_length)
{
guint8 *decoded;
gchar *text_copy;
diff --git a/src/ephy-sync-crypto.h b/src/ephy-sync-crypto.h
index 4cf1adb..814b14a 100644
--- a/src/ephy-sync-crypto.h
+++ b/src/ephy-sync-crypto.h
@@ -136,8 +136,8 @@ gchar *ephy_sync_crypto_base64_urlsafe_encode (guint8 *
gsize data_length,
gboolean strip);
-guint8 *ephy_sync_crypto_base64_urlsafe_decode (gchar *text,
- gsize *out_length);
+guint8 *ephy_sync_crypto_base64_urlsafe_decode (const gchar *text,
+ gsize *out_length);
guint8 *ephy_sync_crypto_aes_256 (EphySyncCryptoAES256Mode mode,
const guint8 *key,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]