# HG changeset patch # User Jeffrey Connelly # Date 1184738972 0 # Node ID bde17299004bed64058dee055c5e591230e5884a # Parent 4001661344e43b3e480efcfeb235b685ddfc6b93 Support unofficial bm code 200, also used by Miranda IM plugin, to report third-party client version. "Get Info" now shows unofficial client information, if available, and buddies coming online are sent this information so they can view it too. Official client version is not currently supported in the same manner. diff -r 4001661344e4 -r bde17299004b libpurple/protocols/myspace/myspace.c --- a/libpurple/protocols/myspace/myspace.c Mon Jul 16 00:48:49 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Wed Jul 18 06:09:32 2007 +0000 @@ -1090,6 +1090,33 @@ return markup; } +/** Handle an incoming buddy message. */ +gboolean +msim_incoming_bm(MsimSession *session, MsimMessage *msg) +{ + guint bm; + + bm = msim_msg_get_integer(msg, "bm"); + + 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_MEDIA: + return msim_incoming_media(session, msg); + case MSIM_BM_UNOFFICIAL_CLIENT: + return msim_incoming_unofficial_client(session, msg); + default: + /* Not really an IM, but show it for informational + * purposes during development. */ + return msim_incoming_im(session, msg); + } +} + /** * Handle an incoming instant message. * @@ -1208,6 +1235,82 @@ return rc; } +/* Process an incoming media (buddy icon) message. */ +gboolean +msim_incoming_media(MsimSession *session, MsimMessage *msg) +{ + gchar *username, *text; + + username = msim_msg_get_string(msg, "_username"); + text = msim_msg_get_string(msg, "msg"); + + g_return_val_if_fail(username != NULL, FALSE); + g_return_val_if_fail(text != NULL, FALSE); + + purple_debug_info("msim", "msim_incoming_media: from %s, got msg=%s\n", username, text); + + /* Media messages are sent when the user opens a window to someone. + * Tell libpurple they started typing and stopped typing, to inform the Psychic + * Mode plugin so it too can open a window to the user. */ + serv_got_typing(session->gc, username, 0, PURPLE_TYPING); + serv_got_typing_stopped(session->gc, username); + + g_free(username); + + return TRUE; +} + +/* Process an incoming "unofficial client" message. The plugin for + * Miranda IM sends this message with the plugin information. */ +gboolean +msim_incoming_unofficial_client(MsimSession *session, MsimMessage *msg) +{ + PurpleBuddy *buddy; + gchar *username, *client_info; + + username = msim_msg_get_string(msg, "_username"); + client_info = msim_msg_get_string(msg, "msg"); + + g_return_val_if_fail(username != NULL, FALSE); + g_return_val_if_fail(client_info != NULL, FALSE); + + purple_debug_info("msim", "msim_incoming_unofficial_client: %s is using client %s\n", + username, client_info); + + buddy = purple_find_buddy(session->account, username); + + g_return_val_if_fail(buddy != NULL, FALSE); + + purple_blist_node_set_string(&buddy->node, "client", client_info); + + + g_free(username); + /* Do not free client_info - the blist now owns it. */ + + return TRUE; +} + + +/** Send our client version to another unofficial client that understands it. */ +gboolean +msim_send_unofficial_client(MsimSession *session, gchar *username) +{ + gchar *our_info; + gboolean ret; + + our_info = g_strdup_printf("Libpurple %d.%d.%d - msimprpl %s", + PURPLE_MAJOR_VERSION, + PURPLE_MINOR_VERSION, + PURPLE_MICRO_VERSION, + MSIM_PRPL_VERSION_STRING); + + ret = msim_send_bm(session, username, our_info, MSIM_BM_UNOFFICIAL_CLIENT); + + g_free(our_info); + + return ret; +} + /** * Handle when our user starts or stops typing to another user. * @@ -1314,9 +1417,9 @@ /* Other information */ - /* Headline comes from buddy status messages */ if (buddy) { + /* Headline comes from buddy status messages */ str = purple_blist_node_get_string(&buddy->node, "Headline"); if (str) purple_notify_user_info_add_pair(user_info, "Headline", str); @@ -1340,6 +1443,14 @@ purple_notify_user_info_add_pair(user_info, _("Total Friends"), g_strdup(str)); + if (buddy) + { + str = purple_blist_node_get_string(&buddy->node, "client"); + if (str) + purple_notify_user_info_add_pair(user_info, _("Client Version"), + g_strdup(str)); + } + purple_notify_userinfo(session->gc, user, user_info, NULL, NULL); purple_debug_info("msim", "msim_get_info_cb: username=%s\n", user); //purple_notify_user_info_destroy(user_info); @@ -1944,22 +2055,7 @@ } else if (msim_msg_get(msg, "sesskey")) { return msim_we_are_logged_on(session, msg); } else if (msim_msg_get(msg, "bm")) { - guint bm; - - bm = msim_msg_get_integer(msg, "bm"); - switch (bm) - { - case MSIM_BM_STATUS: - return msim_status(session, msg); - case MSIM_BM_INSTANT: - return msim_incoming_im(session, msg); - case MSIM_BM_ACTION: - return msim_incoming_action(session, msg); - default: - /* Not really an IM, but show it for informational - * purposes during development. */ - return msim_incoming_im(session, msg); - } + return msim_incoming_bm(session, msg); } else if (msim_msg_get(msg, "rid")) { return msim_process_reply(session, msg); } else if (msim_msg_get(msg, "error")) { @@ -2148,7 +2244,7 @@ * @return TRUE if successful. */ gboolean -msim_status(MsimSession *session, MsimMessage *msg) +msim_incoming_status(MsimSession *session, MsimMessage *msg) { PurpleBuddyList *blist; PurpleBuddy *buddy; @@ -2265,6 +2361,12 @@ purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL)); } + if (status_code == MSIM_STATUS_CODE_ONLINE) + { + /* Secretly whisper to unofficial clients our own version as they come online */ + msim_send_unofficial_client(session, username); + } + g_strfreev(status_array); g_free(status_str); g_free(username); @@ -2651,6 +2753,8 @@ } /* Null terminate */ + purple_debug_info("msim", "msim_input_cb: going to null terminate " + "at n=%d\n", n); session->rxbuf[session->rxoff + n] = 0; #ifdef MSIM_CHECK_EMBEDDED_NULLS @@ -2685,8 +2789,7 @@ msg = msim_parse(g_strdup(session->rxbuf)); if (!msg) { - purple_debug_info("msim", "msim_input_cb: couldn't parse <%s>\n", - session->rxbuf); + purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n"); purple_connection_error(gc, _("Unparseable message")); } else @@ -3172,7 +3275,7 @@ "prpl-myspace", /**< id */ "MySpaceIM", /**< name */ - "0.12", /**< version */ + MSIM_PRPL_VERSION_STRING, /**< version */ /** summary */ "MySpaceIM Protocol Plugin", /** description */ diff -r 4001661344e4 -r bde17299004b libpurple/protocols/myspace/myspace.h --- a/libpurple/protocols/myspace/myspace.h Mon Jul 16 00:48:49 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.h Wed Jul 18 06:09:32 2007 +0000 @@ -73,7 +73,10 @@ #define MSIM_MAX_PASSWORD_LENGTH 10 /* Build version of MySpaceIM to report to servers (1.0.xxx.0) */ -#define MSIM_CLIENT_VERSION 673 +#define MSIM_CLIENT_VERSION 673 + +/* msimprpl version string of this plugin */ +#define MSIM_PRPL_VERSION_STRING "0.12" /* Default server */ #define MSIM_SERVER "im.myspace.akadns.net" @@ -96,10 +99,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_UNKNOWN1 122 */ +#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 /* Authentication algorithm for login2 */ #define MSIM_AUTH_ALGORITHM 196610 @@ -236,8 +241,14 @@ gchar *msim_markup_to_html(MsimSession *, const gchar *raw); gchar *html_to_msim_markup(MsimSession *, const gchar *raw); -int msim_incoming_im(MsimSession *session, MsimMessage *msg); -int msim_incoming_action(MsimSession *session, MsimMessage *msg); +gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg); +gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg); +gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg); +gboolean msim_incoming_action(MsimSession *session, MsimMessage *msg); +gboolean msim_incoming_media(MsimSession *session, MsimMessage *msg); +gboolean msim_incoming_unofficial_client(MsimSession *session, MsimMessage *msg); + +gboolean msim_send_unofficial_client(MsimSession *session, gchar *username); unsigned int msim_send_typing(PurpleConnection *gc, const gchar *name, PurpleTypingState state); void msim_get_info_cb(MsimSession *session, MsimMessage *userinfo, gpointer data); @@ -265,7 +276,6 @@ gboolean msim_error(MsimSession *session, MsimMessage *msg); -gboolean msim_status(MsimSession *session, MsimMessage *msg); void msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group); void msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group);