[epiphany/gnome-3-26] sync: Move sync-related defines to sync-utils.h
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/gnome-3-26] sync: Move sync-related defines to sync-utils.h
- Date: Sat, 25 Nov 2017 19:56:08 +0000 (UTC)
commit 963d2a4f6a532d3f112e83b880c668282dd6a5d1
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date: Sat Nov 25 19:51:51 2017 +0200
sync: Move sync-related defines to sync-utils.h
lib/ephy-sync-utils.c | 8 +++-----
lib/ephy-sync-utils.h | 11 +++++++----
lib/sync/debug/ephy-sync-debug.c | 10 +++++-----
lib/sync/ephy-sync-service.c | 28 +++++++++++++---------------
4 files changed, 28 insertions(+), 29 deletions(-)
---
diff --git a/lib/ephy-sync-utils.c b/lib/ephy-sync-utils.c
index 0bcd704..f3bb391 100644
--- a/lib/ephy-sync-utils.c
+++ b/lib/ephy-sync-utils.c
@@ -27,8 +27,6 @@
#include <stdio.h>
#include <string.h>
-#define SYNC_ID_LEN 12
-
static const char hex_digits[] = "0123456789abcdef";
const SecretSchema *
@@ -37,7 +35,7 @@ ephy_sync_utils_get_secret_schema (void)
static const SecretSchema schema = {
"org.epiphany.SyncSecrets", SECRET_SCHEMA_NONE,
{
- { ACCOUNT_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { EPHY_SYNC_SECRET_ACCOUNT_KEY, SECRET_SCHEMA_ATTRIBUTE_STRING },
{ "NULL", 0 },
}
};
@@ -219,12 +217,12 @@ ephy_sync_utils_get_random_sync_id (void)
/* The sync id is a base64-urlsafe string. Base64 uses 4 chars to represent 3 bytes,
* therefore we need ceil(len * 3 / 4) bytes to cover the requested length. */
- bytes_len = (SYNC_ID_LEN + 3) / 4 * 3;
+ bytes_len = (EPHY_SYNC_BSO_ID_LEN + 3) / 4 * 3;
bytes = g_malloc (bytes_len);
ephy_sync_utils_generate_random_bytes (NULL, bytes_len, bytes);
base64 = ephy_sync_utils_base64_urlsafe_encode (bytes, bytes_len, FALSE);
- id = g_strndup (base64, SYNC_ID_LEN);
+ id = g_strndup (base64, EPHY_SYNC_BSO_ID_LEN);
g_free (base64);
g_free (bytes);
diff --git a/lib/ephy-sync-utils.h b/lib/ephy-sync-utils.h
index 083bea7..4b2a582 100644
--- a/lib/ephy-sync-utils.h
+++ b/lib/ephy-sync-utils.h
@@ -27,11 +27,14 @@ G_BEGIN_DECLS
const SecretSchema *ephy_sync_utils_get_secret_schema (void) G_GNUC_CONST;
-#define ACCOUNT_KEY "firefox_account"
-#define EPHY_SYNC_SECRET_SCHEMA (ephy_sync_utils_get_secret_schema ())
+#define EPHY_SYNC_SECRET_SCHEMA (ephy_sync_utils_get_secret_schema ())
+#define EPHY_SYNC_SECRET_ACCOUNT_KEY "firefox_account"
-#define TOKEN_SERVER_URL "https://token.services.mozilla.com/1.0/sync/1.5"
-#define FIREFOX_ACCOUNTS_SERVER_URL "https://api.accounts.firefox.com/v1"
+#define EPHY_SYNC_FX_TOKEN_SERVER_URL "https://token.services.mozilla.com/1.0/sync/1.5"
+#define EPHY_SYNC_FX_ACCOUNTS_SERVER_URL "https://api.accounts.firefox.com/v1"
+
+#define EPHY_SYNC_STORAGE_VERSION 5
+#define EPHY_SYNC_BSO_ID_LEN 12
char *ephy_sync_utils_encode_hex (const guint8 *data,
gsize data_len);
diff --git a/lib/sync/debug/ephy-sync-debug.c b/lib/sync/debug/ephy-sync-debug.c
index 52063e7..61a2fdb 100644
--- a/lib/sync/debug/ephy-sync-debug.c
+++ b/lib/sync/debug/ephy-sync-debug.c
@@ -48,7 +48,7 @@ ephy_sync_debug_load_secrets (void)
}
attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
- ACCOUNT_KEY, user,
+ EPHY_SYNC_SECRET_ACCOUNT_KEY, user,
NULL);
result = secret_service_search_sync (NULL,
EPHY_SYNC_SECRET_SCHEMA,
@@ -270,7 +270,7 @@ ephy_sync_debug_get_signed_certificate (const char *session_token,
json_node_set_object (node, json_body);
body = json_to_string (node, FALSE);
- url = g_strdup_printf ("%s/certificate/sign", FIREFOX_ACCOUNTS_SERVER_URL);
+ url = g_strdup_printf ("%s/certificate/sign", EPHY_SYNC_FX_ACCOUNTS_SERVER_URL);
msg = ephy_sync_debug_prepare_soup_message (url, "POST", body,
id_hex, key, 32);
session = soup_session_new ();
@@ -342,13 +342,13 @@ ephy_sync_debug_get_storage_credentials (char **storage_endpoint,
if (!certificate)
goto free_keypair;
- audience = ephy_sync_utils_get_audience (TOKEN_SERVER_URL);
+ audience = ephy_sync_utils_get_audience (EPHY_SYNC_FX_TOKEN_SERVER_URL);
assertion = ephy_sync_crypto_create_assertion (certificate, audience, 300, keypair);
kb = ephy_sync_utils_decode_hex (json_object_get_string_member (secrets, "master_key"));
hashed_kb = g_compute_checksum_for_data (G_CHECKSUM_SHA256, kb, 32);
client_state = g_strndup (hashed_kb, 32);
authorization = g_strdup_printf ("BrowserID %s", assertion);
- msg = soup_message_new ("GET", TOKEN_SERVER_URL);
+ msg = soup_message_new ("GET", EPHY_SYNC_FX_TOKEN_SERVER_URL);
soup_message_headers_append (msg->request_headers, "X-Client-State", client_state);
soup_message_headers_append (msg->request_headers, "authorization", authorization);
session = soup_session_new ();
@@ -470,7 +470,7 @@ ephy_sync_debug_view_secrets (void)
#if DEVELOPER_MODE
for (GList *l = result; l && l->data; l = l->next) {
GHashTable *attrs = secret_item_get_attributes (result->data);
- const char *account = g_hash_table_lookup (attrs, ACCOUNT_KEY);
+ const char *account = g_hash_table_lookup (attrs, EPHY_SYNC_SECRET_ACCOUNT_KEY);
SecretValue *value = secret_item_get_secret (result->data);
LOG ("Sync secrets of %s: %s", account, secret_value_get_text (value));
secret_value_unref (value);
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index c43da76..38b753b 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -33,8 +33,6 @@
#include <libsoup/soup.h>
#include <string.h>
-#define EPHY_STORAGE_VERSION 5
-
struct _EphySyncService {
GObject parent_instance;
@@ -406,7 +404,7 @@ ephy_sync_service_fxa_hawk_post (EphySyncService *self,
g_assert (key);
g_assert (request_body);
- url = g_strdup_printf ("%s/%s", FIREFOX_ACCOUNTS_SERVER_URL, endpoint);
+ url = g_strdup_printf ("%s/%s", EPHY_SYNC_FX_ACCOUNTS_SERVER_URL, endpoint);
msg = soup_message_new (SOUP_METHOD_POST, url);
soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY,
request_body, strlen (request_body));
@@ -442,7 +440,7 @@ ephy_sync_service_fxa_hawk_get (EphySyncService *self,
g_assert (id);
g_assert (key);
- url = g_strdup_printf ("%s/%s", FIREFOX_ACCOUNTS_SERVER_URL, endpoint);
+ url = g_strdup_printf ("%s/%s", EPHY_SYNC_FX_ACCOUNTS_SERVER_URL, endpoint);
msg = soup_message_new (SOUP_METHOD_GET, url);
header = ephy_sync_crypto_hawk_header_new (url, "GET", id, key, key_len, NULL);
soup_message_headers_append (msg->request_headers, "authorization", header->header);
@@ -596,7 +594,7 @@ ephy_sync_service_verify_certificate (EphySyncService *self,
g_warning ("JSON object has missing or invalid 'email' member");
goto out;
}
- uri = soup_uri_new (FIREFOX_ACCOUNTS_SERVER_URL);
+ uri = soup_uri_new (EPHY_SYNC_FX_ACCOUNTS_SERVER_URL);
expected = g_strdup_printf ("%s@%s",
ephy_sync_service_get_secret (self, secrets[UID]),
soup_uri_get_host (uri));
@@ -645,7 +643,7 @@ ephy_sync_service_forget_secrets (EphySyncService *self)
g_return_if_fail (user);
attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
- ACCOUNT_KEY, user,
+ EPHY_SYNC_SECRET_ACCOUNT_KEY, user,
NULL);
secret_service_clear (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes, NULL,
(GAsyncReadyCallback)forget_secrets_cb, NULL);
@@ -688,7 +686,7 @@ ephy_sync_service_destroy_session (EphySyncService *self,
session_token = ephy_sync_service_get_secret (self, secrets[SESSION_TOKEN]);
g_assert (session_token);
- url = g_strdup_printf ("%s/session/destroy", FIREFOX_ACCOUNTS_SERVER_URL);
+ url = g_strdup_printf ("%s/session/destroy", EPHY_SYNC_FX_ACCOUNTS_SERVER_URL);
ephy_sync_crypto_derive_session_token (session_token, &token_id,
&req_hmac_key, &tmp);
token_id_hex = ephy_sync_utils_encode_hex (token_id, 32);
@@ -817,7 +815,7 @@ ephy_sync_service_trade_browserid_assertion (EphySyncService *self)
g_assert (self->certificate);
g_assert (self->key_pair);
- audience = ephy_sync_utils_get_audience (TOKEN_SERVER_URL);
+ audience = ephy_sync_utils_get_audience (EPHY_SYNC_FX_TOKEN_SERVER_URL);
assertion = ephy_sync_crypto_create_assertion (self->certificate, audience,
300, self->key_pair);
kb = ephy_sync_utils_decode_hex (ephy_sync_service_get_secret (self, secrets[MASTER_KEY]));
@@ -825,7 +823,7 @@ ephy_sync_service_trade_browserid_assertion (EphySyncService *self)
client_state = g_strndup (hashed_kb, 32);
authorization = g_strdup_printf ("BrowserID %s", assertion);
- msg = soup_message_new (SOUP_METHOD_GET, TOKEN_SERVER_URL);
+ msg = soup_message_new (SOUP_METHOD_GET, EPHY_SYNC_FX_TOKEN_SERVER_URL);
/* We need to add the X-Client-State header so that the Token Server will
* recognize accounts that were previously used to sync Firefox data too.
*/
@@ -1518,7 +1516,7 @@ ephy_sync_service_load_secrets (EphySyncService *self)
user = ephy_sync_utils_get_sync_user ();
attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
- ACCOUNT_KEY, user,
+ EPHY_SYNC_SECRET_ACCOUNT_KEY, user,
NULL);
secret_service_search (NULL, EPHY_SYNC_SECRET_SCHEMA, attributes,
SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
@@ -1580,7 +1578,7 @@ ephy_sync_service_store_secrets (EphySyncService *self)
secret = secret_value_new (json_string, -1, "text/plain");
attributes = secret_attributes_build (EPHY_SYNC_SECRET_SCHEMA,
- ACCOUNT_KEY, self->user,
+ EPHY_SYNC_SECRET_ACCOUNT_KEY, self->user,
NULL);
/* Translators: %s is the email of the user. */
label = g_strdup_printf (_("The sync secrets of %s"), self->user);
@@ -1921,7 +1919,7 @@ ephy_sync_service_upload_meta_global (EphySyncService *self)
json_object_set_object_member (engines, "tabs", make_engine_object (1));
json_object_set_object_member (engines, "forms", make_engine_object (1));
json_object_set_object_member (payload, "engines", engines);
- json_object_set_int_member (payload, "storageVersion", EPHY_STORAGE_VERSION);
+ json_object_set_int_member (payload, "storageVersion", EPHY_SYNC_STORAGE_VERSION);
sync_id = ephy_sync_utils_get_random_sync_id ();
json_object_set_string_member (payload, "syncID", sync_id);
json_node_set_object (node, payload);
@@ -1999,11 +1997,11 @@ verify_storage_version_cb (SoupSession *session,
goto out_error;
}
storage_version = json_object_get_int_member (json, "storageVersion");
- if (storage_version != EPHY_STORAGE_VERSION) {
+ if (storage_version != EPHY_SYNC_STORAGE_VERSION) {
/* Translators: the %d is the storage version, the \n is a newline character. */
message = g_strdup_printf (_("Your Firefox Account uses storage version %d. "
"Web only supports version %d."),
- EPHY_STORAGE_VERSION,
+ EPHY_SYNC_STORAGE_VERSION,
storage_version);
goto out_error;
}
@@ -2306,7 +2304,7 @@ ephy_sync_service_register_device (EphySyncService *self,
g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
/* Make protocol. */
- protocol = g_strdup_printf ("1.%d", EPHY_STORAGE_VERSION);
+ protocol = g_strdup_printf ("1.%d", EPHY_SYNC_STORAGE_VERSION);
array = json_array_new ();
json_array_add_string_element (array, protocol);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]