pidgin: 08979461: Change the way we parse messages on MySp...

markdoliner at pidgin.im markdoliner at pidgin.im
Thu Jun 4 01:25:40 EDT 2009


-----------------------------------------------------------------
Revision: 08979461f8fd9f122c665f3ee192c20788dd1bca
Ancestor: 99982a9d5c9da8620d3b612c7a4625c32684834a
Author: markdoliner at pidgin.im
Date: 2009-06-04T05:19:49
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/08979461f8fd9f122c665f3ee192c20788dd1bca

Modified files:
        libpurple/protocols/myspace/myspace.c
        libpurple/protocols/myspace/myspace.h
        libpurple/protocols/myspace/zap.c

ChangeLog: 

Change the way we parse messages on MySpace a little bit.  This
fixes #8846: people using web myspaceIM can't respond to pidgin myspaceIM

For some reason IMs send using the myspace web site are sent so that
they won't become offline messages if the other person is offline.
I'm not really sure why that decision was made.

So now we treat messages with bm 1 the same as messages with bm 121. This means
we have to combine the function that parses out typing notification with
the function that parses IMs. And we check for typing notifications by
looking for %typing%. Which means if someone sends the IM "%typing%" with
no markup then we'll interpret it as a typing notification. And there's
nothing we can do to differentiate between the two. I asked.

-------------- next part --------------
============================================================
--- libpurple/protocols/myspace/myspace.c	e5821975e39bf9ff06fb52000310468e2ec5c1a2
+++ libpurple/protocols/myspace/myspace.c	a0972c310b4cd50d2cde32cb446f22656cfd808a
@@ -1473,28 +1473,22 @@ static gboolean
  * @return TRUE if successful.
  */
 static gboolean
-msim_incoming_im(MsimSession *session, MsimMessage *msg)
+msim_incoming_im(MsimSession *session, MsimMessage *msg, const gchar *username)
 {
-	gchar *username, *msg_msim_markup, *msg_purple_markup;
+	gchar *msg_msim_markup, *msg_purple_markup;
 	gchar *userid;
 	time_t time_received;
 	PurpleConversation *conv;
 
-	g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
-	g_return_val_if_fail(msg != NULL, FALSE);
-
-	username = msim_msg_get_string(msg, "_username");
 	/* I know this isn't really a string... but we need it to be one for
 	 * purple_find_conversation_with_account(). */
 	userid = msim_msg_get_string(msg, "f");
-	g_return_val_if_fail(username != NULL, FALSE);
 
 	purple_debug_info("msim_incoming_im", "UserID is %s", userid);
 
 	if (msim_is_userid(username)) {
 		purple_debug_info("msim", "Ignoring message from spambot (%s) on account %s\n",
 				username, purple_account_get_username(session->account));
-		g_free(username);
 		return FALSE;
 	}
 
@@ -1519,14 +1513,13 @@ msim_incoming_im(MsimSession *session, M
 
 	serv_got_im(session->gc, username, msg_purple_markup, PURPLE_MESSAGE_RECV, time_received);
 
-	g_free(username);
 	g_free(msg_purple_markup);
 
 	return TRUE;
 }
 
 /**
- * Handle an incoming action message.
+ * Handle an incoming action message or an IM.
  *
  * @param session
  * @param msg
@@ -1534,7 +1527,7 @@ static gboolean
  * @return TRUE if successful.
  */
 static gboolean
-msim_incoming_action(MsimSession *session, MsimMessage *msg)
+msim_incoming_action_or_im(MsimSession *session, MsimMessage *msg)
 {
 	gchar *msg_text, *username;
 	gboolean rc;
@@ -1548,7 +1541,8 @@ msim_incoming_action(MsimSession *sessio
 	username = msim_msg_get_string(msg, "_username");
 	g_return_val_if_fail(username != NULL, FALSE);
 
-	purple_debug_info("msim", "msim_incoming_action: action <%s> from <%s>\n",
+	purple_debug_info("msim",
+			"msim_incoming_action_or_im: action <%s> from <%s>\n",
 			msg_text, username);
 
 	if (g_str_equal(msg_text, "%typing%")) {
@@ -1562,13 +1556,16 @@ msim_incoming_action(MsimSession *sessio
 	} else if (strstr(msg_text, "!!!GroupCount=")) {
 		/* TODO: support group chats. I think the number in msg_text has
 		 * something to do with the 'gid' field. */
-		purple_debug_info("msim", "msim_incoming_action: TODO: implement #4691, group chats: %s\n", msg_text);
+		purple_debug_info("msim",
+				"msim_incoming_action_or_im: "
+				"TODO: implement #4691, group chats: %s\n", msg_text);
 
 		rc = TRUE;
 	} else if (strstr(msg_text, "!!!Offline=")) {
 		/* TODO: support group chats. This one might mean a user
 		 * went offline or exited the chat. */
-		purple_debug_info("msim", "msim_incoming_action: TODO: implement #4691, group chats: %s\n", msg_text);
+		purple_debug_info("msim", "msim_incoming_action_or_im: "
+				"TODO: implement #4691, group chats: %s\n", msg_text);
 
 		rc = TRUE;
 	} else if (msim_msg_get_integer(msg, "aid") != 0) {
@@ -1579,9 +1576,7 @@ msim_incoming_action(MsimSession *sessio
 
 		rc = TRUE;
 	} else {
-		msim_unrecognized(session, msg,
-				"got to msim_incoming_action but unrecognized value for 'msg'");
-		rc = FALSE;
+		rc = msim_incoming_im(session, msg, username);
 	}
 
 	g_free(msg_text);
@@ -1666,10 +1661,9 @@ msim_incoming_bm(MsimSession *session, M
 	switch (bm) {
 		case MSIM_BM_STATUS:
 			return msim_incoming_status(session, msg);
-		case MSIM_BM_INSTANT:
-			return msim_incoming_im(session, msg);
-		case MSIM_BM_ACTION:
-			return msim_incoming_action(session, msg);
+		case MSIM_BM_INSTANT_ACTION_OR_IM:
+		case MSIM_BM_DELAYABLE_ACTION_OR_IM:
+			return msim_incoming_action_or_im(session, msg);
 		case MSIM_BM_MEDIA:
 			return msim_incoming_media(session, msg);
 		case MSIM_BM_UNOFFICIAL_CLIENT:
@@ -1677,7 +1671,8 @@ msim_incoming_bm(MsimSession *session, M
 		default:
 			/* Not really an IM, but show it for informational
 			 * purposes during development. */
-			return msim_incoming_im(session, msg);
+			/* TODO: This is probably wrong */
+			return msim_incoming_action_or_im(session, msg);
 	}
 }
 
@@ -2290,7 +2285,7 @@ msim_send_im(PurpleConnection *gc, const
 
 	message_msim = html_to_msim_markup(session, message);
 
-	if (msim_send_bm(session, who, message_msim, MSIM_BM_INSTANT)) {
+	if (msim_send_bm(session, who, message_msim, MSIM_BM_DELAYABLE_ACTION_OR_IM)) {
 		/* Return 1 to have Purple show this IM as being sent, 0 to not. I always
 		 * return 1 even if the message could not be sent, since I don't know if
 		 * it has failed yet--because the IM is only sent after the userid is
@@ -2343,7 +2338,7 @@ msim_send_typing(PurpleConnection *gc, c
 	}
 
 	purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
-	msim_send_bm(session, name, typing_str, MSIM_BM_ACTION);
+	msim_send_bm(session, name, typing_str, MSIM_BM_INSTANT_ACTION_OR_IM);
 	return 0;
 }
 
============================================================
--- libpurple/protocols/myspace/myspace.h	e294fc90345e61c08b02436888b9907794cc0605
+++ libpurple/protocols/myspace/myspace.h	f5d70f6419e122ee2c24cee6e8a12db4efb1e971
@@ -127,12 +127,12 @@
 #define MSIM_FINAL_STRING           "\\final\\" /**< Message end marker */
 
 /* Messages */
-#define MSIM_BM_INSTANT             1
-#define MSIM_BM_STATUS              100
-#define MSIM_BM_ACTION              121
-#define MSIM_BM_MEDIA               122
-#define MSIM_BM_PROFILE             124
-#define MSIM_BM_UNOFFICIAL_CLIENT   200
+#define MSIM_BM_DELAYABLE_ACTION_OR_IM  1
+#define MSIM_BM_STATUS                  100
+#define MSIM_BM_INSTANT_ACTION_OR_IM    121
+#define MSIM_BM_MEDIA                   122
+#define MSIM_BM_PROFILE                 124
+#define MSIM_BM_UNOFFICIAL_CLIENT       200
 
 /* Authentication algorithm for login2 */
 #define MSIM_AUTH_ALGORITHM         196610
============================================================
--- libpurple/protocols/myspace/zap.c	8460c3de629f94d86b977ef7b916bab2ced0986e
+++ libpurple/protocols/myspace/zap.c	d573d34b178d5b8b9471e71e12c6299d96861b7d
@@ -109,7 +109,7 @@ msim_send_zap(MsimSession *session, cons
 	/* Construct and send the actual zap command. */
 	zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", code);
 
-	if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) {
+	if (!msim_send_bm(session, username, zap_string, MSIM_BM_INSTANT_ACTION_OR_IM)) {
 		purple_debug_info("msim_send_zap",
 				"msim_send_bm failed: zapping %s with %s\n",
 				username, zap_string);


More information about the Commits mailing list