changeset 23618:c3506ae277f6

merge of '2a68f533ef12aaf2b26c7827857687c4ff04b229' and '8022890df03cfa8cce52f7dee5b12ad58b64bbe6'
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 19 Jul 2008 03:10:10 +0000
parents a9db0aec7e59 (current diff) 2eefa8dc7481 (diff)
children d70aad03b491 e53a21941d43
files
diffstat 7 files changed, 190 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/protocols/msn/notification.c	Sat Jul 19 03:10:10 2008 +0000
@@ -989,7 +989,8 @@
 	PurpleConnection *gc;
 	MsnUserList *userlist;
 	char *who = NULL, *text = NULL;
-	xmlnode *payloadNode, *from, *textNode;
+	const char *id = NULL;
+	xmlnode *payloadNode, *from, *msg, *textNode;
 
 	purple_debug_misc("msn", "Incoming Page: {%s}\n", payload);
 
@@ -1014,9 +1015,27 @@
 	   </NOTIFICATION>
 	*/
 
+	/* This is the payload if your message was too long:
+	   <NOTIFICATION id="TrID" siteid="111100400" siteurl="http://mobile.msn.com/">
+	     <TO name="passport@example.com">
+	       <VIA agent="mobile"/>
+	     </TO>
+	     <FROM name="tel:+XXXXXXXXXXX"/>
+	     <MSG pri="1" id="407">
+	       <CAT Id="110110001"/>
+	       <ACTION url="2wayIM.asp"/>
+	       <SUBSCR url="2wayIM.asp"/>
+	       <BODY lcid="1033">
+	         <TEXT></TEXT>
+	       </BODY>
+	     </MSG>
+	   </NOTIFICATION>
+	*/
+
 	if (!(payloadNode = xmlnode_from_str(payload, len)) ||
 		!(from = xmlnode_get_child(payloadNode, "FROM")) ||
-		!(textNode = xmlnode_get_child(payloadNode, "MSG/BODY/TEXT")))
+		!(msg = xmlnode_get_child(payloadNode, "MSG")) ||
+		!(textNode = xmlnode_get_child(msg, "BODY/TEXT")))
 		return;
 
 	who = g_strdup(xmlnode_get_attrib(from, "name"));
@@ -1026,7 +1045,7 @@
 
 	/* Match number to user's mobile number, FROM is a phone number if the
 	   other side page you using your phone number */
-	if(!strncmp(who, "tel:+", 5)) {
+	if (!strncmp(who, "tel:+", 5)) {
 		MsnUser *user =
 			msn_userlist_find_user_with_mobile_phone(userlist, who + 4);
 
@@ -1036,7 +1055,20 @@
 		}
 	}
 
-	serv_got_im(gc, who, text, 0, time(NULL));
+	id = xmlnode_get_attrib(msg, "id");
+
+	if (id && !strcmp(id, "407")) {
+		/* TODO: Use this to NAK the transaction, maybe print the text, too.
+		unsigned int trId;
+		id = xmlnode_get_attrib(payloadNode, "id");
+		trId = atol(id);
+		*/
+		purple_conv_present_error(who, gc->account,
+			_("Mobile message was not sent because it was too long."));
+
+	} else {
+		serv_got_im(gc, who, text, 0, time(NULL));
+	}
 
 	g_free(text);
 	g_free(who);
--- a/libpurple/protocols/msn/oim.c	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/protocols/msn/oim.c	Sat Jul 19 03:10:10 2008 +0000
@@ -381,11 +381,11 @@
 
 					} else if (g_str_equal(faultcode_str, "q0:InvalidContent")) {
 						str_reason = _("Message was not sent because an unknown "
-						               "encoding error occured.");
+						               "encoding error occurred.");
 
 					} else {
 						str_reason = _("Message was not sent because an unknown "
-						               "error occured.");
+						               "error occurred.");
 					}
 					
 					msn_session_report_user(oim->session, msg->to_member, 
--- a/libpurple/protocols/msn/switchboard.c	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/protocols/msn/switchboard.c	Sat Jul 19 03:10:10 2008 +0000
@@ -978,7 +978,13 @@
 		account = cmdproc->session->account;
 		user = msg->remote_user;
 
-		serv_got_attention(account->gc, user, MSN_NUDGE);
+		if (swboard->current_users > 1 ||
+			((swboard->conv != NULL) &&
+			 purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
+			purple_prpl_got_attention_in_chat(account->gc, swboard->chat_id, user, MSN_NUDGE);
+
+		else
+			purple_prpl_got_attention(account->gc, user, MSN_NUDGE);
 
 	} else if (!strcmp(id, "2")) {
 		/* Wink */
--- a/libpurple/prpl.c	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/prpl.c	Sat Jul 19 03:10:10 2008 +0000
@@ -389,6 +389,110 @@
 	return statuses;
 }
 
+void
+purple_prpl_send_attention(PurpleConnection *gc, const char *who, guint type_code)
+{
+	PurpleAttentionType *attn;
+	PurpleMessageFlags flags;
+	PurplePlugin *prpl;
+	PurpleConversation *conv;
+	gboolean (*send_attention)(PurpleConnection *, const char *, guint);
+	PurpleBuddy *buddy;
+	const char *alias;	
+	gchar *description;
+	time_t mtime;
+
+	g_return_if_fail(gc != NULL);
+	g_return_if_fail(who != NULL);
+
+	prpl = purple_find_prpl(purple_account_get_protocol_id(gc->account));
+	send_attention = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->send_attention;
+	g_return_if_fail(send_attention != NULL);
+
+	mtime = time(NULL);
+
+	attn = purple_get_attention_type_from_code(gc->account, type_code);
+
+	if ((buddy = purple_find_buddy(purple_connection_get_account(gc), who)) != NULL)
+		alias = purple_buddy_get_contact_alias(buddy);
+	else
+		alias = who;
+
+	if (attn && purple_attention_type_get_outgoing_desc(attn)) {
+		description = g_strdup_printf(purple_attention_type_get_outgoing_desc(attn), alias);
+	} else {
+		description = g_strdup_printf(_("Requesting %s's attention..."), alias);
+	}
+	
+	flags = PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_SYSTEM;
+
+	purple_debug_info("server", "serv_send_attention: sending '%s' to %s\n",
+			description, who);
+
+	if (!send_attention(gc, who, type_code))
+		return;
+
+	conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, gc->account, who);
+	purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, description, flags, mtime);
+
+	g_free(description);
+}
+
+static void
+got_attention(PurpleConnection *gc, int id, const char *who, guint type_code)
+{
+	PurpleMessageFlags flags;
+	PurpleAttentionType *attn;
+	PurpleBuddy *buddy;
+	const char *alias;
+	gchar *description;
+	time_t mtime;
+
+	mtime = time(NULL);
+
+	attn = purple_get_attention_type_from_code(gc->account, type_code);
+
+	/* PURPLE_MESSAGE_NOTIFY is for attention messages. */
+	flags = PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_RECV;
+
+	/* TODO: if (attn->icon_name) is non-null, use it to lookup an emoticon and display
+	 * it next to the attention command. And if it is null, display a generic icon. */
+
+	if ((buddy = purple_find_buddy(purple_connection_get_account(gc), who)) != NULL)
+		alias = purple_buddy_get_contact_alias(buddy);
+	else
+		alias = who;
+
+	if (attn && purple_attention_type_get_incoming_desc(attn)) {
+		description = g_strdup_printf(purple_attention_type_get_incoming_desc(attn), alias);
+	} else {
+		description = g_strdup_printf(_("%s has requested your attention!"), alias);
+	}
+
+	purple_debug_info("server", "got_attention: got '%s' from %s\n",
+			description, who);
+
+	if (id == -1)
+		serv_got_im(gc, who, description, flags, mtime);
+	else
+		serv_got_chat_in(gc, id, who, flags, description, mtime);
+
+	/* TODO: sounds (depending on PurpleAttentionType), shaking, etc. */
+
+	g_free(description);
+}
+
+void
+purple_prpl_got_attention(PurpleConnection *gc, const char *who, guint type_code)
+{
+	got_attention(gc, -1, who, type_code);
+}
+
+void
+purple_prpl_got_attention_in_chat(PurpleConnection *gc, int id, const char *who, guint type_code)
+{
+	got_attention(gc, id, who, type_code);
+}
 
 /**************************************************************************
  * Protocol Plugin Subsystem API
--- a/libpurple/prpl.h	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/prpl.h	Sat Jul 19 03:10:10 2008 +0000
@@ -693,6 +693,41 @@
  */
 GList *purple_prpl_get_statuses(PurpleAccount *account, PurplePresence *presence);
 
+/** Send an attention request message.
+ *
+ * @param gc The connection to send the message on.
+ * @param who Whose attention to request.
+ * @param type_code An index into the prpl's attention_types list determining the type
+ * 	of the attention request command to send. 0 if prpl only defines one
+ * 	(for example, Yahoo and MSN), but some protocols define more (MySpaceIM).
+ *
+ * Note that you can't send arbitrary PurpleAttentionType's, because there is
+ * only a fixed set of attention commands.
+ * @since 2.5.0
+ */
+void purple_prpl_send_attention(PurpleConnection *gc, const char *who, guint type_code);
+
+/** Process an incoming attention message. 
+ *
+ * @param gc The connection that received the attention message.
+ * @param who Who requested your attention.
+ * @param type_code An index into the prpl's attention_types list determining the type
+ * 	of the attention request command to send.
+ * @since 2.5.0
+ */
+void purple_prpl_got_attention(PurpleConnection *gc, const char *who, guint type_code);
+
+/** Process an incoming attention message in a chat. 
+ *
+ * @param gc The connection that received the attention message.
+ * @param id The chat id.
+ * @param who Who requested your attention.
+ * @param type_code An index into the prpl's attention_types list determining the type
+ * 	of the attention request command to send. 
+ * @since 2.5.0
+ */
+void purple_prpl_got_attention_in_chat(PurpleConnection *gc, int id, const char *who, guint type_code);
+
 /*@}*/
 
 /**************************************************************************/
--- a/libpurple/server.c	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/server.c	Sat Jul 19 03:10:10 2008 +0000
@@ -323,91 +323,13 @@
 void
 serv_send_attention(PurpleConnection *gc, const char *who, guint type_code)
 {
-	PurpleAttentionType *attn;
-	PurpleMessageFlags flags;
-	PurplePlugin *prpl;
-	PurpleConversation *conv;
-	gboolean (*send_attention)(PurpleConnection *, const char *, guint);
-	PurpleBuddy *buddy;
-	const char *alias;	
-	gchar *description;
-	time_t mtime;
-
-	g_return_if_fail(gc != NULL);
-	g_return_if_fail(who != NULL);
-
-	prpl = purple_find_prpl(purple_account_get_protocol_id(gc->account));
-	send_attention = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->send_attention;
-	g_return_if_fail(send_attention != NULL);
-
-	mtime = time(NULL);
-
-	attn = purple_get_attention_type_from_code(gc->account, type_code);
-
-	if ((buddy = purple_find_buddy(purple_connection_get_account(gc), who)) != NULL)
-		alias = purple_buddy_get_contact_alias(buddy);
-	else
-		alias = who;
-
-	if (attn && purple_attention_type_get_outgoing_desc(attn)) {
-		description = g_strdup_printf(purple_attention_type_get_outgoing_desc(attn), alias);
-	} else {
-		description = g_strdup_printf(_("Requesting %s's attention..."), alias);
-	}
-	
-	flags = PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_SYSTEM;
-
-	purple_debug_info("server", "serv_send_attention: sending '%s' to %s\n",
-			description, who);
-
-	if (!send_attention(gc, who, type_code))
-		return;
-
-	conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, gc->account, who);
-	purple_conv_im_write(PURPLE_CONV_IM(conv), NULL, description, flags, mtime);
-
-	g_free(description);
+	purple_prpl_send_attention(gc, who, type_code);
 }
 
 void
 serv_got_attention(PurpleConnection *gc, const char *who, guint type_code)
 {
-	PurpleMessageFlags flags;
-	PurpleAttentionType *attn;
-	PurpleBuddy *buddy;
-	const char *alias;
-	gchar *description;
-	time_t mtime;
-
-	mtime = time(NULL);
-
-	attn = purple_get_attention_type_from_code(gc->account, type_code);
-
-	/* PURPLE_MESSAGE_NOTIFY is for attention messages. */
-	flags = PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NOTIFY | PURPLE_MESSAGE_RECV;
-
-	/* TODO: if (attn->icon_name) is non-null, use it to lookup an emoticon and display
-	 * it next to the attention command. And if it is null, display a generic icon. */
-
-	if ((buddy = purple_find_buddy(purple_connection_get_account(gc), who)) != NULL)
-		alias = purple_buddy_get_contact_alias(buddy);
-	else
-		alias = who;
-
-	if (attn && purple_attention_type_get_incoming_desc(attn)) {
-		description = g_strdup_printf(purple_attention_type_get_incoming_desc(attn), alias);
-	} else {
-		description = g_strdup_printf(_("%s has requested your attention!"), alias);
-	}
-
-	purple_debug_info("server", "serv_got_attention: got '%s' from %s\n",
-			description, who);
-
-	serv_got_im(gc, who, description, flags, mtime);
-	
-	/* TODO: sounds (depending on PurpleAttentionType), shaking, etc. */
-
-	g_free(description);
+	purple_prpl_got_attention(gc, who, type_code);
 }
 
 
--- a/libpurple/server.h	Sat Jul 19 00:18:18 2008 +0000
+++ b/libpurple/server.h	Sat Jul 19 03:10:10 2008 +0000
@@ -63,6 +63,8 @@
 
 /** Send an attention request message.
  *
+ * @deprecated Use purple_prpl_send_attention() instead.
+ *
  * @param gc The connection to send the message on.
  * @param who Whose attention to request.
  * @param type_code An index into the prpl's attention_types list determining the type
@@ -76,6 +78,8 @@
 
 /** Process an incoming attention message. 
  *
+ * @deprecated Use purple_prpl_got_attention() instead.
+ *
  * @param gc The connection that received the attention message.
  * @param who Who requested your attention.
  * @param type_code An index into the prpl's attention_types list determining the type