[epiphany/wip/ephy-sync: 45/86] sync-service: Discard self->parser
- From: Gabriel - Cristian Ivascu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/ephy-sync: 45/86] sync-service: Discard self->parser
- Date: Sat, 30 Jul 2016 17:33:50 +0000 (UTC)
commit 7661a7d7acb684ec869787e95da87a4fad76a514
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Fri Jul 22 13:04:30 2016 +0300
sync-service: Discard self->parser
src/ephy-sync-service.c | 58 +++++++++++++++++++++++++---------------------
1 files changed, 31 insertions(+), 27 deletions(-)
---
diff --git a/src/ephy-sync-service.c b/src/ephy-sync-service.c
index eaab204..2633c13 100644
--- a/src/ephy-sync-service.c
+++ b/src/ephy-sync-service.c
@@ -38,7 +38,6 @@ struct _EphySyncService {
GObject parent_instance;
SoupSession *soup_session;
- JsonParser *parser;
GHashTable *tokens;
@@ -62,12 +61,12 @@ synchronous_hawk_post_request (EphySyncService *self,
guint8 *key,
gsize key_length,
gchar *request_body,
- JsonObject **jobject)
+ JsonNode **node)
{
EphySyncCryptoHawkOptions *hawk_options;
EphySyncCryptoHawkHeader *hawk_header;
SoupMessage *message;
- JsonNode *root;
+ JsonParser *parser;
gchar *url;
const gchar *content_type = "application/json";
@@ -92,13 +91,13 @@ synchronous_hawk_post_request (EphySyncService *self,
"content-type", content_type);
soup_session_send_message (self->soup_session, message);
- if (jobject != NULL) {
- json_parser_load_from_data (self->parser,
+ if (node != NULL) {
+ parser = json_parser_new ();
+ json_parser_load_from_data (parser,
message->response_body->data,
-1, NULL);
- root = json_parser_get_root (self->parser);
- g_assert (JSON_NODE_HOLDS_OBJECT (root));
- *jobject = json_node_get_object (root);
+ *node = json_node_copy (json_parser_get_root (parser));
+ g_object_unref (parser);
}
g_free (url);
@@ -114,11 +113,11 @@ synchronous_hawk_get_request (EphySyncService *self,
const gchar *id,
guint8 *key,
gsize key_length,
- JsonObject **jobject)
+ JsonNode **node)
{
EphySyncCryptoHawkHeader *hawk_header;
SoupMessage *message;
- JsonNode *root;
+ JsonParser *parser;
gchar *url;
url = g_strdup_printf ("%s%s%s", FXA_BASEURL, FXA_VERSION, endpoint);
@@ -133,13 +132,13 @@ LOG ("[%d] Sending synchronous HAWK GET request to %s endpoint", __LINE__, endpo
soup_session_send_message (self->soup_session, message);
LOG ("[%d] Got response from server: %u", __LINE__, message->status_code);
- if (jobject != NULL) {
- json_parser_load_from_data (self->parser,
+ if (node != NULL) {
+ parser = json_parser_new ();
+ json_parser_load_from_data (parser,
message->response_body->data,
-1, NULL);
- root = json_parser_get_root (self->parser);
- g_assert (JSON_NODE_HOLDS_OBJECT (root));
- *jobject = json_node_get_object (root);
+ *node = json_node_copy (json_parser_get_root (parser));
+ g_object_unref (parser);
}
g_free (url);
@@ -391,7 +390,6 @@ ephy_sync_service_finalize (GObject *object)
g_free (self->token_server_key);
g_hash_table_destroy (self->tokens);
g_clear_object (&self->soup_session);
- g_clear_object (&self->parser);
ephy_sync_crypto_rsa_key_pair_free (self->keypair);
G_OBJECT_CLASS (ephy_sync_service_parent_class)->finalize (object);
@@ -413,7 +411,6 @@ ephy_sync_service_init (EphySyncService *self)
self->tokens = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, g_free);
self->soup_session = soup_session_new ();
- self->parser = json_parser_new ();
sync_user = g_settings_get_string (EPHY_SETTINGS_MAIN,
EPHY_PREFS_SYNC_USER);
@@ -564,7 +561,8 @@ ephy_sync_service_fetch_sync_keys (EphySyncService *self,
{
EphySyncCryptoProcessedKFT *processed_kft = NULL;
EphySyncCryptoSyncKeys *sync_keys = NULL;
- JsonObject *jobject;
+ JsonNode *node;
+ JsonObject *json;
guint8 *unwrapKB;
gchar *tokenID;
guint status_code;
@@ -578,15 +576,17 @@ ephy_sync_service_fetch_sync_keys (EphySyncService *self,
tokenID,
processed_kft->reqHMACkey,
EPHY_SYNC_TOKEN_LENGTH,
- &jobject);
+ &node);
+ json = json_node_get_object (node);
+
if (status_code != STATUS_OK) {
g_warning ("FxA server errno: %ld, errmsg: %s",
- json_object_get_int_member (jobject, "errno"),
- json_object_get_string_member (jobject, "message"));
+ json_object_get_int_member (json, "errno"),
+ json_object_get_string_member (json, "message"));
goto out;
}
- sync_keys = ephy_sync_crypto_retrieve_sync_keys (json_object_get_string_member (jobject, "bundle"),
+ sync_keys = ephy_sync_crypto_retrieve_sync_keys (json_object_get_string_member (json, "bundle"),
processed_kft->respHMACkey,
processed_kft->respXORkey,
unwrapKB);
@@ -610,6 +610,7 @@ LOG ("kB: %s", ephy_sync_utils_encode_hex (sync_keys->kB, 0));
out:
ephy_sync_crypto_processed_kft_free (processed_kft);
ephy_sync_crypto_sync_keys_free (sync_keys);
+ json_node_free (node);
g_free (tokenID);
g_free (unwrapKB);
@@ -621,7 +622,8 @@ ephy_sync_service_sign_certificate (EphySyncService *self)
{
EphySyncCryptoProcessedST *processed_st;
EphySyncCryptoRSAKeyPair *keypair;
- JsonObject *jobject;
+ JsonNode *node;
+ JsonObject *json;
gchar *sessionToken;
gchar *tokenID;
gchar *public_key_json;
@@ -656,17 +658,18 @@ ephy_sync_service_sign_certificate (EphySyncService *self)
processed_st->reqHMACkey,
EPHY_SYNC_TOKEN_LENGTH,
request_body,
- &jobject);
+ &node);
+ json = json_node_get_object (node);
if (status_code != STATUS_OK) {
g_warning ("FxA server errno: %ld, errmsg: %s",
- json_object_get_int_member (jobject, "errno"),
- json_object_get_string_member (jobject, "message"));
+ json_object_get_int_member (json, "errno"),
+ json_object_get_string_member (json, "message"));
goto out;
}
/* Check if the certificate is valid */
- certificate = json_object_get_string_member (jobject, "cert");
+ certificate = json_object_get_string_member (json, "cert");
if (check_certificate (self, certificate) == FALSE) {
ephy_sync_crypto_rsa_key_pair_free (keypair);
goto out;
@@ -678,6 +681,7 @@ ephy_sync_service_sign_certificate (EphySyncService *self)
out:
ephy_sync_crypto_processed_st_free (processed_st);
+ json_node_free (node);
g_free (tokenID);
g_free (public_key_json);
g_free (request_body);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]