[epiphany/wip/google-safe-browsing: 21/30] gsb-service: Limit the use of C labels



commit f36ac0b0b2012b443e9f5dcc0d38259695981567
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date:   Wed Sep 20 23:15:55 2017 +0300

    gsb-service: Limit the use of C labels

 lib/safe-browsing/ephy-gsb-service.c |   48 +++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index 9ffd5e7..fc99862 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -194,10 +194,10 @@ ephy_gsb_service_update_thread (GTask          *task,
   JsonNode *body_node;
   JsonObject *body_obj;
   JsonArray *responses;
-  SoupMessage *msg = NULL;
-  GList *threat_lists = NULL;
+  SoupMessage *msg;
+  GList *threat_lists;
   gint64 next_update_time = CURRENT_TIME + DEFAULT_WAIT_TIME;
-  char *url = NULL;
+  char *url;
   char *body;
 
   g_assert (EPHY_IS_GSB_SERVICE (self));
@@ -206,8 +206,10 @@ ephy_gsb_service_update_thread (GTask          *task,
   ephy_gsb_storage_delete_old_full_hashes (self->storage);
 
   threat_lists = ephy_gsb_storage_get_threat_lists (self->storage);
-  if (!threat_lists)
-    goto out;
+  if (!threat_lists) {
+    g_task_return_int (task, next_update_time);
+    return;
+  }
 
   body_obj = ephy_gsb_utils_make_list_updates_request (threat_lists);
   body_node = json_node_new (JSON_NODE_OBJECT);
@@ -219,6 +221,7 @@ ephy_gsb_service_update_thread (GTask          *task,
   soup_message_set_request (msg, "application/json", SOUP_MEMORY_TAKE, body, strlen (body));
   soup_session_send_message (self->session, msg);
 
+  g_free (url);
   /* Reuse these for the response. */
   json_object_unref (body_obj);
   json_node_unref (body_node);
@@ -227,8 +230,9 @@ ephy_gsb_service_update_thread (GTask          *task,
   if (msg->status_code != 200) {
     LOG ("Cannot update threat lists, got: %u, %s", msg->status_code, msg->response_body->data);
     ephy_gsb_service_update_back_off_mode (self);
-    next_update_time = self->back_off_mode_exit_time;
-    goto out;
+    g_object_unref (msg);
+    g_task_return_int (task, self->back_off_mode_exit_time);
+    return;
   }
 
   /* Successful response, reset back-off mode. */
@@ -310,11 +314,8 @@ ephy_gsb_service_update_thread (GTask          *task,
 
   ephy_gsb_storage_set_next_update_time (self->storage, next_update_time);
 
+  g_object_unref (msg);
   json_node_unref (body_node);
-out:
-  g_free (url);
-  if (msg)
-    g_object_unref (msg);
   g_list_free_full (threat_lists, (GDestroyNotify)ephy_gsb_threat_list_free);
 
   g_task_return_int (task, next_update_time);
@@ -497,10 +498,10 @@ ephy_gsb_service_find_full_hashes_cb (SoupSession *session,
 {
   FindFullHashesData *data = (FindFullHashesData *)user_data;
   EphyGSBService *self = data->service;
-  JsonNode *body_node = NULL;
+  JsonNode *body_node;
   JsonObject *body_obj;
   JsonArray *matches;
-  GList *hashes_lookup = NULL;
+  GList *hashes_lookup;
   const char *duration_str;
   double duration;
 
@@ -508,7 +509,9 @@ ephy_gsb_service_find_full_hashes_cb (SoupSession *session,
   if (msg->status_code != 200) {
     LOG ("Cannot update full hashes, got: %u, %s", msg->status_code, msg->response_body->data);
     ephy_gsb_service_update_back_off_mode (self);
-    goto out;
+    data->callback (data->threats, data->user_data);
+    find_full_hashes_data_free (data);
+    return;
   }
 
   /* Successful response, reset back-off mode. */
@@ -570,11 +573,9 @@ ephy_gsb_service_find_full_hashes_cb (SoupSession *session,
     }
   }
 
-out:
   data->callback (data->threats, data->user_data);
 
-  if (body_node)
-    json_node_unref (body_node);
+  json_node_unref (body_node);
   g_list_free_full (hashes_lookup, (GDestroyNotify)ephy_gsb_hash_full_lookup_free);
   find_full_hashes_data_free (data);
 }
@@ -695,7 +696,8 @@ ephy_gsb_service_verify_hashes (EphyGSBService                  *self,
   /* If there are no database matches, then the URL is safe. */
   if (g_hash_table_size (matching_hashes_set) == 0) {
     LOG ("No database match, URL is safe");
-    goto return_result;
+    callback (threats, user_data);
+    goto out;
   }
 
   /* Check for full hashes matches.
@@ -723,7 +725,8 @@ ephy_gsb_service_verify_hashes (EphyGSBService                  *self,
    */
   if (g_hash_table_size (threats) > 0) {
     LOG ("Positive cache hit, URL is not safe");
-    goto return_result;
+    callback (threats, user_data);
+    goto out;
   }
 
   /* Check for negative cache hit. That is, there are no expired
@@ -738,7 +741,8 @@ ephy_gsb_service_verify_hashes (EphyGSBService                  *self,
   }
   if (!has_matching_expired_hashes && !has_matching_expired_prefixes) {
     LOG ("Negative cache hit, URL is safe");
-    goto return_result;
+    callback (threats, user_data);
+    goto out;
   }
 
   /* At this point we have either expired full hash matches and/or
@@ -752,10 +756,6 @@ ephy_gsb_service_verify_hashes (EphyGSBService                  *self,
   ephy_gsb_service_find_full_hashes (self, threats,
                                      matching_prefixes, matching_hashes,
                                      callback, user_data);
-  goto out;
-
-return_result:
-  callback (threats, user_data);
 
 out:
   g_list_free (matching_prefixes);


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