[Telepathy-commits] [telepathy-idle/master] Split long messages properly (Bug #17392)

Jonathon Jongsma jonathon.jongsma at collabora.co.uk
Fri Feb 13 14:05:51 PST 2009


Use the newly-added idle_connection_get_max_message_length() API to split long
messages so that they allow for the server to add a prefix onto the messages
that it relays to others instead of simply using 512 as the max message length

I had to modify the test a bit to get it to behave like a real IRC server, but
now the test passes fine, and I did quite a bit of manual testing (copy/pasting
large chunks of test between two accounts) and have not seen any issues yet.
Part of my manual testing included copy/pasting large amounts of unicode text
from various wikipedia articles in other languages, so I believe that the utf-8
splitting issue is also fixed properly in this branch.
---
 src/idle-connection.c                        |    4 +++-
 src/idle-connection.h                        |    2 +-
 src/idle-text.c                              |    7 ++++---
 src/idle-text.h                              |    2 +-
 tests/twisted/messages/long-message-split.py |    9 ++++++++-
 5 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/idle-connection.c b/src/idle-connection.c
index b12aba4..5d9b6d4 100644
--- a/src/idle-connection.c
+++ b/src/idle-connection.c
@@ -702,7 +702,9 @@ idle_connection_get_max_message_length(IdleConnection *conn)
 {
 	IdleConnectionPrivate *priv = IDLE_CONNECTION_GET_PRIVATE(conn);
 	if (priv->relay_prefix != NULL) {
-		return IRC_MSG_MAXLEN - (strlen(priv->relay_prefix) + 1);
+		/* server will add ':<relay_prefix> ' to all messages it relays on to
+		 * other users.  the +2 is for the initial : and the trailing space */
+		return IRC_MSG_MAXLEN - (strlen(priv->relay_prefix) + 2);
 	}
 	return IRC_MSG_MAXLEN;
 }
diff --git a/src/idle-connection.h b/src/idle-connection.h
index 9cd3eb0..7b41d8e 100644
--- a/src/idle-connection.h
+++ b/src/idle-connection.h
@@ -62,7 +62,7 @@ GType idle_connection_get_type(void);
 void idle_connection_canon_nick_receive(IdleConnection *conn, TpHandle handle, const gchar *canon_nick);
 void idle_connection_emit_queued_aliases_changed(IdleConnection *conn);
 void idle_connection_send(IdleConnection *conn, const gchar *msg);
-void idle_connection_get_max_message_length(IdleConnection *conn);
+gsize idle_connection_get_max_message_length(IdleConnection *conn);
 
 G_END_DECLS
 
diff --git a/src/idle-text.c b/src/idle-text.c
index 5cd4321..fd36671 100644
--- a/src/idle-text.c
+++ b/src/idle-text.c
@@ -51,7 +51,7 @@ gboolean idle_text_decode(const gchar *text, TpChannelTextMessageType *type, gch
 	return TRUE;
 }
 
-GStrv idle_text_encode_and_split(TpChannelTextMessageType type, const gchar *recipient, const gchar *text, GError **error) {
+GStrv idle_text_encode_and_split(TpChannelTextMessageType type, const gchar *recipient, const gchar *text, gsize max_msg_len, GError **error) {
 	GPtrArray *messages;
 	const gchar *remaining_text = text;
 	const gchar * const text_end =  text + strlen(text);
@@ -77,7 +77,7 @@ GStrv idle_text_encode_and_split(TpChannelTextMessageType type, const gchar *rec
 	}
 
 	messages = g_ptr_array_new();
-	max_bytes = IRC_MSG_MAXLEN - (strlen(header) + strlen(footer));
+	max_bytes = max_msg_len - (strlen(header) + strlen(footer));
 
 	while (remaining_text < text_end) {
 		char *newline = strchr(remaining_text, '\n');
@@ -131,7 +131,8 @@ void idle_text_send(GObject *obj, guint type, const gchar *recipient, const gcha
 		return;
 	}
 
-	messages = idle_text_encode_and_split(type, recipient, text, &error);
+	gsize msg_len = idle_connection_get_max_message_length(conn);
+	messages = idle_text_encode_and_split(type, recipient, text, msg_len, &error);
 	if (messages == NULL) {
 		dbus_g_method_return_error(context, error);
 		g_error_free(error);
diff --git a/src/idle-text.h b/src/idle-text.h
index d965a34..10d2241 100644
--- a/src/idle-text.h
+++ b/src/idle-text.h
@@ -31,7 +31,7 @@
 G_BEGIN_DECLS
 
 gboolean idle_text_decode(const gchar *text, TpChannelTextMessageType *type, gchar **body);
-GStrv idle_text_encode_and_split(TpChannelTextMessageType type, const gchar *recipient, const gchar *text, GError **error);
+GStrv idle_text_encode_and_split(TpChannelTextMessageType type, const gchar *recipient, const gchar *text, gsize max_msg_len, GError **error);
 void idle_text_send(GObject *obj, guint type, const gchar *recipient, const gchar *text, IdleConnection *conn, DBusGMethodInvocation *ctx);
 
 G_END_DECLS
diff --git a/tests/twisted/messages/long-message-split.py b/tests/twisted/messages/long-message-split.py
index d0a27b7..6b45337 100644
--- a/tests/twisted/messages/long-message-split.py
+++ b/tests/twisted/messages/long-message-split.py
@@ -10,6 +10,10 @@ from servicetest import EventPattern, call_async
 import dbus
 
 class LongMessageMangler(BaseIRCServer):
+    host = "my.host.name"
+    def get_relay_prefix(self):
+        return '%s!%s@%s' % (self.nick, self.user, self.host)
+
     def handlePRIVMSG(self, args, prefix):
         #chain up to the base class implementation which simply signals a privmsg event
         #BaseIRCServer.handlePRIVMSG(self, args, prefix)
@@ -18,10 +22,13 @@ class LongMessageMangler(BaseIRCServer):
         sent_message = args[1]
         # 'bounce' the message back to all participants, but truncate to the
         # max IRC message size
-        return_msg = ':%s!idle.test.server PRIVMSG %s :%s' % (self.nick, recipient, sent_message)
+        return_msg = ':%s PRIVMSG %s :%s' % (self.get_relay_prefix(), recipient, sent_message)
         # 510 rather than 512 since sendLine will tack on \r\n
         self.sendLine(return_msg[:510])
 
+    def handleWHOIS(self, args, prefix):
+        self.sendMessage('311', self.nick, self.nick, self.user, self.host, '*', ':Full Name', prefix='idle.test.server')
+
 
 LONG_MESSAGE='one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty twenty-one twenty-two twenty-three twenty-four twenty-five twenty-six twenty-seven twenty-eight twenty-nine thirty thirty-one thirty-two thirty-three thirty-four thirty-five thirty-six thirty-seven thirty-eight thirty-nine forty forty-one forty-two forty-three forty-four forty-five forty-six forty-seven forty-eight forty-nine fifty fifty-one fifty-two fifty-three fifty-four fifty-five fifty-six fifty-seven fifty-eight fifty-nine sixty sixty-one sixty-two sixty-three sixty-four sixty-five sixty-six sixty-seven sixty-eight sixty-nine'
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list