changeset 9277:185fbd8b5998

[gaim-migrate @ 10080] I added a util function to turn some binary string into an ASCIIZ string so I can more easily eyeball it and realize I don't know what it means. And I added some yahoo code to print out some strings like that. Actually one of them I do what it means. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Mon, 14 Jun 2004 00:54:45 +0000
parents 9a294bf90cd0
children 2401a9ef74a0
files src/protocols/yahoo/yahoo.c src/protocols/yahoo/yahoo.h src/util.c src/util.h
diffstat 4 files changed, 87 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/yahoo/yahoo.c	Sun Jun 13 20:43:43 2004 +0000
+++ b/src/protocols/yahoo/yahoo.c	Mon Jun 14 00:54:45 2004 +0000
@@ -412,6 +412,22 @@
 				yahoo_update_status(gc, name, f);
 			}
 			break;
+		case 197: /* Avatars? */
+		{
+			char *decoded, *tmp;
+			guint len;
+
+			if (pair->value) {
+				gaim_base64_decode(pair->value, &decoded, &len);
+				if (len) {
+					tmp = gaim_str_binary_to_ascii(decoded, len);
+					gaim_debug_info("yahoo", "Got key 197, value = %s\n", tmp);
+					g_free(tmp);
+				}
+				g_free(decoded);
+			}
+			break;
+		}
 		case 16: /* Custom error message */
 			{
 				char *tmp = yahoo_string_decode(gc, pair->value, TRUE);
@@ -1038,20 +1054,20 @@
 	 *
 	 * Sorry, Yahoo.
 	 */
-		
+
 	md5_byte_t result[16];
 	md5_state_t ctx;
-		
+
 	char *crypt_result;
 	char password_hash[25];
 	char crypt_hash[25];
 	char *hash_string_p = g_malloc(50 + strlen(name));
 	char *hash_string_c = g_malloc(50 + strlen(name));
-		
+
 	char checksum;
-	
+
 	int sv;
-	
+
 	char result6[25];
 	char result96[25];
 
@@ -1062,9 +1078,9 @@
 	md5_append(&ctx, pass, strlen(pass));
 	md5_finish(&ctx, result);
 	to_y64(password_hash, result, 16);
-		
+
 	md5_init(&ctx);
-	crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$");  
+	crypt_result = yahoo_crypt(pass, "$1$_2S43d5f$");
 	md5_append(&ctx, crypt_result, strlen(crypt_result));
 	md5_finish(&ctx, result);
 	to_y64(crypt_hash, result, 16);
@@ -1109,13 +1125,13 @@
 				   "%c%s%s%s", checksum, crypt_hash, name, seed);
 			break;
 	}
-		
-	md5_init(&ctx);  
+
+	md5_init(&ctx);
 	md5_append(&ctx, hash_string_p, strlen(hash_string_p));
 	md5_finish(&ctx, result);
 	to_y64(result6, result, 16);
-	
-	md5_init(&ctx);  
+
+	md5_init(&ctx);
 	md5_append(&ctx, hash_string_c, strlen(hash_string_c));
 	md5_finish(&ctx, result);
 	to_y64(result96, result, 16);
@@ -1125,14 +1141,14 @@
 	yahoo_packet_hash(pack, 6, result6);
 	yahoo_packet_hash(pack, 96, result96);
 	yahoo_packet_hash(pack, 1, name);
-		
+
 	yahoo_send_packet(yd, pack);
-	
+
 	g_free(hash_string_p);
 	g_free(hash_string_c);
-	
+
 	yahoo_packet_free(pack);
-	
+
 }
 
 /* I'm dishing out some uber-mad props to Cerulean Studios for cracking this
@@ -1145,13 +1161,13 @@
 	const char *name = gaim_normalize(account, gaim_account_get_username(account));
 	const char *pass = gaim_account_get_password(account);
 	struct yahoo_data *yd = gc->proto_data;
-	
+
 	md5_byte_t			result[16];
 	md5_state_t			ctx;
-	
+
 	SHA_CTX				ctx1;
 	SHA_CTX				ctx2;
-	
+
 	char				*alphabet1			= "FBZDWAGHrJTLMNOPpRSKUVEXYChImkwQ";
 	char				*alphabet2			= "F0E1D2C3B4A59687abcdefghijklmnop";
 
@@ -1204,7 +1220,7 @@
 	 * Magic: Phase 1.  Generate what seems to be a 30 byte value (could change if base64
 	 * ends up differently?  I don't remember and I'm tired, so use a 64 byte buffer.
 	 */
-	
+
 	magic_ptr = seed;
 
 	while (*magic_ptr != (int)NULL) {
@@ -1309,7 +1325,7 @@
 				cl = (cl & 0x0f) << 6; 
 				bl = ((bl & 0x3f) + cl) << 6; 
 			} 
-			
+
 			cl = magic[magic_cnt++]; 
 			bl = (cl & 0x3f) + bl; 
 		} else
@@ -1449,7 +1465,7 @@
 
 		/* First two bytes of digest stuffed together.
 		 */
-		
+
 		val = digest2[x];
 		val <<= 8;
 		val += digest2[x+1];
@@ -1592,9 +1608,9 @@
 	char *sn   = NULL;
 	GSList *l = pkt->hash;
 	int m = 0;
-	gchar *buf;	
-
-	
+	gchar *buf;
+
+
 	while (l) {
 		struct yahoo_pair *pair = l->data;
 		if (pair->key == 94)
@@ -1605,7 +1621,7 @@
 			m = atoi(pair->value);
 		l = l->next;
 	}
-	
+
 	if (seed) {
 		switch (m) {
 		case 0:
@@ -1800,13 +1816,12 @@
 	g_free(decoded_group);
 }
 
-#if 0
 static void yahoo_process_p2p(GaimConnection *gc, struct yahoo_packet *pkt)
 {
 	GSList *l = pkt->hash;
 	char *who = NULL;
 	char *base64 = NULL;
-	char *decoded, *escaped;
+	char *decoded;
 	int len;
 
 	while (l) {
@@ -1842,13 +1857,16 @@
 		l = l->next;
 	}
 
-	if (0 && base64) {
+	if (base64) {
 		gaim_base64_decode(base64, &decoded, &len);
-		gaim_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, decoded);
+		if (len) {
+			char *tmp = gaim_str_binary_to_ascii(decoded, len);
+			gaim_debug_info("yahoo", "Got P2P service packet (from server): who = %s, ip = %s\n", who, tmp);
+			g_free(tmp);
+		}
 		g_free(decoded);
 	}
 }
-#endif
 
 static void yahoo_packet_process(GaimConnection *gc, struct yahoo_packet *pkt)
 {
@@ -1938,11 +1956,9 @@
 	case YAHOO_SERVICE_FILETRANSFER:
 		yahoo_process_filetransfer(gc, pkt);
 		break;
-#if 0
 	case YAHOO_SERVICE_PEEPTOPEER:
 		yahoo_process_p2p(gc, pkt);
 		break;
-#endif
 	default:
 		gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
 				   "Unhandled service 0x%02x\n", pkt->service);
--- a/src/protocols/yahoo/yahoo.h	Sun Jun 13 20:43:43 2004 +0000
+++ b/src/protocols/yahoo/yahoo.h	Mon Jun 14 00:54:45 2004 +0000
@@ -167,6 +167,9 @@
 	int idle;
 	int away;
 	gboolean sms;
+	char *ip;
+	guint bicon_checksum;
+	gboolean bicon_have;
 };
 
 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (48)
--- a/src/util.c	Sun Jun 13 20:43:43 2004 +0000
+++ b/src/util.c	Mon Jun 14 00:54:45 2004 +0000
@@ -2418,6 +2418,28 @@
 	return g_string_free(gstr, FALSE);
 }
 
+
+char *
+gaim_str_binary_to_ascii(const unsigned char *binary, guint len)
+{
+	GString *ret;
+	guint i;
+
+	g_return_val_if_fail(len > 0, NULL);
+
+	ret = g_string_sized_new(len);
+
+	for (i = 0; i < len; i++)
+		if (binary[i] < 32 || binary[i] > 126)
+			g_string_append_printf(ret, "\\x%02hhx", binary[i]);
+		else if (binary[i] == '\\')
+			g_string_append(ret, "\\\\");
+		else
+			g_string_append_c(ret, binary[i]);
+
+	return g_string_free(ret, FALSE);
+}
+
 /**************************************************************************
  * URI/URL Functions
  **************************************************************************/
--- a/src/util.h	Sun Jun 13 20:43:43 2004 +0000
+++ b/src/util.h	Mon Jun 14 00:54:45 2004 +0000
@@ -567,6 +567,20 @@
  */
 char *gaim_str_seconds_to_string(guint sec);
 
+/**
+ * Converts a binary string into a NUL terminated ascii string,
+ * replacing nonascii characters and characters below SPACE (including
+ * NUL) into \xyy, where yy are two hex digits. Also backslashes are
+ * changed into two backslashes (\\). The returned, newly allocated
+ * can be outputted to the console, and must be g_free()d.
+ *
+ * @param binary A string of random data, possibly with embedded NULs
+ *               and such.
+ * @param len The length in bytes of the input string. Must not be 0.
+ *
+ * @return A newly allocated ASCIIZ string.
+ */
+char *gaim_str_binary_to_ascii(const unsigned char *binary, guint len);
 /*@}*/