[Telepathy-commits] [telepathy-haze/master] Make get_token require a non-NULL avatar, and fix things so it's only used in such a context.

Will Thompson will.thompson at collabora.co.uk
Mon Aug 11 11:12:14 PDT 2008


20080811181214-9f02e-a8e316f03db73c62ea9359cbdd916496a9c1422d.gz
---
 src/connection-avatars.c |   58 ++++++++++++++++++++++-----------------------
 1 files changed, 28 insertions(+), 30 deletions(-)

diff --git a/src/connection-avatars.c b/src/connection-avatars.c
index 4ac9b71..fcaf018 100644
--- a/src/connection-avatars.c
+++ b/src/connection-avatars.c
@@ -111,39 +111,28 @@ get_token (const GArray *avatar)
 {
     gchar *token;
 
-    if (avatar)
-    {
-        /* Taken mostly verbatim from purple_util_get_image_filename; this copy
-         * does not append a file extension to the hash, and also works with
-         * libpurple 2.0
-         */
-        PurpleCipherContext *context;
-        gchar digest[41];
-
-        context = purple_cipher_context_new_by_name("sha1", NULL);
-        if (context == NULL)
-        {
-            g_error ("Could not find libpurple's sha1 cipher");
-        }
+    PurpleCipherContext *context;
+    gchar digest[41];
 
-        /* Hash the image data */
-        purple_cipher_context_append(context, (const guchar *) avatar->data,
-                                     avatar->len);
-        if (!purple_cipher_context_digest_to_str(context, sizeof(digest),
-                                                 digest, NULL))
-        {
-            g_error ("Failed to get SHA-1 digest");
-        }
-        purple_cipher_context_destroy(context);
+    g_assert (avatar != NULL);
 
-        token = g_strdup (digest);
+    context = purple_cipher_context_new_by_name("sha1", NULL);
+    if (context == NULL)
+    {
+        g_error ("Could not find libpurple's sha1 cipher");
     }
-    else
+
+    /* Hash the image data */
+    purple_cipher_context_append(context, (const guchar *) avatar->data,
+            avatar->len);
+    if (!purple_cipher_context_digest_to_str(context, sizeof(digest),
+                digest, NULL))
     {
-        token = g_strdup ("");
+        g_error ("Failed to get SHA-1 digest");
     }
+    purple_cipher_context_destroy(context);
 
-    g_assert (token);
+    token = g_strdup (digest);
 
     return token;
 }
@@ -153,9 +142,18 @@ get_handle_token (HazeConnection *conn,
                   TpHandle handle)
 {
     GArray *avatar = get_avatar (conn, handle);
-    gchar *token = get_token (avatar);
-    if (avatar)
+    gchar *token;
+
+    if (avatar != NULL)
+    {
+        token = get_token (avatar);
         g_array_free (avatar, TRUE);
+    }
+    else
+    {
+        token = g_strdup ("");
+    }
+
     return token;
 }
 
@@ -266,7 +264,7 @@ haze_connection_request_avatars (TpSvcConnectionInterfaceAvatars *self,
     {
         TpHandle handle = g_array_index (contacts, TpHandle, i);
         GArray *avatar = get_avatar (conn, handle);
-        if (avatar)
+        if (avatar != NULL)
         {
             gchar *token = get_token (avatar);
             tp_svc_connection_interface_avatars_emit_avatar_retrieved (
-- 
1.5.6.3




More information about the Telepathy-commits mailing list