comparison 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
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
252 const gchar *from_username; 252 const gchar *from_username;
253 253
254 g_return_val_if_fail(who != NULL, FALSE); 254 g_return_val_if_fail(who != NULL, FALSE);
255 g_return_val_if_fail(text != NULL, FALSE); 255 g_return_val_if_fail(text != NULL, FALSE);
256 256
257 from_username = session->account->username; 257 from_username = purple_account_get_username(session->account);
258 258
259 g_return_val_if_fail(from_username != NULL, FALSE); 259 g_return_val_if_fail(from_username != NULL, FALSE);
260 260
261 purple_debug_info("msim", "sending %d message from %s to %s: %s\n", 261 purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
262 type, from_username, who, text); 262 type, from_username, who, text);
427 g_return_if_fail(user_info != NULL); 427 g_return_if_fail(user_info != NULL);
428 428
429 user = msim_get_user_from_buddy(buddy, TRUE); 429 user = msim_get_user_from_buddy(buddy, TRUE);
430 430
431 if (PURPLE_BUDDY_IS_ONLINE(buddy)) { 431 if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
432 MsimSession *session;
433 PurpleAccount *account = purple_buddy_get_account(buddy); 432 PurpleAccount *account = purple_buddy_get_account(buddy);
434 PurpleConnection *gc = purple_account_get_connection(account); 433 PurpleConnection *gc = purple_account_get_connection(account);
435 434 MsimSession *session = purple_connection_get_protocol_data(gc);
436 session = (MsimSession *)gc->proto_data;
437 435
438 /* TODO: if (full), do something different? */ 436 /* TODO: if (full), do something different? */
439 437
440 /* TODO: request information? have to figure out how to do 438 /* TODO: request information? have to figure out how to do
441 * the asynchronous lookup like oscar does (tooltip shows 439 * the asynchronous lookup like oscar does (tooltip shows
696 " bytes, decoded\n", nc_len); 694 " bytes, decoded\n", nc_len);
697 695
698 if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) { 696 if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) {
699 purple_debug_info("msim", "bad nc length: %" G_GSIZE_MODIFIER 697 purple_debug_info("msim", "bad nc length: %" G_GSIZE_MODIFIER
700 "x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH); 698 "x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH);
701 purple_connection_error_reason (session->gc, 699 purple_connection_error (session->gc,
702 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 700 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
703 _("Unexpected challenge length from server")); 701 _("Unexpected challenge length from server"));
704 return FALSE; 702 return FALSE;
705 } 703 }
706 704
707 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4); 705 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
708 706
709 response_len = 0; 707 response_len = 0;
710 response = msim_compute_login_response(nc, account->username, account->password, &response_len); 708 response = msim_compute_login_response(nc, purple_account_get_username(account), purple_account_get_password(account), &response_len);
711 709
712 g_free(nc); 710 g_free(nc);
713 711
714 ret = msim_send(session, 712 ret = msim_send(session,
715 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, 713 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM,
716 /* This is actually user's email address. */ 714 /* This is actually user's email address. */
717 "username", MSIM_TYPE_STRING, g_strdup(account->username), 715 "username", MSIM_TYPE_STRING, g_strdup(purple_account_get_username(account)),
718 /* GString will be freed in msim_msg_free() in msim_send(). */ 716 /* GString will be freed in msim_msg_free() in msim_send(). */
719 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), 717 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len),
720 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, 718 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION,
721 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH, 719 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH,
722 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH), 720 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH),
752 * 750 *
753 * Filed enhancement ticket for libpurple as #4688. 751 * Filed enhancement ticket for libpurple as #4688.
754 */ 752 */
755 753
756 purple_debug_info("msim", "Unrecognized data on account for %s\n", 754 purple_debug_info("msim", "Unrecognized data on account for %s\n",
757 (session && session->account && session->account->username) ? 755 (session && session->account && purple_account_get_username(session->account)) ?
758 session->account->username : "(NULL)"); 756 purple_account_get_username(session->account) : "(NULL)");
759 if (note) { 757 if (note) {
760 purple_debug_info("msim", "(Note: %s)\n", note); 758 purple_debug_info("msim", "(Note: %s)\n", note);
761 } 759 }
762 760
763 if (msg) { 761 if (msg) {
833 /* purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta); */ 831 /* purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta); */
834 if (delta >= MSIM_KEEPALIVE_INTERVAL) { 832 if (delta >= MSIM_KEEPALIVE_INTERVAL) {
835 purple_debug_info("msim", 833 purple_debug_info("msim",
836 "msim_check_alive: %zu > interval of %d, presumed dead\n", 834 "msim_check_alive: %zu > interval of %d, presumed dead\n",
837 delta, MSIM_KEEPALIVE_INTERVAL); 835 delta, MSIM_KEEPALIVE_INTERVAL);
838 purple_connection_error_reason(session->gc, 836 purple_connection_error(session->gc,
839 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 837 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
840 _("Lost connection with server")); 838 _("Lost connection with server"));
841 839
842 return FALSE; 840 return FALSE;
843 } 841 }
1838 case MSIM_ERROR_INCORRECT_PASSWORD: /* Incorrect password */ 1836 case MSIM_ERROR_INCORRECT_PASSWORD: /* Incorrect password */
1839 reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED; 1837 reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
1840 if (!purple_account_get_remember_password(session->account)) 1838 if (!purple_account_get_remember_password(session->account))
1841 purple_account_set_password(session->account, NULL); 1839 purple_account_set_password(session->account, NULL);
1842 #ifdef MSIM_MAX_PASSWORD_LENGTH 1840 #ifdef MSIM_MAX_PASSWORD_LENGTH
1843 if (session->account->password && (strlen(session->account->password) > MSIM_MAX_PASSWORD_LENGTH)) { 1841 if (purple_account_get_password(session->account) && (strlen(purple_account_get_password(session->account)) > MSIM_MAX_PASSWORD_LENGTH)) {
1844 gchar *suggestion; 1842 gchar *suggestion;
1845 1843
1846 suggestion = g_strdup_printf(_("%s Your password is " 1844 suggestion = g_strdup_printf(_("%s Your password is "
1847 "%zu characters, which is longer than the " 1845 "%zu characters, which is longer than the "
1848 "maximum length of %d. Please shorten your " 1846 "maximum length of %d. Please shorten your "
1849 "password at http://profileedit.myspace.com/index.cfm?fuseaction=accountSettings.changePassword and try again."), 1847 "password at http://profileedit.myspace.com/index.cfm?fuseaction=accountSettings.changePassword and try again."),
1850 full_errmsg, 1848 full_errmsg,
1851 strlen(session->account->password), 1849 strlen(purple_account_get_password(session->account)),
1852 MSIM_MAX_PASSWORD_LENGTH); 1850 MSIM_MAX_PASSWORD_LENGTH);
1853 1851
1854 /* Replace full_errmsg. */ 1852 /* Replace full_errmsg. */
1855 g_free(full_errmsg); 1853 g_free(full_errmsg);
1856 full_errmsg = suggestion; 1854 full_errmsg = suggestion;
1864 reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE; 1862 reason = PURPLE_CONNECTION_ERROR_NAME_IN_USE;
1865 if (!purple_account_get_remember_password(session->account)) 1863 if (!purple_account_get_remember_password(session->account))
1866 purple_account_set_password(session->account, NULL); 1864 purple_account_set_password(session->account, NULL);
1867 break; 1865 break;
1868 } 1866 }
1869 purple_connection_error_reason(session->gc, reason, full_errmsg); 1867 purple_connection_error(session->gc, reason, full_errmsg);
1870 } else { 1868 } else {
1871 purple_notify_error(session->account, _("MySpaceIM Error"), full_errmsg, NULL); 1869 purple_notify_error(session->account, _("MySpaceIM Error"), full_errmsg, NULL);
1872 } 1870 }
1873 1871
1874 g_free(full_errmsg); 1872 g_free(full_errmsg);
2020 2018
2021 g_return_if_fail(gc_uncasted != NULL); 2019 g_return_if_fail(gc_uncasted != NULL);
2022 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ 2020 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */
2023 2021
2024 gc = (PurpleConnection *)(gc_uncasted); 2022 gc = (PurpleConnection *)(gc_uncasted);
2025 session = gc->proto_data; 2023 session = purple_connection_get_protocol_data(gc);
2026 2024
2027 /* libpurple/eventloop.h only defines these two */ 2025 /* libpurple/eventloop.h only defines these two */
2028 if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) { 2026 if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) {
2029 purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond); 2027 purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond);
2030 purple_connection_error_reason (gc, 2028 purple_connection_error (gc,
2031 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 2029 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
2032 _("Invalid input condition")); 2030 _("Invalid input condition"));
2033 return; 2031 return;
2034 } 2032 }
2035 2033
2067 /* No worries */ 2065 /* No worries */
2068 return; 2066 return;
2069 2067
2070 tmp = g_strdup_printf(_("Lost connection with server: %s"), 2068 tmp = g_strdup_printf(_("Lost connection with server: %s"),
2071 g_strerror(errno)); 2069 g_strerror(errno));
2072 purple_connection_error_reason(gc, 2070 purple_connection_error(gc,
2073 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 2071 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
2074 g_free(tmp); 2072 g_free(tmp);
2075 return; 2073 return;
2076 } else if (n == 0) { 2074 } else if (n == 0) {
2077 purple_connection_error_reason(gc, 2075 purple_connection_error(gc,
2078 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 2076 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
2079 _("Server closed the connection")); 2077 _("Server closed the connection"));
2080 return; 2078 return;
2081 } 2079 }
2082 2080
2090 if (strlen(session->rxbuf + session->rxoff) != n) { 2088 if (strlen(session->rxbuf + session->rxoff) != n) {
2091 /* Occurs after login, but it is not a null byte. */ 2089 /* Occurs after login, but it is not a null byte. */
2092 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes" 2090 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
2093 "--null byte encountered?\n", 2091 "--null byte encountered?\n",
2094 strlen(session->rxbuf + session->rxoff), n); 2092 strlen(session->rxbuf + session->rxoff), n);
2095 /*purple_connection_error_reason (gc, 2093 /*purple_connection_error (gc,
2096 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 2094 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
2097 "Invalid message - null byte on input"); */ 2095 "Invalid message - null byte on input"); */
2098 return; 2096 return;
2099 } 2097 }
2100 #endif 2098 #endif
2115 #endif 2113 #endif
2116 *end = 0; 2114 *end = 0;
2117 msg = msim_parse(session->rxbuf); 2115 msg = msim_parse(session->rxbuf);
2118 if (!msg) { 2116 if (!msg) {
2119 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n"); 2117 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n");
2120 purple_connection_error_reason (gc, 2118 purple_connection_error (gc,
2121 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 2119 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
2122 _("Unable to parse message")); 2120 _("Unable to parse message"));
2123 break; 2121 break;
2124 } else { 2122 } else {
2125 /* Process message and then free it (processing function should 2123 /* Process message and then free it (processing function should
2155 MsimSession *session; 2153 MsimSession *session;
2156 2154
2157 g_return_if_fail(data != NULL); 2155 g_return_if_fail(data != NULL);
2158 2156
2159 gc = (PurpleConnection *)data; 2157 gc = (PurpleConnection *)data;
2160 session = (MsimSession *)gc->proto_data; 2158 session = purple_connection_get_protocol_data(gc);
2161 2159
2162 if (source < 0) { 2160 if (source < 0) {
2163 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), 2161 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
2164 error_message); 2162 error_message);
2165 purple_connection_error_reason (gc, 2163 purple_connection_error (gc,
2166 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); 2164 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
2167 g_free(tmp); 2165 g_free(tmp);
2168 return; 2166 return;
2169 } 2167 }
2170 2168
2171 session->fd = source; 2169 session->fd = source;
2172 2170 session->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
2173 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
2174 } 2171 }
2175 2172
2176 /** 2173 /**
2177 * Start logging in to the MSIM servers. 2174 * Start logging in to the MSIM servers.
2178 * 2175 *
2184 PurpleConnection *gc; 2181 PurpleConnection *gc;
2185 const gchar *host; 2182 const gchar *host;
2186 int port; 2183 int port;
2187 2184
2188 g_return_if_fail(acct != NULL); 2185 g_return_if_fail(acct != NULL);
2189 g_return_if_fail(acct->username != NULL); 2186 g_return_if_fail(purple_account_get_username(acct) != NULL);
2190 2187
2191 purple_debug_info("msim", "logging in %s\n", acct->username); 2188 purple_debug_info("msim", "logging in %s\n", purple_account_get_username(acct));
2192 2189
2193 gc = purple_account_get_connection(acct); 2190 gc = purple_account_get_connection(acct);
2194 gc->proto_data = msim_session_new(acct); 2191 purple_connection_set_protocol_data(gc, msim_session_new(acct));
2195 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC; 2192 purple_connection_set_flags(gc, PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC);
2196 2193
2197 /* 2194 /*
2198 * Lets wipe out our local list of blocked buddies. We'll get a 2195 * Lets wipe out our local list of blocked buddies. We'll get a
2199 * list of all blocked buddies from the server, and we shouldn't 2196 * list of all blocked buddies from the server, and we shouldn't
2200 * have stuff in the local list that isn't on the server list. 2197 * have stuff in the local list that isn't on the server list.
2217 2214
2218 /* Calls msim_connect_cb when connected. */ 2215 /* Calls msim_connect_cb when connected. */
2219 if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) { 2216 if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) {
2220 /* TODO: try other ports if in auto mode, then save 2217 /* TODO: try other ports if in auto mode, then save
2221 * working port and try that first next time. */ 2218 * working port and try that first next time. */
2222 purple_connection_error_reason (gc, 2219 purple_connection_error (gc,
2223 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, 2220 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
2224 _("Unable to connect")); 2221 _("Unable to connect"));
2225 return; 2222 return;
2226 } 2223 }
2227 } 2224 }
2257 while (buddies != NULL) { 2254 while (buddies != NULL) {
2258 msim_buddy_free(buddies->data); 2255 msim_buddy_free(buddies->data);
2259 buddies = g_slist_delete_link(buddies, buddies); 2256 buddies = g_slist_delete_link(buddies, buddies);
2260 } 2257 }
2261 2258
2262 session = (MsimSession *)gc->proto_data; 2259 session = purple_connection_get_protocol_data(gc);
2263 if (session == NULL) 2260 if (session == NULL)
2264 return; 2261 return;
2265 2262
2266 gc->proto_data = NULL; 2263 purple_connection_set_protocol_data(gc, NULL);
2267 2264
2268 if (session->gc->inpa) { 2265 if (session->inpa) {
2269 purple_input_remove(session->gc->inpa); 2266 purple_input_remove(session->inpa);
2267 session->inpa = 0;
2270 } 2268 }
2271 if (session->fd >= 0) { 2269 if (session->fd >= 0) {
2272 close(session->fd); 2270 close(session->fd);
2273 session->fd = -1; 2271 session->fd = -1;
2274 } 2272 }
2302 g_return_val_if_fail(who != NULL, -1); 2300 g_return_val_if_fail(who != NULL, -1);
2303 g_return_val_if_fail(message != NULL, -1); 2301 g_return_val_if_fail(message != NULL, -1);
2304 2302
2305 /* 'flags' has many options, not used here. */ 2303 /* 'flags' has many options, not used here. */
2306 2304
2307 session = (MsimSession *)gc->proto_data; 2305 session = purple_connection_get_protocol_data(gc);
2308 2306
2309 message_msim = html_to_msim_markup(session, message); 2307 message_msim = html_to_msim_markup(session, message);
2310 2308
2311 if (msim_send_bm(session, who, message_msim, MSIM_BM_ACTION_OR_IM_DELAYABLE)) { 2309 if (msim_send_bm(session, who, message_msim, MSIM_BM_ACTION_OR_IM_DELAYABLE)) {
2312 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always 2310 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always
2342 MsimSession *session; 2340 MsimSession *session;
2343 2341
2344 g_return_val_if_fail(gc != NULL, 0); 2342 g_return_val_if_fail(gc != NULL, 0);
2345 g_return_val_if_fail(name != NULL, 0); 2343 g_return_val_if_fail(name != NULL, 0);
2346 2344
2347 session = (MsimSession *)gc->proto_data; 2345 session = purple_connection_get_protocol_data(gc);
2348 2346
2349 switch (state) { 2347 switch (state) {
2350 case PURPLE_TYPING: 2348 case PURPLE_TYPING:
2351 typing_str = "%typing%"; 2349 typing_str = "%typing%";
2352 break; 2350 break;
2428 MsimMessage *user_msg; 2426 MsimMessage *user_msg;
2429 2427
2430 g_return_if_fail(gc != NULL); 2428 g_return_if_fail(gc != NULL);
2431 g_return_if_fail(username != NULL); 2429 g_return_if_fail(username != NULL);
2432 2430
2433 session = (MsimSession *)gc->proto_data; 2431 session = purple_connection_get_protocol_data(gc);
2434 2432
2435 /* Obtain uid of buddy. */ 2433 /* Obtain uid of buddy. */
2436 user = msim_find_user(session, username); 2434 user = msim_find_user(session, username);
2437 2435
2438 /* If is on buddy list, lookup by uid since it is faster. */ 2436 /* If is on buddy list, lookup by uid since it is faster. */
2485 * Set your status - callback for when user manually sets it. 2483 * Set your status - callback for when user manually sets it.
2486 */ 2484 */
2487 static void 2485 static void
2488 msim_set_status(PurpleAccount *account, PurpleStatus *status) 2486 msim_set_status(PurpleAccount *account, PurpleStatus *status)
2489 { 2487 {
2488 PurpleConnection *gc = purple_account_get_connection(account);
2490 PurpleStatusType *type; 2489 PurpleStatusType *type;
2491 PurplePresence *pres; 2490 PurplePresence *pres;
2492 MsimSession *session; 2491 MsimSession *session;
2493 guint status_code; 2492 guint status_code;
2494 const gchar *message; 2493 const gchar *message;
2495 gchar *stripped; 2494 gchar *stripped;
2496 gchar *unrecognized_msg; 2495 gchar *unrecognized_msg;
2497 2496
2498 session = (MsimSession *)account->gc->proto_data; 2497 session = purple_connection_get_protocol_data(gc);
2499 2498
2500 type = purple_status_get_type(status); 2499 type = purple_status_get_type(status);
2501 pres = purple_status_get_presence(status); 2500 pres = purple_status_get_presence(status);
2502 2501
2503 switch (purple_status_type_get_primitive(type)) { 2502 switch (purple_status_type_get_primitive(type)) {
2542 2541
2543 msim_set_status_code(session, status_code, stripped); 2542 msim_set_status_code(session, status_code, stripped);
2544 2543
2545 /* If we should be idle, set that status. Time is irrelevant here. */ 2544 /* If we should be idle, set that status. Time is irrelevant here. */
2546 if (purple_presence_is_idle(pres) && status_code != MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN) 2545 if (purple_presence_is_idle(pres) && status_code != MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN)
2547 msim_set_idle(account->gc, 1); 2546 msim_set_idle(purple_account_get_connection(account), 1);
2548 } 2547 }
2549 2548
2550 /** 2549 /**
2551 * Go idle. 2550 * Go idle.
2552 */ 2551 */
2556 MsimSession *session; 2555 MsimSession *session;
2557 PurpleStatus *status; 2556 PurpleStatus *status;
2558 2557
2559 g_return_if_fail(gc != NULL); 2558 g_return_if_fail(gc != NULL);
2560 2559
2561 session = (MsimSession *)gc->proto_data; 2560 session = purple_connection_get_protocol_data(gc);
2562 2561
2563 status = purple_account_get_active_status(session->account); 2562 status = purple_account_get_active_status(session->account);
2564 2563
2565 if (time == 0) { 2564 if (time == 0) {
2566 /* Going back from idle. In msim, idle is mutually exclusive 2565 /* Going back from idle. In msim, idle is mutually exclusive
2626 2625
2627 /** 2626 /**
2628 * Add a buddy to user's buddy list. 2627 * Add a buddy to user's buddy list.
2629 */ 2628 */
2630 static void 2629 static void
2631 msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 2630 msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
2632 { 2631 {
2633 MsimSession *session; 2632 MsimSession *session;
2634 MsimMessage *msg; 2633 MsimMessage *msg;
2635 MsimMessage *msg_persist; 2634 MsimMessage *msg_persist;
2636 MsimMessage *body; 2635 MsimMessage *body;
2637 const char *name, *gname; 2636 const char *name, *gname;
2638 2637
2639 session = (MsimSession *)gc->proto_data; 2638 session = purple_connection_get_protocol_data(gc);
2640 name = purple_buddy_get_name(buddy); 2639 name = purple_buddy_get_name(buddy);
2641 gname = group ? purple_group_get_name(group) : NULL; 2640 gname = group ? purple_group_get_name(group) : NULL;
2642 2641
2643 if (msim_get_user_from_buddy(buddy, FALSE) != NULL) 2642 if (msim_get_user_from_buddy(buddy, FALSE) != NULL)
2644 return; 2643 return;
2707 MsimSession *session; 2706 MsimSession *session;
2708 MsimMessage *delbuddy_msg; 2707 MsimMessage *delbuddy_msg;
2709 MsimMessage *persist_msg; 2708 MsimMessage *persist_msg;
2710 const char *name; 2709 const char *name;
2711 2710
2712 session = (MsimSession *)gc->proto_data; 2711 session = purple_connection_get_protocol_data(gc);
2713 name = purple_buddy_get_name(buddy); 2712 name = purple_buddy_get_name(buddy);
2714 2713
2715 delbuddy_msg = msim_msg_new( 2714 delbuddy_msg = msim_msg_new(
2716 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, 2715 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
2717 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, 2716 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2764 msim_add_deny(PurpleConnection *gc, const char *name) 2763 msim_add_deny(PurpleConnection *gc, const char *name)
2765 { 2764 {
2766 MsimSession *session; 2765 MsimSession *session;
2767 MsimMessage *msg, *body; 2766 MsimMessage *msg, *body;
2768 2767
2769 session = (MsimSession *)gc->proto_data; 2768 session = purple_connection_get_protocol_data(gc);
2770 2769
2771 /* Remove from buddy list */ 2770 /* Remove from buddy list */
2772 msg = msim_msg_new( 2771 msg = msim_msg_new(
2773 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, 2772 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
2774 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, 2773 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2816 msim_rem_deny(PurpleConnection *gc, const char *name) 2815 msim_rem_deny(PurpleConnection *gc, const char *name)
2817 { 2816 {
2818 MsimSession *session; 2817 MsimSession *session;
2819 MsimMessage *msg, *body; 2818 MsimMessage *msg, *body;
2820 2819
2821 session = (MsimSession *)gc->proto_data; 2820 session = purple_connection_get_protocol_data(gc);
2822 2821
2823 /* 2822 /*
2824 * Remove from our list of blocked contacts, so we know they 2823 * Remove from our list of blocked contacts, so we know they
2825 * are no longer blocked if we log in with another client 2824 * are no longer blocked if we log in with another client
2826 */ 2825 */
2863 if (msim_is_userid(str)) { 2862 if (msim_is_userid(str)) {
2864 /* Have user ID, we need to get their username first :) */ 2863 /* Have user ID, we need to get their username first :) */
2865 const char *username; 2864 const char *username;
2866 2865
2867 /* If the account does not exist, we can't look up the user. */ 2866 /* If the account does not exist, we can't look up the user. */
2868 if (!account || !account->gc) 2867 if (!account || !purple_account_get_connection(account))
2869 return str; 2868 return str;
2870 2869
2871 id = atol(str); 2870 id = atol(str);
2872 username = msim_uid2username_from_blist((PurpleAccount *)account, id); 2871 username = msim_uid2username_from_blist((PurpleAccount *)account, id);
2873 if (!username) { 2872 if (!username) {
2946 2945
2947 g_return_val_if_fail(gc != NULL, -1); 2946 g_return_val_if_fail(gc != NULL, -1);
2948 g_return_val_if_fail(buf != NULL, -1); 2947 g_return_val_if_fail(buf != NULL, -1);
2949 g_return_val_if_fail(total_bytes >= 0, -1); 2948 g_return_val_if_fail(total_bytes >= 0, -1);
2950 2949
2951 session = (MsimSession *)gc->proto_data; 2950 session = purple_connection_get_protocol_data(gc);
2952 2951
2953 /* Loop until all data is sent, or a failure occurs. */ 2952 /* Loop until all data is sent, or a failure occurs. */
2954 total_bytes_sent = 0; 2953 total_bytes_sent = 0;
2955 do { 2954 do {
2956 int bytes_sent; 2955 int bytes_sent;
3006 3005
3007 /** 3006 /**
3008 * Callbacks called by Purple, to access this plugin. 3007 * Callbacks called by Purple, to access this plugin.
3009 */ 3008 */
3010 static PurplePluginProtocolInfo prpl_info = { 3009 static PurplePluginProtocolInfo prpl_info = {
3010 sizeof(PurplePluginProtocolInfo), /* struct_size */
3011 /* options */ 3011 /* options */
3012 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */ 3012 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */
3013 | OPT_PROTO_MAIL_CHECK, 3013 | OPT_PROTO_MAIL_CHECK,
3014 3014
3015 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */ 3015 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */
3050 NULL, /* chat_whisper */ 3050 NULL, /* chat_whisper */
3051 NULL, /* chat_send */ 3051 NULL, /* chat_send */
3052 NULL, /* keepalive */ 3052 NULL, /* keepalive */
3053 NULL, /* register_user */ 3053 NULL, /* register_user */
3054 NULL, /* get_cb_info */ 3054 NULL, /* get_cb_info */
3055 NULL, /* get_cb_away */
3056 NULL, /* alias_buddy */ 3055 NULL, /* alias_buddy */
3057 NULL, /* group_buddy */ 3056 NULL, /* group_buddy */
3058 NULL, /* rename_group */ 3057 NULL, /* rename_group */
3059 msim_buddy_free, /* buddy_free */ 3058 msim_buddy_free, /* buddy_free */
3060 NULL, /* convo_closed */ 3059 NULL, /* convo_closed */
3075 msim_send_really_raw, /* send_raw */ 3074 msim_send_really_raw, /* send_raw */
3076 NULL, /* roomlist_room_serialize */ 3075 NULL, /* roomlist_room_serialize */
3077 NULL, /* unregister_user */ 3076 NULL, /* unregister_user */
3078 msim_send_attention, /* send_attention */ 3077 msim_send_attention, /* send_attention */
3079 msim_attention_types, /* attention_types */ 3078 msim_attention_types, /* attention_types */
3080 sizeof(PurplePluginProtocolInfo), /* struct_size */
3081 msim_get_account_text_table, /* get_account_text_table */ 3079 msim_get_account_text_table, /* get_account_text_table */
3082 NULL, /* initiate_media */ 3080 NULL, /* initiate_media */
3083 NULL, /* get_media_caps */ 3081 NULL, /* get_media_caps */
3084 NULL, /* get_moods */ 3082 NULL, /* get_moods */
3085 NULL, /* set_public_alias */ 3083 NULL, /* set_public_alias */
3086 NULL, /* get_public_alias */ 3084 NULL /* get_public_alias */
3087 NULL, /* add_buddy_with_invite */
3088 NULL /* add_buddies_with_invite */
3089 }; 3085 };
3090 3086
3091 /** 3087 /**
3092 * Load the plugin. 3088 * Load the plugin.
3093 */ 3089 */
3149 PurpleConnection *gc; 3145 PurpleConnection *gc;
3150 MsimSession *session; 3146 MsimSession *session;
3151 gchar *group_name; 3147 gchar *group_name;
3152 3148
3153 gc = (PurpleConnection *)action->context; 3149 gc = (PurpleConnection *)action->context;
3154 session = (MsimSession *)gc->proto_data; 3150 session = purple_connection_get_protocol_data(gc);
3155 3151
3156 group_name = "MySpace Friends"; 3152 group_name = "MySpace Friends";
3157 3153
3158 g_return_if_fail(msim_send(session, 3154 g_return_if_fail(msim_send(session,
3159 "persist", MSIM_TYPE_INTEGER, 1, 3155 "persist", MSIM_TYPE_INTEGER, 1,
3528 3524
3529 static gboolean 3525 static gboolean
3530 msim_uri_handler(const gchar *proto, const gchar *cmd, GHashTable *params) 3526 msim_uri_handler(const gchar *proto, const gchar *cmd, GHashTable *params)
3531 { 3527 {
3532 PurpleAccount *account; 3528 PurpleAccount *account;
3529 PurpleConnection *gc;
3533 MsimSession *session; 3530 MsimSession *session;
3534 GList *l; 3531 GList *l;
3535 gchar *uid_str, *cid_str; 3532 gchar *uid_str, *cid_str;
3536 guint uid, cid; 3533 guint uid, cid;
3537 3534
3576 _("Enable the proper MySpaceIM account and try again.")); 3573 _("Enable the proper MySpaceIM account and try again."));
3577 g_free(cid_str); 3574 g_free(cid_str);
3578 return FALSE; 3575 return FALSE;
3579 } 3576 }
3580 3577
3581 session = (MsimSession *)account->gc->proto_data; 3578 gc = purple_account_get_connection(account);
3579 session = purple_connection_get_protocol_data(gc);
3582 g_return_val_if_fail(session != NULL, FALSE); 3580 g_return_val_if_fail(session != NULL, FALSE);
3583 3581
3584 /* Lookup userid to username. TODO: push this down, to IM sending/contact 3582 /* Lookup userid to username. TODO: push this down, to IM sending/contact
3585 * adding functions. */ 3583 * adding functions. */
3586 3584