comparison libpurple/protocols/myspace/myspace.c @ 17681:5e8c02259c81

Add option to sign on as hidden, or as not (previously, always signed on as hidden, which was confusing). Split part of msim_process into msim_we_are_logged_on()
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Tue, 03 Jul 2007 05:14:56 +0000
parents d87916bd1d73
children dbf7fe20799d
comparison
equal deleted inserted replaced
17680:d87916bd1d73 17681:5e8c02259c81
700 msim_msg_free(msg); 700 msim_msg_free(msg);
701 701
702 return rc; 702 return rc;
703 } 703 }
704 704
705
706 #ifdef MSIM_FONT_SIZE_WORKS
705 /** Convert a msim markup font height to points. */ 707 /** Convert a msim markup font height to points. */
706 static guint 708 static guint
707 msim_font_height_to_point(guint height) 709 msim_font_height_to_point(guint height)
708 { 710 {
709 /* See also: libpurple/protocols/bonjour/jabber.c 711 /* See also: libpurple/protocols/bonjour/jabber.c
722 case 20: return 15; 724 case 20: return 15;
723 case 21: return 16; 725 case 21: return 16;
724 default: return 12; 726 default: return 12;
725 } 727 }
726 } 728 }
729 #endif
727 730
728 /** Convert the msim markup <f> (font) tag into HTML. */ 731 /** Convert the msim markup <f> (font) tag into HTML. */
729 static void msim_markup_f_to_html(xmlnode *root, gchar **begin, gchar **end) 732 static void msim_markup_f_to_html(xmlnode *root, gchar **begin, gchar **end)
730 { 733 {
731 const gchar *face, *height_str, *decor_str; 734 const gchar *face, *height_str, *decor_str;
1283 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg); 1286 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg);
1284 1287
1285 g_free(user_to_lookup); 1288 g_free(user_to_lookup);
1286 } 1289 }
1287 1290
1288 /* Set your status. */ 1291 /** Set your status - callback for when user manually sets it. */
1289 /* TODO: set status to online, when go online, if not invisible? */
1290 void 1292 void
1291 msim_set_status(PurpleAccount *account, PurpleStatus *status) 1293 msim_set_status(PurpleAccount *account, PurpleStatus *status)
1292 { 1294 {
1293 PurpleStatusType *type; 1295 PurpleStatusType *type;
1294 guint status_code;
1295 MsimSession *session; 1296 MsimSession *session;
1296 1297
1297 session = (MsimSession *)account->gc->proto_data; 1298 session = (MsimSession *)account->gc->proto_data;
1298 1299
1299 type = purple_status_get_type(status); 1300 type = purple_status_get_type(status);
1300 1301
1301 switch (purple_status_type_get_primitive(type)) 1302 msim_set_status_primitive(session, purple_status_type_get_primitive(type));
1303 }
1304
1305 /** Set status using a status primitive type. */
1306 void
1307 msim_set_status_primitive(MsimSession *session, guint code)
1308 {
1309 guint status_code;
1310
1311 switch (code)
1302 { 1312 {
1303 case PURPLE_STATUS_AVAILABLE: 1313 case PURPLE_STATUS_AVAILABLE:
1304 status_code = MSIM_STATUS_CODE_ONLINE; 1314 status_code = MSIM_STATUS_CODE_ONLINE;
1305 break; 1315 break;
1306 1316
1520 /* Nothing to resolve - send directly to processing. */ 1530 /* Nothing to resolve - send directly to processing. */
1521 return msim_process(session, msg); 1531 return msim_process(session, msg);
1522 } 1532 }
1523 } 1533 }
1524 1534
1535 /** Called when the session key arrives. */
1536 gboolean
1537 msim_we_are_logged_on(MsimSession *session, MsimMessage *msg)
1538 {
1539 purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
1540
1541 session->sesskey = msim_msg_get_integer(msg, "sesskey");
1542 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
1543
1544 /* Comes with: proof,profileid,userid,uniquenick -- all same values
1545 * some of the time, but can vary. This is our own user ID. */
1546 session->userid = msim_msg_get_integer(msg, "userid");
1547
1548
1549 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
1550
1551
1552 /* We now know are our own username, only after we're logged in..
1553 * which is weird, but happens because you login with your email
1554 * address and not username. Will be freed in msim_session_destroy(). */
1555 session->username = msim_msg_get_string(msg, "uniquenick");
1556
1557 #ifdef MSIM_FAKE_SELF_ONLINE
1558 /* Fake our self coming online. */
1559 purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
1560 #endif
1561
1562 /* Set status depending on preference. */
1563 msim_set_status_primitive(session,
1564 purple_account_get_bool(session->account, "hidden", FALSE)
1565 ? PURPLE_STATUS_INVISIBLE
1566 : PURPLE_STATUS_AVAILABLE);
1567
1568 return TRUE;
1569 }
1570
1525 /** 1571 /**
1526 * Process a message. 1572 * Process a message.
1527 * 1573 *
1528 * @param session 1574 * @param session
1529 * @param msg A message from the server, ready for processing (possibly with resolved username information attached). Caller frees. 1575 * @param msg A message from the server, ready for processing (possibly with resolved username information attached). Caller frees.
1544 1590
1545 if (msim_msg_get(msg, "nc")) 1591 if (msim_msg_get(msg, "nc"))
1546 { 1592 {
1547 return msim_login_challenge(session, msg); 1593 return msim_login_challenge(session, msg);
1548 } else if (msim_msg_get(msg, "sesskey")) { 1594 } else if (msim_msg_get(msg, "sesskey")) {
1549 purple_connection_update_progress(session->gc, _("Connected"), 3, 4); 1595 return msim_we_are_logged_on(session, msg);
1550
1551 session->sesskey = msim_msg_get_integer(msg, "sesskey");
1552 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
1553
1554 /* Comes with: proof,profileid,userid,uniquenick -- all same values
1555 * some of the time, but can vary. This is our own user ID. */
1556 session->userid = msim_msg_get_integer(msg, "userid");
1557
1558
1559 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
1560
1561
1562 /* We now know are our own username, only after we're logged in..
1563 * which is weird, but happens because you login with your email
1564 * address and not username. Will be freed in msim_session_destroy(). */
1565 session->username = msim_msg_get_string(msg, "uniquenick");
1566
1567 #ifdef MSIM_FAKE_SELF_ONLINE
1568 /* Fake our self coming online. */
1569 purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
1570 #endif
1571
1572 return TRUE;
1573 } else if (msim_msg_get(msg, "bm")) { 1596 } else if (msim_msg_get(msg, "bm")) {
1574 guint bm; 1597 guint bm;
1575 1598
1576 bm = msim_msg_get_integer(msg, "bm"); 1599 bm = msim_msg_get_integer(msg, "bm");
1577 switch (bm) 1600 switch (bm)
3011 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3034 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3012 3035
3013 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT); 3036 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
3014 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3037 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3015 3038
3039 option = purple_account_option_bool_new(_("Sign on as hidden"), "hidden", FALSE);
3040 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3041
3016 option = purple_account_option_bool_new(_("Show display name in status text"), "show_display_name", TRUE); 3042 option = purple_account_option_bool_new(_("Show display name in status text"), "show_display_name", TRUE);
3017 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3043 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
3018 3044
3019 option = purple_account_option_bool_new(_("Show headline in status text"), "show_headline", TRUE); 3045 option = purple_account_option_bool_new(_("Show headline in status text"), "show_headline", TRUE);
3020 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 3046 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);