Mercurial > pidgin.yaz
changeset 22302:0e2207b46080
In msimprpl, if the user signs in without any username set (this will happen
the first time they login to MySpaceIM if they haven't set a short URL),
have them pick a username and use it. Patch from Jaywalker.
Closes #2844.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sat, 16 Feb 2008 20:20:12 +0000 |
parents | 3ed2c259f656 |
children | 1097406c8f6c |
files | libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h libpurple/protocols/myspace/user.c libpurple/protocols/myspace/user.h |
diffstat | 4 files changed, 295 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c Sat Feb 16 20:02:36 2008 +0000 +++ b/libpurple/protocols/myspace/myspace.c Sat Feb 16 20:20:12 2008 +0000 @@ -73,7 +73,7 @@ static gboolean msim_check_alive(gpointer data); #endif -static gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg); +static gboolean msim_is_username_set(MsimSession *session, MsimMessage *msg); static gboolean msim_process(MsimSession *session, MsimMessage *msg); @@ -1548,9 +1548,8 @@ /** Called when the session key arrives. */ static gboolean -msim_we_are_logged_on(MsimSession *session, MsimMessage *msg) -{ - MsimMessage *body; +msim_is_username_set(MsimSession *session, MsimMessage *msg) { + /*MsimMessage *body;*/ g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); g_return_val_if_fail(msg != NULL, FALSE); @@ -1581,26 +1580,39 @@ /* Set display name to username (otherwise will show email address) */ purple_connection_set_display_name(session->gc, session->username); - /* The session is now set up, ready to be connected. This emits the - * signedOn signal, so clients can now do anything with msimprpl, and - * we're ready for it (session key, userid, username all setup). */ - purple_connection_update_progress(session->gc, _("Connected"), 3, 4); - purple_connection_set_state(session->gc, PURPLE_CONNECTED); - /* Additional post-connect operations */ if (msim_msg_get_integer(msg, "uniquenick") == session->userid) { purple_debug_info("msim_we_are_logged_on", "TODO: pick username\n"); - /* No username is set. */ - purple_notify_error(session->account, - _("No username set"), - _("Please go to http://editprofile.myspace.com/index.cfm?fuseaction=profile.username and choose a username and try to login again."), NULL); - purple_connection_error_reason (session->gc, - PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("No username set")); + g_return_val_if_fail(session->gc != NULL, FALSE); + purple_request_yes_no(session->gc, + _("MySpaceIM - No Username Set"), + _("You appear to have no MySpace username."), + _("Would you like to set one now? (Note: THIS CANNOT BE CHANGED!)"), + 0, + session->account, + NULL, + NULL, + session->gc, G_CALLBACK(msim_set_username_cb), G_CALLBACK(msim_do_not_set_username_cb)); + purple_debug_info("msim","Username Not Set Alert Prompted\n"); return FALSE; } + return TRUE; +} + +/** Called after username is set. */ +gboolean msim_we_are_logged_on(MsimSession *session) { + MsimMessage *body; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + + /* The session is now set up, ready to be connected. This emits the + * signedOn signal, so clients can now do anything with msimprpl, and + * we're ready for it (session key, userid, username all setup). */ + purple_connection_update_progress(session->gc, _("Connected"), 3, 4); + purple_connection_set_state(session->gc, PURPLE_CONNECTED); body = msim_msg_new( "UserID", MSIM_TYPE_INTEGER, session->userid, @@ -1687,7 +1699,14 @@ if (msim_msg_get_integer(msg, "lc") == 1) { return msim_login_challenge(session, msg); } else if (msim_msg_get_integer(msg, "lc") == 2) { - return msim_we_are_logged_on(session, msg); + /* return msim_we_are_logged_on(session, msg); */ + if (msim_is_username_set(session, msg)) { + return msim_we_are_logged_on(session); + } else { + /* No username is set... We'll wait for the callbacks to do their work */ + /* When they're all done, the last one will call msim_we_are_logged_on() and pick up where we left off */ + return FALSE; + } } else if (msim_msg_get(msg, "bm")) { return msim_incoming_bm(session, msg); } else if (msim_msg_get(msg, "rid")) {
--- a/libpurple/protocols/myspace/myspace.h Sat Feb 16 20:02:36 2008 +0000 +++ b/libpurple/protocols/myspace/myspace.h Sat Feb 16 20:20:12 2008 +0000 @@ -45,6 +45,7 @@ #include "cipher.h" /* for SHA-1 */ #include "util.h" /* for base64 */ #include "debug.h" /* for purple_debug_info */ +#include "request.h" /* For dialogs used in setting the username */ #include "xmlnode.h" #include "core.h" @@ -221,6 +222,8 @@ gboolean msim_send_bm(MsimSession *session, const gchar *who, const gchar *text, int type); +gboolean msim_we_are_logged_on(MsimSession *session); + void msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note); guint msim_new_reply_callback(MsimSession *session, MSIM_USER_LOOKUP_CB cb, gpointer data);
--- a/libpurple/protocols/myspace/user.c Sat Feb 16 20:02:36 2008 +0000 +++ b/libpurple/protocols/myspace/user.c Sat Feb 16 20:20:12 2008 +0000 @@ -24,6 +24,15 @@ static void msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message); +/* Callbacks for setting the username bit */ +static void msim_check_username_availability_cb(PurpleConnection *gc, const char *value); +static void msim_username_is_available_cb(MsimSession *session, MsimMessage *userinfo, gpointer data); +static void msim_set_username_confirmed_cb(PurpleConnection *gc); +static void msim_username_is_set_cb(MsimSession *session, MsimMessage *userinfo, gpointer data); +static void msim_set_username(MsimSession *session, const gchar *username, + MSIM_USER_LOOKUP_CB cb, gpointer data); +static char *msim_username_to_set; + /** Format the "now playing" indicator, showing the artist and song. * @return Return a new string (must be g_free()'d), or NULL. */ @@ -537,4 +546,249 @@ user->image_url); /* checksum */ } +/*** + * If they hit cancel or no at any point in the Setting Username process, we come here. * + * Currently.. We're safe letting them get by without setting it.. Unless we hear otherwise.. * + * So for now, give them a menu.. If this becomes an issue with the Official client.. boot them here */ +void msim_do_not_set_username_cb(PurpleConnection *gc) { + purple_debug_info("msim","Dont set username"); + /* Give them the menu option to set one if they want to later */ +} + +/* They've decided to set a username! Yay! */ +void msim_set_username_cb(PurpleConnection *gc) { + g_return_if_fail(gc != NULL); + purple_debug_info("msim","Set username\n"); + purple_request_input(gc, _("MySpaceIM - Please Set a Username"), + _("Please enter a username to check its availability:"), + NULL, + "", FALSE, FALSE, NULL, + _("OK"), G_CALLBACK(msim_check_username_availability_cb), + _("Cancel"), G_CALLBACK(msim_do_not_set_username_cb), + purple_connection_get_account(gc), + NULL, + NULL, + gc); +} +/* Once they've submited their new username, we need to see if its available here */ +static void msim_check_username_availability_cb(PurpleConnection *gc, const char *value) { + MsimMessage *user_msg; + MsimSession *session; + + g_return_if_fail(gc != NULL); + + session = (MsimSession *)gc->proto_data; + + g_return_if_fail(MSIM_SESSION_VALID(session)); + + purple_debug_info("msim","Check username for %s\n",value); + + user_msg = msim_msg_new( + "user", MSIM_TYPE_STRING, g_strdup(value), + NULL); + + /* 25 characters: letters, numbers, underscores */ + /* TODO: VERIFY ABOVE */ + /* \persist\1\sesskey\288500516\cmd\1\dsn\5\uid\204084363\lid\7\rid\367\body\UserName=Jaywalker\final\ */ + /* Official client uses a standard lookup... So do we! */ + msim_lookup_user(session, value, msim_username_is_available_cb, user_msg); +} + +/* \persistr\\cmd\257\dsn\5\uid\204084363\lid\7\rid\367\body\UserName=TheAlbinoRhino1\final\ */ +/* This is where we do a bit more than merely prompt the user. Now we have some real data to tell us the state of their requested username */ +static void msim_username_is_available_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) { + MsimMessage *msg; + gchar *username, *errmsg; + MsimMessage *body; + gint userid; + + purple_debug_info("msim","Look up username callback made\n"); + + msg = (MsimMessage *)data; + g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(msg != NULL); + + username = msim_msg_get_string(msg, "user"); + body = msim_msg_get_dictionary(userinfo, "body"); + + if (!body) { + errmsg = g_strdup("An error occured while trying to set the username.\nPlease try again, or visit http://editprofile.myspace.com/index.cfm?fuseaction=profile.username to set your username."); + purple_debug_info("msim","No body for %s?!\n",username); + purple_connection_error_reason(session->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, errmsg); + return; + } + + userid = msim_msg_get_integer(body, "UserID"); + + purple_debug_info("msim","Returned username is %s and userid is %d\n", username,userid); + msim_msg_free(body); + msim_msg_free(msg); + + /* The response for a free username will ONLY have the UserName in it.. thus making UserID return 0 when we msg_get_integer it */ + if (userid == 0) { + /* This username is currently unused */ + purple_debug_info("msim","Username available. Prompting to Confirm.\n"); + msim_username_to_set = g_strdup(username); + g_free(username); + purple_request_yes_no(session->gc, + _("MySpaceIM - Username Available"), + _("This username is available. Would you like to set it?"), + _("ONCE SET, THIS CANNOT BE CHANGED!"), + 0, + session->account, + NULL, + NULL, + session->gc, G_CALLBACK(msim_set_username_confirmed_cb), G_CALLBACK(msim_do_not_set_username_cb)); + } else { + /* Looks like its in use or we have an invalid response */ + purple_debug_info("msim","Username unavaiable. Prompting for new entry.\n"); + purple_request_input(session->gc, _("MySpaceIM - Please Set a Username"), + _("This username is unavailable."), + _("Please try another username:"), + "", FALSE, FALSE, NULL, + _("OK"), G_CALLBACK(msim_check_username_availability_cb), + _("Cancel"), G_CALLBACK(msim_do_not_set_username_cb), + session->account, + NULL, + NULL, + session->gc); + } +} + +/* They've confirmed that username that was available, Lets make the call to set it */ +static void msim_set_username_confirmed_cb(PurpleConnection *gc) { + MsimMessage *user_msg; + MsimSession *session; + + g_return_if_fail(gc != NULL); + + session = (MsimSession *)gc->proto_data; + + g_return_if_fail(MSIM_SESSION_VALID(session)); + + + user_msg = msim_msg_new( + "user", MSIM_TYPE_STRING, g_strdup(msim_username_to_set), + NULL); + + purple_debug_info("msim","Setting username to %s\n",msim_username_to_set); + + /* Sets our username... keep your fingers crossed :) */ + msim_set_username(session, msim_username_to_set, msim_username_is_set_cb, user_msg); + g_free(msim_username_to_set); +} + +/** + * Asynchronously set new username, calling callback when receive result. + * + * @param session + * @param username The username we're setting for ourselves. Not freed. + * @param cb Callback, called with user information when available. + * @param data An arbitray data pointer passed to the callback. + */ +static void +msim_set_username(MsimSession *session, const gchar *username, + MSIM_USER_LOOKUP_CB cb, gpointer data) +{ + MsimMessage *body; + guint rid; + + g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(username != NULL); + g_return_if_fail(cb != NULL); + + purple_debug_info("msim", "msim_set_username: " + "Setting username %s\n", username); + + msim_msg_dump("msim_set_username: data=%s\n", (MsimMessage *)data); + + /* Setup callback. Response will be associated with request using 'rid'. */ + rid = msim_new_reply_callback(session, cb, data); + + /* TODO: I dont know if the ContactType is -/ALWAYS/- 1 */ + + body = msim_msg_new("UserName", MSIM_TYPE_STRING, g_strdup(username),NULL); +/* \setinfo\\sesskey\469958979\info\Age=21.AvatarUrl=.BandName=.ContactType=1.DisplayName=Msim.Gender=M.ImageURL=http:/1/1x.myspace.com/1images/1no_pic.gif.LastLogin=128335268400000000.Location=US.ShowAvatar=False.SongName=.TotalFriends=1.UserName=msimprpl2\final\ +*/ + + /* Send request */ + g_return_if_fail(msim_send(session, + "setinfo", MSIM_TYPE_BOOLEAN, TRUE, + "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "info", MSIM_TYPE_DICTIONARY, body, + NULL)); + body = msim_msg_new("UserName", MSIM_TYPE_STRING, g_strdup(username),NULL); + g_return_if_fail(msim_send(session, + "persist", MSIM_TYPE_INTEGER, 1, + "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "cmd", MSIM_TYPE_INTEGER, 1, + "dsn", MSIM_TYPE_INTEGER, 5, + "uid", MSIM_TYPE_INTEGER, session->userid, + "lid", MSIM_TYPE_INTEGER, 7, + "rid", MSIM_TYPE_INTEGER, rid, + "body", MSIM_TYPE_DICTIONARY, body, + NULL)); +} + +static void msim_username_is_set_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) { + gchar *username, *errmsg; + MsimMessage *body; + + guint rid; + gint cmd,dsn,uid,lid,code; + /* \persistr\\cmd\258\dsn\9\uid\204084363\lid\14\rid\369\body\UserName=TheAlbinoRhino1.Code=0\final\ */ + + purple_debug_info("msim","username_is_set made\n"); + + g_return_if_fail(MSIM_SESSION_VALID(session)); + + + msim_msg_dump("username_is_set message is: %s\n", userinfo); + cmd = msim_msg_get_integer(userinfo, "cmd"); + dsn = msim_msg_get_integer(userinfo, "dsn"); + uid = msim_msg_get_integer(userinfo, "uid"); + lid = msim_msg_get_integer(userinfo, "lid"); + body = msim_msg_get_dictionary(userinfo, "body"); + errmsg = g_strdup("An error occured while trying to set the username.\nPlease try again, or visit http://editprofile.myspace.com/index.cfm?fuseaction=profile.username to set your username."); + + if (!body) { + purple_debug_info("msim","No body for in msim_username_is_set\n"); + /* Error: No body! */ + purple_connection_error_reason(session->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, errmsg); + } + username = msim_msg_get_string(body, "UserName"); + code = msim_msg_get_integer(body,"Code"); + + msim_msg_free(body); + + purple_debug_info("msim","username_is_set cmd = %d, dsn = %d, lid = %d, code = %d, username = %s\n",cmd,dsn,lid,code,username); + if (cmd == 258 && dsn == 9 && lid == 14) { + purple_debug_info("msim","Proper cmd,dsn,lid for username_is_set!\n"); + purple_debug_info("msim","Username Set with return code %d\n",code); + if (code == 0) { + /* Good! */ + msim_we_are_logged_on(session); + } else { + purple_debug_info("msim","code is %d",code); + } + } else if (cmd == 257 && dsn == 5 && lid == 7) { + /* Not quite done... ONE MORE STEP :) */ + rid = msim_new_reply_callback(session, msim_username_is_set_cb, data); + body = msim_msg_new("UserName", MSIM_TYPE_STRING, g_strdup(username),NULL); + if (!msim_send(session, "persist", MSIM_TYPE_INTEGER, 1, "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "cmd", MSIM_TYPE_INTEGER, 2, "dsn", MSIM_TYPE_INTEGER, 9, "uid", MSIM_TYPE_INTEGER, session->userid, + "lid", MSIM_TYPE_INTEGER, 14, "rid", MSIM_TYPE_INTEGER, rid, "body", MSIM_TYPE_DICTIONARY, body, + NULL)) { + /* Error! */ + /* Can't set... Disconnect */ + purple_connection_error_reason(session->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, errmsg); + } + + } else { + /* Error! */ + purple_debug_info("msim","username_is_set Error: Invalid cmd/dsn/lid combination"); + purple_connection_error_reason(session->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, errmsg); + } + g_free(errmsg); +}
--- a/libpurple/protocols/myspace/user.h Sat Feb 16 20:02:36 2008 +0000 +++ b/libpurple/protocols/myspace/user.h Sat Feb 16 20:20:12 2008 +0000 @@ -52,5 +52,7 @@ gboolean msim_is_userid(const gchar *user); gboolean msim_is_email(const gchar *user); void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data); +void msim_set_username_cb(PurpleConnection *gc); +void msim_do_not_set_username_cb(PurpleConnection *gc); #endif /* !_MYSPACE_USER_H */