/pidgin/main: a0e5b68ff4ef: Switch purple_serv_send_im to Purple...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu May 22 13:37:35 EDT 2014
Changeset: a0e5b68ff4ef9ac70b517d11f1efd10dfe6eaffb
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-05-22 15:15 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/a0e5b68ff4ef
Description:
Switch purple_serv_send_im to PurpleMessage
diffstat:
finch/gntpounce.c | 6 +++-
libpurple/conversation.c | 12 +++++-
libpurple/message.c | 42 +++++++++++++++++++++++++-
libpurple/message.h | 12 +++++++
libpurple/plugins/tcl/tcl_cmds.c | 2 +-
libpurple/protocols/bonjour/bonjour.c | 8 +++-
libpurple/protocols/gg/message-prpl.c | 9 +++--
libpurple/protocols/gg/message-prpl.h | 3 +-
libpurple/protocols/irc/irc.c | 9 +++--
libpurple/protocols/jabber/jabber.c | 3 +-
libpurple/protocols/jabber/message.c | 14 ++------
libpurple/protocols/jabber/message.h | 3 +-
libpurple/protocols/msn/msn.c | 17 +++++----
libpurple/protocols/mxit/mxit.c | 8 ++--
libpurple/protocols/novell/novell.c | 11 +++---
libpurple/protocols/null/nullprpl.c | 10 +++--
libpurple/protocols/oscar/oscar.c | 9 ++++-
libpurple/protocols/oscar/oscarcommon.h | 2 +-
libpurple/protocols/sametime/sametime.c | 18 ++++++----
libpurple/protocols/silc/silc.c | 16 ++++++---
libpurple/protocols/simple/simple.c | 6 +-
libpurple/protocols/yahoo/libymsg.c | 12 ++++---
libpurple/protocols/yahoo/libymsg.h | 2 +-
libpurple/protocols/zephyr/zephyr.c | 11 ++++--
libpurple/prpl.h | 5 +-
libpurple/server.c | 19 ++++++++---
libpurple/server.h | 3 +-
pidgin/gtkpounce.c | 6 +++-
pidgin/plugins/musicmessaging/musicmessaging.c | 6 ++-
29 files changed, 189 insertions(+), 95 deletions(-)
diffs (truncated from 833 to 300 lines):
diff --git a/finch/gntpounce.c b/finch/gntpounce.c
--- a/finch/gntpounce.c
+++ b/finch/gntpounce.c
@@ -868,15 +868,19 @@ pounce_cb(PurplePounce *pounce, PurplePo
if (message != NULL)
{
+ PurpleMessage *pmsg;
+
im = purple_conversations_find_im_with_account(pouncee, account);
if (im == NULL)
im = purple_im_conversation_new(account, pouncee);
+ pmsg = purple_message_new(pouncee, message, 0);
+
purple_conversation_write(PURPLE_CONVERSATION(im), NULL, message,
PURPLE_MESSAGE_SEND, time(NULL));
- purple_serv_send_im(purple_account_get_connection(account), (char *)pouncee, (char *)message, 0);
+ purple_serv_send_im(purple_account_get_connection(account), pmsg);
}
}
diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -133,18 +133,24 @@ common_send(PurpleConversation *conv, co
msgflags |= PURPLE_MESSAGE_SEND;
if (PURPLE_IS_IM_CONVERSATION(conv)) {
+ PurpleMessage *msg;
+
+ 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);
- if (sent != NULL && sent[0] != '\0') {
+ if (!purple_message_is_empty(msg)) {
- err = purple_serv_send_im(gc, purple_conversation_get_name(conv),
- sent, msgflags);
+ err = purple_serv_send_im(gc, msg);
if ((err > 0) && (displayed != NULL))
purple_conversation_write_message(conv, NULL, displayed, msgflags, time(NULL));
+ /* TODO: use msg! */
purple_signal_emit(purple_conversations_get_handle(), "sent-im-msg",
account,
purple_conversation_get_name(conv), sent);
diff --git a/libpurple/message.c b/libpurple/message.c
--- a/libpurple/message.c
+++ b/libpurple/message.c
@@ -87,6 +87,44 @@ purple_message_find_by_id(guint id)
return g_hash_table_lookup(messages, GINT_TO_POINTER(id));
}
+const gchar *
+purple_message_get_who(PurpleMessage *msg)
+{
+ PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->who;
+}
+
+const gchar *
+purple_message_get_contents(PurpleMessage *msg)
+{
+ PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->contents;
+}
+
+gboolean
+purple_message_is_empty(PurpleMessage *msg)
+{
+ const gchar *cont = purple_message_get_contents(msg);
+
+ return (cont == NULL || cont[0] == '\0');
+}
+
+PurpleMessageFlags
+purple_message_get_flags(PurpleMessage *msg)
+{
+ PurpleMessagePrivate *priv = PURPLE_MESSAGE_GET_PRIVATE(msg);
+
+ g_return_val_if_fail(priv != NULL, 0);
+
+ return priv->flags;
+}
+
/******************************************************************************
* Object stuff
******************************************************************************/
@@ -184,7 +222,9 @@ purple_message_class_init(PurpleMessageC
"ID", "The session-unique message id",
0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
properties[PROP_WHO] = g_param_spec_string("who",
- "Author", "The nick of the person, who sent the message",
+ "Who", "The nick of the person, who sent the message (for "
+ "incoming messages) or the recipient (for outgoing). "
+ "Unused for outgoing chat messages.",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
properties[PROP_CONTENTS] = g_param_spec_string("contents",
"Contents", "The message text",
diff --git a/libpurple/message.h b/libpurple/message.h
--- a/libpurple/message.h
+++ b/libpurple/message.h
@@ -92,6 +92,18 @@ purple_message_get_id(PurpleMessage *msg
PurpleMessage *
purple_message_find_by_id(guint id);
+const gchar *
+purple_message_get_who(PurpleMessage *msg);
+
+const gchar *
+purple_message_get_contents(PurpleMessage *msg);
+
+gboolean
+purple_message_is_empty(PurpleMessage *msg);
+
+PurpleMessageFlags
+purple_message_get_flags(PurpleMessage *msg);
+
void
_purple_message_init(void);
diff --git a/libpurple/plugins/tcl/tcl_cmds.c b/libpurple/plugins/tcl/tcl_cmds.c
--- a/libpurple/plugins/tcl/tcl_cmds.c
+++ b/libpurple/plugins/tcl/tcl_cmds.c
@@ -1411,7 +1411,7 @@ int tcl_cmd_send_im(ClientData unused, T
who = Tcl_GetString(objv[2]);
text = Tcl_GetString(objv[3]);
- purple_serv_send_im(gc, who, text, 0);
+ purple_serv_send_im(gc, purple_message_new(who, text, 0));
return TCL_OK;
}
diff --git a/libpurple/protocols/bonjour/bonjour.c b/libpurple/protocols/bonjour/bonjour.c
--- a/libpurple/protocols/bonjour/bonjour.c
+++ b/libpurple/protocols/bonjour/bonjour.c
@@ -205,14 +205,16 @@ bonjour_list_icon(PurpleAccount *account
}
static int
-bonjour_send_im(PurpleConnection *connection, const char *to, const char *msg, PurpleMessageFlags flags)
+bonjour_send_im(PurpleConnection *connection, PurpleMessage *msg)
{
BonjourData *bd = purple_connection_get_protocol_data(connection);
- if(!to || !msg)
+ if (purple_message_is_empty(msg) || !purple_message_get_who(msg))
return 0;
- return bonjour_jabber_send_message(bd->jabber_data, to, msg);
+ return bonjour_jabber_send_message(bd->jabber_data,
+ purple_message_get_who(msg),
+ purple_message_get_contents(msg));
}
static void
diff --git a/libpurple/protocols/gg/message-prpl.c b/libpurple/protocols/gg/message-prpl.c
--- a/libpurple/protocols/gg/message-prpl.c
+++ b/libpurple/protocols/gg/message-prpl.c
@@ -636,18 +636,18 @@ gchar * ggp_message_format_to_gg(PurpleC
return text_new;
}
-int ggp_message_send_im(PurpleConnection *gc, const char *who,
- const char *message, PurpleMessageFlags flags)
+int ggp_message_send_im(PurpleConnection *gc, PurpleMessage *msg)
{
GGPInfo *info = purple_connection_get_protocol_data(gc);
PurpleIMConversation *im;
ggp_buddy_data *buddy_data;
gchar *gg_msg;
gboolean succ;
+ const gchar *who = purple_message_get_who(msg);
/* TODO: return -ENOTCONN, if not connected */
- if (message == NULL || message[0] == '\0')
+ if (purple_message_is_empty(msg))
return 0;
buddy_data = ggp_buddy_get_data(purple_blist_find_buddy(
@@ -659,7 +659,8 @@ int ggp_message_send_im(PurpleConnection
im = purple_conversations_find_im_with_account(
who, purple_connection_get_account(gc));
- gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(im), message);
+ gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(im),
+ purple_message_get_contents(msg));
/* TODO: splitting messages */
if (strlen(gg_msg) > GG_MSG_MAXSIZE) {
diff --git a/libpurple/protocols/gg/message-prpl.h b/libpurple/protocols/gg/message-prpl.h
--- a/libpurple/protocols/gg/message-prpl.h
+++ b/libpurple/protocols/gg/message-prpl.h
@@ -42,8 +42,7 @@ void ggp_message_got(PurpleConnection *g
void ggp_message_got_multilogon(PurpleConnection *gc,
const struct gg_event_msg *ev);
-int ggp_message_send_im(PurpleConnection *gc, const char *who,
- const char *message, PurpleMessageFlags flags);
+int ggp_message_send_im(PurpleConnection *gc, PurpleMessage *msg);
gchar * ggp_message_format_to_gg(PurpleConversation *conv, const gchar *text);
#endif /* _GGP_MESSAGE_PRPL_H */
diff --git a/libpurple/protocols/irc/irc.c b/libpurple/protocols/irc/irc.c
--- a/libpurple/protocols/irc/irc.c
+++ b/libpurple/protocols/irc/irc.c
@@ -50,7 +50,7 @@ static void irc_login_cb_ssl(gpointer da
static void irc_login_cb(gpointer data, gint source, const gchar *error_message);
static void irc_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error, gpointer data);
static void irc_close(PurpleConnection *gc);
-static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags);
+static int irc_im_send(PurpleConnection *gc, PurpleMessage *msg);
static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags);
static void irc_chat_join (PurpleConnection *gc, GHashTable *data);
static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond);
@@ -558,15 +558,16 @@ static void irc_close(PurpleConnection *
g_free(irc);
}
-static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags)
+static int irc_im_send(PurpleConnection *gc, PurpleMessage *msg)
{
struct irc_conn *irc = purple_connection_get_protocol_data(gc);
char *plain;
const char *args[2];
- args[0] = irc_nick_skip_mode(irc, who);
+ args[0] = irc_nick_skip_mode(irc, purple_message_get_who(msg));
- purple_markup_html_to_xhtml(what, NULL, &plain);
+ purple_markup_html_to_xhtml(purple_message_get_contents(msg),
+ NULL, &plain);
args[1] = plain;
irc_cmd_privmsg(irc, "msg", NULL, args);
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -3072,7 +3072,8 @@ static PurpleCmdRet jabber_cmd_chat_msg(
who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]);
- jabber_message_send_im(purple_conversation_get_connection(conv), who, args[1], 0);
+ jabber_message_send_im(purple_conversation_get_connection(conv),
+ purple_message_new(who, args[1], 0));
g_free(who);
return PURPLE_CMD_RET_OK;
diff --git a/libpurple/protocols/jabber/message.c b/libpurple/protocols/jabber/message.c
--- a/libpurple/protocols/jabber/message.c
+++ b/libpurple/protocols/jabber/message.c
@@ -1118,8 +1118,7 @@ jabber_xhtml_plain_equal(const char *xht
return ret;
}
-int jabber_message_send_im(PurpleConnection *gc, const char *who, const char *msg,
- PurpleMessageFlags flags)
+int jabber_message_send_im(PurpleConnection *gc, PurpleMessage *msg)
{
JabberMessage *jm;
JabberBuddy *jb;
@@ -1127,16 +1126,11 @@ int jabber_message_send_im(PurpleConnect
char *xhtml;
char *tmp;
char *resource;
+ const gchar *who = purple_message_get_who(msg);
- if(!who || !msg)
+ if (!who || purple_message_is_empty(msg))
return 0;
- if (purple_debug_is_verbose()) {
- /* TODO: Maybe we need purple_debug_is_really_verbose? :) */
- purple_debug_misc("jabber", "jabber_message_send_im: who='%s'\n"
- "\tmsg='%s'\n", who, msg);
- }
-
resource = jabber_get_resource(who);
jb = jabber_buddy_find(purple_connection_get_protocol_data(gc), who, TRUE);
@@ -1163,7 +1157,7 @@ int jabber_message_send_im(PurpleConnect
}
}
More information about the Commits
mailing list