/pidgin/main: 2e449140fe0b: Switch sending-im-msg to PurpleMessage

Tomasz Wasilczyk twasilczyk at pidgin.im
Thu May 22 13:37:35 EDT 2014


Changeset: 2e449140fe0b5a02c616b3f4d3c3064c695cd4b0
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-05-22 16:38 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/2e449140fe0b

Description:

Switch sending-im-msg to PurpleMessage

diffstat:

 libpurple/conversation.c                       |   4 +--
 libpurple/conversations.c                      |   5 +--
 libpurple/message.c                            |   6 ++++
 libpurple/message.h                            |   3 ++
 libpurple/plugins/codeinline.c                 |  35 +++++++++++++++++++------
 libpurple/plugins/offlinemsg.c                 |  10 +++---
 libpurple/plugins/perl/common/Server.xs        |  21 ---------------
 libpurple/plugins/signals-test.c               |   6 ++-
 libpurple/protocols/irc/cmds.c                 |  14 ++++++---
 pidgin/plugins/musicmessaging/musicmessaging.c |  21 ++++++++-------
 10 files changed, 67 insertions(+), 58 deletions(-)

diffs (truncated from 303 to 300 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -137,10 +137,8 @@ common_send(PurpleConversation *conv, co
 		msg = purple_message_new(purple_conversation_get_name(conv),
 			sent, msgflags);
 
-		/* TODO: use msg! */
 		purple_signal_emit(purple_conversations_get_handle(), "sending-im-msg",
-						 account,
-						 purple_conversation_get_name(conv), &sent);
+			account, msg);
 
 		if (!purple_message_is_empty(msg)) {
 
diff --git a/libpurple/conversations.c b/libpurple/conversations.c
--- a/libpurple/conversations.c
+++ b/libpurple/conversations.c
@@ -305,9 +305,8 @@ purple_conversations_init(void)
 						 PURPLE_TYPE_CONVERSATION, G_TYPE_UINT);
 
 	purple_signal_register(handle, "sending-im-msg",
-						 purple_marshal_VOID__POINTER_POINTER_POINTER,
-						 G_TYPE_NONE, 3, PURPLE_TYPE_ACCOUNT, G_TYPE_STRING,
-						 G_TYPE_POINTER); /* pointer to a string */
+		purple_marshal_VOID__POINTER_POINTER, G_TYPE_NONE,
+		2, PURPLE_TYPE_ACCOUNT, PURPLE_TYPE_MESSAGE);
 
 	purple_signal_register(handle, "sent-im-msg",
 						 purple_marshal_VOID__POINTER_POINTER_POINTER,
diff --git a/libpurple/message.c b/libpurple/message.c
--- a/libpurple/message.c
+++ b/libpurple/message.c
@@ -94,6 +94,12 @@ purple_message_get_who(PurpleMessage *ms
 	return priv->who;
 }
 
+void
+purple_message_set_contents(PurpleMessage *msg, const gchar *cont)
+{
+	g_object_set(msg, "contents", cont, NULL);
+}
+
 const gchar *
 purple_message_get_contents(PurpleMessage *msg)
 {
diff --git a/libpurple/message.h b/libpurple/message.h
--- a/libpurple/message.h
+++ b/libpurple/message.h
@@ -95,6 +95,9 @@ purple_message_find_by_id(guint id);
 const gchar *
 purple_message_get_who(PurpleMessage *msg);
 
+void
+purple_message_set_contents(PurpleMessage *msg, const gchar *cont);
+
 const gchar *
 purple_message_get_contents(PurpleMessage *msg);
 
diff --git a/libpurple/plugins/codeinline.c b/libpurple/plugins/codeinline.c
--- a/libpurple/plugins/codeinline.c
+++ b/libpurple/plugins/codeinline.c
@@ -28,20 +28,37 @@
 
 PurplePlugin *plugin_handle = NULL;
 
-static gboolean outgoing_msg_cb(PurpleAccount *account, const char *who, char **message,
-					PurpleConversation *conv, PurpleMessageFlags flags, gpointer null)
+static char *
+outgoing_msg_common(const char *message)
 {
   char *m;
-  char **ms = g_strsplit(*message, "<u>", -1);
+  char **ms = g_strsplit(message, "<u>", -1);
   m = g_strjoinv("<font face=\"monospace\" color=\"#00b025\">", ms);
   g_strfreev(ms);
 
   ms = g_strsplit(m, "</u>", -1);
   g_free(m);
-  m = g_strjoinv("</font>", ms);
-  g_free(*message);
-  *message = m;
-  return FALSE;
+  return g_strjoinv("</font>", ms);
+}
+
+static gboolean outgoing_msg_cb1(PurpleAccount *account, const char *who, char **message,
+					PurpleConversation *conv, PurpleMessageFlags flags, gpointer null)
+{
+	char *m;
+
+	m = outgoing_msg_common(*message);
+	g_free(*message);
+	*message = m;
+
+	return FALSE;
+}
+
+static void
+outgoing_msg_cb2(PurpleAccount *account, PurpleMessage *msg,
+	PurpleConversation *conv, PurpleMessageFlags flags, gpointer null)
+{
+	purple_message_set_contents(msg,
+		outgoing_msg_common(purple_message_get_contents(msg)));
 }
 
 static gboolean
@@ -50,9 +67,9 @@ plugin_load(PurplePlugin *plugin)
      void *handle = purple_conversations_get_handle();
      plugin_handle = plugin;
      purple_signal_connect(handle, "writing-im-msg", plugin,
-                PURPLE_CALLBACK(outgoing_msg_cb), NULL);
+                PURPLE_CALLBACK(outgoing_msg_cb1), NULL);
      purple_signal_connect(handle, "sending-im-msg", plugin,
-		PURPLE_CALLBACK(outgoing_msg_cb), NULL);
+		PURPLE_CALLBACK(outgoing_msg_cb2), NULL);
 
      return TRUE;
 }
diff --git a/libpurple/plugins/offlinemsg.c b/libpurple/plugins/offlinemsg.c
--- a/libpurple/plugins/offlinemsg.c
+++ b/libpurple/plugins/offlinemsg.c
@@ -112,15 +112,15 @@ record_pounce(OfflineMsg *offline)
 }
 
 static void
-sending_msg_cb(PurpleAccount *account, const char *who, char **message, gpointer handle)
+sending_msg_cb(PurpleAccount *account, PurpleMessage *msg, gpointer handle)
 {
 	PurpleBuddy *buddy;
 	OfflineMsg *offline;
 	PurpleConversation *conv;
 	OfflineMessageSetting setting;
+	const gchar *who = purple_message_get_who(msg);
 
-	if (message == NULL || *message == NULL ||
-			**message == '\0')
+	if (purple_message_is_empty(msg))
 		return;
 
 	buddy = purple_blist_find_buddy(account, who);
@@ -150,8 +150,8 @@ sending_msg_cb(PurpleAccount *account, c
 	offline->conv = conv;
 	offline->account = account;
 	offline->who = g_strdup(who);
-	offline->message = *message;
-	*message = NULL;
+	offline->message = g_strdup(purple_message_get_contents(msg));
+	purple_message_set_contents(msg, NULL);
 
 	if (purple_prefs_get_bool(PREF_ALWAYS) || setting == OFFLINE_MSG_YES)
 		record_pounce(offline);
diff --git a/libpurple/plugins/perl/common/Server.xs b/libpurple/plugins/perl/common/Server.xs
--- a/libpurple/plugins/perl/common/Server.xs
+++ b/libpurple/plugins/perl/common/Server.xs
@@ -30,20 +30,6 @@ purple_serv_chat_leave(a, b)
 	Purple::Connection a
 	int b
 
-int  
-purple_serv_chat_send(con, a, b, flags)
-	Purple::Connection con 
-	int a
-	const char * b
-	Purple::MessageFlags flags
-
-void 
-purple_serv_chat_whisper(con, a, b, c)
-	Purple::Connection con
-	int a
-	const char * b
-	const char * c
-
 void 
 purple_serv_get_info(con, a)
 	Purple::Connection con 
@@ -193,13 +179,6 @@ purple_serv_send_file(gc, who, file)
 	const char *file
 
 int  
-purple_serv_send_im(con, a, b, flags )
-	Purple::Connection con
-	const char * a
-	const char * b
-	Purple::MessageFlags flags
-
-int  
 purple_serv_send_typing(con, a, state)
 	Purple::Connection con
 	const char * a
diff --git a/libpurple/plugins/signals-test.c b/libpurple/plugins/signals-test.c
--- a/libpurple/plugins/signals-test.c
+++ b/libpurple/plugins/signals-test.c
@@ -301,10 +301,12 @@ wrote_im_msg_cb(PurpleAccount *account, 
 }
 
 static void
-sending_im_msg_cb(PurpleAccount *account, char *recipient, char **buffer, void *data)
+sending_im_msg_cb(PurpleAccount *account, PurpleMessage *msg, void *data)
 {
 	purple_debug_misc("signals test", "sending-im-msg (%s, %s, %s)\n",
-					purple_account_get_username(account), recipient, *buffer);
+		purple_account_get_username(account),
+		purple_message_get_who(msg),
+		purple_message_get_contents(msg));
 
 }
 
diff --git a/libpurple/protocols/irc/cmds.c b/libpurple/protocols/irc/cmds.c
--- a/libpurple/protocols/irc/cmds.c
+++ b/libpurple/protocols/irc/cmds.c
@@ -97,6 +97,7 @@ int irc_cmd_ctcp_action(struct irc_conn 
 	const char *src;
 	char *msg;
 	PurpleConversation *convo;
+	PurpleMessage *pmsg;
 
 	if (!args || !args[0] || !gc)
 		return 0;
@@ -107,19 +108,22 @@ int irc_cmd_ctcp_action(struct irc_conn 
 
 	/* XXX: we'd prefer to keep this in conversation.c */
 	if (PURPLE_IS_IM_CONVERSATION(convo)) {
+		pmsg = purple_message_new(purple_conversation_get_name(convo),
+			msg, PURPLE_MESSAGE_SEND);
+
 		purple_signal_emit(purple_conversations_get_handle(),
-			"sending-im-msg", irc->account,
-			purple_conversation_get_name(convo), &msg);
+			"sending-im-msg", irc->account, pmsg);
 	} else {
+		/* TODO: pmsg! */
 		purple_signal_emit(purple_conversations_get_handle(),
 			"sending-chat-msg", irc->account, &msg,
 			purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(convo)));
 	}
 
-	if (!msg || !msg[0]) {
-		g_free(msg);
+	g_free(msg);
+	if (purple_message_is_empty(pmsg))
 		return 0;
-	}
+	msg = g_strdup(purple_message_get_contents(pmsg)); /* XXX: is it really necessary? */
 
 	if (strncmp(msg, "/me ", 4) != 0) {
 		newargs = g_new0(char *, 2);
diff --git a/pidgin/plugins/musicmessaging/musicmessaging.c b/pidgin/plugins/musicmessaging/musicmessaging.c
--- a/pidgin/plugins/musicmessaging/musicmessaging.c
+++ b/pidgin/plugins/musicmessaging/musicmessaging.c
@@ -64,7 +64,7 @@ static void add_button (MMConversation *
 static void remove_widget (GtkWidget *button);
 static void init_conversation (PurpleConversation *conv);
 static void conv_destroyed(PurpleConversation *conv);
-static gboolean intercept_sent(PurpleAccount *account, const char *who, char **message, void* pData);
+static gboolean intercept_sent(PurpleAccount *account, PurpleMessage *msg, void* pData);
 static gboolean intercept_received(PurpleAccount *account, char **sender, char **message, PurpleConversation *conv, int *flags);
 static gboolean send_change_request (const int session, const char *id, const char *command, const char *parameters);
 static gboolean send_change_confirmed (const int session, const char *command, const char *parameters);
@@ -329,33 +329,34 @@ plugin_unload(PurplePlugin *plugin) {
 
 
 static gboolean
-intercept_sent(PurpleAccount *account, const char *who, char **message, void* pData)
+intercept_sent(PurpleAccount *account, PurpleMessage *msg, void* pData)
 {
-	if (message == NULL || *message == NULL || **message == '\0')
+	const gchar *cont = purple_message_get_contents(msg);
+
+	if (purple_message_is_empty(msg))
 		return FALSE;
 
-	if (0 == strncmp(*message, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX)))
+	if (0 == strncmp(cont, MUSICMESSAGING_PREFIX, strlen(MUSICMESSAGING_PREFIX)))
 	{
-		purple_debug_misc("purple-musicmessaging", "Sent MM Message: %s\n", *message);
-		message = 0;
+		purple_debug_misc("purple-musicmessaging", "Sent MM Message: %s\n", cont);
 	}
-	else if (0 == strncmp(*message, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG)))
+	else if (0 == strncmp(cont, MUSICMESSAGING_START_MSG, strlen(MUSICMESSAGING_START_MSG)))
 	{
 		purple_debug_misc("purple-musicmessaging", "Sent MM request.\n");
 		return FALSE;
 	}
-	else if (0 == strncmp(*message, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG)))
+	else if (0 == strncmp(cont, MUSICMESSAGING_CONFIRM_MSG, strlen(MUSICMESSAGING_CONFIRM_MSG)))
 	{
 		purple_debug_misc("purple-musicmessaging", "Sent MM confirm.\n");
 		return FALSE;
 	}
-	else if (0 == strncmp(*message, "test1", strlen("test1")))
+	else if (0 == strncmp(cont, "test1", strlen("test1")))
 	{
 		purple_debug_misc("purple-musicmessaging", "\n\nTEST 1\n\n");
 		send_change_request(0, "test-id", "test-command", "test-parameters");
 		return FALSE;
 	}
-	else if (0 == strncmp(*message, "test2", strlen("test2")))
+	else if (0 == strncmp(cont, "test2", strlen("test2")))



More information about the Commits mailing list