Mercurial > pidgin
diff libpurple/protocols/myspace/myspace.c @ 18895:f732d072b118
Change all code to better match the style of libpurple - use 8-space tabs
for indentation everywhere. Spaces are still used for alignment when needed,
as described on http://derkarl.org/why_to_tabs.html (ack for [^\t]\t to ensure
tabs are only being used for indentation). Lots of vim regexes made this
transformation possible.
Also cuddled a few braces that I missed before.
This is a big commit, but there are no actual code changes.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sat, 11 Aug 2007 05:53:11 +0000 |
parents | daedc9647341 |
children | d0be4366e876 |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c Sat Aug 11 05:02:23 2007 +0000 +++ b/libpurple/protocols/myspace/myspace.c Sat Aug 11 05:53:11 2007 +0000 @@ -55,45 +55,45 @@ * some new smileys specific to MySpaceIM, use them too! */ static struct MSIM_EMOTICON { - gchar *name; - gchar *symbol; + gchar *name; + gchar *symbol; } msim_emoticons[] = { - { "bigsmile", ":D" }, - { "growl", ">:o" }, - { "growl", ">:O" }, - { "mad", ":-[" }, - { "scared", "=-O" }, - { "scared", "=-o" }, - { "tongue", ":P" }, - { "tongue", ":p" }, - { "devil", "O:-)" }, - { "devil", "o:-)" }, - { "happy", ":)" }, - { "happy", ":-)" }, - { "happi", ":-)" }, - { "messed", "8-)" }, - { "sidefrown", ":-$" } , - { "upset", ":-$" }, - { "frazzled", ":-/" } , - { "heart", ";-)" }, - { "heart", ";)" }, - { "nerd", "8-)"}, - { "sinister", ":-,D" } , - { "wink", ";-)" }, - { "winc", ";-)" }, - { "geek", ":-X" }, - { "laugh", ":-D" }, - { "laugh", ":-d" }, - { "oops", ":'(" }, - { "smirk", "8-)" }, - { "worried", ":-(" } , - { "worried", ":(" }, - { "googles", "8-)" }, - { "mohawk", ":-X" }, - { "pirate", ":-)" }, - { "straight", ":-!" }, - { "kiss", ":-*" }, - { NULL, NULL } + { "bigsmile", ":D" }, + { "growl", ">:o" }, + { "growl", ">:O" }, + { "mad", ":-[" }, + { "scared", "=-O" }, + { "scared", "=-o" }, + { "tongue", ":P" }, + { "tongue", ":p" }, + { "devil", "O:-)" }, + { "devil", "o:-)" }, + { "happy", ":)" }, + { "happy", ":-)" }, + { "happi", ":-)" }, + { "messed", "8-)" }, + { "sidefrown", ":-$" } , + { "upset", ":-$" }, + { "frazzled", ":-/" } , + { "heart", ";-)" }, + { "heart", ";)" }, + { "nerd", "8-)"}, + { "sinister", ":-,D" } , + { "wink", ";-)" }, + { "winc", ";-)" }, + { "geek", ":-X" }, + { "laugh", ":-D" }, + { "laugh", ":-d" }, + { "oops", ":'(" }, + { "smirk", "8-)" }, + { "worried", ":-(" } , + { "worried", ":(" }, + { "googles", "8-)" }, + { "mohawk", ":-X" }, + { "pirate", ":-)" }, + { "straight", ":-!" }, + { "kiss", ":-*" }, + { NULL, NULL } }; /* Internal functions */ @@ -104,13 +104,13 @@ #endif static int msim_send_really_raw(PurpleConnection *gc, const char *buf, - int total_bytes); + int total_bytes); static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg); static const gchar *msim_compute_login_response( - const gchar nonce[2 * NONCE_SIZE], const gchar *email, - const gchar *password, guint *response_len); + const gchar nonce[2 * NONCE_SIZE], const gchar *email, + const gchar *password, guint *response_len); static gboolean msim_send_bm(MsimSession *session, const gchar *who, - const gchar *text, int type); + const gchar *text, int type); static guint msim_point_to_purple_size(MsimSession *session, guint point); static guint msim_purple_size_to_point(MsimSession *session, guint size); @@ -120,11 +120,11 @@ static void msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note); static void msim_markup_tag_to_html(MsimSession *, xmlnode *root, - gchar **begin, gchar **end); + gchar **begin, gchar **end); static void html_tag_to_msim_markup(MsimSession *, xmlnode *root, - gchar **begin, gchar **end); + gchar **begin, gchar **end); static gchar *msim_convert_xml(MsimSession *, const gchar *raw, - MSIM_XMLNODE_CONVERT f); + MSIM_XMLNODE_CONVERT f); static gchar *msim_convert_smileys_to_markup(gchar *before); /* High-level msim markup <=> html conversion functions. */ @@ -132,7 +132,7 @@ static gchar *html_to_msim_markup(MsimSession *, const gchar *raw); static gboolean msim_incoming_bm_record_cv(MsimSession *session, - MsimMessage *msg); + MsimMessage *msg); static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg); static gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg); static gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg); @@ -140,23 +140,23 @@ static gboolean msim_incoming_action(MsimSession *session, MsimMessage *msg); static gboolean msim_incoming_media(MsimSession *session, MsimMessage *msg); static gboolean msim_incoming_unofficial_client(MsimSession *session, - MsimMessage *msg); + MsimMessage *msg); #ifdef MSIM_SEND_CLIENT_VERSION static gboolean msim_send_unofficial_client(MsimSession *session, - gchar *username); + gchar *username); #endif static void msim_get_info_cb(MsimSession *session, MsimMessage *userinfo, gpointer data); static void msim_set_status_code(MsimSession *session, guint code, - gchar *statstring); + gchar *statstring); static void msim_store_buddy_info_each(gpointer key, gpointer value, - gpointer user_data); + gpointer user_data); static gboolean msim_store_buddy_info(MsimSession *session, MsimMessage *msg); static gboolean msim_process_server_info(MsimSession *session, - MsimMessage *msg); + MsimMessage *msg); static gboolean msim_web_challenge(MsimSession *session, MsimMessage *msg); static gboolean msim_process_reply(MsimSession *session, MsimMessage *msg); @@ -171,24 +171,24 @@ static gboolean msim_process(MsimSession *session, MsimMessage *msg); static MsimMessage *msim_do_postprocessing(MsimMessage *msg, - const gchar *uid_field_name, const gchar *uid_before, guint uid); + const gchar *uid_field_name, const gchar *uid_before, guint uid); static void msim_postprocess_outgoing_cb(MsimSession *session, - MsimMessage *userinfo, gpointer data); + MsimMessage *userinfo, gpointer data); static gboolean msim_postprocess_outgoing(MsimSession *session, - MsimMessage *msg, const gchar *username, const gchar *uid_field_name, - const gchar *uid_before); + MsimMessage *msg, const gchar *username, const gchar *uid_field_name, + const gchar *uid_before); static gboolean msim_error(MsimSession *session, MsimMessage *msg); static void msim_check_inbox_cb(MsimSession *session, MsimMessage *userinfo, - gpointer data); + gpointer data); static gboolean msim_check_inbox(gpointer data); static void msim_input_cb(gpointer gc_uncasted, gint source, - PurpleInputCondition cond); + PurpleInputCondition cond); static guint msim_new_reply_callback(MsimSession *session, - MSIM_USER_LOOKUP_CB cb, gpointer data); + MSIM_USER_LOOKUP_CB cb, gpointer data); static void msim_connect_cb(gpointer data, gint source, const gchar *error_message); @@ -206,11 +206,11 @@ */ double msim_round(double value) { - if (value < 0) { - return -(floor(-value + 0.5)); - } else { - return floor( value + 0.5); - } + if (value < 0) { + return -(floor(-value + 0.5)); + } else { + return floor( value + 0.5); + } } /** @@ -240,96 +240,96 @@ GList * msim_status_types(PurpleAccount *acct) { - GList *types; - PurpleStatusType *status; - - purple_debug_info("myspace", "returning status types\n"); - - types = NULL; + GList *types; + PurpleStatusType *status; + + purple_debug_info("myspace", "returning status types\n"); + + types = NULL; /* Statuses are almost all the same. Define a macro to reduce code repetition. */ #define _MSIM_ADD_NEW_STATUS(prim) status = \ - purple_status_type_new_with_attrs( \ - prim, /* PurpleStatusPrimitive */ \ - NULL, /* id - use default */ \ - NULL, /* name - use default */ \ - TRUE, /* savable */ \ - TRUE, /* user_settable */ \ - FALSE, /* not independent */ \ - \ - /* Attributes - each status can have a message. */ \ - "message", \ - _("Message"), \ - purple_value_new(PURPLE_TYPE_STRING), \ - NULL); \ - \ - \ - types = g_list_append(types, status) - - - _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AVAILABLE); - _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AWAY); - _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE); - _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE); - - - return types; + purple_status_type_new_with_attrs( \ + prim, /* PurpleStatusPrimitive */ \ + NULL, /* id - use default */ \ + NULL, /* name - use default */ \ + TRUE, /* savable */ \ + TRUE, /* user_settable */ \ + FALSE, /* not independent */ \ + \ + /* Attributes - each status can have a message. */ \ + "message", \ + _("Message"), \ + purple_value_new(PURPLE_TYPE_STRING), \ + NULL); \ + \ + \ + types = g_list_append(types, status) + + + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AVAILABLE); + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_AWAY); + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_OFFLINE); + _MSIM_ADD_NEW_STATUS(PURPLE_STATUS_INVISIBLE); + + + return types; } /** Zap someone. Callback from msim_blist_node_menu zap menu. */ static void msim_send_zap(PurpleBlistNode *node, gpointer zap_num_ptr) { - PurpleBuddy *buddy; - PurpleConnection *gc; - MsimSession *session; - gchar *username, *zap_string, *zap_text; - guint zap; - const gchar *zap_gerund[10]; - - if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { - /* Only know about buddies for now. */ - return; - } - - zap_gerund[0] = _("Zapping"); - zap_gerund[1] = _("Whacking"); - zap_gerund[2] = _("Torching"); - zap_gerund[3] = _("Smooching"); - zap_gerund[4] = _("Hugging"); - zap_gerund[5] = _("Bslapping"); - zap_gerund[6] = _("Goosing"); - zap_gerund[7] = _("Hi-fiving"); - zap_gerund[8] = _("Punking"); - zap_gerund[9] = _("Raspberry'ing"); + PurpleBuddy *buddy; + PurpleConnection *gc; + MsimSession *session; + gchar *username, *zap_string, *zap_text; + guint zap; + const gchar *zap_gerund[10]; + + if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { + /* Only know about buddies for now. */ + return; + } + + zap_gerund[0] = _("Zapping"); + zap_gerund[1] = _("Whacking"); + zap_gerund[2] = _("Torching"); + zap_gerund[3] = _("Smooching"); + zap_gerund[4] = _("Hugging"); + zap_gerund[5] = _("Bslapping"); + zap_gerund[6] = _("Goosing"); + zap_gerund[7] = _("Hi-fiving"); + zap_gerund[8] = _("Punking"); + zap_gerund[9] = _("Raspberry'ing"); - g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); - - buddy = (PurpleBuddy *)node; - gc = purple_account_get_connection(buddy->account); - g_return_if_fail(gc != NULL); - - session = (MsimSession *)(gc->proto_data); - g_return_if_fail(session != NULL); - - username = buddy->name; - g_return_if_fail(username != NULL); - - zap = GPOINTER_TO_INT(zap_num_ptr); - zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", zap); - zap_text = g_strdup_printf("*** %s! ***", zap_gerund[zap]); - - serv_got_im(session->gc, username, zap_text, + g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); + + buddy = (PurpleBuddy *)node; + gc = purple_account_get_connection(buddy->account); + g_return_if_fail(gc != NULL); + + session = (MsimSession *)(gc->proto_data); + g_return_if_fail(session != NULL); + + username = buddy->name; + g_return_if_fail(username != NULL); + + zap = GPOINTER_TO_INT(zap_num_ptr); + zap_string = g_strdup_printf("!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", zap); + zap_text = g_strdup_printf("*** %s! ***", zap_gerund[zap]); + + serv_got_im(session->gc, username, zap_text, PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_SYSTEM, time(NULL)); if (!msim_send_bm(session, username, zap_string, MSIM_BM_ACTION)) { - purple_debug_info("msim_send_zap", "msim_send_bm failed: zapping %s with %s", - username, zap_string); - } - - g_free(zap_string); - g_free(zap_text); - return; + purple_debug_info("msim_send_zap", "msim_send_bm failed: zapping %s with %s", + username, zap_string); + } + + g_free(zap_string); + g_free(zap_text); + return; } @@ -337,41 +337,41 @@ GList * msim_blist_node_menu(PurpleBlistNode *node) { - GList *menu, *zap_menu; - PurpleMenuAction *act; - const gchar *zap_names[10]; - guint i; - - if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { - /* Only know about buddies for now. */ - return NULL; - } - - /* Names from official client. */ - zap_names[0] = _("zap"); - zap_names[1] = _("whack"); - zap_names[2] = _("torch"); - zap_names[3] = _("smooch"); - zap_names[4] = _("hug"); - zap_names[5] = _("bslap"); - zap_names[6] = _("goose"); - zap_names[7] = _("hi-five"); - zap_names[8] = _("punk'd"); - zap_names[9] = _("raspberry"); + GList *menu, *zap_menu; + PurpleMenuAction *act; + const gchar *zap_names[10]; + guint i; + + if (!PURPLE_BLIST_NODE_IS_BUDDY(node)) { + /* Only know about buddies for now. */ + return NULL; + } + + /* Names from official client. */ + zap_names[0] = _("zap"); + zap_names[1] = _("whack"); + zap_names[2] = _("torch"); + zap_names[3] = _("smooch"); + zap_names[4] = _("hug"); + zap_names[5] = _("bslap"); + zap_names[6] = _("goose"); + zap_names[7] = _("hi-five"); + zap_names[8] = _("punk'd"); + zap_names[9] = _("raspberry"); - menu = zap_menu = NULL; - - /* TODO: move to / command, or better yet new API */ - for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i) { - act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap), - GUINT_TO_POINTER(i), NULL); - zap_menu = g_list_append(zap_menu, act); - } - - act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu); - menu = g_list_append(menu, act); - - return menu; + menu = zap_menu = NULL; + + /* TODO: move to / command, or better yet new API */ + for (i = 0; i < sizeof(zap_names) / sizeof(zap_names[0]); ++i) { + act = purple_menu_action_new(zap_names[i], PURPLE_CALLBACK(msim_send_zap), + GUINT_TO_POINTER(i), NULL); + zap_menu = g_list_append(zap_menu, act); + } + + act = purple_menu_action_new(_("Zap"), NULL, NULL, zap_menu); + menu = g_list_append(menu, act); + + return menu; } /** @@ -385,9 +385,9 @@ const gchar * msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy) { - /* Use a MySpace icon submitted by hbons at - * http://developer.pidgin.im/wiki/MySpaceIM. */ - return "myspace"; + /* Use a MySpace icon submitted by hbons at + * http://developer.pidgin.im/wiki/MySpaceIM. */ + return "myspace"; } /** @@ -398,7 +398,7 @@ * @param new The replacement for 'old' within 'str'. * * @return A _new_ string, based on 'str', with 'old' replaced - * by 'new'. Must be g_free()'d by caller. + * by 'new'. Must be g_free()'d by caller. * * This string replace method is based on * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html @@ -420,9 +420,9 @@ static void print_hash_item(gpointer key, gpointer value, gpointer user_data) { - purple_debug_info("msim", "%s=%s\n", - key ? (gchar *)key : "(NULL)", - value ? (gchar *)value : "(NULL)"); + purple_debug_info("msim", "%s=%s\n", + key ? (gchar *)key : "(NULL)", + value ? (gchar *)value : "(NULL)"); } #endif @@ -438,10 +438,10 @@ gboolean msim_send_raw(MsimSession *session, const gchar *msg) { - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); - purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); + purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); return msim_send_really_raw(session->gc, msg, strlen(msg)) == strlen(msg); @@ -463,15 +463,15 @@ msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes) { int total_bytes_sent; - MsimSession *session; - - g_return_val_if_fail(gc != NULL, -1); - g_return_val_if_fail(buf != NULL, -1); - g_return_val_if_fail(total_bytes >= 0, -1); - - session = (MsimSession *)(gc->proto_data); - - g_return_val_if_fail(MSIM_SESSION_VALID(session), -1); + MsimSession *session; + + g_return_val_if_fail(gc != NULL, -1); + g_return_val_if_fail(buf != NULL, -1); + g_return_val_if_fail(total_bytes >= 0, -1); + + session = (MsimSession *)(gc->proto_data); + + g_return_val_if_fail(MSIM_SESSION_VALID(session), -1); /* Loop until all data is sent, or a failure occurs. */ total_bytes_sent = 0; @@ -479,7 +479,7 @@ int bytes_sent; bytes_sent = send(session->fd, buf + total_bytes_sent, - total_bytes - total_bytes_sent, 0); + total_bytes - total_bytes_sent, 0); if (bytes_sent < 0) { purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n", @@ -502,20 +502,20 @@ void msim_login(PurpleAccount *acct) { - PurpleConnection *gc; - const gchar *host; - 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); - - gc = purple_account_get_connection(acct); - gc->proto_data = msim_session_new(acct); - gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC; - - /* Passwords are limited in length. */ + PurpleConnection *gc; + const gchar *host; + 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); + + gc = purple_account_get_connection(acct); + gc->proto_data = msim_session_new(acct); + gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_URLDESC; + + /* Passwords are limited in length. */ if (strlen(acct->password) > MSIM_MAX_PASSWORD_LENGTH) { gchar *str; @@ -528,31 +528,31 @@ /* Notify an error message also, because this is important! */ purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL); - purple_connection_error(gc, str); + purple_connection_error(gc, str); g_free(str); } - /* 1. connect to server */ - purple_connection_update_progress(gc, _("Connecting"), - 0, /* which connection step this is */ - 4); /* total number of steps */ - - host = purple_account_get_string(acct, "server", MSIM_SERVER); - port = purple_account_get_int(acct, "port", MSIM_PORT); - - /* From purple.sf.net/api: - * """Note that this function name can be misleading--although it is called - * "proxy connect," it is used for establishing any outgoing TCP connection, - * whether through a proxy or not.""" */ - - /* Calls msim_connect_cb when connected. */ - 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(gc, _("Couldn't create socket")); - return; - } + /* 1. connect to server */ + purple_connection_update_progress(gc, _("Connecting"), + 0, /* which connection step this is */ + 4); /* total number of steps */ + + host = purple_account_get_string(acct, "server", MSIM_SERVER); + port = purple_account_get_int(acct, "port", MSIM_PORT); + + /* From purple.sf.net/api: + * """Note that this function name can be misleading--although it is called + * "proxy connect," it is used for establishing any outgoing TCP connection, + * whether through a proxy or not.""" */ + + /* Calls msim_connect_cb when connected. */ + 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(gc, _("Couldn't create socket")); + return; + } } /** @@ -566,37 +566,37 @@ static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg) { - PurpleAccount *account; - const gchar *response; + PurpleAccount *account; + const gchar *response; guint response_len; gchar *nc; gsize nc_len; - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE); - - account = session->account; + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE); + + account = session->account; g_return_val_if_fail(account != NULL, FALSE); - purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4); - - purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len); - - if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) { - purple_debug_info("msim", "bad nc length: %x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH); - purple_connection_error(session->gc, _("Unexpected challenge length from server")); - return FALSE; - } - - 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); - - g_free(nc); + purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4); + + purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len); + + if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) { + purple_debug_info("msim", "bad nc length: %x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH); + purple_connection_error(session->gc, _("Unexpected challenge length from server")); + return FALSE; + } + + 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); + + g_free(nc); return msim_send(session, "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, @@ -605,8 +605,8 @@ /* GString and gchar * response 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, - "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH, - "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH), + "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH, + "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH), "reconn", MSIM_TYPE_INTEGER, 0, "status", MSIM_TYPE_INTEGER, 100, "id", MSIM_TYPE_INTEGER, 1, @@ -628,14 +628,14 @@ msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], const gchar *email, const gchar *password, guint *response_len) { - PurpleCipherContext *key_context; - PurpleCipher *sha1; + PurpleCipherContext *key_context; + PurpleCipher *sha1; PurpleCipherContext *rc4; - guchar hash_pw[HASH_SIZE]; - guchar key[HASH_SIZE]; - gchar *password_utf16le, *password_utf8_lc; - guchar *data; + guchar hash_pw[HASH_SIZE]; + guchar key[HASH_SIZE]; + gchar *password_utf16le, *password_utf8_lc; + guchar *data; guchar *data_out; size_t data_len, data_out_len; gsize conv_bytes_read, conv_bytes_written; @@ -644,22 +644,22 @@ int i; #endif - g_return_val_if_fail(nonce != NULL, NULL); - g_return_val_if_fail(email != NULL, NULL); - g_return_val_if_fail(password != NULL, NULL); - g_return_val_if_fail(response_len != NULL, NULL); - - /* Convert password to lowercase (required for passwords containing - * uppercase characters). MySpace passwords are lowercase, - * see ticket #2066. */ - password_utf8_lc = g_utf8_strdown(password, -1); - - /* Convert ASCII password to UTF16 little endian */ - purple_debug_info("msim", "converting password to UTF-16LE\n"); + g_return_val_if_fail(nonce != NULL, NULL); + g_return_val_if_fail(email != NULL, NULL); + g_return_val_if_fail(password != NULL, NULL); + g_return_val_if_fail(response_len != NULL, NULL); + + /* Convert password to lowercase (required for passwords containing + * uppercase characters). MySpace passwords are lowercase, + * see ticket #2066. */ + password_utf8_lc = g_utf8_strdown(password, -1); + + /* Convert ASCII password to UTF16 little endian */ + purple_debug_info("msim", "converting password to UTF-16LE\n"); conv_error = NULL; password_utf16le = g_convert(password_utf8_lc, -1, "UTF-16LE", "UTF-8", &conv_bytes_read, &conv_bytes_written, &conv_error); - g_free(password_utf8_lc); + g_free(password_utf8_lc); g_return_val_if_fail(conv_bytes_read == strlen(password), NULL); @@ -668,69 +668,69 @@ "g_convert password UTF8->UTF16LE failed: %s", conv_error->message); g_error_free(conv_error); - return NULL; + return NULL; } - /* Compute password hash */ - purple_cipher_digest_region("sha1", (guchar *)password_utf16le, + /* Compute password hash */ + purple_cipher_digest_region("sha1", (guchar *)password_utf16le, conv_bytes_written, sizeof(hash_pw), hash_pw, NULL); g_free(password_utf16le); #ifdef MSIM_DEBUG_LOGIN_CHALLENGE - purple_debug_info("msim", "pwhash = "); - for (i = 0; i < sizeof(hash_pw); i++) - purple_debug_info("msim", "%.2x ", hash_pw[i]); - purple_debug_info("msim", "\n"); + purple_debug_info("msim", "pwhash = "); + for (i = 0; i < sizeof(hash_pw); i++) + purple_debug_info("msim", "%.2x ", hash_pw[i]); + purple_debug_info("msim", "\n"); #endif - /* key = sha1(sha1(pw) + nonce2) */ - sha1 = purple_ciphers_find_cipher("sha1"); - key_context = purple_cipher_context_new(sha1, NULL); - purple_cipher_context_append(key_context, hash_pw, HASH_SIZE); - purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE); - purple_cipher_context_digest(key_context, sizeof(key), key, NULL); + /* key = sha1(sha1(pw) + nonce2) */ + sha1 = purple_ciphers_find_cipher("sha1"); + key_context = purple_cipher_context_new(sha1, NULL); + purple_cipher_context_append(key_context, hash_pw, HASH_SIZE); + purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE); + purple_cipher_context_digest(key_context, sizeof(key), key, NULL); #ifdef MSIM_DEBUG_LOGIN_CHALLENGE - purple_debug_info("msim", "key = "); - for (i = 0; i < sizeof(key); i++) { - purple_debug_info("msim", "%.2x ", key[i]); - } - purple_debug_info("msim", "\n"); + purple_debug_info("msim", "key = "); + for (i = 0; i < sizeof(key); i++) { + purple_debug_info("msim", "%.2x ", key[i]); + } + purple_debug_info("msim", "\n"); #endif rc4 = purple_cipher_context_new_by_name("rc4", NULL); - /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash), - * but only first 0x10 used for the RC4 key. */ + /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash), + * but only first 0x10 used for the RC4 key. */ purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10); purple_cipher_context_set_key(rc4, key); - /* TODO: obtain IPs of network interfaces */ - - /* rc4 encrypt: - * nonce1+email+IP list */ - - data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN; - data = g_new0(guchar, data_len); - memcpy(data, nonce, NONCE_SIZE); - memcpy(data + NONCE_SIZE, email, strlen(email)); - memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN); + /* TODO: obtain IPs of network interfaces */ + + /* rc4 encrypt: + * nonce1+email+IP list */ + + data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN; + data = g_new0(guchar, data_len); + memcpy(data, nonce, NONCE_SIZE); + memcpy(data + NONCE_SIZE, email, strlen(email)); + memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN); data_out = g_new0(guchar, data_len); - purple_cipher_context_encrypt(rc4, (const guchar *)data, + purple_cipher_context_encrypt(rc4, (const guchar *)data, data_len, data_out, &data_out_len); purple_cipher_context_destroy(rc4); g_assert(data_out_len == data_len); #ifdef MSIM_DEBUG_LOGIN_CHALLENGE - purple_debug_info("msim", "response=<%s>\n", data_out); + purple_debug_info("msim", "response=<%s>\n", data_out); #endif *response_len = data_out_len; - return (const gchar *)data_out; + return (const gchar *)data_out; } /** @@ -751,21 +751,21 @@ msim_send_im(PurpleConnection *gc, const gchar *who, const gchar *message, PurpleMessageFlags flags) { - MsimSession *session; - gchar *message_msim; - int rc; - - g_return_val_if_fail(gc != NULL, -1); - g_return_val_if_fail(who != NULL, -1); - g_return_val_if_fail(message != NULL, -1); + MsimSession *session; + gchar *message_msim; + int rc; + + g_return_val_if_fail(gc != NULL, -1); + g_return_val_if_fail(who != NULL, -1); + g_return_val_if_fail(message != NULL, -1); /* 'flags' has many options, not used here. */ session = (MsimSession *)gc->proto_data; - g_return_val_if_fail(MSIM_SESSION_VALID(session), -1); - - message_msim = html_to_msim_markup(session, message); + g_return_val_if_fail(MSIM_SESSION_VALID(session), -1); + + message_msim = html_to_msim_markup(session, message); if (msim_send_bm(session, who, message_msim, MSIM_BM_INSTANT)) { /* Return 1 to have Purple show this IM as being sent, 0 to not. I always @@ -773,30 +773,30 @@ * it has failed yet--because the IM is only sent after the userid is * retrieved from the server (which happens after this function returns). */ - /* TODO: maybe if message is delayed, don't echo to conv window, - * but do echo it to conv window manually once it is actually - * sent? Would be complicated. */ + /* TODO: maybe if message is delayed, don't echo to conv window, + * but do echo it to conv window manually once it is actually + * sent? Would be complicated. */ rc = 1; } else { rc = -1; } - g_free(message_msim); - - /* - * In MySpace, you login with your email address, but don't talk to other - * users using their email address. So there is currently an asymmetry in the - * IM windows when using this plugin: - * - * you@example.com: hello - * some_other_user: what's going on? - * you@example.com: just coding a prpl - * - * TODO: Make the sent IM's appear as from the user's username, instead of - * their email address. Purple uses the login (in MSIM, the email)--change this. - */ - - return rc; + g_free(message_msim); + + /* + * In MySpace, you login with your email address, but don't talk to other + * users using their email address. So there is currently an asymmetry in the + * IM windows when using this plugin: + * + * you@example.com: hello + * some_other_user: what's going on? + * you@example.com: just coding a prpl + * + * TODO: Make the sent IM's appear as from the user's username, instead of + * their email address. Purple uses the login (in MSIM, the email)--change this. + */ + + return rc; } /** Send a buddy message of a given type. @@ -817,18 +817,18 @@ { gboolean rc; MsimMessage *msg; - const gchar *from_username; - - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(who != NULL, FALSE); - g_return_val_if_fail(text != NULL, FALSE); + const gchar *from_username; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(who != NULL, FALSE); + g_return_val_if_fail(text != NULL, FALSE); from_username = session->account->username; - g_return_val_if_fail(from_username != NULL, FALSE); - - purple_debug_info("msim", "sending %d message from %s to %s: %s\n", - type, from_username, who, text); + g_return_val_if_fail(from_username != NULL, FALSE); + + purple_debug_info("msim", "sending %d message from %s to %s: %s\n", + type, from_username, who, text); msg = msim_msg_new(TRUE, "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type), @@ -858,57 +858,57 @@ static guint msim_point_to_purple_size(MsimSession *session, guint point) { - guint size, this_point, base; - gdouble scale; - - base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE); + guint size, this_point, base; + gdouble scale; + + base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE); - for (size = 0; - size < sizeof(_font_scale) / sizeof(_font_scale[0]); - ++size) { - scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1]; - this_point = (guint)msim_round(scale * base); - - if (this_point >= point) { - purple_debug_info("msim", "msim_point_to_purple_size: %d pt -> size=%d\n", - point, size); - return size; - } - } - - /* No HTML font size was this big; return largest possible. */ - return this_point; + for (size = 0; + size < sizeof(_font_scale) / sizeof(_font_scale[0]); + ++size) { + scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1]; + this_point = (guint)msim_round(scale * base); + + if (this_point >= point) { + purple_debug_info("msim", "msim_point_to_purple_size: %d pt -> size=%d\n", + point, size); + return size; + } + } + + /* No HTML font size was this big; return largest possible. */ + return this_point; } /** Convert HTML font size to point size. */ static guint msim_purple_size_to_point(MsimSession *session, guint size) { - gdouble scale; - guint point; - guint base; - - scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1]; - - base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE); - - point = (guint)msim_round(scale * base); - - purple_debug_info("msim", "msim_purple_size_to_point: size=%d -> %d pt\n", - size, point); - - return point; + gdouble scale; + guint point; + guint base; + + scale = _font_scale[CLAMP(size, 1, MAX_FONT_SIZE) - 1]; + + base = purple_account_get_int(session->account, "base_font_size", MSIM_BASE_FONT_POINT_SIZE); + + point = (guint)msim_round(scale * base); + + purple_debug_info("msim", "msim_purple_size_to_point: size=%d -> %d pt\n", + size, point); + + return point; } /** Convert a msim markup font pixel height to the more usual point size, for incoming messages. */ static guint msim_height_to_point(MsimSession *session, guint height) { - guint dpi; - - dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI); - - return (guint)msim_round((POINTS_PER_INCH * 1. / dpi) * height); + guint dpi; + + dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI); + + return (guint)msim_round((POINTS_PER_INCH * 1. / dpi) * height); /* See also: libpurple/protocols/bonjour/jabber.c * _font_size_ichat_to_purple */ @@ -918,11 +918,11 @@ static guint msim_point_to_height(MsimSession *session, guint point) { - guint dpi; - - dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI); - - return (guint)msim_round((dpi * 1. / POINTS_PER_INCH) * point); + guint dpi; + + dpi = purple_account_get_int(session->account, "port", MSIM_DEFAULT_DPI); + + return (guint)msim_round((dpi * 1. / POINTS_PER_INCH) * point); } /** Convert the msim markup <f> (font) tag into HTML. */ @@ -933,33 +933,33 @@ GString *gs_end, *gs_begin; guint decor, height; - face = xmlnode_get_attrib(root, "f"); + face = xmlnode_get_attrib(root, "f"); height_str = xmlnode_get_attrib(root, "h"); decor_str = xmlnode_get_attrib(root, "s"); if (height_str) { height = atol(height_str); - } else { + } else { height = 12; - } + } if (decor_str) { decor = atol(decor_str); - } else { + } else { decor = 0; - } + } gs_begin = g_string_new(""); /* TODO: get font size working */ if (height && !face) { g_string_printf(gs_begin, "<font size='%d'>", - msim_point_to_purple_size(session, msim_height_to_point(session, height))); - } else if (height && face) { + msim_point_to_purple_size(session, msim_height_to_point(session, height))); + } else if (height && face) { g_string_printf(gs_begin, "<font face='%s' size='%d'>", face, - msim_point_to_purple_size(session, msim_height_to_point(session, height))); - } else { - g_string_printf(gs_begin, "<font>"); - } + msim_point_to_purple_size(session, msim_height_to_point(session, height))); + } else { + g_string_printf(gs_begin, "<font>"); + } /* No support for font-size CSS? */ /* g_string_printf(gs_begin, "<span style='font-family: %s; font-size: %dpt'>", face, @@ -974,12 +974,12 @@ if (decor & MSIM_TEXT_ITALIC) { g_string_append(gs_begin, "<i>"); - g_string_append(gs_end, "</i>"); + g_string_append(gs_end, "</i>"); } if (decor & MSIM_TEXT_UNDERLINE) { g_string_append(gs_begin, "<u>"); - g_string_append(gs_end, "</u>"); + g_string_append(gs_end, "</u>"); } @@ -1000,7 +1000,7 @@ if (!msim) { return g_strdup("black"); - } + } if (sscanf(msim, "rgb(%d,%d,%d)", &red, &green, &blue) != 3) { /* Color name. */ @@ -1009,13 +1009,13 @@ /* TODO: rgba (alpha). */ return g_strdup_printf("#%.2x%.2x%.2x", red, green, blue); -} +} /** Convert the msim markup <p> (paragraph) tag into HTML. */ static void msim_markup_p_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end) { - /* Just pass through unchanged. + /* Just pass through unchanged. * * Note: attributes currently aren't passed, if there are any. */ *begin = g_strdup("<p>"); @@ -1079,9 +1079,9 @@ msim_markup_i_to_html(MsimSession *session, xmlnode *root, gchar **begin, gchar **end) { const gchar *name; - guint i; - struct MSIM_EMOTICON *emote; - + guint i; + struct MSIM_EMOTICON *emote; + name = xmlnode_get_attrib(root, "n"); if (!name) { purple_debug_info("msim", "msim_markup_i_to_html: <i> w/o n"); @@ -1091,28 +1091,28 @@ return; } - for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) { - gchar *name; - gchar *symbol; - - name = emote->name; - symbol = emote->symbol; - - if (!strcmp(name, name)) { - *begin = g_strdup(symbol); - *end = g_strdup(""); - return; - } - } - - *begin = g_strdup(name); - *end = g_strdup(""); + for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) { + gchar *name; + gchar *symbol; + + name = emote->name; + symbol = emote->symbol; + + if (!strcmp(name, name)) { + *begin = g_strdup(symbol); + *end = g_strdup(""); + return; + } + } + + *begin = g_strdup(name); + *end = g_strdup(""); } /** Convert an individual msim markup tag to HTML. */ static void msim_markup_tag_to_html(MsimSession *session, xmlnode *root, gchar **begin, - gchar **end) + gchar **end) { if (!strcmp(root->name, "f")) { msim_markup_f_to_html(session, root, begin, end); @@ -1127,7 +1127,7 @@ } else { purple_debug_info("msim", "msim_markup_tag_to_html: " "unknown tag name=%s, ignoring", - (root && root->name) ? root->name : "(NULL)"); + (root && root->name) ? root->name : "(NULL)"); *begin = g_strdup(""); *end = g_strdup(""); } @@ -1136,53 +1136,52 @@ /** Convert an individual HTML tag to msim markup. */ static void html_tag_to_msim_markup(MsimSession *session, xmlnode *root, gchar **begin, - gchar **end) + gchar **end) { - /* TODO: Coalesce nested tags into one <f> tag! - * Currently, the 's' value will be overwritten when b/i/u is nested - * within another one, and only the inner-most formatting will be - * applied to the text. */ - if (!strcmp(root->name, "root")) { - *begin = g_strdup(""); - *end = g_strdup(""); - } else if (!strcmp(root->name, "b")) { - *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_BOLD); - *end = g_strdup("</f>"); - } else if (!strcmp(root->name, "i")) { - *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_ITALIC); - *end = g_strdup("</f>"); - } else if (!strcmp(root->name, "u")) { - *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_UNDERLINE); - *end = g_strdup("</f>"); - } else if (!strcmp(root->name, "font")) { - const gchar *size; - const gchar *face; - - size = xmlnode_get_attrib(root, "size"); - face = xmlnode_get_attrib(root, "face"); - - if (face && size) - { - *begin = g_strdup_printf("<f f='%s' h='%d'>", face, - msim_point_to_height(session, - msim_purple_size_to_point(session, atoi(size)))); - } else if (face) { - *begin = g_strdup_printf("<f f='%s'>", face); - } else if (size) { - *begin = g_strdup_printf("<f h='%d'>", - msim_point_to_height(session, - msim_purple_size_to_point(session, atoi(size)))); - } else { - *begin = g_strdup("<f>"); - } - - *end = g_strdup("</f>"); - - /* TODO: color (bg uses <body>), emoticons */ - } else { - *begin = g_strdup_printf("[%s]", root->name); - *end = g_strdup_printf("[/%s]", root->name); - } + /* TODO: Coalesce nested tags into one <f> tag! + * Currently, the 's' value will be overwritten when b/i/u is nested + * within another one, and only the inner-most formatting will be + * applied to the text. */ + if (!strcmp(root->name, "root")) { + *begin = g_strdup(""); + *end = g_strdup(""); + } else if (!strcmp(root->name, "b")) { + *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_BOLD); + *end = g_strdup("</f>"); + } else if (!strcmp(root->name, "i")) { + *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_ITALIC); + *end = g_strdup("</f>"); + } else if (!strcmp(root->name, "u")) { + *begin = g_strdup_printf("<f s='%d'>", MSIM_TEXT_UNDERLINE); + *end = g_strdup("</f>"); + } else if (!strcmp(root->name, "font")) { + const gchar *size; + const gchar *face; + + size = xmlnode_get_attrib(root, "size"); + face = xmlnode_get_attrib(root, "face"); + + if (face && size) { + *begin = g_strdup_printf("<f f='%s' h='%d'>", face, + msim_point_to_height(session, + msim_purple_size_to_point(session, atoi(size)))); + } else if (face) { + *begin = g_strdup_printf("<f f='%s'>", face); + } else if (size) { + *begin = g_strdup_printf("<f h='%d'>", + msim_point_to_height(session, + msim_purple_size_to_point(session, atoi(size)))); + } else { + *begin = g_strdup("<f>"); + } + + *end = g_strdup("</f>"); + + /* TODO: color (bg uses <body>), emoticons */ + } else { + *begin = g_strdup_printf("[%s]", root->name); + *end = g_strdup_printf("[/%s]", root->name); + } } /** Convert an xmlnode of msim markup or HTML to an HTML string or msim markup. @@ -1196,25 +1195,25 @@ { xmlnode *node; gchar *begin, *inner, *end; - GString *final; + GString *final; if (!root || !root->name) { return g_strdup(""); - } + } purple_debug_info("msim", "msim_convert_xmlnode: got root=%s\n", root->name); begin = inner = end = NULL; - final = g_string_new(""); - - f(session, root, &begin, &end); - - g_string_append(final, begin); + final = g_string_new(""); + + f(session, root, &begin, &end); + + g_string_append(final, begin); /* Loop over all child nodes. */ - for (node = root->child; node != NULL; node = node->next) { + for (node = root->child; node != NULL; node = node->next) { switch (node->type) { case XMLNODE_TYPE_ATTRIB: /* Attributes handled above. */ @@ -1223,20 +1222,20 @@ case XMLNODE_TYPE_TAG: /* A tag or tag with attributes. Recursively descend. */ inner = msim_convert_xmlnode(session, node, f); - g_return_val_if_fail(inner != NULL, NULL); + g_return_val_if_fail(inner != NULL, NULL); purple_debug_info("msim", " ** node name=%s\n", - (node && node->name) ? node->name : "(NULL)"); + (node && node->name) ? node->name : "(NULL)"); break; - case XMLNODE_TYPE_DATA: + case XMLNODE_TYPE_DATA: /* Literal text. */ inner = g_new0(char, node->data_sz + 1); strncpy(inner, node->data, node->data_sz); inner[node->data_sz] = 0; purple_debug_info("msim", " ** node data=%s\n", - inner ? inner : "(NULL)"); + inner ? inner : "(NULL)"); break; default: @@ -1245,16 +1244,16 @@ inner = g_strdup(""); } - if (inner) { - g_string_append(final, inner); - } - } - - /* TODO: Note that msim counts each piece of text enclosed by <f> as - * a paragraph and will display each on its own line. You actually have - * to _nest_ <f> tags to intersperse different text in one paragraph! - * Comment out this line below to see. */ - g_string_append(final, end); + if (inner) { + g_string_append(final, inner); + } + } + + /* TODO: Note that msim counts each piece of text enclosed by <f> as + * a paragraph and will display each on its own line. You actually have + * to _nest_ <f> tags to intersperse different text in one paragraph! + * Comment out this line below to see. */ + g_string_append(final, end); purple_debug_info("msim", "msim_markup_xmlnode_to_gtkhtml: RETURNING %s\n", (final && final->str) ? final->str : "(NULL)"); @@ -1268,27 +1267,27 @@ { xmlnode *root; gchar *str; - gchar *enclosed_raw; - - g_return_val_if_fail(raw != NULL, NULL); - - /* Enclose text in one root tag, to try to make it valid XML for parsing. */ - enclosed_raw = g_strconcat("<root>", raw, "</root>", NULL); + gchar *enclosed_raw; + + g_return_val_if_fail(raw != NULL, NULL); + + /* Enclose text in one root tag, to try to make it valid XML for parsing. */ + enclosed_raw = g_strconcat("<root>", raw, "</root>", NULL); root = xmlnode_from_str(enclosed_raw, -1); if (!root) { purple_debug_info("msim", "msim_markup_to_html: couldn't parse " "%s as XML, returning raw: %s\n", enclosed_raw, raw); - /* TODO: msim_unrecognized */ - g_free(enclosed_raw); + /* TODO: msim_unrecognized */ + g_free(enclosed_raw); return g_strdup(raw); } - g_free(enclosed_raw); + g_free(enclosed_raw); str = msim_convert_xmlnode(session, root, f); - g_return_val_if_fail(str != NULL, NULL); + g_return_val_if_fail(str != NULL, NULL); purple_debug_info("msim", "msim_markup_to_html: returning %s\n", str); xmlnode_free(root); @@ -1304,35 +1303,35 @@ static gchar * msim_convert_smileys_to_markup(gchar *before) { - gchar *old, *new, *replacement; - guint i; - struct MSIM_EMOTICON *emote; - - old = before; - new = NULL; - - for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) { - gchar *name, *symbol; - - name = emote->name; - symbol = emote->symbol; - - replacement = g_strdup_printf("<i n=\"%s\"/>", name); - - purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n", - symbol ? symbol : "(NULL)", - replacement ? replacement : "(NULL)"); - new = str_replace(old, symbol, replacement); - - g_free(replacement); - g_free(old); - - old = new; - } - - return new; + gchar *old, *new, *replacement; + guint i; + struct MSIM_EMOTICON *emote; + + old = before; + new = NULL; + + for (i = 0; (emote = &msim_emoticons[i]) && emote->name != NULL; ++i) { + gchar *name, *symbol; + + name = emote->name; + symbol = emote->symbol; + + replacement = g_strdup_printf("<i n=\"%s\"/>", name); + + purple_debug_info("msim", "msim_convert_smileys_to_markup: %s->%s\n", + symbol ? symbol : "(NULL)", + replacement ? replacement : "(NULL)"); + new = str_replace(old, symbol, replacement); + + g_free(replacement); + g_free(old); + + old = new; + } + + return new; } - + /** High-level function to convert MySpaceIM markup to Purple (HTML) markup. * @@ -1340,8 +1339,8 @@ static gchar * msim_markup_to_html(MsimSession *session, const gchar *raw) { - return msim_convert_xml(session, raw, - (MSIM_XMLNODE_CONVERT)(msim_markup_tag_to_html)); + return msim_convert_xml(session, raw, + (MSIM_XMLNODE_CONVERT)(msim_markup_tag_to_html)); } /** High-level function to convert Purple (HTML) to MySpaceIM markup. @@ -1350,74 +1349,74 @@ static gchar * html_to_msim_markup(MsimSession *session, const gchar *raw) { - gchar *markup; - - markup = msim_convert_xml(session, raw, - (MSIM_XMLNODE_CONVERT)(html_tag_to_msim_markup)); - - if (purple_account_get_bool(session->account, "emoticons", TRUE)) { - /* Frees markup and allocates a new one. */ - markup = msim_convert_smileys_to_markup(markup); - } - - return markup; + gchar *markup; + + markup = msim_convert_xml(session, raw, + (MSIM_XMLNODE_CONVERT)(html_tag_to_msim_markup)); + + if (purple_account_get_bool(session->account, "emoticons", TRUE)) { + /* Frees markup and allocates a new one. */ + markup = msim_convert_smileys_to_markup(markup); + } + + return markup; } /** Record the client version in the buddy list, from an incoming message. */ static gboolean msim_incoming_bm_record_cv(MsimSession *session, MsimMessage *msg) { - gchar *username, *cv; - gboolean ret; - PurpleBuddy *buddy; - - username = msim_msg_get_string(msg, "_username"); - cv = msim_msg_get_string(msg, "cv"); - - g_return_val_if_fail(username != NULL, FALSE); - g_return_val_if_fail(cv != NULL, FALSE); - - buddy = purple_find_buddy(session->account, username); - - if (buddy) { - purple_blist_node_set_int(&buddy->node, "client_cv", atol(cv)); - ret = TRUE; - } else { - ret = FALSE; - } - - g_free(username); - g_free(cv); - - return ret; + gchar *username, *cv; + gboolean ret; + PurpleBuddy *buddy; + + username = msim_msg_get_string(msg, "_username"); + cv = msim_msg_get_string(msg, "cv"); + + g_return_val_if_fail(username != NULL, FALSE); + g_return_val_if_fail(cv != NULL, FALSE); + + buddy = purple_find_buddy(session->account, username); + + if (buddy) { + purple_blist_node_set_int(&buddy->node, "client_cv", atol(cv)); + ret = TRUE; + } else { + ret = FALSE; + } + + g_free(username); + g_free(cv); + + return ret; } /** Handle an incoming buddy message. */ static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg) { - guint bm; + guint bm; - bm = msim_msg_get_integer(msg, "bm"); - - msim_incoming_bm_record_cv(session, msg); - - switch (bm) { - case MSIM_BM_STATUS: - return msim_incoming_status(session, msg); - case MSIM_BM_INSTANT: - return msim_incoming_im(session, msg); - case MSIM_BM_ACTION: - return msim_incoming_action(session, msg); - case MSIM_BM_MEDIA: - return msim_incoming_media(session, msg); - case MSIM_BM_UNOFFICIAL_CLIENT: - return msim_incoming_unofficial_client(session, msg); - default: - /* Not really an IM, but show it for informational - * purposes during development. */ - return msim_incoming_im(session, msg); - } + bm = msim_msg_get_integer(msg, "bm"); + + msim_incoming_bm_record_cv(session, msg); + + switch (bm) { + case MSIM_BM_STATUS: + return msim_incoming_status(session, msg); + case MSIM_BM_INSTANT: + return msim_incoming_im(session, msg); + case MSIM_BM_ACTION: + return msim_incoming_action(session, msg); + case MSIM_BM_MEDIA: + return msim_incoming_media(session, msg); + case MSIM_BM_UNOFFICIAL_CLIENT: + return msim_incoming_unofficial_client(session, msg); + default: + /* Not really an IM, but show it for informational + * purposes during development. */ + return msim_incoming_im(session, msg); + } } /** @@ -1425,28 +1424,28 @@ * * @param session The session * @param msg Message from the server, containing 'f' (userid from) and 'msg'. - * Should also contain username in _username from preprocessing. + * Should also contain username in _username from preprocessing. * * @return TRUE if successful. */ static gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg) { - gchar *username, *msg_msim_markup, *msg_purple_markup; - - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - username = msim_msg_get_string(msg, "_username"); - g_return_val_if_fail(username != NULL, FALSE); + gchar *username, *msg_msim_markup, *msg_purple_markup; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + username = msim_msg_get_string(msg, "_username"); + g_return_val_if_fail(username != NULL, FALSE); msg_msim_markup = msim_msg_get_string(msg, "msg"); - g_return_val_if_fail(msg_msim_markup != NULL, FALSE); + g_return_val_if_fail(msg_msim_markup != NULL, FALSE); msg_purple_markup = msim_markup_to_html(session, msg_msim_markup); g_free(msg_msim_markup); - serv_got_im(session->gc, username, msg_purple_markup, + serv_got_im(session->gc, username, msg_purple_markup, PURPLE_MESSAGE_RECV, time(NULL)); g_free(username); @@ -1466,8 +1465,8 @@ msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note) { /* TODO: Some more context, outwardly equivalent to a backtrace, - * for helping figure out what this msg is for. What was going on? - * But not too much information so that a user + * for helping figure out what this msg is for. What was going on? + * But not too much information so that a user * posting this dump reveals confidential information. */ @@ -1476,56 +1475,56 @@ * by Alexandr Shutko, who maintains OSCAR protocol documentation). */ purple_debug_info("msim", "Unrecognized data on account for %s\n", - session->account->username ? session->account->username - : "(NULL)"); + session->account->username ? session->account->username + : "(NULL)"); if (note) { purple_debug_info("msim", "(Note: %s)\n", note); } - if (msg) { - msim_msg_dump("Unrecognized message dump: %s\n", msg); - } + if (msg) { + msim_msg_dump("Unrecognized message dump: %s\n", msg); + } } /** Process an incoming zap. */ static gboolean msim_incoming_zap(MsimSession *session, MsimMessage *msg) { - gchar *msg_text, *username, *zap_text; - gint zap; - const gchar *zap_past_tense[10]; - - zap_past_tense[0] = _("zapped"); - zap_past_tense[1] = _("whacked"); - zap_past_tense[2] = _("torched"); - zap_past_tense[3] = _("smooched"); - zap_past_tense[4] = _("hugged"); - zap_past_tense[5] = _("bslapped"); - zap_past_tense[6] = _("goosed"); - zap_past_tense[7] = _("hi-fived"); - zap_past_tense[8] = _("punk'd"); - zap_past_tense[9] = _("raspberried"); - - msg_text = msim_msg_get_string(msg, "msg"); - username = msim_msg_get_string(msg, "_username"); - - g_return_val_if_fail(msg_text != NULL, FALSE); - g_return_val_if_fail(username != NULL, FALSE); - - g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE); - - zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0])); - - zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]); - - serv_got_im(session->gc, username, zap_text, + gchar *msg_text, *username, *zap_text; + gint zap; + const gchar *zap_past_tense[10]; + + zap_past_tense[0] = _("zapped"); + zap_past_tense[1] = _("whacked"); + zap_past_tense[2] = _("torched"); + zap_past_tense[3] = _("smooched"); + zap_past_tense[4] = _("hugged"); + zap_past_tense[5] = _("bslapped"); + zap_past_tense[6] = _("goosed"); + zap_past_tense[7] = _("hi-fived"); + zap_past_tense[8] = _("punk'd"); + zap_past_tense[9] = _("raspberried"); + + msg_text = msim_msg_get_string(msg, "msg"); + username = msim_msg_get_string(msg, "_username"); + + g_return_val_if_fail(msg_text != NULL, FALSE); + g_return_val_if_fail(username != NULL, FALSE); + + g_return_val_if_fail(sscanf(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_%d", &zap) == 1, FALSE); + + zap = CLAMP(zap, 0, sizeof(zap_past_tense) / sizeof(zap_past_tense[0])); + + zap_text = g_strdup_printf(_("*** You have been %s! ***"), zap_past_tense[zap]); + + serv_got_im(session->gc, username, zap_text, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_SYSTEM, time(NULL)); - g_free(zap_text); - g_free(msg_text); - g_free(username); - - return TRUE; + g_free(zap_text); + g_free(msg_text); + g_free(username); + + return TRUE; } /** @@ -1543,32 +1542,32 @@ gchar *msg_text, *username; gboolean rc; - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); msg_text = msim_msg_get_string(msg, "msg"); - g_return_val_if_fail(msg_text != NULL, FALSE); + g_return_val_if_fail(msg_text != NULL, FALSE); username = msim_msg_get_string(msg, "_username"); - g_return_val_if_fail(username != NULL, FALSE); + g_return_val_if_fail(username != NULL, FALSE); purple_debug_info("msim", "msim_incoming_action: action <%s> from <%d>\n", - msg_text, username); + msg_text, username); if (strcmp(msg_text, "%typing%") == 0) { /* TODO: find out if msim repeatedly sends typing messages, so we can - * give it a timeout. Right now, there does seem to be an inordinately - * amount of time between typing stopped-typing notifications. */ + * give it a timeout. Right now, there does seem to be an inordinately + * amount of time between typing stopped-typing notifications. */ serv_got_typing(session->gc, username, 0, PURPLE_TYPING); rc = TRUE; } else if (strcmp(msg_text, "%stoptyping%") == 0) { serv_got_typing_stopped(session->gc, username); rc = TRUE; - } else if (strstr(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_")) { - rc = msim_incoming_zap(session, msg); + } else if (strstr(msg_text, "!!!ZAP_SEND!!!=RTE_BTN_ZAPS_")) { + rc = msim_incoming_zap(session, msg); } else { msim_unrecognized(session, msg, - "got to msim_incoming_action but unrecognized value for 'msg'"); + "got to msim_incoming_action but unrecognized value for 'msg'"); rc = FALSE; } @@ -1582,25 +1581,25 @@ static gboolean msim_incoming_media(MsimSession *session, MsimMessage *msg) { - gchar *username, *text; - - username = msim_msg_get_string(msg, "_username"); - text = msim_msg_get_string(msg, "msg"); - - g_return_val_if_fail(username != NULL, FALSE); - g_return_val_if_fail(text != NULL, FALSE); - - purple_debug_info("msim", "msim_incoming_media: from %s, got msg=%s\n", username, text); - - /* Media messages are sent when the user opens a window to someone. - * Tell libpurple they started typing and stopped typing, to inform the Psychic - * Mode plugin so it too can open a window to the user. */ - serv_got_typing(session->gc, username, 0, PURPLE_TYPING); - serv_got_typing_stopped(session->gc, username); - - g_free(username); - - return TRUE; + gchar *username, *text; + + username = msim_msg_get_string(msg, "_username"); + text = msim_msg_get_string(msg, "msg"); + + g_return_val_if_fail(username != NULL, FALSE); + g_return_val_if_fail(text != NULL, FALSE); + + purple_debug_info("msim", "msim_incoming_media: from %s, got msg=%s\n", username, text); + + /* Media messages are sent when the user opens a window to someone. + * Tell libpurple they started typing and stopped typing, to inform the Psychic + * Mode plugin so it too can open a window to the user. */ + serv_got_typing(session->gc, username, 0, PURPLE_TYPING); + serv_got_typing_stopped(session->gc, username); + + g_free(username); + + return TRUE; } /* Process an incoming "unofficial client" message. The plugin for @@ -1608,29 +1607,29 @@ static gboolean msim_incoming_unofficial_client(MsimSession *session, MsimMessage *msg) { - PurpleBuddy *buddy; - gchar *username, *client_info; - - username = msim_msg_get_string(msg, "_username"); - client_info = msim_msg_get_string(msg, "msg"); - - g_return_val_if_fail(username != NULL, FALSE); - g_return_val_if_fail(client_info != NULL, FALSE); - - purple_debug_info("msim", "msim_incoming_unofficial_client: %s is using client %s\n", - username, client_info); + PurpleBuddy *buddy; + gchar *username, *client_info; + + username = msim_msg_get_string(msg, "_username"); + client_info = msim_msg_get_string(msg, "msg"); + + g_return_val_if_fail(username != NULL, FALSE); + g_return_val_if_fail(client_info != NULL, FALSE); + + purple_debug_info("msim", "msim_incoming_unofficial_client: %s is using client %s\n", + username, client_info); buddy = purple_find_buddy(session->account, username); - - g_return_val_if_fail(buddy != NULL, FALSE); - - purple_blist_node_remove_setting(&buddy->node, "client"); - purple_blist_node_set_string(&buddy->node, "client", client_info); - - g_free(username); - /* Do not free client_info - the blist now owns it. */ - - return TRUE; + + g_return_val_if_fail(buddy != NULL, FALSE); + + purple_blist_node_remove_setting(&buddy->node, "client"); + purple_blist_node_set_string(&buddy->node, "client", client_info); + + g_free(username); + /* Do not free client_info - the blist now owns it. */ + + return TRUE; } @@ -1639,18 +1638,18 @@ static gboolean msim_send_unofficial_client(MsimSession *session, gchar *username) { - gchar *our_info; - gboolean ret; - - our_info = g_strdup_printf("Libpurple %d.%d.%d - msimprpl %s", - PURPLE_MAJOR_VERSION, - PURPLE_MINOR_VERSION, - PURPLE_MICRO_VERSION, - MSIM_PRPL_VERSION_STRING); + gchar *our_info; + gboolean ret; + + our_info = g_strdup_printf("Libpurple %d.%d.%d - msimprpl %s", + PURPLE_MAJOR_VERSION, + PURPLE_MINOR_VERSION, + PURPLE_MICRO_VERSION, + MSIM_PRPL_VERSION_STRING); ret = msim_send_bm(session, username, our_info, MSIM_BM_UNOFFICIAL_CLIENT); - return ret; + return ret; } #endif @@ -1665,19 +1664,19 @@ */ unsigned int msim_send_typing(PurpleConnection *gc, const gchar *name, - PurpleTypingState state) + PurpleTypingState state) { const gchar *typing_str; MsimSession *session; - g_return_val_if_fail(gc != NULL, 0); - g_return_val_if_fail(name != NULL, 0); + g_return_val_if_fail(gc != NULL, 0); + g_return_val_if_fail(name != NULL, 0); session = (MsimSession *)gc->proto_data; - g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); - - switch (state) { + g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); + + switch (state) { case PURPLE_TYPING: typing_str = "%typing%"; break; @@ -1697,7 +1696,7 @@ /** Callback for msim_get_info(), for when user info is received. */ static void msim_get_info_cb(MsimSession *session, MsimMessage *user_info_msg, - gpointer data) + gpointer data) { GHashTable *body; gchar *body_str; @@ -1707,12 +1706,12 @@ PurpleBuddy *buddy; const gchar *str, *str2; - g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(MSIM_SESSION_VALID(session)); /* Get user{name,id} from msim_get_info, passed as an MsimMessage for orthogonality. */ msg = (MsimMessage *)data; - g_return_if_fail(msg != NULL); + g_return_if_fail(msg != NULL); user = msim_msg_get_string(msg, "user"); if (!user) { @@ -1724,13 +1723,13 @@ purple_debug_info("msim", "msim_get_info_cb: got for user: %s\n", user); body_str = msim_msg_get_string(user_info_msg, "body"); - g_return_if_fail(body_str != NULL); + g_return_if_fail(body_str != NULL); body = msim_parse_body(body_str); g_free(body_str); buddy = purple_find_buddy(session->account, user); /* Note: don't assume buddy is non-NULL; will be if lookup random user - * not on blist. */ + * not on blist. */ user_info = purple_notify_user_info_new(); @@ -1743,7 +1742,7 @@ purple_notify_user_info_add_pair(user_info, _("User ID"), g_strdup(str)); - /* a/s/l...the vitals */ + /* a/s/l...the vitals */ str = g_hash_table_lookup(body, "Age"); if (str) purple_notify_user_info_add_pair(user_info, _("Age"), g_strdup(str)); @@ -1760,7 +1759,7 @@ /* Other information */ if (buddy) { - /* Headline comes from buddy status messages */ + /* Headline comes from buddy status messages */ str = purple_blist_node_get_string(&buddy->node, "Headline"); if (str) purple_notify_user_info_add_pair(user_info, "Headline", str); @@ -1782,19 +1781,19 @@ if (str) { purple_notify_user_info_add_pair(user_info, _("Total Friends"), g_strdup(str)); - } - - if (buddy) { - gint cv; - - str = purple_blist_node_get_string(&buddy->node, "client"); - cv = purple_blist_node_get_int(&buddy->node, "client_cv"); - - if (str) { - purple_notify_user_info_add_pair(user_info, _("Client Version"), - g_strdup_printf("%s (build %d)", str, cv)); - } - } + } + + if (buddy) { + gint cv; + + str = purple_blist_node_get_string(&buddy->node, "client"); + cv = purple_blist_node_get_int(&buddy->node, "client_cv"); + + if (str) { + purple_notify_user_info_add_pair(user_info, _("Client Version"), + g_strdup_printf("%s (build %d)", str, cv)); + } + } purple_notify_userinfo(session->gc, user, user_info, NULL, NULL); purple_debug_info("msim", "msim_get_info_cb: username=%s\n", user); @@ -1814,12 +1813,12 @@ gchar *user_to_lookup; MsimMessage *user_msg; - g_return_if_fail(gc != NULL); - g_return_if_fail(user != NULL); + g_return_if_fail(gc != NULL); + g_return_if_fail(user != NULL); session = (MsimSession *)gc->proto_data; - g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(MSIM_SESSION_VALID(session)); /* Obtain uid of buddy. */ buddy = purple_find_buddy(session->account, user); @@ -1863,31 +1862,31 @@ { PurpleStatusType *type; MsimSession *session; - guint status_code; - const gchar *statstring; + guint status_code; + const gchar *statstring; session = (MsimSession *)account->gc->proto_data; - g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(MSIM_SESSION_VALID(session)); type = purple_status_get_type(status); switch (purple_status_type_get_primitive(type)) { case PURPLE_STATUS_AVAILABLE: - purple_debug_info("msim", "msim_set_status: available (%d->%d)\n", PURPLE_STATUS_AVAILABLE, - MSIM_STATUS_CODE_ONLINE); + purple_debug_info("msim", "msim_set_status: available (%d->%d)\n", PURPLE_STATUS_AVAILABLE, + MSIM_STATUS_CODE_ONLINE); status_code = MSIM_STATUS_CODE_ONLINE; break; case PURPLE_STATUS_INVISIBLE: - purple_debug_info("msim", "msim_set_status: invisible (%d->%d)\n", PURPLE_STATUS_INVISIBLE, - MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN); + purple_debug_info("msim", "msim_set_status: invisible (%d->%d)\n", PURPLE_STATUS_INVISIBLE, + MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN); status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN; break; case PURPLE_STATUS_AWAY: - purple_debug_info("msim", "msim_set_status: away (%d->%d)\n", PURPLE_STATUS_AWAY, - MSIM_STATUS_CODE_AWAY); + purple_debug_info("msim", "msim_set_status: away (%d->%d)\n", PURPLE_STATUS_AWAY, + MSIM_STATUS_CODE_AWAY); status_code = MSIM_STATUS_CODE_AWAY; break; @@ -1898,38 +1897,38 @@ break; } - statstring = purple_status_get_attr_string(status, "message"); - - if (!statstring) { - statstring = g_strdup(""); - } - - msim_set_status_code(session, status_code, g_strdup(statstring)); + statstring = purple_status_get_attr_string(status, "message"); + + if (!statstring) { + statstring = g_strdup(""); + } + + msim_set_status_code(session, status_code, g_strdup(statstring)); } /** Go idle. */ void msim_set_idle(PurpleConnection *gc, int time) { - MsimSession *session; - - g_return_if_fail(gc != NULL); - - session = (MsimSession *)gc->proto_data; - - g_return_if_fail(MSIM_SESSION_VALID(session)); - - if (time == 0) { - /* Going back from idle. In msim, idle is mutually exclusive - * from the other states (you can only be away or idle, but not - * both, for example), so by going non-idle I go online. - */ - /* TODO: find out how to keep old status string? */ - msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE, g_strdup("")); - } else { - /* msim doesn't support idle time, so just go idle */ - msim_set_status_code(session, MSIM_STATUS_CODE_IDLE, g_strdup("")); - } + MsimSession *session; + + g_return_if_fail(gc != NULL); + + session = (MsimSession *)gc->proto_data; + + g_return_if_fail(MSIM_SESSION_VALID(session)); + + if (time == 0) { + /* Going back from idle. In msim, idle is mutually exclusive + * from the other states (you can only be away or idle, but not + * both, for example), so by going non-idle I go online. + */ + /* TODO: find out how to keep old status string? */ + msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE, g_strdup("")); + } else { + /* msim doesn't support idle time, so just go idle */ + msim_set_status_code(session, MSIM_STATUS_CODE_IDLE, g_strdup("")); + } } /** Set status using an MSIM_STATUS_CODE_* value. @@ -1939,18 +1938,18 @@ static void msim_set_status_code(MsimSession *session, guint status_code, gchar *statstring) { - g_return_if_fail(MSIM_SESSION_VALID(session)); - g_return_if_fail(statstring != NULL); - - purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n", - status_code, statstring); + g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(statstring != NULL); + + purple_debug_info("msim", "msim_set_status_code: going to set status to code=%d,str=%s\n", + status_code, statstring); if (!msim_send(session, "status", MSIM_TYPE_INTEGER, status_code, "sesskey", MSIM_TYPE_INTEGER, session->sesskey, "statstring", MSIM_TYPE_STRING, statstring, "locstring", MSIM_TYPE_STRING, g_strdup(""), - NULL)) + NULL)) { purple_debug_info("msim", "msim_set_status: failed to set status"); } @@ -1972,8 +1971,8 @@ gchar *username; MsimMessage *msg; - g_return_if_fail(MSIM_SESSION_VALID(session)); - g_return_if_fail(userinfo != NULL); + g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(userinfo != NULL); body_str = msim_msg_get_string(userinfo, "body"); g_return_if_fail(body_str != NULL); @@ -1986,14 +1985,14 @@ msg = (MsimMessage *)data; - g_return_if_fail(msg != NULL); - - /* TODO: more elegant solution than below. attach whole message? */ + g_return_if_fail(msg != NULL); + + /* TODO: more elegant solution than below. attach whole message? */ /* Special elements name beginning with '_', we'll use internally within the * program (did not come directly from the wire). */ msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username)); - /* TODO: attach more useful information, like ImageURL */ + /* TODO: attach more useful information, like ImageURL */ msim_process(session, msg); @@ -2039,17 +2038,17 @@ uid = purple_blist_node_get_int(&buddy->node, "UserID"); //uid = purple_blist_node_get_int(node, "UserID"); - /* name = buddy->name; */ /* crash */ - /* name = PURPLE_BLIST_NODE_NAME(&buddy->node); */ /* crash */ + /* name = buddy->name; */ /* crash */ + /* name = PURPLE_BLIST_NODE_NAME(&buddy->node); */ /* crash */ /* XXX Is this right? Memory corruption here somehow. Happens only * when return one of these values. */ - name = purple_buddy_get_name(buddy); /* crash */ - //name = purple_buddy_get_name((PurpleBuddy *)node); /* crash */ - /* return name; */ /* crash (with above) */ - - /* name = NULL; */ /* no crash */ - /* return NULL; */ /* no crash (with anything) */ + name = purple_buddy_get_name(buddy); /* crash */ + //name = purple_buddy_get_name((PurpleBuddy *)node); /* crash */ + /* return name; */ /* crash (with above) */ + + /* name = NULL; */ /* no crash */ + /* return NULL; */ /* no crash (with anything) */ /* crash = *** glibc detected *** pidgin: realloc(): invalid pointer: 0x0000000000d2aec0 *** @@ -2080,12 +2079,12 @@ #6 0x00002b40749868bf in g_strdup () from /usr/lib/libglib-2.0.so.0 #7 0x00002b407810969f in msim_parse ( raw=0xd2a910 "\\bm\\100\\f\\3656574\\msg\\|s|0|ss|Offline") - at message.c:648 + at message.c:648 #8 0x00002b407810889c in msim_input_cb (gc_uncasted=0xcf92c0, source=<value optimized out>, cond=<value optimized out>) at myspace.c:1478 - Why is it crashing in msim_parse()'s g_strdup()? +Why is it crashing in msim_parse()'s g_strdup()? */ purple_debug_info("msim", "msim_uid2username_from_blist: %s's uid=%d (want %d)\n", name, uid, wanted_uid); @@ -2115,8 +2114,8 @@ static gboolean msim_preprocess_incoming(MsimSession *session, MsimMessage *msg) { - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); if (msim_msg_get(msg, "bm") && msim_msg_get(msg, "f")) { guint uid; @@ -2164,31 +2163,31 @@ static gboolean msim_check_alive(gpointer data) { - MsimSession *session; - time_t delta; - gchar *errmsg; - - session = (MsimSession *)data; - - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - - delta = time(NULL) - session->last_comm; - //purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta); - if (delta >= MSIM_KEEPALIVE_INTERVAL) { - errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), (int)delta); - - purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n", - errmsg, MSIM_KEEPALIVE_INTERVAL); - purple_connection_error(session->gc, errmsg); - - purple_notify_error(session->gc, NULL, errmsg, NULL); - - g_free(errmsg); - - return FALSE; - } - - return TRUE; + MsimSession *session; + time_t delta; + gchar *errmsg; + + session = (MsimSession *)data; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + + delta = time(NULL) - session->last_comm; + //purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta); + if (delta >= MSIM_KEEPALIVE_INTERVAL) { + errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), (int)delta); + + purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n", + errmsg, MSIM_KEEPALIVE_INTERVAL); + purple_connection_error(session->gc, errmsg); + + purple_notify_error(session->gc, NULL, errmsg, NULL); + + g_free(errmsg); + + return FALSE; + } + + return TRUE; } #endif @@ -2196,126 +2195,126 @@ static void msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data) { - GHashTable *body; - gchar *body_str; - GString *notification; - guint old_inbox_status; - guint i, n; - const gchar *froms[5], *tos[5], *urls[5], *subjects[5]; - - /* Three parallel arrays for each new inbox message type. */ - static const gchar *inbox_keys[] = - { - "Mail", - "BlogComment", - "ProfileComment", - "FriendRequest", - "PictureComment" - }; - - static const guint inbox_bits[] = - { - MSIM_INBOX_MAIL, - MSIM_INBOX_BLOG_COMMENT, - MSIM_INBOX_PROFILE_COMMENT, - MSIM_INBOX_FRIEND_REQUEST, - MSIM_INBOX_PICTURE_COMMENT - }; - - static const gchar *inbox_urls[] = - { - "http://messaging.myspace.com/index.cfm?fuseaction=mail.inbox", - "http://blog.myspace.com/index.cfm?fuseaction=blog", - "http://home.myspace.com/index.cfm?fuseaction=user", - "http://messaging.myspace.com/index.cfm?fuseaction=mail.friendRequests", - "http://home.myspace.com/index.cfm?fuseaction=user" - }; - - static const gchar *inbox_text[5]; - - /* Can't write _()'d strings in array initializers. Workaround. */ - inbox_text[0] = _("New mail messages"); - inbox_text[1] = _("New blog comments"); - inbox_text[2] = _("New profile comments"); - inbox_text[3] = _("New friend requests!"); - inbox_text[4] = _("New picture comments"); - - g_return_if_fail(reply != NULL); - - msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply); - - body_str = msim_msg_get_string(reply, "body"); - g_return_if_fail(body_str != NULL); - - body = msim_parse_body(body_str); - g_free(body_str); - - notification = g_string_new(""); - - old_inbox_status = session->inbox_status; - - n = 0; - - for (i = 0; i < sizeof(inbox_keys) / sizeof(inbox_keys[0]); ++i) { - const gchar *key; - guint bit; - - key = inbox_keys[i]; - bit = inbox_bits[i]; - - if (g_hash_table_lookup(body, key)) { - /* Notify only on when _changes_ from no mail -> has mail - * (edge triggered) */ - if (!(session->inbox_status & bit)) { - purple_debug_info("msim", "msim_check_inbox_cb: got %s, at %d\n", - key ? key : "(NULL)", n); - - subjects[n] = inbox_text[i]; - froms[n] = _("MySpace"); - tos[n] = session->username; - /* TODO: append token, web challenge, so automatically logs in. - * Would also need to free strings because they won't be static - */ - urls[n] = inbox_urls[i]; - - ++n; - } else { - purple_debug_info("msim", - "msim_check_inbox_cb: already notified of %s\n", - key ? key : "(NULL)"); - } - - session->inbox_status |= bit; - } - } - - if (n) { - purple_debug_info("msim", - "msim_check_inbox_cb: notifying of %d\n", n); - - /* TODO: free strings with callback _if_ change to dynamic (w/ token) */ - purple_notify_emails(session->gc, /* handle */ - n, /* count */ - TRUE, /* detailed */ - subjects, froms, tos, urls, - NULL, /* PurpleNotifyCloseCallback cb */ - NULL); /* gpointer user_data */ - - } - - g_hash_table_destroy(body); + GHashTable *body; + gchar *body_str; + GString *notification; + guint old_inbox_status; + guint i, n; + const gchar *froms[5], *tos[5], *urls[5], *subjects[5]; + + /* Three parallel arrays for each new inbox message type. */ + static const gchar *inbox_keys[] = + { + "Mail", + "BlogComment", + "ProfileComment", + "FriendRequest", + "PictureComment" + }; + + static const guint inbox_bits[] = + { + MSIM_INBOX_MAIL, + MSIM_INBOX_BLOG_COMMENT, + MSIM_INBOX_PROFILE_COMMENT, + MSIM_INBOX_FRIEND_REQUEST, + MSIM_INBOX_PICTURE_COMMENT + }; + + static const gchar *inbox_urls[] = + { + "http://messaging.myspace.com/index.cfm?fuseaction=mail.inbox", + "http://blog.myspace.com/index.cfm?fuseaction=blog", + "http://home.myspace.com/index.cfm?fuseaction=user", + "http://messaging.myspace.com/index.cfm?fuseaction=mail.friendRequests", + "http://home.myspace.com/index.cfm?fuseaction=user" + }; + + static const gchar *inbox_text[5]; + + /* Can't write _()'d strings in array initializers. Workaround. */ + inbox_text[0] = _("New mail messages"); + inbox_text[1] = _("New blog comments"); + inbox_text[2] = _("New profile comments"); + inbox_text[3] = _("New friend requests!"); + inbox_text[4] = _("New picture comments"); + + g_return_if_fail(reply != NULL); + + msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply); + + body_str = msim_msg_get_string(reply, "body"); + g_return_if_fail(body_str != NULL); + + body = msim_parse_body(body_str); + g_free(body_str); + + notification = g_string_new(""); + + old_inbox_status = session->inbox_status; + + n = 0; + + for (i = 0; i < sizeof(inbox_keys) / sizeof(inbox_keys[0]); ++i) { + const gchar *key; + guint bit; + + key = inbox_keys[i]; + bit = inbox_bits[i]; + + if (g_hash_table_lookup(body, key)) { + /* Notify only on when _changes_ from no mail -> has mail + * (edge triggered) */ + if (!(session->inbox_status & bit)) { + purple_debug_info("msim", "msim_check_inbox_cb: got %s, at %d\n", + key ? key : "(NULL)", n); + + subjects[n] = inbox_text[i]; + froms[n] = _("MySpace"); + tos[n] = session->username; + /* TODO: append token, web challenge, so automatically logs in. + * Would also need to free strings because they won't be static + */ + urls[n] = inbox_urls[i]; + + ++n; + } else { + purple_debug_info("msim", + "msim_check_inbox_cb: already notified of %s\n", + key ? key : "(NULL)"); + } + + session->inbox_status |= bit; + } + } + + if (n) { + purple_debug_info("msim", + "msim_check_inbox_cb: notifying of %d\n", n); + + /* TODO: free strings with callback _if_ change to dynamic (w/ token) */ + purple_notify_emails(session->gc, /* handle */ + n, /* count */ + TRUE, /* detailed */ + subjects, froms, tos, urls, + NULL, /* PurpleNotifyCloseCallback cb */ + NULL); /* gpointer user_data */ + + } + + g_hash_table_destroy(body); } /* Send request to check if there is new mail. */ static gboolean msim_check_inbox(gpointer data) { - MsimSession *session; - - session = (MsimSession *)data; - - purple_debug_info("msim", "msim_check_inbox: checking mail\n"); - g_return_val_if_fail(msim_send(session, + MsimSession *session; + + session = (MsimSession *)data; + + purple_debug_info("msim", "msim_check_inbox: checking mail\n"); + g_return_val_if_fail(msim_send(session, "persist", MSIM_TYPE_INTEGER, 1, "sesskey", MSIM_TYPE_INTEGER, session->sesskey, "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_GET, @@ -2323,108 +2322,108 @@ "lid", MSIM_TYPE_INTEGER, MG_CHECK_MAIL_LID, "uid", MSIM_TYPE_INTEGER, session->userid, "rid", MSIM_TYPE_INTEGER, - msim_new_reply_callback(session, msim_check_inbox_cb, NULL), + msim_new_reply_callback(session, msim_check_inbox_cb, NULL), "body", MSIM_TYPE_STRING, g_strdup(""), NULL), TRUE); - /* Always return true, so that we keep checking for mail. */ - return TRUE; + /* Always return true, so that we keep checking for mail. */ + return TRUE; } /** Called when the session key arrives. */ static gboolean msim_we_are_logged_on(MsimSession *session, MsimMessage *msg) { - MsimMessage *body; - - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - purple_connection_update_progress(session->gc, _("Connected"), 3, 4); - purple_connection_set_state(session->gc, PURPLE_CONNECTED); - - session->sesskey = msim_msg_get_integer(msg, "sesskey"); - purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey); - - /* What is proof? Used to be uid, but now is 52 base64'd bytes... */ - - /* Comes with: proof,profileid,userid,uniquenick -- all same values - * some of the time, but can vary. This is our own user ID. */ - session->userid = msim_msg_get_integer(msg, "userid"); - - /* Not sure what profileid is used for. */ - if (msim_msg_get_integer(msg, "profileid") != session->userid) { - msim_unrecognized(session, msg, - "Profile ID didn't match user ID, don't know why"); - } - - /* We now know are our own username, only after we're logged in.. - * which is weird, but happens because you login with your email - * address and not username. Will be freed in msim_session_destroy(). */ - session->username = msim_msg_get_string(msg, "uniquenick"); - - if (msim_msg_get_integer(msg, "uniquenick") == session->userid) { - purple_debug_info("msim_we_are_logged_on", "TODO: pick username"); - } - - body = msim_msg_new(TRUE, - "UserID", MSIM_TYPE_INTEGER, session->userid, - NULL); - - /* Request IM info about ourself. */ - msim_send(session, - "persist", MSIM_TYPE_STRING, g_strdup("persist"), - "sesskey", MSIM_TYPE_INTEGER, session->sesskey, - "dsn", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_DSN, - "uid", MSIM_TYPE_INTEGER, session->userid, - "lid", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_LID, - "rid", MSIM_TYPE_INTEGER, session->next_rid++, - "body", MSIM_TYPE_DICTIONARY, body, - NULL); - - /* Request MySpace info about ourself. */ - msim_send(session, - "persist", MSIM_TYPE_STRING, g_strdup("persist"), - "sesskey", MSIM_TYPE_INTEGER, session->sesskey, - "dsn", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_DSN, - "uid", MSIM_TYPE_INTEGER, session->userid, - "lid", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_LID, - "rid", MSIM_TYPE_INTEGER, session->next_rid++, - "body", MSIM_TYPE_STRING, g_strdup(""), - NULL); - - /* TODO: set options (persist cmd=514,dsn=1,lid=10) */ - /* TODO: set blocklist */ - - /* Notify servers of our current status. */ - purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n"); - msim_set_status(session->account, - purple_account_get_active_status(session->account)); - - /* TODO: setinfo */ - /* - body = msim_msg_new(TRUE, - "TotalFriends", MSIM_TYPE_INTEGER, 666, - NULL); - msim_send(session, - "setinfo", MSIM_TYPE_BOOLEAN, TRUE, - "sesskey", MSIM_TYPE_INTEGER, session->sesskey, - "info", MSIM_TYPE_DICTIONARY, body, - NULL); - */ - - /* Disable due to problems with timeouts. TODO: fix. */ + MsimMessage *body; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + purple_connection_update_progress(session->gc, _("Connected"), 3, 4); + purple_connection_set_state(session->gc, PURPLE_CONNECTED); + + session->sesskey = msim_msg_get_integer(msg, "sesskey"); + purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey); + + /* What is proof? Used to be uid, but now is 52 base64'd bytes... */ + + /* Comes with: proof,profileid,userid,uniquenick -- all same values + * some of the time, but can vary. This is our own user ID. */ + session->userid = msim_msg_get_integer(msg, "userid"); + + /* Not sure what profileid is used for. */ + if (msim_msg_get_integer(msg, "profileid") != session->userid) { + msim_unrecognized(session, msg, + "Profile ID didn't match user ID, don't know why"); + } + + /* We now know are our own username, only after we're logged in.. + * which is weird, but happens because you login with your email + * address and not username. Will be freed in msim_session_destroy(). */ + session->username = msim_msg_get_string(msg, "uniquenick"); + + if (msim_msg_get_integer(msg, "uniquenick") == session->userid) { + purple_debug_info("msim_we_are_logged_on", "TODO: pick username"); + } + + body = msim_msg_new(TRUE, + "UserID", MSIM_TYPE_INTEGER, session->userid, + NULL); + + /* Request IM info about ourself. */ + msim_send(session, + "persist", MSIM_TYPE_STRING, g_strdup("persist"), + "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "dsn", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_DSN, + "uid", MSIM_TYPE_INTEGER, session->userid, + "lid", MSIM_TYPE_INTEGER, MG_OWN_MYSPACE_INFO_LID, + "rid", MSIM_TYPE_INTEGER, session->next_rid++, + "body", MSIM_TYPE_DICTIONARY, body, + NULL); + + /* Request MySpace info about ourself. */ + msim_send(session, + "persist", MSIM_TYPE_STRING, g_strdup("persist"), + "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "dsn", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_DSN, + "uid", MSIM_TYPE_INTEGER, session->userid, + "lid", MSIM_TYPE_INTEGER, MG_OWN_IM_INFO_LID, + "rid", MSIM_TYPE_INTEGER, session->next_rid++, + "body", MSIM_TYPE_STRING, g_strdup(""), + NULL); + + /* TODO: set options (persist cmd=514,dsn=1,lid=10) */ + /* TODO: set blocklist */ + + /* Notify servers of our current status. */ + purple_debug_info("msim", "msim_we_are_logged_on: notifying servers of status\n"); + msim_set_status(session->account, + purple_account_get_active_status(session->account)); + + /* TODO: setinfo */ + /* + body = msim_msg_new(TRUE, + "TotalFriends", MSIM_TYPE_INTEGER, 666, + NULL); + msim_send(session, + "setinfo", MSIM_TYPE_BOOLEAN, TRUE, + "sesskey", MSIM_TYPE_INTEGER, session->sesskey, + "info", MSIM_TYPE_DICTIONARY, body, + NULL); + */ + + /* Disable due to problems with timeouts. TODO: fix. */ #ifdef MSIM_USE_KEEPALIVE - purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, - (GSourceFunc)msim_check_alive, session); + purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, + (GSourceFunc)msim_check_alive, session); #endif - purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK, - (GSourceFunc)msim_check_inbox, session); - - msim_check_inbox(session); - - return TRUE; + purple_timeout_add(MSIM_MAIL_INTERVAL_CHECK, + (GSourceFunc)msim_check_inbox, session); + + msim_check_inbox(session); + + return TRUE; } /** @@ -2438,29 +2437,29 @@ static gboolean msim_process(MsimSession *session, MsimMessage *msg) { - g_return_val_if_fail(session != NULL, FALSE); - g_return_val_if_fail(msg != NULL, FALSE); + g_return_val_if_fail(session != NULL, FALSE); + g_return_val_if_fail(msg != NULL, FALSE); #ifdef MSIM_DEBUG_MSG - msim_msg_dump("ready to process: %s\n", msg); + msim_msg_dump("ready to process: %s\n", msg); #endif - if (msim_msg_get_integer(msg, "lc") == 1) { - return msim_login_challenge(session, msg); - } else if (msim_msg_get_integer(msg, "lc") == 2) { - return msim_we_are_logged_on(session, msg); - } else if (msim_msg_get(msg, "bm")) { - return msim_incoming_bm(session, msg); - } else if (msim_msg_get(msg, "rid")) { - return msim_process_reply(session, msg); - } else if (msim_msg_get(msg, "error")) { - return msim_error(session, msg); - } else if (msim_msg_get(msg, "ka")) { - return TRUE; - } else { + if (msim_msg_get_integer(msg, "lc") == 1) { + return msim_login_challenge(session, msg); + } else if (msim_msg_get_integer(msg, "lc") == 2) { + return msim_we_are_logged_on(session, msg); + } else if (msim_msg_get(msg, "bm")) { + return msim_incoming_bm(session, msg); + } else if (msim_msg_get(msg, "rid")) { + return msim_process_reply(session, msg); + } else if (msim_msg_get(msg, "error")) { + return msim_error(session, msg); + } else if (msim_msg_get(msg, "ka")) { + return TRUE; + } else { msim_unrecognized(session, msg, "in msim_process"); - return FALSE; - } + return FALSE; + } } /** Store an field of information about a buddy. */ @@ -2501,8 +2500,8 @@ PurpleBuddy *buddy; guint rid; - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); rid = msim_msg_get_integer(msg, "rid"); @@ -2519,15 +2518,15 @@ if (!username) { purple_debug_info("msim", "msim_process_reply: not caching body, no UserName\n"); - g_hash_table_destroy(body); + g_hash_table_destroy(body); return FALSE; } uid = g_hash_table_lookup(body, "UserID"); - if (!uid) { - g_hash_table_destroy(body); - g_return_val_if_fail(uid, FALSE); - } + if (!uid) { + g_hash_table_destroy(body); + g_return_val_if_fail(uid, FALSE); + } purple_debug_info("msim", "associating uid %s with username %s\n", uid, username); @@ -2536,17 +2535,17 @@ g_hash_table_foreach(body, msim_store_buddy_info_each, buddy); } - if (msim_msg_get_integer(msg, "dsn") == MG_OWN_IM_INFO_DSN && - msim_msg_get_integer(msg, "lid") == MG_OWN_IM_INFO_LID) { - /* TODO: do something with our own IM info, if we need it for some - * specific purpose. Otherwise it is available on the buddy list, - * if the user has themselves as their own buddy. */ - } else if (msim_msg_get_integer(msg, "dsn") == MG_OWN_MYSPACE_INFO_DSN && - msim_msg_get_integer(msg, "lid") == MG_OWN_MYSPACE_INFO_LID) { - /* TODO: same as above, but for MySpace info. */ - } - - g_hash_table_destroy(body); + if (msim_msg_get_integer(msg, "dsn") == MG_OWN_IM_INFO_DSN && + msim_msg_get_integer(msg, "lid") == MG_OWN_IM_INFO_LID) { + /* TODO: do something with our own IM info, if we need it for some + * specific purpose. Otherwise it is available on the buddy list, + * if the user has themselves as their own buddy. */ + } else if (msim_msg_get_integer(msg, "dsn") == MG_OWN_MYSPACE_INFO_DSN && + msim_msg_get_integer(msg, "lid") == MG_OWN_MYSPACE_INFO_LID) { + /* TODO: same as above, but for MySpace info. */ + } + + g_hash_table_destroy(body); return TRUE; } @@ -2555,16 +2554,16 @@ static gboolean msim_process_server_info(MsimSession *session, MsimMessage *msg) { - gchar *body_str; - GHashTable *body; - - body_str = msim_msg_get_string(msg, "body"); - g_return_val_if_fail(body_str != NULL, FALSE); - body = msim_parse_body(body_str); - g_free(body_str); - g_return_val_if_fail(body != NULL, FALSE); + gchar *body_str; + GHashTable *body; + + body_str = msim_msg_get_string(msg, "body"); + g_return_val_if_fail(body_str != NULL, FALSE); + body = msim_parse_body(body_str); + g_free(body_str); + g_return_val_if_fail(body != NULL, FALSE); - /* Example body: + /* Example body: AdUnitRefreshInterval=10. AlertPollInterval=360. AllowChatRoomEmoticonSharing=False. @@ -2582,25 +2581,25 @@ UseWebChallenge=1. WebTicketGoHome=False - Anything useful? TODO: use what is useful, and use it. + Anything useful? TODO: use what is useful, and use it. */ - purple_debug_info("msim_process_server_info", - "maximum contacts: %s\n", - g_hash_table_lookup(body, "MaxContacts") ? - g_hash_table_lookup(body, "MaxContacts") : "(NULL)"); - - session->server_info = body; - /* session->server_info freed in msim_session_destroy */ - - return TRUE; + purple_debug_info("msim_process_server_info", + "maximum contacts: %s\n", + g_hash_table_lookup(body, "MaxContacts") ? + g_hash_table_lookup(body, "MaxContacts") : "(NULL)"); + + session->server_info = body; + /* session->server_info freed in msim_session_destroy */ + + return TRUE; } /** Process a web challenge, used to login to the web site. */ static gboolean msim_web_challenge(MsimSession *session, MsimMessage *msg) { - /* TODO: web challenge, store token */ - return FALSE; + /* TODO: web challenge, store token */ + return FALSE; } /** @@ -2616,44 +2615,44 @@ static gboolean msim_process_reply(MsimSession *session, MsimMessage *msg) { - MSIM_USER_LOOKUP_CB cb; - gpointer data; - guint rid, cmd, dsn, lid; - - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - msim_store_buddy_info(session, msg); - - rid = msim_msg_get_integer(msg, "rid"); - cmd = msim_msg_get_integer(msg, "cmd"); - dsn = msim_msg_get_integer(msg, "dsn"); - lid = msim_msg_get_integer(msg, "lid"); - - /* Unsolicited messages */ - if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET)) { - if (dsn == MG_SERVER_INFO_DSN && lid == MG_SERVER_INFO_LID) { - return msim_process_server_info(session, msg); - } else if (dsn == MG_WEB_CHALLENGE_DSN && lid == MG_WEB_CHALLENGE_LID) { - return msim_web_challenge(session, msg); - } - } - - /* If a callback is registered for this userid lookup, call it. */ - cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid)); - data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); - - if (cb) { - purple_debug_info("msim", - "msim_process_body: calling callback now\n"); - /* Clone message, so that the callback 'cb' can use it (needs to free it also). */ - cb(session, msim_msg_clone(msg), data); - g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid)); - g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); - } else { - purple_debug_info("msim", - "msim_process_body: no callback for rid %d\n", rid); - } + MSIM_USER_LOOKUP_CB cb; + gpointer data; + guint rid, cmd, dsn, lid; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + msim_store_buddy_info(session, msg); + + rid = msim_msg_get_integer(msg, "rid"); + cmd = msim_msg_get_integer(msg, "cmd"); + dsn = msim_msg_get_integer(msg, "dsn"); + lid = msim_msg_get_integer(msg, "lid"); + + /* Unsolicited messages */ + if (cmd == (MSIM_CMD_BIT_REPLY | MSIM_CMD_GET)) { + if (dsn == MG_SERVER_INFO_DSN && lid == MG_SERVER_INFO_LID) { + return msim_process_server_info(session, msg); + } else if (dsn == MG_WEB_CHALLENGE_DSN && lid == MG_WEB_CHALLENGE_LID) { + return msim_web_challenge(session, msg); + } + } + + /* If a callback is registered for this userid lookup, call it. */ + cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid)); + data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); + + if (cb) { + purple_debug_info("msim", + "msim_process_body: calling callback now\n"); + /* Clone message, so that the callback 'cb' can use it (needs to free it also). */ + cb(session, msim_msg_clone(msg), data); + g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid)); + g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); + } else { + purple_debug_info("msim", + "msim_process_body: no callback for rid %d\n", rid); + } return TRUE; } @@ -2669,32 +2668,32 @@ static gboolean msim_error(MsimSession *session, MsimMessage *msg) { - gchar *errmsg, *full_errmsg; + gchar *errmsg, *full_errmsg; guint err; - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - err = msim_msg_get_integer(msg, "err"); - errmsg = msim_msg_get_string(msg, "errmsg"); - - full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err, + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + err = msim_msg_get_integer(msg, "err"); + errmsg = msim_msg_get_string(msg, "errmsg"); + + full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err, errmsg ? errmsg : "no 'errmsg' given"); g_free(errmsg); - purple_debug_info("msim", "msim_error: %s\n", full_errmsg); - - purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")), - full_errmsg, NULL); + purple_debug_info("msim", "msim_error: %s\n", full_errmsg); + + purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")), + full_errmsg, NULL); /* Destroy session if fatal. */ - if (msim_msg_get(msg, "fatal")) { - purple_debug_info("msim", "fatal error, closing\n"); - purple_connection_error(session->gc, full_errmsg); - } - - return TRUE; + if (msim_msg_get(msg, "fatal")) { + purple_debug_info("msim", "fatal error, closing\n"); + purple_connection_error(session->gc, full_errmsg); + } + + return TRUE; } /** @@ -2708,71 +2707,67 @@ static gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg) { - PurpleBuddyList *blist; - PurpleBuddy *buddy; - //PurpleStatus *status; - //gchar **status_array; - GList *list; - gchar *status_headline; - //gchar *status_str; - //gint i; - gint status_code, purple_status_code; - gchar *username; - - g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); - g_return_val_if_fail(msg != NULL, FALSE); + PurpleBuddyList *blist; + PurpleBuddy *buddy; + GList *list; + gchar *status_headline; + gint status_code, purple_status_code; + gchar *username; + + g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); + g_return_val_if_fail(msg != NULL, FALSE); msim_msg_dump("msim_status msg=%s\n", msg); /* Helpfully looked up by msim_incoming_resolve() for us. */ - username = msim_msg_get_string(msg, "_username"); - g_return_val_if_fail(username != NULL, FALSE); - - { - gchar *ss; - - ss = msim_msg_get_string(msg, "msg"); - purple_debug_info("msim", - "msim_status: updating status for <%s> to <%s>\n", - username, ss ? ss : "(NULL)"); - g_free(ss); - } - - /* Example fields: + username = msim_msg_get_string(msg, "_username"); + g_return_val_if_fail(username != NULL, FALSE); + + { + gchar *ss; + + ss = msim_msg_get_string(msg, "msg"); + purple_debug_info("msim", + "msim_status: updating status for <%s> to <%s>\n", + username, ss ? ss : "(NULL)"); + g_free(ss); + } + + /* Example fields: * |s|0|ss|Offline * |s|1|ss|:-)|ls||ip|0|p|0 */ - list = msim_msg_get_list(msg, "msg"); - - status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE)); + list = msim_msg_get_list(msg, "msg"); + + status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE)); purple_debug_info("msim", "msim_status: %s's status code = %d\n", username, status_code); - status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE); - - blist = purple_get_blist(); - - /* Add buddy if not found */ - buddy = purple_find_buddy(session->account, username); - if (!buddy) { - purple_debug_info("msim", + status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE); + + blist = purple_get_blist(); + + /* Add buddy if not found */ + buddy = purple_find_buddy(session->account, username); + if (!buddy) { + purple_debug_info("msim", "msim_status: making new buddy for %s\n", username); - buddy = purple_buddy_new(session->account, username, NULL); - - purple_blist_add_buddy(buddy, NULL, NULL, NULL); + buddy = purple_buddy_new(session->account, username, NULL); + + purple_blist_add_buddy(buddy, NULL, NULL, NULL); /* All buddies on list should have 'uid' integer associated with them. */ purple_blist_node_set_int(&buddy->node, "UserID", msim_msg_get_integer(msg, "f")); msim_store_buddy_info(session, msg); - } else { - purple_debug_info("msim", "msim_status: found buddy %s\n", username); - } + } else { + purple_debug_info("msim", "msim_status: found buddy %s\n", username); + } purple_blist_node_set_string(&buddy->node, "Headline", status_headline); - /* Set user status */ - switch (status_code) { + /* Set user status */ + switch (status_code) { case MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN: - purple_status_code = PURPLE_STATUS_OFFLINE; + purple_status_code = PURPLE_STATUS_OFFLINE; break; case MSIM_STATUS_CODE_ONLINE: @@ -2783,10 +2778,10 @@ purple_status_code = PURPLE_STATUS_AWAY; break; - case MSIM_STATUS_CODE_IDLE: - /* will be handled below */ - purple_status_code = -1; - break; + case MSIM_STATUS_CODE_IDLE: + /* will be handled below */ + purple_status_code = -1; + break; default: purple_debug_info("msim", "msim_status for %s, unknown status code %d, treating as available\n", @@ -2794,27 +2789,27 @@ purple_status_code = PURPLE_STATUS_AVAILABLE; } - purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL); - - if (status_code == MSIM_STATUS_CODE_IDLE) { - purple_debug_info("msim", "msim_status: got idle: %s\n", username); - purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL)); - } else { - /* All other statuses indicate going back to non-idle. */ - purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL)); - } + purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL); + + if (status_code == MSIM_STATUS_CODE_IDLE) { + purple_debug_info("msim", "msim_status: got idle: %s\n", username); + purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL)); + } else { + /* All other statuses indicate going back to non-idle. */ + purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL)); + } #ifdef MSIM_SEND_CLIENT_VERSION - if (status_code == MSIM_STATUS_CODE_ONLINE) { - /* Secretly whisper to unofficial clients our own version as they come online */ - msim_send_unofficial_client(session, username); - } + if (status_code == MSIM_STATUS_CODE_ONLINE) { + /* Secretly whisper to unofficial clients our own version as they come online */ + msim_send_unofficial_client(session, username); + } #endif g_free(username); - msim_msg_list_free(list); - - return TRUE; + msim_msg_list_free(list); + + return TRUE; } /** Add a buddy to user's buddy list. */ @@ -2823,12 +2818,12 @@ { MsimSession *session; MsimMessage *msg; - MsimMessage *msg_persist; - MsimMessage *body; + MsimMessage *msg_persist; + MsimMessage *body; session = (MsimSession *)gc->proto_data; purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", - buddy->name, (group && group->name) ? group->name : "(no group)"); + buddy->name, (group && group->name) ? group->name : "(no group)"); msg = msim_msg_new(TRUE, "addbuddy", MSIM_TYPE_BOOLEAN, TRUE, @@ -2847,14 +2842,14 @@ /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from * buddy list since Purple adds it locally. */ - body = msim_msg_new(TRUE, - "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"), - "GroupName", MSIM_TYPE_STRING, g_strdup(group->name), - "Position", MSIM_TYPE_INTEGER, 1000, - "Visibility", MSIM_TYPE_INTEGER, 1, - "NickName", MSIM_TYPE_STRING, g_strdup(""), - "NameSelect", MSIM_TYPE_INTEGER, 0, - NULL); + body = msim_msg_new(TRUE, + "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"), + "GroupName", MSIM_TYPE_STRING, g_strdup(group->name), + "Position", MSIM_TYPE_INTEGER, 1000, + "Visibility", MSIM_TYPE_INTEGER, 1, + "NickName", MSIM_TYPE_STRING, g_strdup(""), + "NameSelect", MSIM_TYPE_INTEGER, 0, + NULL); /* TODO: Update blocklist. */ @@ -2868,7 +2863,7 @@ /* TODO: Use msim_new_reply_callback to get rid. */ "rid", MSIM_TYPE_INTEGER, session->next_rid++, "body", MSIM_TYPE_DICTIONARY, body, - NULL); + NULL); if (!msim_postprocess_outgoing(session, msg_persist, buddy->name, "body", NULL)) { @@ -2899,7 +2894,7 @@ static MsimMessage * msim_do_postprocessing(MsimMessage *msg, const gchar *uid_before, const gchar *uid_field_name, guint uid) -{ +{ msim_msg_dump("msim_do_postprocessing msg: %s\n", msg); /* First, check - if the field already exists, replace <uid> within it */ @@ -2908,42 +2903,42 @@ gchar *fmt_string; gchar *uid_str, *new_str; - /* Warning: this is a delicate, but safe, operation */ + /* Warning: this is a delicate, but safe, operation */ elem = msim_msg_get(msg, uid_field_name); - /* Get the packed element, flattening it. This allows <uid> to be - * replaced within nested data structures, since the replacement is done - * on the linear, packed data, not on a complicated data structure. - * - * For example, if the field was originally a dictionary or a list, you - * would have to iterate over all the items in it to see what needs to - * be replaced. But by packing it first, the <uid> marker is easily replaced - * just by a string replacement. - */ - fmt_string = msim_msg_pack_element_data(elem); + /* Get the packed element, flattening it. This allows <uid> to be + * replaced within nested data structures, since the replacement is done + * on the linear, packed data, not on a complicated data structure. + * + * For example, if the field was originally a dictionary or a list, you + * would have to iterate over all the items in it to see what needs to + * be replaced. But by packing it first, the <uid> marker is easily replaced + * just by a string replacement. + */ + fmt_string = msim_msg_pack_element_data(elem); uid_str = g_strdup_printf("%d", uid); new_str = str_replace(fmt_string, "<uid>", uid_str); g_free(uid_str); g_free(fmt_string); - /* Free the old element data */ - msim_msg_free_element_data(elem->data); - - /* Replace it with our new data */ - elem->data = new_str; - elem->type = MSIM_TYPE_RAW; + /* Free the old element data */ + msim_msg_free_element_data(elem->data); + + /* Replace it with our new data */ + elem->data = new_str; + elem->type = MSIM_TYPE_RAW; } else { /* Otherwise, insert new field into outgoing message. */ msg = msim_msg_insert_before(msg, uid_before, uid_field_name, MSIM_TYPE_INTEGER, GUINT_TO_POINTER(uid)); } - msim_msg_dump("msim_postprocess_outgoing_cb: postprocessed msg=%s\n", msg); + msim_msg_dump("msim_postprocess_outgoing_cb: postprocessed msg=%s\n", msg); return msg; -} +} /** Callback for msim_postprocess_outgoing() to add a userid to a message, and send it (once receiving userid). * @@ -2960,7 +2955,7 @@ */ static void msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, - gpointer data) + gpointer data) { gchar *body_str; GHashTable *body; @@ -2997,7 +2992,7 @@ g_free(uid_field_name); g_free(uid_before); - g_hash_table_destroy(body); + g_hash_table_destroy(body); //msim_msg_free(msg); } @@ -3017,11 +3012,11 @@ const gchar *username, const gchar *uid_field_name, const gchar *uid_before) { - PurpleBuddy *buddy; + PurpleBuddy *buddy; guint uid; gboolean rc; - g_return_val_if_fail(msg != NULL, FALSE); + g_return_val_if_fail(msg != NULL, FALSE); /* Store information for msim_postprocess_outgoing_cb(). */ msim_msg_dump("msim_postprocess_outgoing: msg before=%s\n", msg); @@ -3030,9 +3025,9 @@ msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before)); /* First, try the most obvious. If numeric userid is given, use that directly. */ - if (msim_is_userid(username)) { + if (msim_is_userid(username)) { uid = atol(username); - } else { + } else { /* Next, see if on buddy list and know uid. */ buddy = purple_find_buddy(session->account, username); if (buddy) { @@ -3049,7 +3044,7 @@ msim_msg_dump("msim_postprocess_outgoing - scheduling lookup, msg=%s\n", msg); /* TODO: where is cloned message freed? Should be in _cb. */ msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg)); - return TRUE; /* not sure of status yet - haven't sent! */ + return TRUE; /* not sure of status yet - haven't sent! */ } } @@ -3076,7 +3071,7 @@ MsimMessage *delbuddy_msg; MsimMessage *persist_msg; MsimMessage *blocklist_msg; - GList *blocklist_updates; + GList *blocklist_updates; session = (MsimSession *)gc->proto_data; @@ -3088,10 +3083,10 @@ if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL)) { purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed")); - msim_msg_free(delbuddy_msg); + msim_msg_free(delbuddy_msg); return; } - msim_msg_free(delbuddy_msg); + msim_msg_free(delbuddy_msg); persist_msg = msim_msg_new(TRUE, "persist", MSIM_TYPE_INTEGER, 1, @@ -3106,33 +3101,33 @@ NULL); if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL)) { - purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed")); - msim_msg_free(persist_msg); + purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed")); + msim_msg_free(persist_msg); return; } - msim_msg_free(persist_msg); - - blocklist_updates = NULL; - blocklist_updates = g_list_prepend(blocklist_updates, "a-"); - blocklist_updates = g_list_prepend(blocklist_updates, "<uid>"); - blocklist_updates = g_list_prepend(blocklist_updates, "b-"); - blocklist_updates = g_list_prepend(blocklist_updates, "<uid>"); - blocklist_updates = g_list_reverse(blocklist_updates); + msim_msg_free(persist_msg); + + blocklist_updates = NULL; + blocklist_updates = g_list_prepend(blocklist_updates, "a-"); + blocklist_updates = g_list_prepend(blocklist_updates, "<uid>"); + blocklist_updates = g_list_prepend(blocklist_updates, "b-"); + blocklist_updates = g_list_prepend(blocklist_updates, "<uid>"); + blocklist_updates = g_list_reverse(blocklist_updates); blocklist_msg = msim_msg_new(TRUE, "blocklist", MSIM_TYPE_BOOLEAN, TRUE, "sesskey", MSIM_TYPE_INTEGER, session->sesskey, /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */ //"idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"), - "idlist", MSIM_TYPE_LIST, blocklist_updates, + "idlist", MSIM_TYPE_LIST, blocklist_updates, NULL); if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL)) { purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed")); - msim_msg_free(blocklist_msg); + msim_msg_free(blocklist_msg); return; } - msim_msg_free(blocklist_msg); + msim_msg_free(blocklist_msg); } /** Return whether the buddy can be messaged while offline. @@ -3158,120 +3153,120 @@ static void msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond) { - PurpleConnection *gc; - PurpleAccount *account; - MsimSession *session; - gchar *end; - int n; - - g_return_if_fail(gc_uncasted != NULL); - g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ - - gc = (PurpleConnection *)(gc_uncasted); - account = purple_connection_get_account(gc); - session = gc->proto_data; - - g_return_if_fail(cond == PURPLE_INPUT_READ); + PurpleConnection *gc; + PurpleAccount *account; + MsimSession *session; + gchar *end; + int n; + + g_return_if_fail(gc_uncasted != NULL); + g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ + + gc = (PurpleConnection *)(gc_uncasted); + account = purple_connection_get_account(gc); + session = gc->proto_data; + + g_return_if_fail(cond == PURPLE_INPUT_READ); g_return_if_fail(MSIM_SESSION_VALID(session)); - /* Mark down that we got data, so don't timeout. */ - session->last_comm = time(NULL); - - /* Only can handle so much data at once... - * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE. - * Should be large enough to hold the largest protocol message. - */ - if (session->rxoff >= MSIM_READ_BUF_SIZE) { - purple_debug_error("msim", - "msim_input_cb: %d-byte read buffer full! rxoff=%d\n", - MSIM_READ_BUF_SIZE, session->rxoff); - purple_connection_error(gc, _("Read buffer full")); - return; - } - - purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n", - session->rxoff, MSIM_READ_BUF_SIZE, + /* Mark down that we got data, so don't timeout. */ + session->last_comm = time(NULL); + + /* Only can handle so much data at once... + * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE. + * Should be large enough to hold the largest protocol message. + */ + if (session->rxoff >= MSIM_READ_BUF_SIZE) { + purple_debug_error("msim", + "msim_input_cb: %d-byte read buffer full! rxoff=%d\n", + MSIM_READ_BUF_SIZE, session->rxoff); + purple_connection_error(gc, _("Read buffer full")); + return; + } + + purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n", + session->rxoff, MSIM_READ_BUF_SIZE, MSIM_READ_BUF_SIZE - session->rxoff); - /* Read into buffer. On Win32, need recv() not read(). session->fd also holds - * the file descriptor, but it sometimes differs from the 'source' parameter. - */ - n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0); - - if (n < 0 && errno == EAGAIN) { - return; - } else if (n < 0) { - purple_debug_error("msim", "msim_input_cb: read error, ret=%d, " + /* Read into buffer. On Win32, need recv() not read(). session->fd also holds + * the file descriptor, but it sometimes differs from the 'source' parameter. + */ + n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0); + + if (n < 0 && errno == EAGAIN) { + return; + } else if (n < 0) { + purple_debug_error("msim", "msim_input_cb: read error, ret=%d, " "error=%s, source=%d, fd=%d (%X))\n", n, strerror(errno), source, session->fd, session->fd); - purple_connection_error(gc, _("Read error")); - return; - } else if (n == 0) { - purple_debug_info("msim", "msim_input_cb: server disconnected\n"); - purple_connection_error(gc, _("Server has disconnected")); - return; - } - - if (n + session->rxoff >= MSIM_READ_BUF_SIZE) { - purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n", - n, n + session->rxoff, MSIM_READ_BUF_SIZE); - /* TODO: g_realloc like msn, yahoo, irc, jabber? */ - purple_connection_error(gc, _("Read buffer full")); - } - - /* Null terminate */ - purple_debug_info("msim", "msim_input_cb: going to null terminate " - "at n=%d\n", n); - session->rxbuf[session->rxoff + n] = 0; + purple_connection_error(gc, _("Read error")); + return; + } else if (n == 0) { + purple_debug_info("msim", "msim_input_cb: server disconnected\n"); + purple_connection_error(gc, _("Server has disconnected")); + return; + } + + if (n + session->rxoff >= MSIM_READ_BUF_SIZE) { + purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n", + n, n + session->rxoff, MSIM_READ_BUF_SIZE); + /* TODO: g_realloc like msn, yahoo, irc, jabber? */ + purple_connection_error(gc, _("Read buffer full")); + } + + /* Null terminate */ + purple_debug_info("msim", "msim_input_cb: going to null terminate " + "at n=%d\n", n); + session->rxbuf[session->rxoff + n] = 0; #ifdef MSIM_CHECK_EMBEDDED_NULLS - /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */ - if (strlen(session->rxbuf + session->rxoff) != n) { - /* Occurs after login, but it is not a null byte. */ - purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes" - "--null byte encountered?\n", + /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */ + if (strlen(session->rxbuf + session->rxoff) != n) { + /* Occurs after login, but it is not a null byte. */ + 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(gc, "Invalid message - null byte on input"); - return; - } + //purple_connection_error(gc, "Invalid message - null byte on input"); + return; + } #endif - session->rxoff += n; - purple_debug_info("msim", "msim_input_cb: read=%d\n", n); + session->rxoff += n; + purple_debug_info("msim", "msim_input_cb: read=%d\n", n); #ifdef MSIM_DEBUG_RXBUF - purple_debug_info("msim", "buf=<%s>\n", session->rxbuf); + purple_debug_info("msim", "buf=<%s>\n", session->rxbuf); #endif - /* Look for \\final\\ end markers. If found, process message. */ - while((end = strstr(session->rxbuf, MSIM_FINAL_STRING))) { - MsimMessage *msg; + /* Look for \\final\\ end markers. If found, process message. */ + while((end = strstr(session->rxbuf, MSIM_FINAL_STRING))) { + MsimMessage *msg; #ifdef MSIM_DEBUG_RXBUF - purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf); + purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf); #endif - *end = 0; - msg = msim_parse(g_strdup(session->rxbuf)); - if (!msg) { - purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n"); - purple_connection_error(gc, _("Unparseable message")); - } else { - /* Process message and then free it (processing function should + *end = 0; + msg = msim_parse(g_strdup(session->rxbuf)); + if (!msg) { + purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n"); + purple_connection_error(gc, _("Unparseable message")); + } else { + /* Process message and then free it (processing function should * clone message if it wants to keep it afterwards.) */ - if (!msim_preprocess_incoming(session, msg)) { + if (!msim_preprocess_incoming(session, msg)) { msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg); } msim_msg_free(msg); - } - - /* Move remaining part of buffer to beginning. */ - session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING); - memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING), - MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf)); - - /* Clear end of buffer */ - //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf)); - } + } + + /* Move remaining part of buffer to beginning. */ + session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING); + memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING), + MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf)); + + /* Clear end of buffer */ + //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf)); + } } /* Setup a callback, to be called when a reply is received with the returned rid. @@ -3280,7 +3275,7 @@ * @param data Arbitrary user data to be passed to callback (probably an MsimMessage *). * * @return The request/reply ID, used to link replies with requests, or -1. - * Put the rid in your request, 'rid' field. + * Put the rid in your request, 'rid' field. * * TODO: Make more generic and more specific: * 1) MSIM_USER_LOOKUP_CB - make it for PERSIST_REPLY, not just user lookup @@ -3292,12 +3287,12 @@ { guint rid; - g_return_val_if_fail(MSIM_SESSION_VALID(session), -1); + g_return_val_if_fail(MSIM_SESSION_VALID(session), -1); rid = session->next_rid++; - g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb); - g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data); + g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb); + g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data); return rid; } @@ -3312,26 +3307,26 @@ static void msim_connect_cb(gpointer data, gint source, const gchar *error_message) { - PurpleConnection *gc; - MsimSession *session; - - g_return_if_fail(data != NULL); - - gc = (PurpleConnection *)data; - session = (MsimSession *)gc->proto_data; - - if (source < 0) { - purple_connection_error(gc, _("Couldn't connect to host")); - purple_connection_error(gc, g_strdup_printf( + PurpleConnection *gc; + MsimSession *session; + + g_return_if_fail(data != NULL); + + gc = (PurpleConnection *)data; + session = (MsimSession *)gc->proto_data; + + if (source < 0) { + purple_connection_error(gc, _("Couldn't connect to host")); + purple_connection_error(gc, g_strdup_printf( _("Couldn't connect to host: %s (%d)"), - error_message ? error_message : "no message given", + error_message ? error_message : "no message given", source)); - return; - } - - session->fd = source; - - gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc); + return; + } + + session->fd = source; + + gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc); } /* Session methods */ @@ -3346,39 +3341,39 @@ MsimSession * msim_session_new(PurpleAccount *acct) { - MsimSession *session; - - g_return_val_if_fail(acct != NULL, NULL); - - session = g_new0(MsimSession, 1); - - session->magic = MSIM_SESSION_STRUCT_MAGIC; - session->account = acct; - session->gc = purple_account_get_connection(acct); + MsimSession *session; + + g_return_val_if_fail(acct != NULL, NULL); + + session = g_new0(MsimSession, 1); + + session->magic = MSIM_SESSION_STRUCT_MAGIC; + session->account = acct; + session->gc = purple_account_get_connection(acct); session->sesskey = 0; session->userid = 0; session->username = NULL; - session->fd = -1; + session->fd = -1; /* TODO: Remove. */ - session->user_lookup_cb = g_hash_table_new_full(g_direct_hash, + session->user_lookup_cb = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */ - session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, + session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are, they could be integers inside gpointers or strings, so I don't freed them. Figure this out, once free cache. */ - /* Created in msim_process_server_info() */ - session->server_info = NULL; - - session->rxoff = 0; - session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE); + /* Created in msim_process_server_info() */ + session->server_info = NULL; + + session->rxoff = 0; + session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE); session->next_rid = 1; - session->last_comm = time(NULL); - session->inbox_status = 0; - - return session; + session->last_comm = time(NULL); + session->inbox_status = 0; + + return session; } /** @@ -3389,24 +3384,24 @@ void msim_session_destroy(MsimSession *session) { - g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(MSIM_SESSION_VALID(session)); - session->magic = -1; - - g_free(session->rxbuf); + session->magic = -1; + + g_free(session->rxbuf); g_free(session->username); /* TODO: Remove. */ g_hash_table_destroy(session->user_lookup_cb); g_hash_table_destroy(session->user_lookup_cb_data); - if (session->server_info) { - g_hash_table_destroy(session->server_info); - } + if (session->server_info) { + g_hash_table_destroy(session->server_info); + } - g_free(session); + g_free(session); } - + /** * Close the connection. * @@ -3419,7 +3414,7 @@ if (gc == NULL) { return; - } + } session = (MsimSession *)gc->proto_data; if (session == NULL) @@ -3429,13 +3424,13 @@ if (!MSIM_SESSION_VALID(session)) { return; - } - - if (session->gc->inpa) { + } + + if (session->gc->inpa) { purple_input_remove(session->gc->inpa); - } - - msim_session_destroy(session); + } + + msim_session_destroy(session); } @@ -3449,9 +3444,9 @@ static gboolean msim_is_userid(const gchar *user) { - g_return_val_if_fail(user != NULL, FALSE); - - return strspn(user, "0123456789") == strlen(user); + g_return_val_if_fail(user != NULL, FALSE); + + return strspn(user, "0123456789") == strlen(user); } /** @@ -3469,9 +3464,9 @@ static gboolean msim_is_email(const gchar *user) { - g_return_val_if_fail(user != NULL, FALSE); - - return strchr(user, '@') != NULL; + g_return_val_if_fail(user != NULL, FALSE); + + return strchr(user, '@') != NULL; } @@ -3488,43 +3483,43 @@ msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data) { - MsimMessage *body; - gchar *field_name; - guint rid, cmd, dsn, lid; - - g_return_if_fail(MSIM_SESSION_VALID(session)); - g_return_if_fail(user != NULL); - g_return_if_fail(cb != NULL); - - purple_debug_info("msim", "msim_lookup_userid: " + MsimMessage *body; + gchar *field_name; + guint rid, cmd, dsn, lid; + + g_return_if_fail(MSIM_SESSION_VALID(session)); + g_return_if_fail(user != NULL); + g_return_if_fail(cb != NULL); + + purple_debug_info("msim", "msim_lookup_userid: " "asynchronously looking up <%s>\n", user); msim_msg_dump("msim_lookup_user: data=%s\n", (MsimMessage *)data); - /* Setup callback. Response will be associated with request using 'rid'. */ - rid = msim_new_reply_callback(session, cb, data); - - /* Send request */ - - cmd = MSIM_CMD_GET; - - if (msim_is_userid(user)) { - field_name = "UserID"; - dsn = MG_MYSPACE_INFO_BY_ID_DSN; - lid = MG_MYSPACE_INFO_BY_ID_LID; - } else if (msim_is_email(user)) { - field_name = "Email"; - dsn = MG_MYSPACE_INFO_BY_STRING_DSN; - lid = MG_MYSPACE_INFO_BY_STRING_LID; - } else { - field_name = "UserName"; - dsn = MG_MYSPACE_INFO_BY_STRING_DSN; - lid = MG_MYSPACE_INFO_BY_STRING_LID; - } - - body = msim_msg_new(TRUE, - field_name, MSIM_TYPE_STRING, g_strdup(user), - NULL); + /* Setup callback. Response will be associated with request using 'rid'. */ + rid = msim_new_reply_callback(session, cb, data); + + /* Send request */ + + cmd = MSIM_CMD_GET; + + if (msim_is_userid(user)) { + field_name = "UserID"; + dsn = MG_MYSPACE_INFO_BY_ID_DSN; + lid = MG_MYSPACE_INFO_BY_ID_LID; + } else if (msim_is_email(user)) { + field_name = "Email"; + dsn = MG_MYSPACE_INFO_BY_STRING_DSN; + lid = MG_MYSPACE_INFO_BY_STRING_LID; + } else { + field_name = "UserName"; + dsn = MG_MYSPACE_INFO_BY_STRING_DSN; + lid = MG_MYSPACE_INFO_BY_STRING_LID; + } + + body = msim_msg_new(TRUE, + field_name, MSIM_TYPE_STRING, g_strdup(user), + NULL); g_return_if_fail(msim_send(session, "persist", MSIM_TYPE_INTEGER, 1, @@ -3550,22 +3545,22 @@ char * msim_status_text(PurpleBuddy *buddy) { - MsimSession *session; + MsimSession *session; const gchar *display_name, *headline; - g_return_val_if_fail(buddy != NULL, NULL); - - session = (MsimSession *)buddy->account->gc->proto_data; - g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); + g_return_val_if_fail(buddy != NULL, NULL); + + session = (MsimSession *)buddy->account->gc->proto_data; + g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); display_name = headline = NULL; /* Retrieve display name and/or headline, depending on user preference. */ - if (purple_account_get_bool(session->account, "show_display_name", TRUE)) { + if (purple_account_get_bool(session->account, "show_display_name", TRUE)) { display_name = purple_blist_node_get_string(&buddy->node, "DisplayName"); } - if (purple_account_get_bool(session->account, "show_headline", FALSE)) { + if (purple_account_get_bool(session->account, "show_headline", FALSE)) { headline = purple_blist_node_get_string(&buddy->node, "Headline"); } @@ -3573,15 +3568,15 @@ if (display_name && headline) { return g_strconcat(display_name, " ", headline, NULL); - } + } if (display_name) { return g_strdup(display_name); - } + } if (headline) { return g_strdup(headline); - } + } return NULL; } @@ -3601,201 +3596,201 @@ const gchar *str, *str2; gint n; - g_return_if_fail(buddy != NULL); - g_return_if_fail(user_info != NULL); - - if (PURPLE_BUDDY_IS_ONLINE(buddy)) { - MsimSession *session; - - session = (MsimSession *)buddy->account->gc->proto_data; - - g_return_if_fail(MSIM_SESSION_VALID(session)); - - /* TODO: if (full), do something different */ + g_return_if_fail(buddy != NULL); + g_return_if_fail(user_info != NULL); + + if (PURPLE_BUDDY_IS_ONLINE(buddy)) { + MsimSession *session; + + session = (MsimSession *)buddy->account->gc->proto_data; + + g_return_if_fail(MSIM_SESSION_VALID(session)); + + /* TODO: if (full), do something different */ /* Useful to identify the account the tooltip refers to. * Other prpls show this. */ str = purple_blist_node_get_string(&buddy->node, "UserName"); if (str) { purple_notify_user_info_add_pair(user_info, _("User Name"), str); - } - - /* a/s/l...the vitals */ + } + + /* a/s/l...the vitals */ n = purple_blist_node_get_int(&buddy->node, "Age"); if (n) { purple_notify_user_info_add_pair(user_info, _("Age"), g_strdup_printf("%d", n)); - } + } str = purple_blist_node_get_string(&buddy->node, "Gender"); if (str) { purple_notify_user_info_add_pair(user_info, _("Gender"), str); - } + } str = purple_blist_node_get_string(&buddy->node, "Location"); if (str) { purple_notify_user_info_add_pair(user_info, _("Location"), str); - } + } /* Other information */ - str = purple_blist_node_get_string(&buddy->node, "Headline"); + str = purple_blist_node_get_string(&buddy->node, "Headline"); if (str) { purple_notify_user_info_add_pair(user_info, _("Headline"), str); - } + } str = purple_blist_node_get_string(&buddy->node, "BandName"); str2 = purple_blist_node_get_string(&buddy->node, "SongName"); if (str || str2) { purple_notify_user_info_add_pair(user_info, _("Song"), - g_strdup_printf("%s - %s", + g_strdup_printf("%s - %s", str ? str : _("Unknown Artist"), str2 ? str2 : _("Unknown Song"))); - } + } n = purple_blist_node_get_int(&buddy->node, "TotalFriends"); if (n) { purple_notify_user_info_add_pair(user_info, _("Total Friends"), g_strdup_printf("%d", n)); - } - - } + } + + } } /** Actions menu for account. */ GList * msim_actions(PurplePlugin *plugin, gpointer context) { - PurpleConnection *gc; - GList *menu; - //PurplePluginAction *act; - - gc = (PurpleConnection *)context; - - menu = NULL; + PurpleConnection *gc; + GList *menu; + //PurplePluginAction *act; + + gc = (PurpleConnection *)context; + + menu = NULL; #if 0 - /* TODO: find out how */ - act = purple_plugin_action_new(_("Find people..."), msim_); - menu = g_list_append(menu, act); - - act = purple_plugin_action_new(_("Import friends..."), NULL); - menu = g_list_append(menu, act); - - act = purple_plugin_action_new(_("Change IM name..."), NULL); - menu = g_list_append(menu, act); + /* TODO: find out how */ + act = purple_plugin_action_new(_("Find people..."), msim_); + menu = g_list_append(menu, act); + + act = purple_plugin_action_new(_("Import friends..."), NULL); + menu = g_list_append(menu, act); + + act = purple_plugin_action_new(_("Change IM name..."), NULL); + menu = g_list_append(menu, act); #endif - return menu; + return menu; } /** Callbacks called by Purple, to access this plugin. */ PurplePluginProtocolInfo prpl_info = { /* options */ - OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */ + OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */ | OPT_PROTO_MAIL_CHECK, - /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */ - NULL, /* user_splits */ - NULL, /* protocol_options */ - NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */ - msim_list_icon, /* list_icon */ - NULL, /* list_emblems */ - msim_status_text, /* status_text */ - msim_tooltip_text, /* tooltip_text */ - msim_status_types, /* status_types */ - msim_blist_node_menu, /* blist_node_menu */ - NULL, /* chat_info */ - NULL, /* chat_info_defaults */ - msim_login, /* login */ - msim_close, /* close */ - msim_send_im, /* send_im */ - NULL, /* set_info */ - msim_send_typing, /* send_typing */ - msim_get_info, /* get_info */ - msim_set_status, /* set_status */ - msim_set_idle, /* set_idle */ - NULL, /* change_passwd */ - msim_add_buddy, /* add_buddy */ - NULL, /* add_buddies */ - msim_remove_buddy, /* remove_buddy */ - NULL, /* remove_buddies */ - NULL, /* add_permit */ - NULL, /* add_deny */ - NULL, /* rem_permit */ - NULL, /* rem_deny */ - NULL, /* set_permit_deny */ - NULL, /* join_chat */ - NULL, /* reject chat invite */ - NULL, /* get_chat_name */ - NULL, /* chat_invite */ - NULL, /* chat_leave */ - NULL, /* chat_whisper */ - NULL, /* chat_send */ - NULL, /* keepalive */ - NULL, /* register_user */ - NULL, /* get_cb_info */ - NULL, /* get_cb_away */ - NULL, /* alias_buddy */ - NULL, /* group_buddy */ - NULL, /* rename_group */ - NULL, /* buddy_free */ - NULL, /* convo_closed */ - NULL, /* normalize */ - NULL, /* set_buddy_icon */ - NULL, /* remove_group */ - NULL, /* get_cb_real_name */ - NULL, /* set_chat_topic */ - NULL, /* find_blist_chat */ - NULL, /* roomlist_get_list */ - NULL, /* roomlist_cancel */ - NULL, /* roomlist_expand_category */ - NULL, /* can_receive_file */ - NULL, /* send_file */ - NULL, /* new_xfer */ - msim_offline_message, /* offline_message */ - NULL, /* whiteboard_prpl_ops */ - msim_send_really_raw, /* send_raw */ - NULL, /* roomlist_room_serialize */ - NULL, /* _purple_reserved1 */ - NULL, /* _purple_reserved2 */ - NULL, /* _purple_reserved3 */ - NULL /* _purple_reserved4 */ + /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */ + NULL, /* user_splits */ + NULL, /* protocol_options */ + NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */ + msim_list_icon, /* list_icon */ + NULL, /* list_emblems */ + msim_status_text, /* status_text */ + msim_tooltip_text, /* tooltip_text */ + msim_status_types, /* status_types */ + msim_blist_node_menu, /* blist_node_menu */ + NULL, /* chat_info */ + NULL, /* chat_info_defaults */ + msim_login, /* login */ + msim_close, /* close */ + msim_send_im, /* send_im */ + NULL, /* set_info */ + msim_send_typing, /* send_typing */ + msim_get_info, /* get_info */ + msim_set_status, /* set_status */ + msim_set_idle, /* set_idle */ + NULL, /* change_passwd */ + msim_add_buddy, /* add_buddy */ + NULL, /* add_buddies */ + msim_remove_buddy, /* remove_buddy */ + NULL, /* remove_buddies */ + NULL, /* add_permit */ + NULL, /* add_deny */ + NULL, /* rem_permit */ + NULL, /* rem_deny */ + NULL, /* set_permit_deny */ + NULL, /* join_chat */ + NULL, /* reject chat invite */ + NULL, /* get_chat_name */ + NULL, /* chat_invite */ + NULL, /* chat_leave */ + NULL, /* chat_whisper */ + NULL, /* chat_send */ + NULL, /* keepalive */ + NULL, /* register_user */ + NULL, /* get_cb_info */ + NULL, /* get_cb_away */ + NULL, /* alias_buddy */ + NULL, /* group_buddy */ + NULL, /* rename_group */ + NULL, /* buddy_free */ + NULL, /* convo_closed */ + NULL, /* normalize */ + NULL, /* set_buddy_icon */ + NULL, /* remove_group */ + NULL, /* get_cb_real_name */ + NULL, /* set_chat_topic */ + NULL, /* find_blist_chat */ + NULL, /* roomlist_get_list */ + NULL, /* roomlist_cancel */ + NULL, /* roomlist_expand_category */ + NULL, /* can_receive_file */ + NULL, /* send_file */ + NULL, /* new_xfer */ + msim_offline_message, /* offline_message */ + NULL, /* whiteboard_prpl_ops */ + msim_send_really_raw, /* send_raw */ + NULL, /* roomlist_room_serialize */ + NULL, /* _purple_reserved1 */ + NULL, /* _purple_reserved2 */ + NULL, /* _purple_reserved3 */ + NULL /* _purple_reserved4 */ }; /** Based on MSN's plugin info comments. */ PurplePluginInfo info = { - PURPLE_PLUGIN_MAGIC, - PURPLE_MAJOR_VERSION, - PURPLE_MINOR_VERSION, - PURPLE_PLUGIN_PROTOCOL, /**< type */ - NULL, /**< ui_requirement */ - 0, /**< flags */ - NULL, /**< dependencies */ - PURPLE_PRIORITY_DEFAULT, /**< priority */ - - "prpl-myspace", /**< id */ - "MySpaceIM", /**< name */ - MSIM_PRPL_VERSION_STRING, /**< version */ - /** summary */ - "MySpaceIM Protocol Plugin", - /** description */ - "MySpaceIM Protocol Plugin", - "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */ - "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */ - - msim_load, /**< load */ - NULL, /**< unload */ - NULL, /**< destroy */ - NULL, /**< ui_info */ - &prpl_info, /**< extra_info */ - NULL, /**< prefs_info */ - msim_actions, /**< msim_actions */ - NULL, /**< reserved1 */ - NULL, /**< reserved2 */ - NULL, /**< reserved3 */ - NULL /**< reserved4 */ + PURPLE_PLUGIN_MAGIC, + PURPLE_MAJOR_VERSION, + PURPLE_MINOR_VERSION, + PURPLE_PLUGIN_PROTOCOL, /**< type */ + NULL, /**< ui_requirement */ + 0, /**< flags */ + NULL, /**< dependencies */ + PURPLE_PRIORITY_DEFAULT, /**< priority */ + + "prpl-myspace", /**< id */ + "MySpaceIM", /**< name */ + MSIM_PRPL_VERSION_STRING, /**< version */ + /** summary */ + "MySpaceIM Protocol Plugin", + /** description */ + "MySpaceIM Protocol Plugin", + "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */ + "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */ + + msim_load, /**< load */ + NULL, /**< unload */ + NULL, /**< destroy */ + NULL, /**< ui_info */ + &prpl_info, /**< extra_info */ + NULL, /**< prefs_info */ + msim_actions, /**< msim_actions */ + NULL, /**< reserved1 */ + NULL, /**< reserved2 */ + NULL, /**< reserved3 */ + NULL /**< reserved4 */ }; @@ -3827,14 +3822,14 @@ msim_test_msg(void) { MsimMessage *msg, *msg_cloned, *msg2; - GList *list; + GList *list; gchar *packed, *packed_expected, *packed_cloned; guint failures; failures = 0; purple_debug_info("msim", "\n\nTesting MsimMessage\n"); - msg = msim_msg_new(FALSE); /* Create a new, empty message. */ + msg = msim_msg_new(FALSE); /* Create a new, empty message. */ /* Append some new elements. */ msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3)); @@ -3871,31 +3866,31 @@ msim_msg_free(msg_cloned); msim_msg_free(msg); - /* Try some of the more advanced functionality */ - list = NULL; - - list = g_list_prepend(list, "item3"); - list = g_list_prepend(list, "item2"); - list = g_list_prepend(list, "item1"); - list = g_list_prepend(list, "item0"); - - msg = msim_msg_new(FALSE); - msg = msim_msg_append(msg, "string", MSIM_TYPE_STRING, g_strdup("string value")); - msg = msim_msg_append(msg, "raw", MSIM_TYPE_RAW, g_strdup("raw value")); - msg = msim_msg_append(msg, "integer", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(3140)); - msg = msim_msg_append(msg, "boolean", MSIM_TYPE_BOOLEAN, GUINT_TO_POINTER(FALSE)); - msg = msim_msg_append(msg, "list", MSIM_TYPE_LIST, list); - - msim_msg_dump("msg with list=%s\n", msg); - purple_debug_info("msim", "msg with list packed=%s\n", msim_msg_pack(msg)); - - msg2 = msim_msg_new(FALSE); - msg2 = msim_msg_append(msg2, "outer", MSIM_TYPE_STRING, g_strdup("outer value")); - msg2 = msim_msg_append(msg2, "body", MSIM_TYPE_DICTIONARY, msg); - msim_msg_dump("msg with dict=%s\n", msg2); /* msg2 now 'owns' msg */ - purple_debug_info("msim", "msg with dict packed=%s\n", msim_msg_pack(msg2)); - - msim_msg_free(msg2); + /* Try some of the more advanced functionality */ + list = NULL; + + list = g_list_prepend(list, "item3"); + list = g_list_prepend(list, "item2"); + list = g_list_prepend(list, "item1"); + list = g_list_prepend(list, "item0"); + + msg = msim_msg_new(FALSE); + msg = msim_msg_append(msg, "string", MSIM_TYPE_STRING, g_strdup("string value")); + msg = msim_msg_append(msg, "raw", MSIM_TYPE_RAW, g_strdup("raw value")); + msg = msim_msg_append(msg, "integer", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(3140)); + msg = msim_msg_append(msg, "boolean", MSIM_TYPE_BOOLEAN, GUINT_TO_POINTER(FALSE)); + msg = msim_msg_append(msg, "list", MSIM_TYPE_LIST, list); + + msim_msg_dump("msg with list=%s\n", msg); + purple_debug_info("msim", "msg with list packed=%s\n", msim_msg_pack(msg)); + + msg2 = msim_msg_new(FALSE); + msg2 = msim_msg_append(msg2, "outer", MSIM_TYPE_STRING, g_strdup("outer value")); + msg2 = msim_msg_append(msg2, "body", MSIM_TYPE_DICTIONARY, msg); + msim_msg_dump("msg with dict=%s\n", msg2); /* msg2 now 'owns' msg */ + purple_debug_info("msim", "msg with dict packed=%s\n", msim_msg_pack(msg2)); + + msim_msg_free(msg2); return failures; } @@ -3928,7 +3923,7 @@ if (0 != strcmp(raw, unescaped)) { purple_debug_info("msim", "!!!(%d), msim_unescape failed: %s != %s\n", ++failures, raw, unescaped); - } + } return failures; } @@ -3957,14 +3952,14 @@ option = purple_account_option_bool_new(_("Show headline in status text"), "show_headline", TRUE); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); - option = purple_account_option_bool_new(_("Send emoticons"), "emoticons", FALSE); + option = purple_account_option_bool_new(_("Send emoticons"), "emoticons", FALSE); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); #ifdef MSIM_USER_REALLY_CARES_ABOUT_PRECISE_FONT_SIZES - option = purple_account_option_int_new(_("Screen resolution (dots per inch)"), "dpi", MSIM_DEFAULT_DPI); + option = purple_account_option_int_new(_("Screen resolution (dots per inch)"), "dpi", MSIM_DEFAULT_DPI); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); - option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE); + option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); #endif }