Mercurial > pidgin
changeset 22100:1226083ed7e2
Implement prpl_info->normalize for msimprpl, modified patch from Jaywalker.
This makes buddy names treated the same regardless of case and spacing. It
also allows user IDs to be normalized into usernames, _if_ the user is on
the buddy list (making it work in the general case is #4631).
This allows you to IM 6221 and have a conversion with 'tom' instead of his
number. Closes #2802.
mtn: beginning commit on branch 'im.pidgin.pidgin'
mtn: misuse: empty log message; commit canceled
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Mon, 14 Jan 2008 02:06:47 +0000 |
parents | d943df776c09 |
children | 0b823f16162c |
files | COPYRIGHT libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h |
diffstat | 3 files changed, 67 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Sat Jan 12 14:44:12 2008 +0000 +++ b/COPYRIGHT Mon Jan 14 02:06:47 2008 +0000 @@ -426,6 +426,7 @@ Andrew Whewell Simon Wilkinson Dan Willemsen +Justin Williams (Jaywalker) Jason Willis Matt Wilson Dan Winship
--- a/libpurple/protocols/myspace/myspace.c Sat Jan 12 14:44:12 2008 +0000 +++ b/libpurple/protocols/myspace/myspace.c Mon Jan 14 02:06:47 2008 +0000 @@ -2316,6 +2316,69 @@ msim_msg_free(blocklist_msg); } +/** + * Borrowed this code from oscar_normalize. Added checking for "if userid, get name before normalizing" + * + * Basically... Returns a string that has been formated with all the spaces and caps removed. + */ +const char *msim_normalize(const PurpleAccount *account, const char *str) { + static char normalized[BUF_LEN]; + MsimSession *session; + char *tmp1, *tmp2; + int i, j; + guint id; + + g_return_val_if_fail(str != NULL, NULL); + + if (msim_is_userid(str)) { + /* Have user ID, we need to get their username first :) */ + const char *username; + + /* If the account does not exist, we can't look up the user. */ + g_return_val_if_fail(account != NULL, str); + g_return_val_if_fail(account->gc != NULL, str); + g_return_val_if_fail(account->gc->state == PURPLE_CONNECTED, str); + + purple_debug_info("msim_normalize", "%s is a userid\n",str); + + session = (MsimSession *)account->gc->proto_data; + id = atol(str); + username = msim_uid2username_from_blist(session, id); + if (!username) { + /* Not in buddy list... scheisse... TODO: Manual Lookup! */ + /* Note: manual lookup using msim_lookup_user() is a problem inside + * msim_normalize(), because msim_lookup_user() calls a callback function + * when the user information has been looked up, but msim_normalize() expects + * the result immediately. */ + purple_debug_info("msim_normalize", "Failure! %s is not in my list\n", str); + strncpy(normalized, str, BUF_LEN); + } else { + purple_debug_info("msim_normalize","%d is %s\n", id, username); + strncpy(normalized, username, BUF_LEN); + } + } else { + /* Have username. */ + strncpy(normalized, str, BUF_LEN); + } + + /* Strip spaces. */ + for (i=0, j=0; normalized[j]; i++, j++) { + while (normalized[j] == ' ') + j++; + normalized[i] = normalized[j]; + } + normalized[i] = '\0'; + + /* Lowercase and perform UTF-8 normalization. */ + tmp1 = g_utf8_strdown(normalized, -1); + tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT); + g_snprintf(normalized, sizeof(normalized), "%s", tmp2); + g_free(tmp2); + g_free(tmp1); + + return normalized; +} + /** Return whether the buddy can be messaged while offline. * * The protocol supports offline messages in just the same way as online @@ -2970,7 +3033,7 @@ NULL, /* rename_group */ NULL, /* buddy_free */ NULL, /* convo_closed */ - NULL, /* normalize */ + msim_normalize, /* normalize */ NULL, /* set_buddy_icon */ NULL, /* remove_group */ NULL, /* get_cb_real_name */
--- a/libpurple/protocols/myspace/myspace.h Sat Jan 12 14:44:12 2008 +0000 +++ b/libpurple/protocols/myspace/myspace.h Mon Jan 14 02:06:47 2008 +0000 @@ -201,6 +201,8 @@ void msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group); void msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group); +const char *msim_normalize(const PurpleAccount *account, const char *str); + gboolean msim_offline_message(const PurpleBuddy *buddy); void msim_close(PurpleConnection *gc);