Mercurial > pidgin.yaz
changeset 31131:6376fc7a092e
propagate from branch 'im.pidgin.pidgin' (head 8a0b15ca6f7e80f487af0b74bda066a717062d0f)
to branch 'im.pidgin.cpw.qulogic.msnp16' (head 985d7e2eada00fd3ff1b4eba6e0d030bdfdff7fb)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 06 Feb 2010 05:26:27 +0000 |
parents | 8e007ad2421d (current diff) 1830fa548302 (diff) |
children | 33b4ae796648 |
files | libpurple/protocols/msn/msn.h libpurple/protocols/msn/notification.h libpurple/protocols/msn/session.h libpurple/protocols/msn/state.c libpurple/protocols/msn/state.h libpurple/protocols/msn/user.c libpurple/protocols/msn/user.h |
diffstat | 11 files changed, 677 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/msn.c Sat Feb 06 05:26:27 2010 +0000 @@ -364,6 +364,115 @@ g_free(tmp); } +typedef struct MsnLocationData { + PurpleAccount *account; + MsnSession *session; + PurpleRequestFieldGroup *group; +} MsnLocationData; + +static void +update_endpoint_cb(MsnLocationData *data, PurpleRequestFields *fields) +{ + PurpleAccount *account; + MsnSession *session; + const char *old_name; + const char *name; + GList *others; + + session = data->session; + account = data->account; + + /* Update the current location's name */ + old_name = purple_account_get_string(account, "endpoint-name", NULL); + name = purple_request_fields_get_string(fields, "endpoint-name"); + if (!g_str_equal(old_name, name)) { + purple_account_set_string(account, "endpoint-name", name); + msn_notification_send_uux_private_endpointdata(session); + } + + /* Sign out other locations */ + for (others = purple_request_field_group_get_fields(data->group); + others; + others = g_list_next(others)) { + PurpleRequestField *field = others->data; + if (purple_request_field_get_type(field) != PURPLE_REQUEST_FIELD_BOOLEAN) + continue; + if (purple_request_field_bool_get_value(field)) { + const char *id = purple_request_field_get_id(field); + char *user; + purple_debug_info("msn", "Disconnecting Endpoint %s\n", id); + + user = g_strdup_printf("%s;%s", purple_account_get_username(account), id); + msn_notification_send_uun(session, user, MSN_UNIFIED_NOTIFICATION_MPOP, "goawyplzthxbye"); + g_free(user); + } + } + + g_free(data); +} + +static void +create_endpoint_fields(gpointer key, gpointer value, gpointer user_data) +{ + const char *id = key; + MsnUserEndpoint *ep = value; + MsnLocationData *data = user_data; + PurpleRequestField *field; + + if (g_str_equal(id, data->session->guid)) + return; + + field = purple_request_field_bool_new(id, ep->name, FALSE); + purple_request_field_group_add_field(data->group, field); +} + +static void +msn_show_locations(PurplePluginAction *action) +{ + PurpleConnection *pc; + PurpleAccount *account; + MsnSession *session; + PurpleRequestFields *fields; + PurpleRequestFieldGroup *group; + PurpleRequestField *field; + MsnLocationData *data; + + pc = (PurpleConnection *)action->context; + account = purple_connection_get_account(pc); + session = purple_connection_get_protocol_data(pc); + + fields = purple_request_fields_new(); + + group = purple_request_field_group_new(_("This Location")); + purple_request_fields_add_group(fields, group); + field = purple_request_field_label_new("endpoint-label", _("This is the name that identifies this location")); + purple_request_field_group_add_field(group, field); + field = purple_request_field_string_new("endpoint-name", + _("Name"), + purple_account_get_string(account, "endpoint-name", NULL), + FALSE); + purple_request_field_set_required(field, TRUE); + purple_request_field_group_add_field(group, field); + + group = purple_request_field_group_new(_("Other Locations")); + purple_request_fields_add_group(fields, group); + field = purple_request_field_label_new("others-label", _("You can sign out from other locations here")); + purple_request_field_group_add_field(group, field); + + data = g_new0(MsnLocationData, 1); + data->account = account; + data->session = session; + data->group = group; + g_hash_table_foreach(session->user->endpoints, create_endpoint_fields, data); + + purple_request_fields(pc, NULL, NULL, NULL, + fields, + _("OK"), G_CALLBACK(update_endpoint_cb), + _("Cancel"), G_CALLBACK(g_free), + account, NULL, NULL, + data); +} + static void msn_show_set_home_phone(PurplePluginAction *action) { @@ -937,6 +1046,11 @@ m = g_list_append(m, act); m = g_list_append(m, NULL); + act = purple_plugin_action_new(_("View Locations..."), + msn_show_locations); + m = g_list_append(m, act); + m = g_list_append(m, NULL); + act = purple_plugin_action_new(_("Set Home Phone Number..."), msn_show_set_home_phone); m = g_list_append(m, act); @@ -1071,6 +1185,10 @@ username = purple_account_get_string(account, "display-name", NULL); purple_connection_set_display_name(gc, username); + if (purple_account_get_string(account, "endpoint-name", NULL) == NULL) { + purple_account_set_string(account, "endpoint-name", "Pidgin"); + } + if (!msn_session_connect(session, host, port, http_method)) purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
--- a/libpurple/protocols/msn/msn.h Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/msn.h Sat Feb 06 05:26:27 2010 +0000 @@ -109,9 +109,9 @@ #define MSN_SERVER "messenger.hotmail.com" #define MSN_HTTPCONN_SERVER "gateway.messenger.hotmail.com" #define MSN_PORT 1863 -#define WLM_PROT_VER 15 +#define WLM_PROT_VER 16 -#define WLM_MAX_PROTOCOL 15 +#define WLM_MAX_PROTOCOL 16 #define WLM_MIN_PROTOCOL 15 #define MSN_TYPING_RECV_TIMEOUT 6 @@ -134,15 +134,14 @@ /* Index into attention_types */ #define MSN_NUDGE 0 -#define MSN_CLIENT_ID_VERSION MSN_CLIENT_VER_7_0 +#define MSN_CLIENT_ID_VERSION MSN_CLIENT_VER_9_0 #define MSN_CLIENT_ID_CAPABILITIES (MSN_CLIENT_CAP_PACKET|MSN_CLIENT_CAP_INK_GIF|MSN_CLIENT_CAP_VOICEIM) +#define MSN_CLIENT_ID_EXT_CAPS (0) #define MSN_CLIENT_ID \ ((MSN_CLIENT_ID_VERSION << 24) | \ (MSN_CLIENT_ID_CAPABILITIES)) -#define MSN_CLIENT_EXT_ID 0 - gboolean msn_email_is_valid(const char *passport); void msn_act_id(PurpleConnection *gc, const char *entry); void msn_send_privacy(PurpleConnection *gc);
--- a/libpurple/protocols/msn/notification.c Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/notification.c Sat Feb 06 05:26:27 2010 +0000 @@ -22,6 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #include "msn.h" +#include "core.h" #include "notification.h" #include "contact.h" #include "state.h" @@ -161,7 +162,10 @@ msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH_END); - msn_cmdproc_send(cmdproc, "USR", "SSO S %s %s", ticket, response); + if (session->protocol_ver >= 16) + msn_cmdproc_send(cmdproc, "USR", "SSO S %s %s %s", ticket, response, session->guid); + else + msn_cmdproc_send(cmdproc, "USR", "SSO S %s %s", ticket, response); } static void @@ -233,20 +237,22 @@ MsnSession *session; PurpleAccount *account; gboolean protocol_supported = FALSE; - char proto_str[8]; + int proto_ver; size_t i; session = cmdproc->session; account = session->account; - g_snprintf(proto_str, sizeof(proto_str), "MSNP%d", session->protocol_ver); - + session->protocol_ver = 0; for (i = 1; i < cmd->param_count; i++) { - if (!strcmp(cmd->params[i], proto_str)) - { - protocol_supported = TRUE; - break; + if (sscanf(cmd->params[i], "MSNP%d", &proto_ver) == 1) { + if (proto_ver >= WLM_MIN_PROTOCOL + && proto_ver <= WLM_MAX_PROTOCOL + && proto_ver > session->protocol_ver) { + protocol_supported = TRUE; + session->protocol_ver = proto_ver; + } } } @@ -257,6 +263,8 @@ return; } + purple_debug_info("msn", "Negotiated protocol version %d with the server.\n", session->protocol_ver); + /* * Windows Live Messenger 8.5 * Notice :CVR String discriminate! @@ -1081,7 +1089,8 @@ PurpleConnection *gc; MsnUser *user; MsnObject *msnobj = NULL; - unsigned long clientid; + unsigned long clientid, extcaps; + char *extcap_str; int networkid = 0; const char *state, *passport; char *friendly; @@ -1102,7 +1111,11 @@ /* Yahoo! Buddy, looks like */ networkid = atoi(cmd->params[3]); friendly = g_strdup(purple_url_decode(cmd->params[4])); - clientid = strtoul(cmd->params[5], NULL, 10); + clientid = strtoul(cmd->params[5], &extcap_str, 10); + if (session->protocol_ver >= 16 && extcap_str && *extcap_str) + extcaps = strtoul(extcap_str+1, NULL, 10); + else + extcaps = 0; /* cmd->params[7] seems to be a URL to a Yahoo! icon: https://sec.yimg.com/i/us/nt/b/purpley.1.0.png @@ -1112,7 +1125,11 @@ /* MSNP14+ with Display Picture object */ networkid = atoi(cmd->params[3]); friendly = g_strdup(purple_url_decode(cmd->params[4])); - clientid = strtoul(cmd->params[5], NULL, 10); + clientid = strtoul(cmd->params[5], &extcap_str, 10); + if (session->protocol_ver >= 16 && extcap_str && *extcap_str) + extcaps = strtoul(extcap_str+1, NULL, 10); + else + extcaps = 0; msnobj = msn_object_new_from_string(purple_url_decode(cmd->params[6])); } else if (cmd->param_count == 6) { /* Yes, this is 5. The friendly name could start with a number, @@ -1121,17 +1138,29 @@ /* MSNP14 without Display Picture object */ networkid = atoi(cmd->params[3]); friendly = g_strdup(purple_url_decode(cmd->params[4])); - clientid = strtoul(cmd->params[5], NULL, 10); + clientid = strtoul(cmd->params[5], &extcap_str, 10); + if (session->protocol_ver >= 16 && extcap_str && *extcap_str) + extcaps = strtoul(extcap_str+1, NULL, 10); + else + extcaps = 0; } else { /* MSNP8+ with Display Picture object */ friendly = g_strdup(purple_url_decode(cmd->params[3])); - clientid = strtoul(cmd->params[4], NULL, 10); + clientid = strtoul(cmd->params[4], &extcap_str, 10); + if (session->protocol_ver >= 16 && extcap_str && *extcap_str) + extcaps = strtoul(extcap_str+1, NULL, 10); + else + extcaps = 0; msnobj = msn_object_new_from_string(purple_url_decode(cmd->params[5])); } } else if (cmd->param_count == 5) { /* MSNP8+ without Display Picture object */ friendly = g_strdup(purple_url_decode(cmd->params[3])); - clientid = strtoul(cmd->params[4], NULL, 10); + clientid = strtoul(cmd->params[4], &extcap_str, 10); + if (session->protocol_ver >= 16 && extcap_str && *extcap_str) + extcaps = strtoul(extcap_str+1, NULL, 10); + else + extcaps = 0; } else { purple_debug_warning("msn", "Received ILN with unknown number of parameters.\n"); return; @@ -1146,6 +1175,7 @@ user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->extinfo && user->extinfo->phone_mobile && user->extinfo->phone_mobile[0] == '+'); msn_user_set_clientid(user, clientid); + msn_user_set_extcaps(user, extcaps); msn_user_set_network(user, networkid); msn_user_set_state(user, state); @@ -1284,7 +1314,8 @@ PurpleConnection *gc; MsnUser *user; MsnObject *msnobj; - unsigned long clientid; + unsigned long clientid, extcaps; + char *extcap_str; int networkid; const char *state, *passport, *friendly; @@ -1297,7 +1328,10 @@ networkid = atoi(cmd->params[2]); friendly = purple_url_decode(cmd->params[3]); - user = msn_userlist_find_user(session->userlist, passport); + if (g_str_equal(passport, session->user->passport)) + user = session->user; + else + user = msn_userlist_find_user(session->userlist, passport); if (user == NULL) return; if (msn_user_set_friendly_name(user, friendly)) @@ -1315,10 +1349,16 @@ msn_user_set_object(user, NULL); } - clientid = strtoul(cmd->params[4], NULL, 10); + clientid = strtoul(cmd->params[4], &extcap_str, 10); + if (session->protocol_ver >= 16 && extcap_str && *extcap_str) + extcaps = strtoul(extcap_str+1, NULL, 10); + else + extcaps = 0; + user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->extinfo && user->extinfo->phone_mobile && user->extinfo->phone_mobile[0] == '+'); msn_user_set_clientid(user, clientid); + msn_user_set_extcaps(user, extcaps); msn_user_set_network(user, networkid); msn_user_set_state(user, state); @@ -1599,6 +1639,77 @@ /*get the payload content*/ } +static void +parse_user_endpoints(MsnUser *user, xmlnode *payloadNode) +{ + xmlnode *epNode, *capsNode; + MsnUserEndpoint data; + const char *id; + char *caps, *tmp; + + purple_debug_info("msn", "Get EndpointData\n"); + + for (epNode = xmlnode_get_child(payloadNode, "EndpointData"); + epNode; + epNode = xmlnode_get_next_twin(epNode)) { + id = xmlnode_get_attrib(epNode, "id"); + capsNode = xmlnode_get_child(epNode, "Capabilities"); + + if (capsNode != NULL) { + caps = xmlnode_get_data(capsNode); + + data.clientid = strtoul(caps, &tmp, 10); + if (tmp && *tmp) + data.extcaps = strtoul(tmp + 1, NULL, 10); + else + data.extcaps = 0; + + g_free(caps); + + } else { + data.clientid = 0; + data.extcaps = 0; + } + + msn_user_set_endpoint_data(user, id, &data); + } + + /* Need to shortcut this check, probably... */ + if (user == user->userlist->session->user) { + for (epNode = xmlnode_get_child(payloadNode, "PrivateEndpointData"); + epNode; + epNode = xmlnode_get_next_twin(epNode)) { + MsnUserEndpoint *ep; + xmlnode *nameNode, *clientNode; + + /* <PrivateEndpointData id='{GUID}'> + <EpName>Endpoint Name</EpName> + <Idle>true/false</Idle> + <ClientType>1</ClientType> + <State>NLN</State> + </PrivateEndpointData> + */ + id = xmlnode_get_attrib(epNode, "id"); + ep = msn_user_get_endpoint_data(user, id); + + if (ep != NULL) { + nameNode = xmlnode_get_child(epNode, "EpName"); + if (nameNode != NULL) { + g_free(ep->name); + ep->name = xmlnode_get_data(nameNode); + } + + clientNode = xmlnode_get_child(epNode, "ClientType"); + if (clientNode != NULL) { + tmp = xmlnode_get_data(clientNode); + ep->type = strtoul(tmp, NULL, 10); + g_free(tmp); + } + } + } + } +} + static void parse_currentmedia(MsnUser *user, const char *cmedia) { char **cmedia_array; @@ -1669,13 +1780,17 @@ PurpleAccount *account; MsnUser *user; const char *passport; + xmlnode *payloadNode; char *psm_str, *str; session = cmdproc->session; account = session->account; passport = cmd->params[0]; - user = msn_userlist_find_user(session->userlist, passport); + if (g_str_equal(passport, session->user->passport)) + user = session->user; + else + user = msn_userlist_find_user(session->userlist, passport); if (user == NULL) { char *str = g_strndup(payload, len); purple_debug_info("msn", "unknown user %s, payload is %s\n", @@ -1695,13 +1810,28 @@ } if (len != 0) { - psm_str = msn_get_psm(cmd->payload,len); + payloadNode = xmlnode_from_str(payload, len); + if (!payloadNode) { + purple_debug_error("msn", "UBX XML parse Error!\n"); + + msn_user_set_statusline(user, NULL); + + msn_user_update(user); + return; + } + + psm_str = msn_get_psm(payloadNode); msn_user_set_statusline(user, psm_str); g_free(psm_str); - str = msn_get_currentmedia(cmd->payload, len); + str = msn_get_currentmedia(payloadNode); parse_currentmedia(user, str); g_free(str); + + parse_user_endpoints(user, payloadNode); + + xmlnode_free(payloadNode); + } else { msn_user_set_statusline(user, NULL); } @@ -1734,6 +1864,158 @@ cmd->payload_len = atoi(cmd->params[1]); } +void +msn_notification_send_uux(MsnSession *session, const char *payload) +{ + MsnTransaction *trans; + MsnCmdProc *cmdproc; + size_t len = strlen(payload); + + cmdproc = session->notification->cmdproc; + purple_debug_misc("msn", "Sending UUX command with payload: %s\n", payload); + trans = msn_transaction_new(cmdproc, "UUX", "%" G_GSIZE_FORMAT, len); + msn_transaction_set_payload(trans, payload, len); + msn_cmdproc_send_trans(cmdproc, trans); +} + +void msn_notification_send_uux_endpointdata(MsnSession *session) +{ + xmlnode *epDataNode; + xmlnode *capNode; + char *caps; + char *payload; + int length; + + epDataNode = xmlnode_new("EndpointData"); + + capNode = xmlnode_new_child(epDataNode, "Capabilities"); + caps = g_strdup_printf("%d:%02d", MSN_CLIENT_ID_CAPABILITIES, MSN_CLIENT_ID_EXT_CAPS); + xmlnode_insert_data(capNode, caps, -1); + g_free(caps); + + payload = xmlnode_to_str(epDataNode, &length); + + msn_notification_send_uux(session, payload); + + xmlnode_free(epDataNode); + g_free(payload); +} + +void msn_notification_send_uux_private_endpointdata(MsnSession *session) +{ + xmlnode *private; + const char *name; + xmlnode *epname; + xmlnode *idle; + GHashTable *ui_info; + const gchar *ui_type; + xmlnode *client_type; + xmlnode *state; + char *payload; + int length; + + private = xmlnode_new("PrivateEndpointData"); + + name = purple_account_get_string(session->account, "endpoint-name", NULL); + epname = xmlnode_new_child(private, "EpName"); + xmlnode_insert_data(epname, name, -1); + + idle = xmlnode_new_child(private, "Idle"); + xmlnode_insert_data(idle, "false", -1); + + /* ClientType info (from amsn guys): + 0: None + 1: Computer + 2: Website + 3: Mobile / none + 4: Xbox / phone /mobile + 9: MsnGroup + 32: Email member, currently Yahoo! + */ + client_type = xmlnode_new_child(private, "ClientType"); + ui_info = purple_core_get_ui_info(); + ui_type = ui_info ? g_hash_table_lookup(ui_info, "client_type") : NULL; + if (ui_type) { + if (strcmp(ui_type, "pc") == 0) + xmlnode_insert_data(client_type, "1", -1); + else if (strcmp(ui_type, "web") == 0) + xmlnode_insert_data(client_type, "2", -1); + else if (strcmp(ui_type, "phone") == 0) + xmlnode_insert_data(client_type, "3", -1); + else if (strcmp(ui_type, "handheld") == 0) + xmlnode_insert_data(client_type, "3", -1); + else + xmlnode_insert_data(client_type, "1", -1); + } + else + xmlnode_insert_data(client_type, "1", -1); + + state = xmlnode_new_child(private, "State"); + xmlnode_insert_data(state, msn_state_get_text(msn_state_from_account(session->account)), -1); + + payload = xmlnode_to_str(private, &length); + + msn_notification_send_uux(session, payload); + + xmlnode_free(private); + g_free(payload); +} + +static void +ubn_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, + size_t len) +{ + /* Do Nothing, right now. */ + if (payload != NULL) + purple_debug_info("msn", "UBN payload:\n%s\n", payload); +} + +static void +ubn_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) +{ + purple_debug_misc("msn", "UBN received from %s.\n", cmd->params[0]); + cmdproc->last_cmd->payload_cb = ubn_cmd_post; + cmd->payload_len = atoi(cmd->params[2]); +} + +static void +uun_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, + size_t len) +{ + /* Do Nothing, right now. */ + if (payload != NULL) + purple_debug_info("msn", "UUN payload:\n%s\n", payload); +} + +static void +uun_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) +{ + if (strcmp(cmd->params[1], "OK") != 0) { + purple_debug_misc("msn", "UUN received.\n"); + cmdproc->last_cmd->payload_cb = uun_cmd_post; + cmd->payload_len = atoi(cmd->params[1]); + } + else + purple_debug_misc("msn", "UUN OK received.\n"); +} + +void +msn_notification_send_uun(MsnSession *session, const char *user, + MsnUnifiedNotificationType type, const char *payload) +{ + MsnTransaction *trans; + MsnCmdProc *cmdproc; + size_t len = strlen(payload); + + cmdproc = session->notification->cmdproc; + purple_debug_misc("msn", "Sending UUN command %d to %s with payload: %s\n", + type, user, payload); + trans = msn_transaction_new(cmdproc, "UUN", "%s %d %" G_GSIZE_FORMAT, + user, type, len); + msn_transaction_set_payload(trans, payload, len); + msn_cmdproc_send_trans(cmdproc, trans); +} + /************************************************************************** * Message Types **************************************************************************/ @@ -2190,6 +2472,9 @@ msn_table_add_cmd(cbs_table, NULL, "UBX", ubx_cmd); msn_table_add_cmd(cbs_table, NULL, "UUX", uux_cmd); + msn_table_add_cmd(cbs_table, NULL, "UBN", ubn_cmd); + msn_table_add_cmd(cbs_table, NULL, "UUN", uun_cmd); + msn_table_add_cmd(cbs_table, NULL, "URL", url_cmd); msn_table_add_cmd(cbs_table, "fallback", "XFR", xfr_cmd);
--- a/libpurple/protocols/msn/notification.h Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/notification.h Sat Feb 06 05:26:27 2010 +0000 @@ -62,6 +62,15 @@ typedef void (*MsnFqyCb)(MsnSession *session, const char *passport, MsnNetwork network, gpointer data); +/* Type used for msn_notification_send_uun */ +typedef enum { + MSN_UNIFIED_NOTIFICATION_SHARED_FOLDERS = 1, + MSN_UNIFIED_NOTIFICATION_UNKNOWN1 = 2, + MSN_UNIFIED_NOTIFICATION_P2P = 3, + MSN_UNIFIED_NOTIFICATION_MPOP = 4 + +} MsnUnifiedNotificationType; + void uum_send_msg(MsnSession *session, MsnMessage *msg); void msn_notification_end(void); @@ -83,6 +92,17 @@ void msn_notification_disconnect(MsnNotification *notification); void msn_notification_dump_contact(MsnSession *session); +void msn_notification_send_uux(MsnSession *session, const char *payload); + +void msn_notification_send_uux_endpointdata(MsnSession *session); + +void msn_notification_send_uux_private_endpointdata(MsnSession *session); + +void msn_notification_send_uun(MsnSession *session, + const char *user, + MsnUnifiedNotificationType type, + const char *payload); + /** * Closes a notification. *
--- a/libpurple/protocols/msn/session.c Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/session.c Sat Feb 06 05:26:27 2010 +0000 @@ -22,6 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ #include "msn.h" +#include "msnutils.h" #include "session.h" #include "notification.h" #include "oim.h" @@ -45,7 +46,9 @@ purple_account_get_username(account), NULL); session->oim = msn_oim_new(session); - session->protocol_ver = WLM_PROT_VER; + session->protocol_ver = 0; + + session->guid = rand_guid(); return session; } @@ -90,6 +93,7 @@ msn_userlist_destroy(session->userlist); g_free(session->psm); + g_free(session->guid); g_free(session->abch_cachekey); #if 0 g_free(session->blocked_text); @@ -448,6 +452,11 @@ msn_session_sync_users(session); } + if (session->protocol_ver >= 16) { + /* TODO: Send this when updating status instead? */ + msn_notification_send_uux_endpointdata(session); + msn_notification_send_uux_private_endpointdata(session); + } msn_change_status(session); }
--- a/libpurple/protocols/msn/session.h Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/session.h Sat Feb 06 05:26:27 2010 +0000 @@ -119,6 +119,7 @@ GHashTable *soap_table; guint soap_cleanup_handle; + char *guid; }; /**
--- a/libpurple/protocols/msn/state.c Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/state.c Sat Feb 06 05:26:27 2010 +0000 @@ -27,6 +27,7 @@ #include "core.h" #include "msn.h" +#include "notification.h" #include "state.h" static const char *away_text[] = @@ -43,10 +44,6 @@ N_("Available") }; -/* Local Function Prototype*/ -static char *msn_build_psm(const char *psmstr,const char *mediastr, - const char *guidstr); - /* * WLM media PSM info build prcedure * @@ -56,7 +53,7 @@ * <CurrentMedia>\0Office\01\0Office Message\0Office App Name\0</CurrentMedia>" */ static char * -msn_build_psm(const char *psmstr,const char *mediastr, const char *guidstr) +msn_build_psm(const char *psmstr,const char *mediastr, const char *guidstr, guint protocol_ver) { xmlnode *dataNode,*psmNode,*mediaNode,*guidNode; char *result; @@ -82,60 +79,50 @@ } xmlnode_insert_child(dataNode, guidNode); + if (protocol_ver >= 16) { + /* TODO: What is this for? */ + xmlnode *ddpNode = xmlnode_new("DDP"); + xmlnode_insert_child(dataNode, ddpNode); + } + result = xmlnode_to_str(dataNode, &length); xmlnode_free(dataNode); return result; } -/* get the CurrentMedia info from the XML string */ +/* get the CurrentMedia info from the XML node */ char * -msn_get_currentmedia(char *xml_str, gsize len) +msn_get_currentmedia(xmlnode *payloadNode) { - xmlnode *payloadNode, *currentmediaNode; + xmlnode *currentmediaNode; char *currentmedia; purple_debug_info("msn", "Get CurrentMedia\n"); - payloadNode = xmlnode_from_str(xml_str, len); - if (!payloadNode) { - purple_debug_error("msn", "PSM XML parse Error!\n"); - return NULL; - } currentmediaNode = xmlnode_get_child(payloadNode, "CurrentMedia"); if (currentmediaNode == NULL) { purple_debug_info("msn", "No CurrentMedia Node\n"); - xmlnode_free(payloadNode); return NULL; } currentmedia = xmlnode_get_data(currentmediaNode); - xmlnode_free(payloadNode); - return currentmedia; } -/*get the PSM info from the XML string*/ +/* Get the PSM info from the XML node */ char * -msn_get_psm(char *xml_str, gsize len) +msn_get_psm(xmlnode *payloadNode) { - xmlnode *payloadNode, *psmNode; + xmlnode *psmNode; char *psm; purple_debug_info("msn", "msn get PSM\n"); - payloadNode = xmlnode_from_str(xml_str, len); - if (!payloadNode) { - purple_debug_error("msn", "PSM XML parse Error!\n"); - return NULL; - } psmNode = xmlnode_get_child(payloadNode, "PSM"); if (psmNode == NULL) { purple_debug_info("msn", "No PSM status Node\n"); - xmlnode_free(payloadNode); return NULL; } psm = xmlnode_get_data(psmNode); - xmlnode_free(payloadNode); - return psm; } @@ -181,8 +168,6 @@ PurpleAccount *account; PurplePresence *presence; PurpleStatus *status; - MsnCmdProc *cmdproc; - MsnTransaction *trans; char *payload; const char *statusline; gchar *statusline_stripped, *media = NULL; @@ -191,7 +176,6 @@ g_return_if_fail(session->notification != NULL); account = session->account; - cmdproc = session->notification->cmdproc; /* Get the PSM string from Purple's Status Line */ presence = purple_account_get_presence(account); @@ -202,13 +186,11 @@ statusline_stripped = purple_markup_strip_html(statusline); media = create_media_string(presence); g_free(session->psm); - session->psm = msn_build_psm(statusline_stripped, media, NULL); + session->psm = msn_build_psm(statusline_stripped, media, session->protocol_ver >= 16 ? session->guid : NULL, session->protocol_ver); payload = session->psm; - purple_debug_misc("msn", "Sending UUX command with payload: %s\n", payload); - trans = msn_transaction_new(cmdproc, "UUX", "%" G_GSIZE_FORMAT, strlen(payload)); - msn_transaction_set_payload(trans, payload, strlen(payload)); - msn_cmdproc_send_trans(cmdproc, trans); + + msn_notification_send_uux(session, payload); g_free(statusline_stripped); g_free(media); @@ -256,11 +238,16 @@ if (!session->logged_in) return; + msn_set_psm(session); + msnobj = msn_user_get_object(user); if (msnobj == NULL) { - msn_cmdproc_send(cmdproc, "CHG", "%s %d", state_text, caps); + if (session->protocol_ver >= 16) + msn_cmdproc_send(cmdproc, "CHG", "%s %u:%02u 0", state_text, caps, MSN_CLIENT_ID_EXT_CAPS); + else + msn_cmdproc_send(cmdproc, "CHG", "%s %d", state_text, caps); } else { @@ -268,12 +255,15 @@ msnobj_str = msn_object_to_string(msnobj); - msn_cmdproc_send(cmdproc, "CHG", "%s %d %s", state_text, - caps, purple_url_encode(msnobj_str)); + if (session->protocol_ver >= 16) + msn_cmdproc_send(cmdproc, "CHG", "%s %u:%02u %s", state_text, + caps, MSN_CLIENT_ID_EXT_CAPS, purple_url_encode(msnobj_str)); + else + msn_cmdproc_send(cmdproc, "CHG", "%s %d %s", state_text, + caps, purple_url_encode(msnobj_str)); g_free(msnobj_str); } - msn_set_psm(session); } const char *
--- a/libpurple/protocols/msn/state.h Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/state.h Sat Feb 06 05:26:27 2010 +0000 @@ -60,11 +60,11 @@ void msn_set_psm(MsnSession *session); -/* Get the CurrentMedia info from the XML string */ -char *msn_get_currentmedia(char *xml_str, gsize len); +/* Get the CurrentMedia info from the XML node */ +char *msn_get_currentmedia(xmlnode *payloadNode); -/*get the PSM info from the XML string*/ -char *msn_get_psm(char *xml_str, gsize len); +/* Get the PSM info from the XML node */ +char *msn_get_psm(xmlnode *payloadNode); MsnAwayType msn_state_from_account(PurpleAccount *account);
--- a/libpurple/protocols/msn/switchboard.c Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/switchboard.c Sat Feb 06 05:26:27 2010 +0000 @@ -243,6 +243,12 @@ return; } + /* Don't add ourselves either... */ + if (g_str_equal(passport, purple_account_get_username(account))) { + g_free(passport); + return; + } + swboard->users = g_list_prepend(swboard->users, passport); swboard->current_users++; swboard->empty = FALSE; @@ -265,7 +271,7 @@ PURPLE_CBFLAGS_NONE, TRUE); msn_servconn_set_idle_timeout(swboard->servconn, 0); } - else if (swboard->current_users > 1 || swboard->total_users > 1) + else if (swboard->current_users > 1) { msn_servconn_set_idle_timeout(swboard->servconn, 0); if (swboard->conv == NULL || @@ -964,6 +970,7 @@ MsnTransaction *trans; MsnCmdProc *cmdproc; PurpleAccount *account; + char *username; cmdproc = servconn->cmdproc; g_return_if_fail(cmdproc != NULL); @@ -972,24 +979,33 @@ swboard = cmdproc->data; g_return_if_fail(swboard != NULL); + if (servconn->session->protocol_ver >= 16) + username = g_strdup_printf("%s;{%s}", + purple_account_get_username(account), + servconn->session->guid); + else + username = g_strdup(purple_account_get_username(account)); + if (msn_switchboard_is_invited(swboard)) { swboard->empty = FALSE; trans = msn_transaction_new(cmdproc, "ANS", "%s %s %s", - purple_account_get_username(account), + username, swboard->auth_key, swboard->session_id); } else { trans = msn_transaction_new(cmdproc, "USR", "%s %s", - purple_account_get_username(account), + username, swboard->auth_key); } msn_transaction_set_error_cb(trans, ans_usr_error); msn_transaction_set_data(trans, swboard); msn_cmdproc_send_trans(cmdproc, trans); + + g_free(username); } static void
--- a/libpurple/protocols/msn/user.c Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/user.c Sat Feb 06 05:26:27 2010 +0000 @@ -25,6 +25,8 @@ #include "user.h" #include "slp.h" +static void free_user_endpoint(MsnUserEndpoint *data); + /*new a user object*/ MsnUser * msn_user_new(MsnUserList *userlist, const char *passport, @@ -39,6 +41,9 @@ msn_user_set_passport(user, passport); msn_user_set_friendly_name(user, friendly_name); + user->endpoints = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, (GDestroyNotify)free_user_endpoint); + return user; } @@ -48,6 +53,9 @@ { g_return_if_fail(user != NULL); + if (user->endpoints != NULL) + g_hash_table_destroy(user->endpoints); + if (user->clientcaps != NULL) g_hash_table_destroy(user->clientcaps); @@ -186,6 +194,9 @@ { g_return_val_if_fail(user != NULL, FALSE); + if (user == user->userlist->session->user) + return FALSE; + if (user->friendly_name && name && (!strcmp(user->friendly_name, name) || !strcmp(user->passport, name))) return FALSE; @@ -216,6 +227,44 @@ user->uid = g_strdup(uid); } +static void +free_user_endpoint(MsnUserEndpoint *data) +{ + g_free(data->id); + g_free(data->name); + g_free(data); +} + +void +msn_user_set_endpoint_data(MsnUser *user, const char *input, MsnUserEndpoint *data) +{ + MsnUserEndpoint *new; + char *endpoint; + + g_return_if_fail(user != NULL); + g_return_if_fail(input != NULL); + + endpoint = g_ascii_strdown(input, -1); + + if (data == NULL) { + g_hash_table_remove(user->endpoints, endpoint); + g_free(endpoint); + return; + } + + new = g_hash_table_lookup(user->endpoints, endpoint); + if (!new) { + new = g_new0(MsnUserEndpoint, 1); + new->id = g_strdup(endpoint); + g_hash_table_insert(user->endpoints, g_strdup(endpoint), new); + } + + new->clientid = data->clientid; + new->extcaps = data->extcaps; + + g_free(endpoint); +} + void msn_user_set_op(MsnUser *user, MsnListOp list_op) { @@ -406,6 +455,14 @@ } void +msn_user_set_extcaps(MsnUser *user, guint extcaps) +{ + g_return_if_fail(user != NULL); + + user->extcaps = extcaps; +} + +void msn_user_set_network(MsnUser *user, MsnNetwork network) { g_return_if_fail(user != NULL); @@ -423,7 +480,7 @@ user->msnobj = obj; - if (user->list_op & MSN_LIST_FL_OP) + if (user != user->userlist->session->user && user->list_op & MSN_LIST_FL_OP) msn_queue_buddy_icon_request(user); } @@ -496,6 +553,30 @@ return user->clientid; } +guint +msn_user_get_extcaps(const MsnUser *user) +{ + g_return_val_if_fail(user != NULL, 0); + + return user->extcaps; +} + +MsnUserEndpoint * +msn_user_get_endpoint_data(MsnUser *user, const char *input) +{ + char *endpoint; + MsnUserEndpoint *data; + + g_return_val_if_fail(user != NULL, NULL); + g_return_val_if_fail(input != NULL, NULL); + + endpoint = g_ascii_strdown(input, -1); + data = g_hash_table_lookup(user->endpoints, endpoint); + g_free(endpoint); + + return data; +} + MsnObject * msn_user_get_object(const MsnUser *user) { @@ -520,3 +601,22 @@ return user->invite_message; } +gboolean +msn_user_is_capable(MsnUser *user, char *endpoint, guint capability, guint extcap) +{ + g_return_val_if_fail(user != NULL, FALSE); + + if (endpoint != NULL) { + MsnUserEndpoint *ep = g_hash_table_lookup(user->endpoints, endpoint); + if (ep != NULL) + return (ep->clientid & capability) == capability + && (ep->extcaps & extcap) == extcap; + else + return FALSE; + } + + return (user->clientid & capability) == capability + && (user->extcaps & extcap) == extcap; +} + +
--- a/libpurple/protocols/msn/user.h Fri Feb 05 23:04:41 2010 +0000 +++ b/libpurple/protocols/msn/user.h Sat Feb 06 05:26:27 2010 +0000 @@ -83,6 +83,7 @@ char *friendly_name; /**< The friendly name. */ char *uid; /*< User ID */ + GHashTable *endpoints; /*< Endpoint-specific data */ const char *status; /**< The state of the user. */ char *statusline; /**< The state of the user. */ @@ -102,6 +103,7 @@ GHashTable *clientcaps; /**< The client's capabilities. */ guint clientid; /**< The client's ID */ + guint extcaps; /**< The client's extended capabilities */ MsnNetwork networkid; /**< The user's network */ @@ -116,6 +118,18 @@ char *invite_message; /**< Invite message of user request */ }; +/** + * A specific user endpoint. + */ +typedef struct MsnUserEndpoint { + char *id; /**< The client's endpoint ID */ + char *name; /**< The client's endpoint's name */ + int type; /**< The client's endpoint type */ + guint clientid; /**< The client's ID */ + guint extcaps; /**< The client's extended capabilites */ + +} MsnUserEndpoint; + /************************************************************************** ** @name User API * **************************************************************************/ @@ -252,6 +266,16 @@ void msn_user_set_uid(MsnUser *user, const char *uid); /** + * Sets endpoint data for a user. + * + * @param user The user. + * @param endpoint The endpoint. + * @param data The endpoint data. + */ +void +msn_user_set_endpoint_data(MsnUser *user, const char *endpoint, MsnUserEndpoint *data); + +/** * Sets the client id for a user. * * @param user The user. @@ -260,6 +284,14 @@ void msn_user_set_clientid(MsnUser *user, guint clientid); /** + * Sets the client id for a user. + * + * @param user The user. + * @param extcaps The client's extended capabilities. + */ +void msn_user_set_extcaps(MsnUser *user, guint extcaps); + +/** * Sets the network id for a user. * * @param user The user. @@ -346,6 +378,17 @@ const char *msn_user_get_mobile_phone(const MsnUser *user); /** + * Gets endpoint data for a user. + * + * @param user The user. + * @param endpoint The endpoint. + * + * @return The user's endpoint data. + */ +MsnUserEndpoint * +msn_user_get_endpoint_data(MsnUser *user, const char *endpoint); + +/** * Returns the client id for a user. * * @param user The user. @@ -355,6 +398,15 @@ guint msn_user_get_clientid(const MsnUser *user); /** + * Returns the extended capabilities for a user. + * + * @param user The user. + * + * @return The user's extended capabilities. + */ +guint msn_user_get_extcaps(const MsnUser *user); + +/** * Returns the network id for a user. * * @param user The user. @@ -398,11 +450,24 @@ /** * check to see if user is Yahoo User */ -gboolean msn_user_is_yahoo(PurpleAccount *account ,const char *name); +gboolean msn_user_is_yahoo(PurpleAccount *account, const char *name); void msn_user_set_op(MsnUser *user, MsnListOp list_op); void msn_user_unset_op(MsnUser *user, MsnListOp list_op); +/** + * Checks whether a user is capable of some task. + * + * @param user The user. + * @param endpoint The endpoint. Can be @NULL to check overall capabilities. + * @param capability The capability (including client version). + * @param extcap The extended capability. + * + * @return Whether the user supports the capability. + */ +gboolean +msn_user_is_capable(MsnUser *user, char *endpoint, guint capability, guint extcap); + /*@}*/ #endif /* MSN_USER_H */