Mercurial > pidgin
diff libpurple/protocols/msn/msn.c @ 31558:ce968e115c95
propagate from branch 'im.pidgin.cpw.masca.p2p' (head 33ca865dacb9e5bcf763d06f6a42cbaca337cc64)
to branch 'im.pidgin.pidgin' (head 92f47f4e8b0cbb107fd97e1ab814d1cedbf109ad)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Fri, 06 May 2011 06:25:14 +0000 |
parents | 0c981f2c169a |
children | 5f6bbe89d873 |
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c Tue Jan 04 05:05:06 2011 +0000 +++ b/libpurple/protocols/msn/msn.c Fri May 06 06:25:14 2011 +0000 @@ -95,13 +95,6 @@ MsnObject *obj; } MsnEmoticon; -typedef struct -{ - PurpleConnection *pc; - PurpleBuddy *buddy; - PurpleGroup *group; -} MsnAddReqData; - static const char * msn_normalize(const PurpleAccount *account, const char *str) { @@ -110,11 +103,9 @@ g_return_val_if_fail(str != NULL, NULL); - g_snprintf(buf, sizeof(buf), "%s%s", str, - (strchr(str, '@') ? "" : "@hotmail.com")); - - tmp = g_utf8_strdown(buf, -1); - strncpy(buf, tmp, sizeof(buf)); + tmp = g_strchomp(g_utf8_strdown(str, -1)); + g_snprintf(buf, sizeof(buf), "%s%s", tmp, + (strchr(tmp, '@') ? "" : "@hotmail.com")); g_free(tmp); return buf; @@ -200,7 +191,7 @@ { const char *type, *friendlyname; struct public_alias_closure *closure; - + g_return_if_fail(cmd->param_count >= 3); type = cmd->params[1]; g_return_if_fail(!strcmp(type, "MFN")); @@ -737,7 +728,7 @@ char *blocked_text; blocked_text = g_strdup_printf(_("MSN servers are currently blocking the following regular expressions:<br/>%s"), session->blocked_text); - + purple_notify_formatted(pc, title, title, NULL, blocked_text, NULL, NULL); g_free(blocked_text); } @@ -760,7 +751,7 @@ return; } - /** apparently the correct value is 777, use 750 as a failsafe */ + /** apparently the correct value is 777, use 750 as a failsafe */ if ((session->passport_info.mail_url == NULL) || (time (NULL) - session->passport_info.mail_timestamp >= 750)) { MsnTransaction *trans; @@ -931,8 +922,8 @@ if (session) { MsnUser *user = msn_userlist_find_user(session->userlist, who); if (user) { - /* Include these too: MSN_CLIENT_CAP_MSNMOBILE|MSN_CLIENT_CAP_MSNDIRECT ? */ - if ((user->clientid & MSN_CLIENT_CAP_WEBMSGR) || + /* Include these too: MSN_CAP_MOBILE_ON|MSN_CAP_WEB_WATCH ? */ + if ((user->clientid & MSN_CAP_VIA_WEBIM) || user->networkid == MSN_NETWORK_YAHOO) ret = FALSE; else @@ -961,16 +952,16 @@ MsnUser *user = purple_buddy_get_protocol_data(b); if (user != NULL) { - if (user->clientid & MSN_CLIENT_CAP_BOT) + if (user->clientid & MSN_CAP_BOT) return "bot"; - if (user->clientid & MSN_CLIENT_CAP_WIN_MOBILE) + if (user->clientid & MSN_CAP_VIA_MOBILE) return "mobile"; #if 0 /* XXX: Since we don't support this, there's no point in showing it just yet */ - if (user->clientid & MSN_CLIENT_CAP_SCHANNEL) + if (user->clientid & MSN_CAP_SCHANNEL) return "secure"; #endif - if (user->clientid & MSN_CLIENT_CAP_WEBMSGR) + if (user->clientid & MSN_CAP_VIA_WEBIM) return "external"; if (user->networkid == MSN_NETWORK_YAHOO) return "yahoo"; @@ -1042,7 +1033,6 @@ const char *psm, *name; const char *mediatype = NULL; char *currentmedia = NULL; - char *tmp; psm = purple_status_get_attr_string(status, "message"); if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) { @@ -1086,9 +1076,7 @@ } if (psm != NULL && *psm) { - tmp = g_markup_escape_text(psm, -1); - purple_notify_user_info_add_pair(user_info, tmp2, tmp); - g_free(tmp); + purple_notify_user_info_add_pair_plaintext(user_info, tmp2, psm); } else { purple_notify_user_info_add_pair(user_info, _("Status"), tmp2); } @@ -1096,13 +1084,11 @@ g_free(tmp2); } else { if (psm != NULL && *psm) { - tmp = g_markup_escape_text(psm, -1); if (purple_presence_is_idle(presence)) { - purple_notify_user_info_add_pair(user_info, _("Idle"), tmp); + purple_notify_user_info_add_pair_plaintext(user_info, _("Idle"), psm); } else { - purple_notify_user_info_add_pair(user_info, _("Status"), tmp); + purple_notify_user_info_add_pair_plaintext(user_info, _("Status"), psm); } - g_free(tmp); } else { if (purple_presence_is_idle(presence)) { purple_notify_user_info_add_pair(user_info, _("Status"), @@ -1586,7 +1572,7 @@ swboard != NULL) { /*User online or have a swboard open because it's invisible * and sent us a message,then send Online Instant Message*/ - + if (msglen + strlen(msgformat) + strlen(VERSION) > 1564) { g_free(msgformat); @@ -1751,65 +1737,49 @@ MsnUser *user) { char *group; + MsnUserList *userlist; + MsnUser *user2; g_return_if_fail(user != NULL); + if (network == MSN_NETWORK_UNKNOWN) { + purple_debug_error("msn", "Network in FQY response was unknown. " + "Assuming %s is a passport user and adding anyway.\n", who); + network = MSN_NETWORK_PASSPORT; + } + group = msn_user_remove_pending_group(user); - if (network != MSN_NETWORK_UNKNOWN) { - MsnUserList *userlist = session->userlist; - MsnUser *user2 = msn_userlist_find_user(userlist, who); - if (user2 != NULL) { - /* User already in userlist, so just update it. */ - msn_user_unref(user); - user = user2; - } else { - msn_userlist_add_user(userlist, user); - } - - msn_user_set_network(user, network); - msn_userlist_add_buddy(userlist, who, group); - } - else - { - PurpleBuddy * buddy = purple_find_buddy(session->account, who); - gchar *buf; - buf = g_strdup_printf(_("Unable to add the buddy %s because the username is invalid. Usernames must be valid email addresses."), who); - if (!purple_conv_present_error(who, session->account, buf)) - purple_notify_error(purple_account_get_connection(session->account), NULL, _("Unable to Add"), buf); - g_free(buf); - - /* Remove from local list */ - purple_blist_remove_buddy(buddy); + userlist = session->userlist; + user2 = msn_userlist_find_user(userlist, who); + if (user2 != NULL) { + /* User already in userlist, so just update it. */ + msn_user_unref(user); + user = user2; + } else { + msn_userlist_add_user(userlist, user); msn_user_unref(user); } + + msn_user_set_network(user, network); + msn_userlist_add_buddy(userlist, who, group); + g_free(group); } static void -finish_auth_request(MsnAddReqData *data, char *msg) +msn_add_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group, const char *message) { - PurpleConnection *pc; - PurpleBuddy *buddy; - PurpleGroup *group; PurpleAccount *account; + const char *bname, *gname; MsnSession *session; MsnUserList *userlist; - const char *who, *gname; MsnUser *user; - pc = data->pc; - buddy = data->buddy; - group = data->group; - g_free(data); - account = purple_connection_get_account(pc); - session = pc->proto_data; - userlist = session->userlist; - - who = msn_normalize(account, purple_buddy_get_name(buddy)); - gname = group ? purple_group_get_name(group) : NULL; - purple_debug_info("msn", "Add user:%s to group:%s\n", who, gname ? gname : "(null)"); + session = purple_connection_get_protocol_data(pc); + bname = purple_buddy_get_name(buddy); + if (!session->logged_in) { purple_debug_error("msn", "msn_add_buddy called before connected\n"); @@ -1819,56 +1789,20 @@ /* XXX - Would group ever be NULL here? I don't think so... * shx: Yes it should; MSN handles non-grouped buddies, and this is only - * internal. */ - user = msn_userlist_find_user(userlist, who); - if ((user != NULL) && (user->networkid != MSN_NETWORK_UNKNOWN)) { - /* We already know this buddy and their network. This function knows - what to do with users already in the list and stuff... */ - msn_user_set_invite_message(user, msg); - msn_userlist_add_buddy(userlist, who, gname); - } else { - char **tokens; - char *fqy; - /* We need to check the network for this buddy first */ - user = msn_user_new(userlist, who, NULL); - msn_user_set_invite_message(user, msg); - msn_user_set_pending_group(user, gname); - msn_user_set_network(user, MSN_NETWORK_UNKNOWN); - tokens = g_strsplit(who, "@", 2); - fqy = g_strdup_printf("<ml><d n=\"%s\"><c n=\"%s\"/></d></ml>", - tokens[1], - tokens[0]); - msn_notification_send_fqy(session, fqy, strlen(fqy), - (MsnFqyCb)add_pending_buddy, user); - g_free(fqy); - g_strfreev(tokens); - } -} - -static void -cancel_auth_request(MsnAddReqData *data, char *msg) -{ - /* Remove from local list */ - purple_blist_remove_buddy(data->buddy); - - g_free(data); -} - -static void -msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) -{ - const char *bname; - MsnAddReqData *data; - MsnSession *session; - MsnUser *user; - - bname = purple_buddy_get_name(buddy); + * internal. + * KingAnt: But PurpleBuddys must always exist inside PurpleGroups, so + * won't group always be non-NULL here? + */ + bname = msn_normalize(account, bname); + gname = group ? purple_group_get_name(group) : NULL; + purple_debug_info("msn", "Add user:%s to group:%s\n", + bname, gname ? gname : "(null)"); if (!msn_email_is_valid(bname)) { gchar *buf; buf = g_strdup_printf(_("Unable to add the buddy %s because the username is invalid. Usernames must be valid email addresses."), bname); - if (!purple_conv_present_error(bname, purple_connection_get_account(gc), buf)) - purple_notify_error(gc, NULL, _("Unable to Add"), buf); + if (!purple_conv_present_error(bname, account, buf)) + purple_notify_error(pc, NULL, _("Unable to Add"), buf); g_free(buf); /* Remove from local list */ @@ -1877,22 +1811,38 @@ return; } - data = g_new0(MsnAddReqData, 1); - data->pc = gc; - data->buddy = buddy; - data->group = group; - - session = purple_connection_get_protocol_data(gc); - user = msn_userlist_find_user(session->userlist, bname); + /* Make sure name is normalized */ + purple_blist_rename_buddy(buddy, bname); + + userlist = session->userlist; + user = msn_userlist_find_user(userlist, bname); if (user && user->authorized) { - finish_auth_request(data, NULL); + message = NULL; + } + if ((user != NULL) && (user->networkid != MSN_NETWORK_UNKNOWN)) { + /* We already know this buddy and their network. This function knows + what to do with users already in the list and stuff... */ + msn_user_set_invite_message(user, message); + msn_userlist_add_buddy(userlist, bname, gname); } else { - purple_request_input(gc, NULL, _("Authorization Request Message:"), - NULL, _("Please authorize me!"), TRUE, FALSE, NULL, - _("_OK"), G_CALLBACK(finish_auth_request), - _("_Cancel"), G_CALLBACK(cancel_auth_request), - purple_connection_get_account(gc), bname, NULL, - data); + char **tokens; + char *fqy; + /* We need to check the network for this buddy first */ + user = msn_user_new(userlist, bname, NULL); + msn_user_set_invite_message(user, message); + msn_user_set_pending_group(user, gname); + msn_user_set_network(user, MSN_NETWORK_UNKNOWN); + /* Should probably re-use the msn_add_contact_xml function here */ + tokens = g_strsplit(bname, "@", 2); + fqy = g_strdup_printf("<ml><d n=\"%s\"><c n=\"%s\"/></d></ml>", + tokens[1], + tokens[0]); + /* TODO: I think user will leak if we disconnect before receiving + a response to this FQY request */ + msn_notification_send_fqy(session, fqy, strlen(fqy), + (MsnFqyCb)add_pending_buddy, user); + g_free(fqy); + g_strfreev(tokens); } } @@ -2305,9 +2255,7 @@ alias = purple_buddy_get_local_buddy_alias(b); if (alias && alias[0]) { - char *aliastext = g_markup_escape_text(alias, -1); - purple_notify_user_info_add_pair(user_info, _("Alias"), aliastext); - g_free(aliastext); + purple_notify_user_info_add_pair_plaintext(user_info, _("Alias"), alias); } if ((alias = purple_buddy_get_server_alias(b)) != NULL) @@ -2979,7 +2927,7 @@ static PurplePluginProtocolInfo prpl_info = { - OPT_PROTO_MAIL_CHECK, + OPT_PROTO_MAIL_CHECK|OPT_PROTO_INVITE_MESSAGE, NULL, /* user_splits */ NULL, /* protocol_options */ {"png,gif", 0, 0, 96, 96, 0, PURPLE_ICON_SCALE_SEND}, /* icon_spec */ @@ -3000,7 +2948,7 @@ msn_set_status, /* set_away */ msn_set_idle, /* set_idle */ NULL, /* change_passwd */ - msn_add_buddy, /* add_buddy */ + NULL, /* add_buddy */ NULL, /* add_buddies */ msn_rem_buddy, /* remove_buddy */ NULL, /* remove_buddies */ @@ -3050,7 +2998,9 @@ NULL, /* get_media_caps */ NULL, /* get_moods */ msn_set_public_alias, /* set_public_alias */ - msn_get_public_alias /* get_public_alias */ + msn_get_public_alias, /* get_public_alias */ + msn_add_buddy, /* add_buddy_with_invite */ + NULL /* add_buddies_with_invite */ }; static PurplePluginInfo info =