pidgin.vv.yahoo.voice: eb388989: Use purple_base64_encode and swap out so...

maiku at pidgin.im maiku at pidgin.im
Sat Aug 29 18:01:53 EDT 2009


-----------------------------------------------------------------
Revision: eb388989020c606fb52bbd62b9ed1d22f243ef18
Ancestor: 73020a8edef357e9fd6bc50d9712be4b6cea44d7
Author: maiku at pidgin.im
Date: 2009-08-29T21:53:37
Branch: im.pidgin.pidgin.vv.yahoo.voice
URL: http://d.pidgin.im/viewmtn/revision/info/eb388989020c606fb52bbd62b9ed1d22f243ef18

Modified files:
        libpurple/protocols/yahoo/yahoo_sip.c

ChangeLog: 

Use purple_base64_encode and swap out some characters for y64.

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/yahoo_sip.c	a4a5c29684d541274b76dddbd98a28814cf9bf34
+++ libpurple/protocols/yahoo/yahoo_sip.c	b4b4a1084bd7330104aea58a77ef0d340e114175
@@ -58,37 +58,6 @@ struct _YahooSip {
 
 #ifdef USE_VV
 #ifdef USE_SOFIASIP
-/* This is the y64 alphabet... it's like base64, but has a . and a _ */
-static const char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._";
-
-/* This is taken from Sylpheed by Hiroyuki Yamamoto.  We have our own tobase64 function
- * in util.c, but it has a bug I don't feel like finding right now ;) */
-static void to_y64(char *out, const unsigned char *in, gsize inlen)
-     /* raw bytes in quasi-big-endian order to base 64 string (NUL-terminated) */
-{
-	for (; inlen >= 3; inlen -= 3)
-		{
-			*out++ = base64digits[in[0] >> 2];
-			*out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)];
-			*out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
-			*out++ = base64digits[in[2] & 0x3f];
-			in += 3;
-		}
-	if (inlen > 0)
-		{
-			unsigned char fragment;
-
-			*out++ = base64digits[in[0] >> 2];
-			fragment = (in[0] << 4) & 0x30;
-			if (inlen > 1)
-				fragment |= in[1] >> 4;
-			*out++ = base64digits[fragment];
-			*out++ = (inlen < 2) ? '-' : base64digits[(in[1] << 2) & 0x3c];
-			*out++ = '-';
-		}
-	*out = '\0';
-}
-
 static void yahoo_sip_candidates_prepared_cb(PurpleMedia *media,
 		gchar *sid, gchar *name, nua_handle_t *nh);
 static void yahoo_sip_codecs_changed_cb(PurpleMedia *media,
@@ -250,7 +219,7 @@ event_callback(nua_event_t event, int st
 		gchar *auth, *cookie;
 		PurpleCipher *cipher;
 		PurpleCipherContext *context;
-		gchar *to_hash, response[25];
+		gchar *to_hash, *response;
 		guchar digest[16];
 
 		if (!wa) {
@@ -277,11 +246,13 @@ event_callback(nua_event_t event, int st
 		purple_cipher_context_digest(context, sizeof(digest),
 				digest, NULL);
 		purple_cipher_context_destroy(context);
-		to_y64(response, digest, 16);
 
-		auth = g_strdup_printf("%s:%s:%s:%s", method, realm,
-				purple_account_get_username(account),
-				purple_connection_get_password(pc));
+		/* to y64 */
+		response = purple_base64_encode(digest, 16);
+		purple_util_chrreplace(response, '=', '-');
+		purple_util_chrreplace(response, '+', '.');
+		purple_util_chrreplace(response, '/', '_');
+
 		/*
 		 * Should this be used instead?
 		 * "Y-Cookie: Y=%s; path=/; domain=.yahoo.com; T=%s; path=/;"
@@ -289,7 +260,12 @@ event_callback(nua_event_t event, int st
 		 */
 		cookie = g_strdup_printf("Y-Cookie: Y=%s; T=%s; AT=2; CRUMB=%s",
 				yd->cookie_y, yd->cookie_t, response);
+		g_free(response);
 
+		auth = g_strdup_printf("%s:%s:%s:%s", method, realm,
+				purple_account_get_username(account),
+				purple_connection_get_password(pc));
+
 		nua_authenticate(nh, NUTAG_AUTH(auth),
 				SIPTAG_HEADER_STR(cookie),
 				SIPTAG_HEADER_STR("Y-User-Agent: intl=us; "


More information about the Commits mailing list