changeset 17364:e64bcff3b674

Transition msim_incoming_im() to the callbackless infrastructure. Remove msim_incoming_im_cb(), instead relying on the _username field provided by preprocessing in msim_preprocess_incoming().
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Tue, 05 Jun 2007 02:42:46 +0000
parents 3a02e7db91c7
children 1277a0f82304
files libpurple/protocols/myspace/myspace.c libpurple/protocols/myspace/myspace.h
diffstat 2 files changed, 11 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/myspace.c	Tue Jun 05 02:36:17 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Tue Jun 05 02:42:46 2007 +0000
@@ -690,63 +690,27 @@
 } 
 
 /**
- * Callback to handle incoming messages, after resolving userid.
- *
- * @param session 
- * @param userinfo Message from server on user's info, containing UserName.
- * @param data A MsimMessage * of the incoming message, will be freed.
- */
-void msim_incoming_im_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
-{
-    gchar *username, *body_str;
-	MsimMessage *msg;
-    GHashTable *body;
-
-    g_return_if_fail(MSIM_SESSION_VALID(session));
-    g_return_if_fail(userinfo != NULL);
-
-	body_str = msim_msg_get_string(userinfo, "body");
-    body = msim_parse_body(body_str);
-	g_free(body_str);
-	g_return_if_fail(body != NULL);
-
-    username = g_hash_table_lookup(body, "UserName");
-
-    msg = (MsimMessage *)data;
-    serv_got_im(session->gc, username, msim_msg_get_string(msg, "msg"), PURPLE_MESSAGE_RECV, time(NULL));
-
-	/* msim_msg_free(userinfo);   */ /* TODO: Should we? */
-    g_hash_table_destroy(body);
-	/* Free copy cloned in msim_incoming_im(). */
-	msim_msg_free(msg);
-}
-
-/**
  * Handle an incoming instant message.
  *
  * @param session The session
- * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
+ * @param msg Message from the server, containing 'f' (userid from) and 'msg'. 
+ * 			  Should also contain username in _username from preprocessing.
  *
  * @return TRUE if successful.
  */
 gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg)
 {
-    gchar *userid;
+    gchar *username;
 
-    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");
+
+    serv_got_im(session->gc, username, msim_msg_get_string(msg, "msg"), PURPLE_MESSAGE_RECV, time(NULL));
 
-	/* TODO: where freed? */
-    userid = msim_msg_get_string(msg, "f");
-    
-    purple_debug_info("msim", 
-			"msim_incoming_im: got msg from <%s>, resolving username\n", userid);
+	g_free(username);
+	/* TODO: Free copy cloned from msim_incoming_im(). */
+	//msim_msg_free(msg);
 
-	/* TODO: don't use callbacks */
-	/* Cloned msg will be freed in callback */
-    msim_lookup_user(session, userid, msim_incoming_im_cb, msim_msg_clone(msg));
-
-    return TRUE;
+	return TRUE;
 }
 
 /**
@@ -828,8 +792,7 @@
 
 	msim_process(session, msg);
 
-	/* Free copy cloned in msim_preprocess_incoming(). */
-	/* TODO: find out freedom */
+	/* TODO: Free copy cloned from  msim_preprocess_incoming(). */
 	//XXX msim_msg_free(msg);
 	g_hash_table_destroy(body);
 }
--- a/libpurple/protocols/myspace/myspace.h	Tue Jun 05 02:36:17 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.h	Tue Jun 05 02:42:46 2007 +0000
@@ -157,8 +157,6 @@
 int msim_send_im(PurpleConnection *gc, const char *who, const char *message, 
 	PurpleMessageFlags flags);
 void msim_send_im_cb(MsimSession *session, MsimMessage *userinfo, gpointer data);
-void msim_incoming_im_cb(MsimSession *session, MsimMessage *userinfo, 
-		               gpointer data);
 
 int msim_incoming_im(MsimSession *session, MsimMessage *msg);
 int msim_incoming_action(MsimSession *session, MsimMessage *msg);