[rhythmbox] audioscrobbler: use g_compute_checksum_for_string to generate md5 hashes



commit d1699492743f584de500c9b9ed4209ff5f486f4f
Author: Jamie Nicol <jamie thenicols net>
Date:   Mon Jul 19 12:32:25 2010 +0100

    audioscrobbler: use g_compute_checksum_for_string to generate md5 hashes

 plugins/audioscrobbler/rb-audioscrobbler-account.c |   19 +-------------
 .../rb-audioscrobbler-radio-source.c               |   19 +-------------
 plugins/audioscrobbler/rb-audioscrobbler-user.c    |   21 ++--------------
 plugins/audioscrobbler/rb-audioscrobbler.c         |   25 ++-----------------
 4 files changed, 10 insertions(+), 74 deletions(-)
---
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-account.c b/plugins/audioscrobbler/rb-audioscrobbler-account.c
index 9c26e6d..719661a 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-account.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-account.c
@@ -306,21 +306,6 @@ rb_audioscrobbler_account_get_login_status (RBAudioscrobblerAccount *account)
 	return account->priv->login_status;
 }
 
-static gchar *
-mkmd5 (char *string)
-{
-	GChecksum *checksum;
-	gchar *md5_result;
-
-	checksum = g_checksum_new (G_CHECKSUM_MD5);
-	g_checksum_update (checksum, (guchar *)string, -1);
-
-	md5_result = g_strdup (g_checksum_get_string (checksum));
-	g_checksum_free (checksum);
-
-	return md5_result;
-}
-
 static void
 rb_audioscrobbler_account_load_session_settings (RBAudioscrobblerAccount *account)
 {
@@ -526,7 +511,7 @@ rb_audioscrobbler_account_request_token (RBAudioscrobblerAccount *account)
 	sig_arg = g_strdup_printf ("api_key%smethodauth.getToken%s",
 	                           api_key,
 	                           api_secret);
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 	url = g_strdup_printf ("%s?method=auth.getToken&api_key=%s&api_sig=%s",
 			       api_url, api_key, sig);
 
@@ -640,7 +625,7 @@ rb_audioscrobbler_account_request_session_key_timeout_cb (gpointer user_data)
 	                           api_key,
 	                           account->priv->auth_token,
 	                           api_secret);
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 	url = g_strdup_printf ("%s?method=auth.getSession&api_key=%s&token=%s&api_sig=%s",
 	                       api_url,
 	                       api_key,
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
index fb6c331..b8148bb 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-radio-source.c
@@ -530,21 +530,6 @@ rb_audioscrobbler_radio_source_set_property (GObject *object,
 	}
 }
 
-static gchar *
-mkmd5 (char *string)
-{
-	GChecksum *checksum;
-	gchar *md5_result;
-
-	checksum = g_checksum_new (G_CHECKSUM_MD5);
-	g_checksum_update (checksum, (guchar *)string, -1);
-
-	md5_result = g_strdup (g_checksum_get_string (checksum));
-	g_checksum_free (checksum);
-
-	return md5_result;
-}
-
 static void
 rb_audioscrobbler_radio_source_playing_song_changed_cb (RBShellPlayer *player,
                                                         RhythmDBEntry *entry,
@@ -635,7 +620,7 @@ rb_audioscrobbler_radio_source_tune (RBAudioscrobblerRadioSource *source)
 	                           source->priv->station_url,
 	                           rb_audioscrobbler_service_get_api_secret (source->priv->service));
 
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 
 	escaped_station_url = g_uri_escape_string (source->priv->station_url,
 	                                   NULL,
@@ -757,7 +742,7 @@ rb_audioscrobbler_radio_source_fetch_playlist (RBAudioscrobblerRadioSource *sour
 	                           source->priv->session_key,
 	                           rb_audioscrobbler_service_get_api_secret (source->priv->service));
 
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 
 	request = g_strdup_printf ("method=radio.getPlaylist&api_key=%s&api_sig=%s&sk=%s&raw=true",
 	                           rb_audioscrobbler_service_get_api_key (source->priv->service),
diff --git a/plugins/audioscrobbler/rb-audioscrobbler-user.c b/plugins/audioscrobbler/rb-audioscrobbler-user.c
index 41094b9..b941cb4 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler-user.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler-user.c
@@ -454,21 +454,6 @@ rb_audioscrobbler_user_set_property (GObject *object,
 	}
 }
 
-static gchar *
-mkmd5 (char *string)
-{
-	GChecksum *checksum;
-	gchar *md5_result;
-
-	checksum = g_checksum_new (G_CHECKSUM_MD5);
-	g_checksum_update (checksum, (guchar *)string, -1);
-
-	md5_result = g_strdup (g_checksum_get_string (checksum));
-	g_checksum_free (checksum);
-
-	return md5_result;
-}
-
 void
 rb_audioscrobbler_user_set_authentication_details (RBAudioscrobblerUser *user,
                                                    const char *username,
@@ -1327,7 +1312,7 @@ rb_audioscrobbler_user_request_recommended_artists (RBAudioscrobblerUser *user,
 	                           limit,
 	                           user->priv->session_key,
 	                           rb_audioscrobbler_service_get_api_secret (user->priv->service));
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 
 	msg_url = g_strdup_printf ("%s?method=user.getRecommendedArtists&api_key=%s&api_sig=%s&sk=%s&limit=%i&format=json",
 	                           rb_audioscrobbler_service_get_api_url (user->priv->service),
@@ -1651,7 +1636,7 @@ rb_audioscrobbler_user_love_track (RBAudioscrobblerUser *user,
 	                           title,
 	                           rb_audioscrobbler_service_get_api_secret (user->priv->service));
 
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 
 	request = g_strdup_printf ("method=track.love&track=%s&artist=%s&api_key=%s&api_sig=%s&sk=%s",
 	                           title,
@@ -1705,7 +1690,7 @@ rb_audioscrobbler_user_ban_track (RBAudioscrobblerUser *user,
 	                           title,
 	                           rb_audioscrobbler_service_get_api_secret (user->priv->service));
 
-	sig = mkmd5 (sig_arg);
+	sig = g_compute_checksum_for_string (G_CHECKSUM_MD5, sig_arg, -1);
 
 	request = g_strdup_printf ("method=track.ban&track=%s&artist=%s&api_key=%s&api_sig=%s&sk=%s",
 	                           title,
diff --git a/plugins/audioscrobbler/rb-audioscrobbler.c b/plugins/audioscrobbler/rb-audioscrobbler.c
index 3ad1d46..b6e8b9e 100644
--- a/plugins/audioscrobbler/rb-audioscrobbler.c
+++ b/plugins/audioscrobbler/rb-audioscrobbler.c
@@ -157,7 +157,6 @@ static void	     rb_audioscrobbler_finalize (GObject *object);
 static void	     rb_audioscrobbler_add_timeout (RBAudioscrobbler *audioscrobbler);
 static gboolean	     rb_audioscrobbler_timeout_cb (RBAudioscrobbler *audioscrobbler);
 
-static gchar *	     mkmd5 (char *string);
 static void	     rb_audioscrobbler_parse_response (RBAudioscrobbler *audioscrobbler, SoupMessage *msg, gboolean handshake);
 
 static void	     rb_audioscrobbler_do_handshake (RBAudioscrobbler *audioscrobbler);
@@ -733,24 +732,6 @@ rb_audioscrobbler_offline_play_notify_cb (RhythmDB *db,
 	}
 }
 
-
-
-/* Audioscrobbler functions: */
-static gchar *
-mkmd5 (char *string)
-{
-	GChecksum *checksum;
-	gchar *md5_result;
-	
-	checksum = g_checksum_new(G_CHECKSUM_MD5);	
-	g_checksum_update(checksum, (guchar *)string, -1);
-	
-	md5_result = g_strdup(g_checksum_get_string(checksum));
-	g_checksum_free(checksum);
-	
-	return (md5_result);
-}
-
 static void
 rb_audioscrobbler_parse_response (RBAudioscrobbler *audioscrobbler, SoupMessage *msg, gboolean handshake)
 {
@@ -924,7 +905,7 @@ rb_audioscrobbler_do_handshake (RBAudioscrobbler *audioscrobbler)
 		autharg = g_strdup_printf ("%s%d",
 			                   rb_audioscrobbler_service_get_api_secret (audioscrobbler->priv->service),
 			                   timestamp);
-		auth = mkmd5 (autharg);
+		auth = g_compute_checksum_for_string (G_CHECKSUM_MD5, autharg, -1);
 
 		url = g_strdup_printf ("%s?hs=true&p=%s&c=%s&v=%s&u=%s&t=%d&a=%s&api_key=%s&sk=%s",
 				       rb_audioscrobbler_service_get_scrobbler_url (audioscrobbler->priv->service),
@@ -939,9 +920,9 @@ rb_audioscrobbler_do_handshake (RBAudioscrobbler *audioscrobbler)
 	} else {
 		/* password auth */
 		autharg = g_strdup_printf ("%s%d",
-		                           mkmd5 (audioscrobbler->priv->password),
+		                           g_compute_checksum_for_string (G_CHECKSUM_MD5, audioscrobbler->priv->password, 1),
 		                           timestamp);
-		auth = mkmd5 (autharg);
+		auth = g_compute_checksum_for_string (G_CHECKSUM_MD5, autharg, -1);
 
 		url = g_strdup_printf ("%s?hs=true&p=%s&c=%s&v=%s&u=%s&t=%d&a=%s",
 				       rb_audioscrobbler_service_get_scrobbler_url (audioscrobbler->priv->service),



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