pidgin: aa109172: When sending MSN OIM's, wrap Base64'd te...

qulogic at pidgin.im qulogic at pidgin.im
Mon Jul 14 21:50:42 EDT 2008


-----------------------------------------------------------------
Revision: aa1091727852b14118b50e7b20134127c4bf09d3
Ancestor: 42c781022327add4641b756f0a78587ef3ce2d1a
Author: qulogic at pidgin.im
Date: 2008-07-15T01:42:01
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/aa1091727852b14118b50e7b20134127c4bf09d3

Modified files:
        libpurple/protocols/msn/oim.c

ChangeLog: 

When sending MSN OIM's, wrap Base64'd text at 76 characters. Because 
it's Base64-encoded, this problem doesn't necessarily occur at exactly 
76 characters of text to *send*.
Really fixes #5379.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/oim.c	297b1c4d34b16b6c9a75b2753078c22238509d86
+++ libpurple/protocols/msn/oim.c	0d64864aa018bd11de963bbbc973f0c856048dac
@@ -270,16 +270,31 @@ msn_oim_msg_to_str(MsnOim *oim, const ch
 static gchar *
 msn_oim_msg_to_str(MsnOim *oim, const char *body)
 {
-	char *oim_body,*oim_base64;
+	GString *oim_body;
+	char *oim_base64;
+	char *c;
+	int len;
 
-	purple_debug_info("msn", "encode OIM Message...\n");
-	oim_base64 = purple_base64_encode((const guchar *)body, strlen(body));
-	purple_debug_info("msn", "encoded base64 body:{%s}\n", oim_base64);
-	oim_body = g_strdup_printf(MSN_OIM_MSG_TEMPLATE,
-				oim->run_id,oim->send_seq,oim_base64);
+	purple_debug_info("msn", "Encoding OIM Message...\n");
+	len = strlen(body);
+	c = oim_base64 = purple_base64_encode((const guchar *)body, len);
+	purple_debug_info("msn", "Encoded base64 body:{%s}\n", oim_base64);
+
+	oim_body = g_string_new(NULL);
+	g_string_printf(oim_body, MSN_OIM_MSG_TEMPLATE,
+	                oim->run_id, oim->send_seq);
+
+	len = ((len / 3) + 1) * 4 - 76;
+	while ((c - oim_base64) < len) {
+		g_string_append_len(oim_body, c, 76);
+		g_string_append_c(oim_body, '\n');
+		c += 76;
+	}
+	g_string_append(oim_body, c);
+
 	g_free(oim_base64);
 
-	return oim_body;
+	return g_string_free(oim_body, FALSE);
 }
 
 /*


More information about the Commits mailing list