comparison libpurple/protocols/myspace/myspace.c @ 17967:c9acdf96e74e

Update login process to more closely match official client.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 22 Jul 2007 06:53:48 +0000
parents f1827c3dc65a
children a2298513db8b
comparison
equal deleted inserted replaced
17966:f1827c3dc65a 17967:c9acdf96e74e
520 /* This is actually user's email address. */ 520 /* This is actually user's email address. */
521 "username", MSIM_TYPE_STRING, g_strdup(account->username), 521 "username", MSIM_TYPE_STRING, g_strdup(account->username),
522 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */ 522 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */
523 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), 523 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len),
524 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, 524 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION,
525 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH,
526 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH),
525 "reconn", MSIM_TYPE_INTEGER, 0, 527 "reconn", MSIM_TYPE_INTEGER, 0,
526 "status", MSIM_TYPE_INTEGER, 100, 528 "status", MSIM_TYPE_INTEGER, 100,
527 "id", MSIM_TYPE_INTEGER, 1, 529 "id", MSIM_TYPE_INTEGER, 1,
528 NULL); 530 NULL);
529 } 531 }
2250 { 2252 {
2251 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); 2253 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
2252 g_return_val_if_fail(msg != NULL, FALSE); 2254 g_return_val_if_fail(msg != NULL, FALSE);
2253 2255
2254 purple_connection_update_progress(session->gc, _("Connected"), 3, 4); 2256 purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
2257 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
2255 2258
2256 session->sesskey = msim_msg_get_integer(msg, "sesskey"); 2259 session->sesskey = msim_msg_get_integer(msg, "sesskey");
2257 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey); 2260 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
2261
2262 /* What is proof? Used to be uid, but now is 52 base64'd bytes... */
2258 2263
2259 /* Comes with: proof,profileid,userid,uniquenick -- all same values 2264 /* Comes with: proof,profileid,userid,uniquenick -- all same values
2260 * some of the time, but can vary. This is our own user ID. */ 2265 * some of the time, but can vary. This is our own user ID. */
2261 session->userid = msim_msg_get_integer(msg, "userid"); 2266 session->userid = msim_msg_get_integer(msg, "userid");
2262 2267
2263 purple_connection_set_state(session->gc, PURPLE_CONNECTED); 2268 /* Not sure what profileid is used for. */
2269 if (msim_msg_get_integer(msg, "profileid") != session->userid)
2270 {
2271 msim_unrecognized(session, msg,
2272 "Profile ID didn't match user ID, don't know why");
2273 }
2264 2274
2265 /* We now know are our own username, only after we're logged in.. 2275 /* We now know are our own username, only after we're logged in..
2266 * which is weird, but happens because you login with your email 2276 * which is weird, but happens because you login with your email
2267 * address and not username. Will be freed in msim_session_destroy(). */ 2277 * address and not username. Will be freed in msim_session_destroy(). */
2268 session->username = msim_msg_get_string(msg, "uniquenick"); 2278 session->username = msim_msg_get_string(msg, "uniquenick");
2270 if (msim_msg_get_integer(msg, "uniquenick") == session->userid) 2280 if (msim_msg_get_integer(msg, "uniquenick") == session->userid)
2271 { 2281 {
2272 purple_debug_info("msim_we_are_logged_on", "TODO: pick username"); 2282 purple_debug_info("msim_we_are_logged_on", "TODO: pick username");
2273 } 2283 }
2274 2284
2285
2286 /* Request IM info about ourself. */
2287 msim_send(session,
2288 "persist", MSIM_TYPE_STRING, g_strdup("persist"),
2289 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2290 "dsn", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_DSN,
2291 "uid", MSIM_TYPE_INTEGER, session->userid,
2292 "lid", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_LID,
2293 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
2294 "body", MSIM_TYPE_STRING,
2295 g_strdup_printf("UserID=%d", session->userid),
2296 NULL);
2297
2298 /* Request MySpace info about ourself. */
2299 msim_send(session,
2300 "persist", MSIM_TYPE_STRING, g_strdup("persist"),
2301 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2302 "dsn", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_DSN,
2303 "uid", MSIM_TYPE_INTEGER, session->userid,
2304 "lid", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_LID,
2305 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
2306 "body", MSIM_TYPE_STRING, g_strdup(""),
2307 NULL);
2308
2275 /* TODO: set options (persist cmd=514,dsn=1,lid=10) */ 2309 /* TODO: set options (persist cmd=514,dsn=1,lid=10) */
2276 /* TODO: set blocklist */ 2310 /* TODO: set blocklist */
2277 2311
2278 /* Notify servers of our current status. */ 2312 /* Notify servers of our current status. */
2279 purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n"); 2313 purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n");
2280 msim_set_status(session->account, 2314 msim_set_status(session->account,
2281 purple_account_get_active_status(session->account)); 2315 purple_account_get_active_status(session->account));
2282 2316
2283 /* TODO: find out what 'setinfo' is */ 2317 /* TODO: setinfo */
2318 /*
2319 msim_send(session,
2320 "setinfo", MSIM_TYPE_BOOLEAN, TRUE,
2321 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2322 "info", MSIM_TYPE_STRING,
2323 g_strdup_printf("TotalFriends=666"),
2324 NULL);
2325 */
2284 2326
2285 /* Disable due to problems with timeouts. TODO: fix. */ 2327 /* Disable due to problems with timeouts. TODO: fix. */
2286 #ifdef MSIM_USE_KEEPALIVE 2328 #ifdef MSIM_USE_KEEPALIVE
2287 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, 2329 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK,
2288 (GSourceFunc)msim_check_alive, session); 2330 (GSourceFunc)msim_check_alive, session);
2409 buddy = purple_find_buddy(session->account, username); 2451 buddy = purple_find_buddy(session->account, username);
2410 if (buddy) 2452 if (buddy)
2411 { 2453 {
2412 g_hash_table_foreach(body, msim_store_buddy_info_each, buddy); 2454 g_hash_table_foreach(body, msim_store_buddy_info_each, buddy);
2413 } 2455 }
2456
2457 if (msim_msg_get_integer(msg, "dsn") == MG_OWN_IM_INFO_DSN &&
2458 msim_msg_get_integer(msg, "lid") == MG_OWN_IM_INFO_LID)
2459 {
2460 /* TODO: do something with our own IM info, if we need it for some
2461 * specific purpose. Otherwise it is available on the buddy list,
2462 * if the user has themselves as their own buddy. */
2463 } else if (msim_msg_get_integer(msg, "dsn") == MG_OWN_MYSPACE_INFO_DSN &&
2464 msim_msg_get_integer(msg, "lid") == MG_OWN_MYSPACE_INFO_LID) {
2465 /* TODO: same as above, but for MySpace info. */
2466 }
2414 2467
2415 g_hash_table_destroy(body); 2468 g_hash_table_destroy(body);
2416 2469
2417 return TRUE; 2470 return TRUE;
2418 } 2471 }
2457 /* session->server_info freed in msim_session_destroy */ 2510 /* session->server_info freed in msim_session_destroy */
2458 2511
2459 return TRUE; 2512 return TRUE;
2460 } 2513 }
2461 2514
2515 /** Process a web challenge, used to login to the web site. */
2516 gboolean
2517 msim_web_challenge(MsimSession *session, MsimMessage *msg)
2518 {
2519 /* TODO: web challenge, store token */
2520 return FALSE;
2521 }
2522
2462 /** 2523 /**
2463 * Process a persistance message reply from the server. 2524 * Process a persistance message reply from the server.
2464 * 2525 *
2465 * @param session 2526 * @param session
2466 * @param msg Message reply from server. 2527 * @param msg Message reply from server.
2484 rid = msim_msg_get_integer(msg, "rid"); 2545 rid = msim_msg_get_integer(msg, "rid");
2485 cmd = msim_msg_get_integer(msg, "cmd"); 2546 cmd = msim_msg_get_integer(msg, "cmd");
2486 dsn = msim_msg_get_integer(msg, "dsn"); 2547 dsn = msim_msg_get_integer(msg, "dsn");
2487 lid = msim_msg_get_integer(msg, "lid"); 2548 lid = msim_msg_get_integer(msg, "lid");
2488 2549
2489 if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET) && 2550 /* Unsolicited messages */
2490 dsn == MG_SERVER_INFO_DSN && 2551 if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET))
2491 lid == MG_SERVER_INFO_LID) 2552 {
2492 { 2553 if (dsn == MG_SERVER_INFO_DSN && lid == MG_SERVER_INFO_LID)
2493 return msim_process_server_info(session, msg); 2554 {
2555 return msim_process_server_info(session, msg);
2556 } else if (dsn == MG_WEB_CHALLENGE_DSN && lid == MG_WEB_CHALLENGE_LID) {
2557 return msim_web_challenge(session, msg);
2558 }
2494 } 2559 }
2495 2560
2496 /* If a callback is registered for this userid lookup, call it. */ 2561 /* If a callback is registered for this userid lookup, call it. */
2497 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid)); 2562 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid));
2498 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); 2563 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
3855 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3920 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3856 3921
3857 option = purple_account_option_bool_new(_("Send emoticons"), "emoticons", FALSE); 3922 option = purple_account_option_bool_new(_("Send emoticons"), "emoticons", FALSE);
3858 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3923 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3859 3924
3925 #ifdef MSIM_USER_REALLY_CARES_ABOUT_PRECISE_FONT_SIZES
3860 option = purple_account_option_int_new(_("Screen resolution (dots per inch)"), "dpi", MSIM_DEFAULT_DPI); 3926 option = purple_account_option_int_new(_("Screen resolution (dots per inch)"), "dpi", MSIM_DEFAULT_DPI);
3861 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3927 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3862 3928
3863 option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE); 3929 option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
3864 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3930 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3931 #endif
3865 } 3932 }
3866 3933
3867 PURPLE_INIT_PLUGIN(myspace, init_plugin, info); 3934 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);