[epiphany/wip/sync: 38/47] sync: Have more compact comparisons
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 38/47] sync: Have more compact comparisons
- Date: Tue, 7 Mar 2017 18:14:04 +0000 (UTC)
commit df5203500430355c2dd38e6092c2912e5f6a8337
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Wed Mar 1 01:36:03 2017 +0200
sync: Have more compact comparisons
src/sync/ephy-sync-crypto.c | 142 +++++++++++++++++++++---------------------
src/sync/ephy-sync-secret.c | 36 +++++-----
src/sync/ephy-sync-service.c | 66 ++++++++++----------
src/sync/ephy-sync-utils.c | 16 +++---
4 files changed, 130 insertions(+), 130 deletions(-)
---
diff --git a/src/sync/ephy-sync-crypto.c b/src/sync/ephy-sync-crypto.c
index 0e109f7..7e37cb2 100644
--- a/src/sync/ephy-sync-crypto.c
+++ b/src/sync/ephy-sync-crypto.c
@@ -64,7 +64,7 @@ ephy_sync_crypto_hawk_options_new (const char *app,
void
ephy_sync_crypto_hawk_options_free (EphySyncCryptoHawkOptions *options)
{
- g_return_if_fail (options != NULL);
+ g_return_if_fail (options);
g_free (options->app);
g_free (options->dlg);
@@ -111,7 +111,7 @@ ephy_sync_crypto_hawk_artifacts_new (const char *app,
static void
ephy_sync_crypto_hawk_artifacts_free (EphySyncCryptoHawkArtifacts *artifacts)
{
- g_assert (artifacts != NULL);
+ g_assert (artifacts);
g_free (artifacts->app);
g_free (artifacts->dlg);
@@ -143,7 +143,7 @@ ephy_sync_crypto_hawk_header_new (char *header,
void
ephy_sync_crypto_hawk_header_free (EphySyncCryptoHawkHeader *hheader)
{
- g_return_if_fail (hheader != NULL);
+ g_return_if_fail (hheader);
g_free (hheader->header);
ephy_sync_crypto_hawk_artifacts_free (hheader->artifacts);
@@ -167,7 +167,7 @@ ephy_sync_crypto_rsa_key_pair_new (struct rsa_public_key public,
void
ephy_sync_crypto_rsa_key_pair_free (EphySyncCryptoRSAKeyPair *keypair)
{
- g_return_if_fail (keypair != NULL);
+ g_return_if_fail (keypair);
rsa_public_key_clear (&keypair->public);
rsa_private_key_clear (&keypair->private);
@@ -178,7 +178,7 @@ ephy_sync_crypto_rsa_key_pair_free (EphySyncCryptoRSAKeyPair *keypair)
static char *
ephy_sync_crypto_kw (const char *name)
{
- g_assert (name != NULL);
+ g_assert (name);
/* Concatenate the given name to the Mozilla prefix.
* See https://raw.githubusercontent.com/wiki/mozilla/fxa-auth-server/images/onepw-create.png
@@ -193,8 +193,8 @@ ephy_sync_crypto_xor (guint8 *a,
{
guint8 *xored;
- g_assert (a != NULL);
- g_assert (b != NULL);
+ g_assert (a);
+ g_assert (b);
xored = g_malloc (length);
for (gsize i = 0; i < length; i++)
@@ -208,8 +208,8 @@ ephy_sync_crypto_equals (guint8 *a,
guint8 *b,
gsize length)
{
- g_assert (a != NULL);
- g_assert (b != NULL);
+ g_assert (a);
+ g_assert (b);
for (gsize i = 0; i < length; i++)
if (a[i] != b[i])
@@ -229,8 +229,8 @@ ephy_sync_crypto_normalize_string (const char *type,
char *normalized;
char *tmp;
- g_assert (type != NULL);
- g_assert (artifacts != NULL);
+ g_assert (type);
+ g_assert (artifacts);
info = g_strdup_printf ("hawk.%d.%s", HAWK_VERSION, type);
method = g_ascii_strup (artifacts->method, -1);
@@ -272,7 +272,7 @@ ephy_sync_crypto_parse_content_type (const char *content_type)
char **tokens;
char *retval;
- g_assert (content_type != NULL);
+ g_assert (content_type);
tokens = g_strsplit (content_type, ";", -1);
retval = g_ascii_strdown (g_strstrip (tokens[0]), -1);
@@ -291,8 +291,8 @@ ephy_sync_crypto_calculate_payload_hash (const char *payload,
char *update;
char *hash;
- g_assert (payload != NULL);
- g_assert (content_type != NULL);
+ g_assert (payload);
+ g_assert (content_type);
content = ephy_sync_crypto_parse_content_type (content_type);
update = g_strdup_printf ("hawk.%d.payload\n%s\n%s\n",
@@ -321,9 +321,9 @@ ephy_sync_crypto_calculate_mac (const char *type,
char *normalized;
char *mac;
- g_assert (type != NULL);
- g_assert (key != NULL);
- g_assert (artifacts != NULL);
+ g_assert (type);
+ g_assert (key);
+ g_assert (artifacts);
/* Serialize the mac type and artifacts into a HAWK string. */
normalized = ephy_sync_crypto_normalize_string (type, artifacts);
@@ -346,9 +346,9 @@ ephy_sync_crypto_append_to_header (char *header,
char *new_header;
char *tmp;
- g_assert (header != NULL);
- g_assert (name != NULL);
- g_assert (value != NULL);
+ g_assert (header);
+ g_assert (name);
+ g_assert (value);
tmp = header;
new_header = g_strconcat (header, ", ", name, "=\"", value, "\"", NULL);
@@ -378,9 +378,9 @@ ephy_sync_crypto_hkdf (guint8 *in,
gsize data_len;
gsize n;
- g_assert (in != NULL);
- g_assert (info != NULL);
- g_assert (out != NULL);
+ g_assert (in);
+ g_assert (info);
+ g_assert (out);
hash_len = g_checksum_type_get_length (G_CHECKSUM_SHA256);
g_assert (out_len <= hash_len * 255);
@@ -389,7 +389,7 @@ ephy_sync_crypto_hkdf (guint8 *in,
* See https://tools.ietf.org/html/rfc5869 */
/* If salt value was not provided, use an array of hash_len zeros. */
- if (salt == NULL) {
+ if (!salt) {
salt = g_malloc0 (hash_len);
salt_len = hash_len;
}
@@ -434,7 +434,7 @@ ephy_sync_crypto_hkdf (guint8 *in,
static void
ephy_sync_crypto_b64_to_b64_urlsafe (char *text)
{
- g_assert (text != NULL);
+ g_assert (text);
/* Replace '+' with '-' and '/' with '_' */
g_strcanon (text, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=/", '-');
@@ -444,7 +444,7 @@ ephy_sync_crypto_b64_to_b64_urlsafe (char *text)
static void
ephy_sync_crypto_b64_urlsafe_to_b64 (char *text)
{
- g_assert (text != NULL);
+ g_assert (text);
/* Replace '-' with '+' and '_' with '/' */
g_strcanon (text, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=_", '+');
@@ -465,11 +465,11 @@ ephy_sync_crypto_process_key_fetch_token (const char *keyFetchToken,
char *info_kft;
char *info_keys;
- g_return_if_fail (keyFetchToken != NULL);
- g_return_if_fail (tokenID != NULL);
- g_return_if_fail (reqHMACkey != NULL);
- g_return_if_fail (respHMACkey != NULL);
- g_return_if_fail (respXORkey != NULL);
+ g_return_if_fail (keyFetchToken);
+ g_return_if_fail (tokenID);
+ g_return_if_fail (reqHMACkey);
+ g_return_if_fail (respHMACkey);
+ g_return_if_fail (respXORkey);
kft = ephy_sync_crypto_decode_hex (keyFetchToken);
info_kft = ephy_sync_crypto_kw ("keyFetchToken");
@@ -519,10 +519,10 @@ ephy_sync_crypto_process_session_token (const char *sessionToken,
guint8 *out;
char *info;
- g_return_if_fail (sessionToken != NULL);
- g_return_if_fail (tokenID != NULL);
- g_return_if_fail (reqHMACkey != NULL);
- g_return_if_fail (requestKey != NULL);
+ g_return_if_fail (sessionToken);
+ g_return_if_fail (tokenID);
+ g_return_if_fail (reqHMACkey);
+ g_return_if_fail (requestKey);
st = ephy_sync_crypto_decode_hex (sessionToken);
info = ephy_sync_crypto_kw ("sessionToken");
@@ -562,12 +562,12 @@ ephy_sync_crypto_compute_sync_keys (const char *bundle,
guint8 *wrapKB;
char *respMAC2_hex;
- g_return_if_fail (bundle != NULL);
- g_return_if_fail (respHMACkey != NULL);
- g_return_if_fail (respXORkey != NULL);
- g_return_if_fail (unwrapBKey != NULL);
- g_return_if_fail (kA != NULL);
- g_return_if_fail (kB != NULL);
+ g_return_if_fail (bundle);
+ g_return_if_fail (respHMACkey);
+ g_return_if_fail (respXORkey);
+ g_return_if_fail (unwrapBKey);
+ g_return_if_fail (kA);
+ g_return_if_fail (kB);
bdl = ephy_sync_crypto_decode_hex (bundle);
ciphertext = g_malloc (2 * EPHY_SYNC_TOKEN_LENGTH);
@@ -582,7 +582,7 @@ ephy_sync_crypto_compute_sync_keys (const char *bundle,
respHMACkey, EPHY_SYNC_TOKEN_LENGTH,
ciphertext, 2 * EPHY_SYNC_TOKEN_LENGTH);
respMAC2 = ephy_sync_crypto_decode_hex (respMAC2_hex);
- g_assert (ephy_sync_crypto_equals (respMAC, respMAC2, EPHY_SYNC_TOKEN_LENGTH) == TRUE);
+ g_assert (ephy_sync_crypto_equals (respMAC, respMAC2, EPHY_SYNC_TOKEN_LENGTH));
/* XOR the extracted ciphertext with the respXORkey, then split in into the
* separate kA and wrap(kB) values. */
@@ -621,30 +621,30 @@ ephy_sync_crypto_compute_hawk_header (const char *url,
char *timestamp;
gint64 ts;
- g_return_val_if_fail (url != NULL, NULL);
- g_return_val_if_fail (method != NULL, NULL);
- g_return_val_if_fail (id != NULL, NULL);
- g_return_val_if_fail (key != NULL, NULL);
+ g_return_val_if_fail (url, NULL);
+ g_return_val_if_fail (method, NULL);
+ g_return_val_if_fail (id, NULL);
+ g_return_val_if_fail (key, NULL);
ts = ephy_sync_utils_current_time_seconds ();
hash = options ? g_strdup (options->hash) : NULL;
payload = options ? options->payload : NULL;
timestamp = options ? options->timestamp : NULL;
uri = soup_uri_new (url);
- resource = soup_uri_get_query (uri) == NULL ? g_strdup (soup_uri_get_path (uri))
- : g_strconcat (soup_uri_get_path (uri),
- "?",
- soup_uri_get_query (uri),
- NULL);
+ resource = !soup_uri_get_query (uri) ? g_strdup (soup_uri_get_path (uri))
+ : g_strconcat (soup_uri_get_path (uri),
+ "?",
+ soup_uri_get_query (uri),
+ NULL);
- if (options != NULL && options->nonce != NULL) {
+ if (options && options->nonce) {
nonce = g_strdup (options->nonce);
} else {
nonce = g_malloc0 (NONCE_LEN + 1);
ephy_sync_crypto_random_hex_gen (NULL, NONCE_LEN, (guint8 *)nonce);
}
- if (timestamp != NULL) {
+ if (timestamp) {
char *local_time_offset;
gint64 offset;
@@ -653,7 +653,7 @@ ephy_sync_crypto_compute_hawk_header (const char *url,
ts = g_ascii_strtoll (timestamp, NULL, 10) + offset;
}
- if (hash == NULL && payload != NULL) {
+ if (!hash && payload) {
const char *content_type = options ? options->content_type : "text/plain";
/* Calculate the hash for the given payload. */
@@ -678,11 +678,11 @@ ephy_sync_crypto_compute_hawk_header (const char *url,
NULL);
/* Append pre-calculated payload hash if any. */
- if (artifacts->hash != NULL && strlen (artifacts->hash) > 0)
+ if (artifacts->hash && strlen (artifacts->hash) > 0)
header = ephy_sync_crypto_append_to_header (header, "hash", artifacts->hash);
/* Append the application specific data if any. */
- if (artifacts->ext != NULL && strlen (artifacts->ext) > 0) {
+ if (artifacts->ext && strlen (artifacts->ext) > 0) {
char *h_ext;
char *tmp_ext;
@@ -699,11 +699,11 @@ ephy_sync_crypto_compute_hawk_header (const char *url,
header = ephy_sync_crypto_append_to_header (header, "mac", mac);
/* Append the Oz application id if any. */
- if (artifacts->app != NULL) {
+ if (artifacts->app) {
header = ephy_sync_crypto_append_to_header (header, "app", artifacts->app);
/* Append the Oz delegated-by application id if any. */
- if (artifacts->dlg != NULL)
+ if (artifacts->dlg)
header = ephy_sync_crypto_append_to_header (header, "dlg", artifacts->dlg);
}
@@ -764,9 +764,9 @@ ephy_sync_crypto_create_assertion (const char *certificate,
gsize expected_size;
gsize count;
- g_return_val_if_fail (certificate != NULL, NULL);
- g_return_val_if_fail (audience != NULL, NULL);
- g_return_val_if_fail (keypair != NULL, NULL);
+ g_return_val_if_fail (certificate, NULL);
+ g_return_val_if_fail (audience, NULL);
+ g_return_val_if_fail (keypair, NULL);
/* Encode the header and body to base64 url safe and join them. */
expires_at = g_get_real_time () / 1000 + duration * 1000;
@@ -851,13 +851,13 @@ ephy_sync_crypto_base64_urlsafe_encode (guint8 *data,
gsize start = 0;
gssize end;
- g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (data, NULL);
base64 = g_base64_encode (data, data_len);
end = strlen (base64) - 1;
/* Strip the data of any leading or trailing '=' characters. */
- if (strip == TRUE) {
+ if (strip) {
while (start < strlen (base64) && base64[start] == '=')
start++;
@@ -882,11 +882,11 @@ ephy_sync_crypto_base64_urlsafe_decode (const char *text,
char *to_decode;
char *suffix = NULL;
- g_return_val_if_fail (text != NULL, NULL);
- g_return_val_if_fail (out_len != NULL, NULL);
+ g_return_val_if_fail (text, NULL);
+ g_return_val_if_fail (out_len, NULL);
/* Fill the text with trailing '=' characters up to the proper length. */
- if (fill == TRUE)
+ if (fill)
suffix = g_strnfill ((4 - strlen (text) % 4) % 4, '=');
to_decode = g_strconcat (text, suffix, NULL);
@@ -911,8 +911,8 @@ ephy_sync_crypto_aes_256 (EphySyncCryptoAES256Mode mode,
guint8 *padded_data;
guint8 *out;
- g_return_val_if_fail (key != NULL, NULL);
- g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (key, NULL);
+ g_return_val_if_fail (data, NULL);
/* Since Nettle enforces the length of the data to be a multiple of
* AES_BLOCK_SIZE, the data needs to be padded accordingly. Because any
@@ -936,7 +936,7 @@ ephy_sync_crypto_aes_256 (EphySyncCryptoAES256Mode mode,
aes256_decrypt (&aes, padded_len, out, padded_data);
}
- if (out_len != NULL)
+ if (out_len)
*out_len = padded_len;
g_free (padded_data);
@@ -951,7 +951,7 @@ ephy_sync_crypto_encode_hex (guint8 *data,
char *retval;
gsize length;
- g_return_val_if_fail (data != NULL, NULL);
+ g_return_val_if_fail (data, NULL);
length = data_len == 0 ? EPHY_SYNC_TOKEN_LENGTH : data_len;
retval = g_malloc (length * 2 + 1);
@@ -974,7 +974,7 @@ ephy_sync_crypto_decode_hex (const char *hex)
guint8 *retval;
gsize hex_len = strlen (hex);
- g_return_val_if_fail (hex != NULL, NULL);
+ g_return_val_if_fail (hex, NULL);
g_return_val_if_fail (hex_len % 2 == 0, NULL);
retval = g_malloc (hex_len / 2);
diff --git a/src/sync/ephy-sync-secret.c b/src/sync/ephy-sync-secret.c
index b4269e9..9db7971 100644
--- a/src/sync/ephy-sync-secret.c
+++ b/src/sync/ephy-sync-secret.c
@@ -55,7 +55,7 @@ forget_tokens_cb (SecretService *service,
secret_service_clear_finish (service, result, &error);
- if (error != NULL) {
+ if (error) {
g_warning ("sync-secret: Failed to clear the secret schema: %s", error->message);
g_error_free (error);
}
@@ -94,12 +94,12 @@ load_tokens_cb (SecretService *service,
matches = secret_service_search_finish (service, result, &error);
- if (error != NULL || matches == NULL) {
+ if (error || !matches) {
g_set_error (&ret_error,
SYNC_SECRET_ERROR,
SYNC_SECRET_ERROR_LOAD,
_("The sync tokens could not be found."));
- if (error != NULL)
+ if (error)
g_warning ("sync-secret: Failed to find the tokens: %s", error->message);
goto out;
}
@@ -118,7 +118,7 @@ load_tokens_cb (SecretService *service,
email = g_hash_table_lookup (attributes, EMAIL_KEY);
user_email = ephy_sync_service_get_user_email (sync_service);
- if (email == NULL || g_strcmp0 (email, user_email) != 0) {
+ if (!email || g_strcmp0 (email, user_email)) {
g_set_error (&ret_error,
SYNC_SECRET_ERROR,
SYNC_SECRET_ERROR_LOAD,
@@ -128,7 +128,7 @@ load_tokens_cb (SecretService *service,
}
value = secret_item_get_secret (item);
- if (value == NULL) {
+ if (!value) {
g_set_error (&ret_error,
SYNC_SECRET_ERROR,
SYNC_SECRET_ERROR_LOAD,
@@ -141,7 +141,7 @@ load_tokens_cb (SecretService *service,
tokens = secret_value_get_text (value);
json_parser_load_from_data (parser, tokens, -1, &error);
- if (error != NULL) {
+ if (error) {
g_set_error (&ret_error,
SYNC_SECRET_ERROR,
SYNC_SECRET_ERROR_LOAD,
@@ -164,16 +164,16 @@ out:
/* Notify whether the tokens were successfully loaded. */
g_signal_emit_by_name (sync_service, "sync-tokens-load-finished", ret_error);
- if (error != NULL)
+ if (error)
g_error_free (error);
- if (ret_error != NULL)
+ if (ret_error)
g_error_free (ret_error);
- if (value != NULL)
+ if (value)
secret_value_unref (value);
- if (parser != NULL)
+ if (parser)
g_object_unref (parser);
g_list_free (members);
@@ -206,7 +206,7 @@ store_tokens_cb (SecretService *service,
/* Notify whether the tokens were successfully stored. */
g_signal_emit_by_name (sync_service, "sync-tokens-store-finished", error);
- if (error != NULL)
+ if (error)
g_error_free (error);
}
@@ -225,13 +225,13 @@ ephy_sync_secret_store_tokens (EphySyncService *service,
char *tokens;
char *label;
- g_return_if_fail (email != NULL);
- g_return_if_fail (uid != NULL);
- g_return_if_fail (sessionToken != NULL);
- g_return_if_fail (keyFetchToken != NULL);
- g_return_if_fail (unwrapBKey != NULL);
- g_return_if_fail (kA != NULL);
- g_return_if_fail (kB != NULL);
+ g_return_if_fail (email);
+ g_return_if_fail (uid);
+ g_return_if_fail (sessionToken);
+ g_return_if_fail (keyFetchToken);
+ g_return_if_fail (unwrapBKey);
+ g_return_if_fail (kA);
+ g_return_if_fail (kB);
tokens = ephy_sync_utils_build_json_string ("uid", uid,
"sessionToken", sessionToken,
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index f90633e..0327c17 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -119,7 +119,7 @@ storage_server_request_async_data_new (char *endpoint,
static void
storage_server_request_async_data_free (StorageRequestAsyncData *data)
{
- g_assert (data != NULL);
+ g_assert (data);
g_free (data->endpoint);
g_free (data->request_body);
@@ -131,7 +131,7 @@ ephy_sync_service_storage_credentials_is_expired (EphySyncService *self)
{
g_assert (EPHY_IS_SYNC_SERVICE (self));
- if (self->storage_credentials_id == NULL || self->storage_credentials_key == NULL)
+ if (!self->storage_credentials_id || !self->storage_credentials_key)
return TRUE;
if (self->storage_credentials_expiry_time == 0)
@@ -205,7 +205,7 @@ ephy_sync_service_fxa_hawk_get_sync (EphySyncService *self,
soup_message_headers_append (msg->request_headers, "authorization", hheader->header);
soup_session_send_message (self->session, msg);
- if (node != NULL) {
+ if (node) {
parser = json_parser_new ();
json_parser_load_from_data (parser, msg->response_body->data, -1, NULL);
*node = json_node_copy (json_parser_get_root (parser));
@@ -254,7 +254,7 @@ ephy_sync_service_certificate_is_valid (EphySyncService *self,
json = json_node_get_object (json_parser_get_root (parser));
alg = json_object_get_string_member (json, "alg");
- if (g_strcmp0 (alg, "RS256") != 0) {
+ if (g_strcmp0 (alg, "RS256")) {
g_warning ("Expected algorithm RS256, found %s. Giving up.", alg);
goto out;
}
@@ -265,7 +265,7 @@ ephy_sync_service_certificate_is_valid (EphySyncService *self,
email = json_object_get_string_member (principal, "email");
uid_email = g_strdup_printf ("%s@%s", self->uid, soup_uri_get_host (uri));
- if (g_strcmp0 (uid_email, email) != 0) {
+ if (g_strcmp0 (uid_email, email)) {
g_warning ("Expected email %s, found %s. Giving up.", uid_email, email);
goto out;
}
@@ -402,7 +402,7 @@ obtain_signed_certificate_cb (SoupSession *session,
certificate = json_object_get_string_member (json, "cert");
- if (ephy_sync_service_certificate_is_valid (service, certificate) == FALSE) {
+ if (!ephy_sync_service_certificate_is_valid (service, certificate)) {
ephy_sync_crypto_rsa_key_pair_free (service->keypair);
service->locked = FALSE;
goto out;
@@ -431,7 +431,7 @@ ephy_sync_service_obtain_signed_certificate (EphySyncService *self)
g_assert (self->sessionToken);
/* Generate a new RSA key pair that is going to be used to sign the new certificate. */
- if (self->keypair != NULL)
+ if (self->keypair)
ephy_sync_crypto_rsa_key_pair_free (self->keypair);
self->keypair = ephy_sync_crypto_generate_rsa_key_pair ();
@@ -478,14 +478,14 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
url = g_strdup_printf ("%s/%s", self->storage_endpoint, data->endpoint);
msg = soup_message_new (data->method, url);
- if (data->request_body != NULL) {
+ if (data->request_body) {
hoptions = ephy_sync_crypto_hawk_options_new (NULL, NULL, NULL, content_type,
NULL, NULL, NULL, data->request_body, NULL);
soup_message_set_request (msg, content_type, SOUP_MEMORY_COPY,
data->request_body, strlen (data->request_body));
}
- if (g_strcmp0 (data->method, SOUP_METHOD_POST) == 0)
+ if (!g_strcmp0 (data->method, SOUP_METHOD_POST))
soup_message_headers_append (msg->request_headers, "content-type", content_type);
if (data->modified_since >= 0) {
@@ -505,7 +505,7 @@ ephy_sync_service_send_storage_request (EphySyncService *self,
soup_message_headers_append (msg->request_headers, "authorization", hheader->header);
soup_session_queue_message (self->session, msg, data->callback, data->user_data);
- if (hoptions != NULL)
+ if (hoptions)
ephy_sync_crypto_hawk_options_free (hoptions);
g_free (url);
@@ -564,7 +564,7 @@ ephy_sync_service_finalize (GObject *object)
{
EphySyncService *self = EPHY_SYNC_SERVICE (object);
- if (self->keypair != NULL)
+ if (self->keypair)
ephy_sync_crypto_rsa_key_pair_free (self->keypair);
g_queue_free_full (self->storage_queue, (GDestroyNotify) storage_server_request_async_data_free);
@@ -629,7 +629,7 @@ ephy_sync_service_init (EphySyncService *self)
email = g_settings_get_string (EPHY_SETTINGS_MAIN, EPHY_PREFS_SYNC_USER);
- if (g_strcmp0 (email, "") != 0) {
+ if (g_strcmp0 (email, "")) {
ephy_sync_service_set_user_email (self, email);
ephy_sync_secret_load_tokens (self);
}
@@ -722,7 +722,7 @@ ephy_sync_service_set_token (EphySyncService *self,
EphySyncTokenType type)
{
g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- g_return_if_fail (value != NULL);
+ g_return_if_fail (value);
switch (type) {
case TOKEN_UID:
@@ -821,9 +821,9 @@ ephy_sync_service_destroy_session (EphySyncService *self,
g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- if (sessionToken == NULL)
+ if (!sessionToken)
sessionToken = ephy_sync_service_get_token (self, TOKEN_SESSIONTOKEN);
- g_return_if_fail (sessionToken != NULL);
+ g_return_if_fail (sessionToken);
url = g_strdup_printf ("%s%s", MOZILLA_FXA_SERVER_URL, endpoint);
ephy_sync_crypto_process_session_token (sessionToken, &tokenID, &reqHMACkey, &requestKey);
@@ -902,14 +902,14 @@ ephy_sync_service_finish_sign_in (EphySyncService *self,
char *kB_hex;
g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
- g_return_if_fail (email != NULL);
- g_return_if_fail (uid != NULL);
- g_return_if_fail (sessionToken != NULL);
- g_return_if_fail (keyFetchToken != NULL);
- g_return_if_fail (unwrapBKey != NULL);
- g_return_if_fail (bundle != NULL);
- g_return_if_fail (respHMACkey != NULL);
- g_return_if_fail (respXORkey != NULL);
+ g_return_if_fail (email);
+ g_return_if_fail (uid);
+ g_return_if_fail (sessionToken);
+ g_return_if_fail (keyFetchToken);
+ g_return_if_fail (unwrapBKey);
+ g_return_if_fail (bundle);
+ g_return_if_fail (respHMACkey);
+ g_return_if_fail (respXORkey);
/* Derive the sync keys form the received key bundle. */
unwrapKB = ephy_sync_crypto_decode_hex (unwrapBKey);
@@ -1120,7 +1120,7 @@ ephy_sync_service_delete_bookmark (EphySyncService *self,
/* If the bookmark does not exist on the server, delete it from the local
* instance too. */
- if (conditional == TRUE) {
+ if (conditional) {
ephy_sync_service_queue_storage_request (self, endpoint,
SOUP_METHOD_GET, NULL, -1, -1,
delete_bookmark_conditional_cb,
@@ -1168,17 +1168,17 @@ sync_bookmarks_first_time_cb (SoupSession *session,
EphyBookmark *remote = ephy_bookmark_from_bso (bso);
EphyBookmark *local;
- if (remote == NULL)
+ if (!remote)
continue;
local = ephy_bookmarks_manager_get_bookmark_by_id (manager, ephy_bookmark_get_id (remote));
- if (local == NULL) {
+ if (!local) {
local = ephy_bookmarks_manager_get_bookmark_by_url (manager, ephy_bookmark_get_url (remote));
/* If there is no local equivalent of the remote bookmark, then add it to
* the local instance together with its tags. */
- if (local == NULL) {
+ if (!local) {
ephy_bookmarks_manager_add_bookmark (manager, remote);
/* We have to manually add the tags to the bookmarks manager. */
@@ -1233,7 +1233,7 @@ sync_bookmarks_first_time_cb (SoupSession *session,
!g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
EphyBookmark *bookmark = g_sequence_get (iter);
- if (g_hash_table_contains (marked, bookmark) == FALSE)
+ if (!g_hash_table_contains (marked, bookmark))
ephy_sync_service_upload_bookmark (service, bookmark, TRUE);
}
@@ -1289,12 +1289,12 @@ sync_bookmarks_cb (SoupSession *session,
EphyBookmark *remote = ephy_bookmark_from_bso (bso);
EphyBookmark *local;
- if (remote == NULL)
+ if (!remote)
continue;
local = ephy_bookmarks_manager_get_bookmark_by_id (manager, ephy_bookmark_get_id (remote));
- if (local == NULL) {
+ if (!local) {
ephy_bookmarks_manager_add_bookmark (manager, remote);
/* We have to manually add the tags to the bookmarks manager. */
@@ -1324,7 +1324,7 @@ handle_local_bookmarks:
!g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) {
EphyBookmark *bookmark = EPHY_BOOKMARK (g_sequence_get (iter));
- if (ephy_bookmark_is_uploaded (bookmark) == TRUE)
+ if (ephy_bookmark_is_uploaded (bookmark))
ephy_sync_service_delete_bookmark (service, bookmark, TRUE);
else
ephy_sync_service_upload_bookmark (service, bookmark, FALSE);
@@ -1355,7 +1355,7 @@ ephy_sync_service_sync_bookmarks (EphySyncService *self,
endpoint = g_strdup_printf ("storage/%s?full=true", EPHY_BOOKMARKS_COLLECTION);
- if (first == TRUE) {
+ if (first) {
ephy_sync_service_queue_storage_request (self, endpoint,
SOUP_METHOD_GET, NULL, -1, -1,
sync_bookmarks_first_time_cb, NULL);
@@ -1387,7 +1387,7 @@ ephy_sync_service_start_periodical_sync (EphySyncService *self,
g_return_if_fail (EPHY_IS_SYNC_SERVICE (self));
g_return_if_fail (ephy_sync_service_is_signed_in (self));
- if (now == TRUE)
+ if (now)
do_periodical_sync (self);
self->source_id = g_timeout_add_seconds (SYNC_FREQUENCY, do_periodical_sync, NULL);
diff --git a/src/sync/ephy-sync-utils.c b/src/sync/ephy-sync-utils.c
index 35a9ff1..03e345a 100644
--- a/src/sync/ephy-sync-utils.c
+++ b/src/sync/ephy-sync-utils.c
@@ -69,7 +69,7 @@ ephy_sync_utils_make_audience (const char *url)
char *audience;
char *port;
- g_return_val_if_fail (url != NULL, NULL);
+ g_return_val_if_fail (url, NULL);
uri = soup_uri_new (url);
scheme = soup_uri_get_scheme (uri);
@@ -80,7 +80,7 @@ ephy_sync_utils_make_audience (const char *url)
* the default port for the url's scheme so we need to check if the port was
* really present in the url.
*/
- if (g_strstr_len (url, -1, port) != NULL)
+ if (g_strstr_len (url, -1, port))
audience = g_strdup_printf ("%s://%s%s", scheme, host, port);
else
audience = g_strdup_printf ("%s://%s", scheme, host);
@@ -115,17 +115,17 @@ ephy_sync_utils_token_name_from_type (EphySyncTokenType type)
EphySyncTokenType
ephy_sync_utils_token_type_from_name (const char *name)
{
- if (g_strcmp0 (name, "uid") == 0) {
+ if (!g_strcmp0 (name, "uid")) {
return TOKEN_UID;
- } else if (g_strcmp0 (name, "sessionToken") == 0) {
+ } else if (!g_strcmp0 (name, "sessionToken")) {
return TOKEN_SESSIONTOKEN;
- } else if (g_strcmp0 (name, "keyFetchToken") == 0) {
+ } else if (!g_strcmp0 (name, "keyFetchToken")) {
return TOKEN_KEYFETCHTOKEN;
- } else if (g_strcmp0 (name, "unwrapBKey") == 0) {
+ } else if (!g_strcmp0 (name, "unwrapBKey")) {
return TOKEN_UNWRAPBKEY;
- } else if (g_strcmp0 (name, "kA") == 0) {
+ } else if (!g_strcmp0 (name, "kA")) {
return TOKEN_KA;
- } else if (g_strcmp0 (name, "kB") == 0) {
+ } else if (!g_strcmp0 (name, "kB")) {
return TOKEN_KB;
} else {
g_assert_not_reached ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]