diff libpurple/protocols/myspace/myspace.c @ 24732:3c224208b814

Use a GString here when constructing the data. It's way more convenient.
author Mark Doliner <mark@kingant.net>
date Tue, 16 Dec 2008 03:49:05 +0000
parents 295464ae2d2a
children 512c7c31eb21 212fb65cef7f
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Tue Dec 16 03:35:22 2008 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Tue Dec 16 03:49:05 2008 +0000
@@ -542,9 +542,9 @@
 	guchar hash_pw[HASH_SIZE];
 	guchar key[HASH_SIZE];
 	gchar *password_utf16le, *password_utf8_lc;
-	guchar *data;
+	GString *data;
 	guchar *data_out;
-	size_t data_len, data_out_len;
+	size_t data_out_len;
 	gsize conv_bytes_read, conv_bytes_written;
 	GError *conv_error;
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
@@ -618,25 +618,25 @@
 	/* rc4 encrypt:
 	 * nonce1+email+IP list */
 
-	data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN;
-	data = g_new0(guchar, data_len);
-	memcpy(data, nonce, NONCE_SIZE);
-	memcpy(data + NONCE_SIZE, email, strlen(email));
-	memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
-
-	data_out = g_new0(guchar, data_len);
-
-	purple_cipher_context_encrypt(rc4, (const guchar *)data,
-			data_len, data_out, &data_out_len);
+	data = g_string_new(NULL);
+	g_string_append_len(data, nonce, NONCE_SIZE);
+	g_string_append(data, email);
+	g_string_append_len(data, MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
+
+	data_out = g_new0(guchar, data->len);
+
+	purple_cipher_context_encrypt(rc4, (const guchar *)data->str,
+			data->len, data_out, &data_out_len);
 	purple_cipher_context_destroy(rc4);
-	g_free(data);
-
-	if (data_out_len != data_len) {
+
+	if (data_out_len != data->len) {
 		purple_debug_info("msim", "msim_compute_login_response: "
 				"data length mismatch: %" G_GSIZE_FORMAT " != %"
-				G_GSIZE_FORMAT "\n", data_out_len, data_len);
+				G_GSIZE_FORMAT "\n", data_out_len, data->len);
 	}
 
+	g_string_free(data, TRUE);
+
 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
 	purple_debug_info("msim", "response=<%s>\n", data_out);
 #endif