[ekg2-commit] ekg2: commands.c (HEAD) [peres]

CVS commit cvs w toxygen.net
Nie, 21 Paź 2007, 16:21:22 CEST


Module name:	ekg2
Changes by:	peres	2007-10-21 16:21:20

Modified files:
	commands.c

Log message:
Spec says we should wrap encoded image at 72-th char.

Index: commands.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/commands.c,v
diff -d -u -r1.207 -r1.208
--- commands.c	21 Oct 2007 13:44:28 -0000	1.207
+++ commands.c	21 Oct 2007 14:21:20 -0000	1.208
@@ -1084,9 +1084,13 @@
 	} else if (len >= sizeof(buf))
 		printq("io_toobig", path, itoa(len), sizeof(buf)-1);
 	else {
-		char *enc = base64_encode(buf, len);
+		char *enc		= base64_encode(buf, len);
 		char *out;
-		const char *type = "application/octet-stream";
+		const char *type	= "application/octet-stream";
+
+		string_t str		= string_init(NULL);
+		int enclen		= xstrlen(enc);
+		char *p			= enc;
 
 			/* those are from 'magic.mime', from 'file' utility */ 
 		if (len > 4 && !xstrncmp(buf, "\x89PNG", 4))
@@ -1099,8 +1103,17 @@
 		fclose(fd);
 		session_set(s, "photo_hash", buffer_sha1_digest(buf, len));
 
-		out = saprintf("<PHOTO><TYPE>%s</TYPE><BINVAL>%s</BINVAL></PHOTO>", type, enc);
+		while (enclen > 72) {
+			string_append_n(str, p, 72);
+			string_append_c(str, '\n');
+			
+			p += 72;
+			enclen -= 72;
+		}
+		string_append(str, p);
 		xfree(enc);
+
+		out = saprintf("<PHOTO><TYPE>%s</TYPE><BINVAL>\n%s\n</BINVAL></PHOTO>", type, string_free(str, 0));
 		return out;
 	}
 


Więcej informacji o liście dyskusyjnej ekg2-commit