Mercurial > pidgin
diff libpurple/protocols/myspace/myspace.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | a5f50581b7c0 |
children |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c Sat Jun 02 02:30:13 2012 +0000 +++ b/libpurple/protocols/myspace/myspace.c Sat Jun 02 02:30:49 2012 +0000 @@ -254,7 +254,7 @@ g_return_val_if_fail(who != NULL, FALSE); g_return_val_if_fail(text != NULL, FALSE); - from_username = session->account->username; + from_username = purple_account_get_username(session->account); g_return_val_if_fail(from_username != NULL, FALSE); @@ -429,11 +429,9 @@ user = msim_get_user_from_buddy(buddy, TRUE); if (PURPLE_BUDDY_IS_ONLINE(buddy)) { - MsimSession *session; PurpleAccount *account = purple_buddy_get_account(buddy); PurpleConnection *gc = purple_account_get_connection(account); - - session = (MsimSession *)gc->proto_data; + MsimSession *session = purple_connection_get_protocol_data(gc); /* TODO: if (full), do something different? */ @@ -698,7 +696,7 @@ if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) { purple_debug_info("msim", "bad nc length: %" G_GSIZE_MODIFIER "x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH); - purple_connection_error_reason (session->gc, + purple_connection_error (session->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unexpected challenge length from server")); return FALSE; @@ -707,14 +705,14 @@ purple_connection_update_progress(session->gc, _("Logging in"), 2, 4); response_len = 0; - response = msim_compute_login_response(nc, account->username, account->password, &response_len); + response = msim_compute_login_response(nc, purple_account_get_username(account), purple_account_get_password(account), &response_len); g_free(nc); ret = msim_send(session, "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, /* This is actually user's email address. */ - "username", MSIM_TYPE_STRING, g_strdup(account->username), + "username", MSIM_TYPE_STRING, g_strdup(purple_account_get_username(account)), /* GString will be freed in msim_msg_free() in msim_send(). */ "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, @@ -754,8 +752,8 @@ */ purple_debug_info("msim", "Unrecognized data on account for %s\n", - (session && session->account && session->account->username) ? - session->account->username : "(NULL)"); + (session && session->account && purple_account_get_username(session->account)) ? + purple_account_get_username(session->account) : "(NULL)"); if (note) { purple_debug_info("msim", "(Note: %s)\n", note); } @@ -835,7 +833,7 @@ purple_debug_info("msim", "msim_check_alive: %zu > interval of %d, presumed dead\n", delta, MSIM_KEEPALIVE_INTERVAL); - purple_connection_error_reason(session->gc, + purple_connection_error(session->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Lost connection with server")); @@ -1840,7 +1838,7 @@ if (!purple_account_get_remember_password(session->account)) purple_account_set_password(session->account, NULL); #ifdef MSIM_MAX_PASSWORD_LENGTH - if (session->account->password && (strlen(session->account->password) > MSIM_MAX_PASSWORD_LENGTH)) { + if (purple_account_get_password(session->account) && (strlen(purple_account_get_password(session->account)) > MSIM_MAX_PASSWORD_LENGTH)) { gchar *suggestion; suggestion = g_strdup_printf(_("%s Your password is " @@ -1848,7 +1846,7 @@ "maximum length of %d. Please shorten your " "password at http://profileedit.myspace.com/index.cfm?fuseaction=accountSettings.changePassword and try again."), full_errmsg, - strlen(session->account->password), + strlen(purple_account_get_password(session->account)), MSIM_MAX_PASSWORD_LENGTH); /* Replace full_errmsg. */ @@ -1866,7 +1864,7 @@ purple_account_set_password(session->account, NULL); break; } - purple_connection_error_reason(session->gc, reason, full_errmsg); + purple_connection_error(session->gc, reason, full_errmsg); } else { purple_notify_error(session->account, _("MySpaceIM Error"), full_errmsg, NULL); } @@ -2022,12 +2020,12 @@ g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ gc = (PurpleConnection *)(gc_uncasted); - session = gc->proto_data; + session = purple_connection_get_protocol_data(gc); /* libpurple/eventloop.h only defines these two */ if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) { purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond); - purple_connection_error_reason (gc, + purple_connection_error (gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Invalid input condition")); return; @@ -2069,12 +2067,12 @@ tmp = g_strdup_printf(_("Lost connection with server: %s"), g_strerror(errno)); - purple_connection_error_reason(gc, + purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); g_free(tmp); return; } else if (n == 0) { - purple_connection_error_reason(gc, + purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Server closed the connection")); return; @@ -2092,7 +2090,7 @@ purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes" "--null byte encountered?\n", strlen(session->rxbuf + session->rxoff), n); - /*purple_connection_error_reason (gc, + /*purple_connection_error (gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, "Invalid message - null byte on input"); */ return; @@ -2117,7 +2115,7 @@ msg = msim_parse(session->rxbuf); if (!msg) { purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n"); - purple_connection_error_reason (gc, + purple_connection_error (gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to parse message")); break; @@ -2157,20 +2155,19 @@ g_return_if_fail(data != NULL); gc = (PurpleConnection *)data; - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); if (source < 0) { gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), error_message); - purple_connection_error_reason (gc, + purple_connection_error (gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); g_free(tmp); return; } session->fd = source; - - gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc); + session->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc); } /** @@ -2186,13 +2183,13 @@ int port; g_return_if_fail(acct != NULL); - g_return_if_fail(acct->username != NULL); - - purple_debug_info("msim", "logging in %s\n", acct->username); + g_return_if_fail(purple_account_get_username(acct) != NULL); + + purple_debug_info("msim", "logging in %s\n", purple_account_get_username(acct)); gc = purple_account_get_connection(acct); - gc->proto_data = msim_session_new(acct); - gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC; + purple_connection_set_protocol_data(gc, msim_session_new(acct)); + purple_connection_set_flags(gc, PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC); /* * Lets wipe out our local list of blocked buddies. We'll get a @@ -2219,7 +2216,7 @@ if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) { /* TODO: try other ports if in auto mode, then save * working port and try that first next time. */ - purple_connection_error_reason (gc, + purple_connection_error (gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect")); return; @@ -2259,14 +2256,15 @@ buddies = g_slist_delete_link(buddies, buddies); } - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); if (session == NULL) return; - gc->proto_data = NULL; - - if (session->gc->inpa) { - purple_input_remove(session->gc->inpa); + purple_connection_set_protocol_data(gc, NULL); + + if (session->inpa) { + purple_input_remove(session->inpa); + session->inpa = 0; } if (session->fd >= 0) { close(session->fd); @@ -2304,7 +2302,7 @@ /* 'flags' has many options, not used here. */ - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); message_msim = html_to_msim_markup(session, message); @@ -2344,7 +2342,7 @@ g_return_val_if_fail(gc != NULL, 0); g_return_val_if_fail(name != NULL, 0); - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); switch (state) { case PURPLE_TYPING: @@ -2430,7 +2428,7 @@ g_return_if_fail(gc != NULL); g_return_if_fail(username != NULL); - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); /* Obtain uid of buddy. */ user = msim_find_user(session, username); @@ -2487,6 +2485,7 @@ static void msim_set_status(PurpleAccount *account, PurpleStatus *status) { + PurpleConnection *gc = purple_account_get_connection(account); PurpleStatusType *type; PurplePresence *pres; MsimSession *session; @@ -2495,7 +2494,7 @@ gchar *stripped; gchar *unrecognized_msg; - session = (MsimSession *)account->gc->proto_data; + session = purple_connection_get_protocol_data(gc); type = purple_status_get_type(status); pres = purple_status_get_presence(status); @@ -2544,7 +2543,7 @@ /* If we should be idle, set that status. Time is irrelevant here. */ if (purple_presence_is_idle(pres) && status_code != MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN) - msim_set_idle(account->gc, 1); + msim_set_idle(purple_account_get_connection(account), 1); } /** @@ -2558,7 +2557,7 @@ g_return_if_fail(gc != NULL); - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); status = purple_account_get_active_status(session->account); @@ -2628,7 +2627,7 @@ * Add a buddy to user's buddy list. */ static void -msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) +msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message) { MsimSession *session; MsimMessage *msg; @@ -2636,7 +2635,7 @@ MsimMessage *body; const char *name, *gname; - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); name = purple_buddy_get_name(buddy); gname = group ? purple_group_get_name(group) : NULL; @@ -2709,7 +2708,7 @@ MsimMessage *persist_msg; const char *name; - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); name = purple_buddy_get_name(buddy); delbuddy_msg = msim_msg_new( @@ -2766,7 +2765,7 @@ MsimSession *session; MsimMessage *msg, *body; - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); /* Remove from buddy list */ msg = msim_msg_new( @@ -2818,7 +2817,7 @@ MsimSession *session; MsimMessage *msg, *body; - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); /* * Remove from our list of blocked contacts, so we know they @@ -2865,7 +2864,7 @@ const char *username; /* If the account does not exist, we can't look up the user. */ - if (!account || !account->gc) + if (!account || !purple_account_get_connection(account)) return str; id = atol(str); @@ -2948,7 +2947,7 @@ g_return_val_if_fail(buf != NULL, -1); g_return_val_if_fail(total_bytes >= 0, -1); - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); /* Loop until all data is sent, or a failure occurs. */ total_bytes_sent = 0; @@ -3008,6 +3007,7 @@ * Callbacks called by Purple, to access this plugin. */ static PurplePluginProtocolInfo prpl_info = { + sizeof(PurplePluginProtocolInfo), /* struct_size */ /* options */ OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */ | OPT_PROTO_MAIL_CHECK, @@ -3052,7 +3052,6 @@ NULL, /* keepalive */ NULL, /* register_user */ NULL, /* get_cb_info */ - NULL, /* get_cb_away */ NULL, /* alias_buddy */ NULL, /* group_buddy */ NULL, /* rename_group */ @@ -3077,15 +3076,12 @@ NULL, /* unregister_user */ msim_send_attention, /* send_attention */ msim_attention_types, /* attention_types */ - sizeof(PurplePluginProtocolInfo), /* struct_size */ msim_get_account_text_table, /* get_account_text_table */ NULL, /* initiate_media */ NULL, /* get_media_caps */ NULL, /* get_moods */ NULL, /* set_public_alias */ - NULL, /* get_public_alias */ - NULL, /* add_buddy_with_invite */ - NULL /* add_buddies_with_invite */ + NULL /* get_public_alias */ }; /** @@ -3151,7 +3147,7 @@ gchar *group_name; gc = (PurpleConnection *)action->context; - session = (MsimSession *)gc->proto_data; + session = purple_connection_get_protocol_data(gc); group_name = "MySpace Friends"; @@ -3530,6 +3526,7 @@ msim_uri_handler(const gchar *proto, const gchar *cmd, GHashTable *params) { PurpleAccount *account; + PurpleConnection *gc; MsimSession *session; GList *l; gchar *uid_str, *cid_str; @@ -3578,7 +3575,8 @@ return FALSE; } - session = (MsimSession *)account->gc->proto_data; + gc = purple_account_get_connection(account); + session = purple_connection_get_protocol_data(gc); g_return_val_if_fail(session != NULL, FALSE); /* Lookup userid to username. TODO: push this down, to IM sending/contact