changeset 26684:06da00c70eae

Fix XMPP prpl->set_chat_topic with an empty string (or NULL) The slash-command /topic displays the message with no arguments, but the set_chat_topic should not. Closes #8810.
author Paul Aurich <paul@darkrain42.org>
date Sun, 26 Apr 2009 00:06:30 +0000
parents 317f8d7e88f1
children 90d5e3b94a37
files libpurple/protocols/jabber/chat.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/message.c
diffstat 3 files changed, 36 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/chat.c	Sat Apr 25 23:33:13 2009 +0000
+++ b/libpurple/protocols/jabber/chat.c	Sun Apr 26 00:06:30 2009 +0000
@@ -597,37 +597,25 @@
 /* merge this with the function below when we get everyone on the same page wrt /commands */
 void jabber_chat_change_topic(JabberChat *chat, const char *topic)
 {
-	if(topic && *topic) {
-		JabberMessage *jm;
-		jm = g_new0(JabberMessage, 1);
-		jm->js = chat->js;
-		jm->type = JABBER_MESSAGE_GROUPCHAT;
-		jm->subject = purple_markup_strip_html(topic);
-		jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
-		jabber_message_send(jm);
-		jabber_message_free(jm);
-	} else {
-		const char *cur = purple_conv_chat_get_topic(PURPLE_CONV_CHAT(chat->conv));
-		char *buf, *tmp, *tmp2;
+	JabberMessage *jm;
+
+	jm = g_new0(JabberMessage, 1);
+	jm->js = chat->js;
+	jm->type = JABBER_MESSAGE_GROUPCHAT;
+	jm->to = g_strdup_printf("%s@%s", chat->room, chat->server);
 
-		if(cur) {
-			tmp = g_markup_escape_text(cur, -1);
-			tmp2 = purple_markup_linkify(tmp);
-			buf = g_strdup_printf(_("current topic is: %s"), tmp2);
-			g_free(tmp);
-			g_free(tmp2);
-		} else
-			buf = g_strdup(_("No topic is set"));
-		purple_conv_chat_write(PURPLE_CONV_CHAT(chat->conv), "", buf,
-				PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL));
-		g_free(buf);
-	}
+	if (topic && *topic)
+		jm->subject = purple_markup_strip_html(topic);
+	else
+		jm->subject = g_strdup("");
 
+	jabber_message_send(jm);
+	jabber_message_free(jm);
 }
 
 void jabber_chat_set_topic(PurpleConnection *gc, int id, const char *topic)
 {
-	JabberStream *js = gc->proto_data;
+	JabberStream *js = purple_connection_get_protocol_data(gc);
 	JabberChat *chat = jabber_chat_find_by_id(js, id);
 
 	if(!chat)
--- a/libpurple/protocols/jabber/jabber.c	Sat Apr 25 23:33:13 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sun Apr 26 00:06:30 2009 +0000
@@ -2305,7 +2305,25 @@
 	if (!chat)
 		return PURPLE_CMD_RET_FAILED;
 
-	jabber_chat_change_topic(chat, args ? args[0] : NULL);
+	if (args && args[0] && *args[0])
+		jabber_chat_change_topic(chat, args[0]);
+	else {
+		const char *cur = purple_conv_chat_get_topic(PURPLE_CONV_CHAT(conv));
+		char *buf, *tmp, *tmp2;
+
+		if (cur) {
+			tmp = g_markup_escape_text(cur, -1);
+			tmp2 = purple_markup_linkify(tmp);
+			buf = g_strdup_printf(_("current topic is: %s"), tmp2);
+			g_free(tmp);
+			g_free(tmp2);
+		} else
+			buf = g_strdup(_("No topic is set"));
+		purple_conv_chat_write(PURPLE_CONV_CHAT(conv), "", buf,
+				PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LOG, time(NULL));
+		g_free(buf);
+	}
+
 	return PURPLE_CMD_RET_OK;
 }
 
--- a/libpurple/protocols/jabber/message.c	Sat Apr 25 23:33:13 2009 +0000
+++ b/libpurple/protocols/jabber/message.c	Sun Apr 26 00:06:30 2009 +0000
@@ -597,8 +597,11 @@
 			/* The following tests expect xmlns != NULL */
 			continue;
 		} else if(!strcmp(child->name, "subject") && !strcmp(xmlns,"jabber:client")) {
-			if(!jm->subject)
+			if(!jm->subject) {
 				jm->subject = xmlnode_get_data(child);
+				if(!jm->subject)
+					jm->subject = g_strdup("");
+			}
 		} else if(!strcmp(child->name, "thread") && !strcmp(xmlns,"jabber:client")) {
 			if(!jm->thread_id)
 				jm->thread_id = xmlnode_get_data(child);