comparison libpurple/protocols/myspace/myspace.c @ 17305:6476a55a9542

msim_status_cb() now takes a MsimMessage *, just like msim_send_im_cb() and msim_incoming_im_cb(). This will ease the transition to a callbackless system.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Mon, 04 Jun 2007 04:06:58 +0000
parents 4a62ba3baa0c
children 3a02e7db91c7
comparison
equal deleted inserted replaced
17304:4a62ba3baa0c 17305:6476a55a9542
991 /** 991 /**
992 * Callback to update incoming status messages, after looked up username. 992 * Callback to update incoming status messages, after looked up username.
993 * 993 *
994 * @param session 994 * @param session
995 * @param userinfo Looked up user information from server. 995 * @param userinfo Looked up user information from server.
996 * @param data gchar * status string, will be freed. 996 * @param data MsimMessage * The status message.
997 * 997 *
998 */ 998 */
999 void msim_status_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) 999 void msim_status_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
1000 { 1000 {
1001 MsimMessage *msg;
1001 PurpleBuddyList *blist; 1002 PurpleBuddyList *blist;
1002 PurpleBuddy *buddy; 1003 PurpleBuddy *buddy;
1003 GHashTable *body; 1004 GHashTable *body;
1004 gchar *body_str; 1005 gchar *body_str;
1005 //PurpleStatus *status; 1006 //PurpleStatus *status;
1011 gchar *username; 1012 gchar *username;
1012 1013
1013 g_return_if_fail(MSIM_SESSION_VALID(session)); 1014 g_return_if_fail(MSIM_SESSION_VALID(session));
1014 g_return_if_fail(userinfo != NULL); 1015 g_return_if_fail(userinfo != NULL);
1015 1016
1016 status_str = (gchar *)data; 1017 msg = (MsimMessage *)data;
1018
1019 status_str = msim_msg_get_string(msg, "msg");
1017 1020
1018 body_str = msim_msg_get_string(userinfo, "body"); 1021 body_str = msim_msg_get_string(userinfo, "body");
1019 body = msim_parse_body(body_str); 1022 body = msim_parse_body(body_str);
1020 g_free(body_str); 1023 g_free(body_str);
1021 g_return_if_fail(body != NULL); 1024 g_return_if_fail(body != NULL);
1087 purple_status_code = PURPLE_STATUS_AVAILABLE; 1090 purple_status_code = PURPLE_STATUS_AVAILABLE;
1088 } 1091 }
1089 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL); 1092 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
1090 1093
1091 g_strfreev(status_array); 1094 g_strfreev(status_array);
1095 g_free(status_str);
1092 g_list_free(list); 1096 g_list_free(list);
1093 g_hash_table_destroy(body); 1097 g_hash_table_destroy(body);
1094 /* msim_msg_free(userinfo); TODO: right? */ 1098 msim_msg_free(msg);
1095 /* Do not free status_str - it will currently be freed by g_hash_table_destroy
1096 * on session->user_lookup_cb_data. But this is questionable (TODO: unask) since
1097 * sometimes user_lookup_cb_data stores integers in gpointers, and sometimes
1098 * real gpointers that need to be freed, like our status_str.
1099 */
1100 /* g_free(status_str); */
1101 } 1099 }
1102 1100
1103 /** 1101 /**
1104 * Process incoming status messages. 1102 * Process incoming status messages.
1105 * 1103 *
1108 * 1106 *
1109 * @return TRUE if successful. 1107 * @return TRUE if successful.
1110 */ 1108 */
1111 gboolean msim_status(MsimSession *session, MsimMessage *msg) 1109 gboolean msim_status(MsimSession *session, MsimMessage *msg)
1112 { 1110 {
1113 gchar *status_str;
1114 gchar *userid; 1111 gchar *userid;
1115 1112
1116 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); 1113 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
1117 g_return_val_if_fail(msg != NULL, FALSE); 1114 g_return_val_if_fail(msg != NULL, FALSE);
1118 1115
1119 /* TODO: free */ 1116 /* TODO: free? */
1120 status_str = msim_msg_get_string(msg, "msg");
1121 g_return_val_if_fail(status_str != NULL, FALSE);
1122
1123 /* TODO: free */
1124 userid = msim_msg_get_string(msg, "f"); 1117 userid = msim_msg_get_string(msg, "f");
1125 g_return_val_if_fail(userid != NULL, FALSE); 1118 g_return_val_if_fail(userid != NULL, FALSE);
1126 1119
1127 /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup 1120 /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup
1128 * before updating the status! Much more efficient. */ 1121 * before updating the status! Much more efficient. */
1129 purple_debug_info("msim", 1122 purple_debug_info("msim",
1130 "msim_status: got status msg <%s> for <%s>, scheduling lookup\n", 1123 "msim_status: got status for <%s>, scheduling lookup\n", userid);
1131 status_str, userid);
1132 1124
1133 /* Actually update status, once username is obtained. 1125 /* Actually update status, once username is obtained.
1134 * status_str() will currently be freed by g_hash_table_destroy() on 1126 * status_str() will currently be freed by g_hash_table_destroy() on
1135 * user_lookup_cb_data (TODO: this is questionable, since it can also 1127 * user_lookup_cb_data (TODO: this is questionable, since it can also
1136 * store gpointers. Fix this, and the 2 other TODOs of the same problem.) 1128 * store gpointers. Fix this, and the 2 other TODOs of the same problem.)
1137 */ 1129 */
1138 /* TODO: don't use callbacks */ 1130 /* TODO: don't use callbacks */
1139 msim_lookup_user(session, userid, msim_status_cb, status_str); 1131 /* callback will free cloned msg */
1132 msim_lookup_user(session, userid, msim_status_cb, msim_msg_clone(msg));
1140 1133
1141 return TRUE; 1134 return TRUE;
1142 } 1135 }
1143 1136
1144 /** Add a buddy to user's buddy list. TODO: make work. Should receive statuses from added buddy. */ 1137 /** Add a buddy to user's buddy list. TODO: make work. Should receive statuses from added buddy. */