changeset 18909:c32fcdef2809

Only say we are connected after the MsimSession structure is fully setup. (Also change a few debugging statements to help find this bug.) Previously, purple_connection_set_state(..., PURPLE_CONNECTED) was called too early, so that if a client called any msimprpl functions that operated on MsimSession (pretty much all of them) within the signed-on signal handler, the userid etc., would not yet be correct and the call would fail. Now, the call is called at the right time so it works as expected. Closes #2520.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 12 Aug 2007 18:48:03 +0000
parents 6541b0edee26
children 2115910c5746
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/myspace.c
diffstat 2 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Sun Aug 12 18:20:24 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Sun Aug 12 18:48:03 2007 +0000
@@ -425,7 +425,9 @@
 		return;
 	}
 
+#ifdef MSIM_MSG_DEBUG_FREE
 	msim_msg_dump("msim_msg_free: freeing %s", msg);
+#endif
 
 	g_list_foreach(msg, msim_msg_free_element, NULL);
 	g_list_free(msg);
--- a/libpurple/protocols/myspace/myspace.c	Sun Aug 12 18:20:24 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sun Aug 12 18:48:03 2007 +0000
@@ -2324,9 +2324,6 @@
 	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);
 
@@ -2347,6 +2344,16 @@
 	 * address and not username. Will be freed in msim_session_destroy(). */
 	session->username = msim_msg_get_string(msg, "uniquenick");
 
+	/* The session is now set up, ready to be connected. This emits the
+	 * signedOn signal, so clients can now do anything with msimprpl, and
+	 * we're ready for it (session key, userid, username all setup). */
+	purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
+	purple_connection_set_state(session->gc, PURPLE_CONNECTED);
+
+
+	/* Additional post-connect operations */
+
+
 	if (msim_msg_get_integer(msg, "uniquenick") == session->userid) {
 		purple_debug_info("msim_we_are_logged_on", "TODO: pick username");
 	}
@@ -2670,7 +2677,8 @@
 
 	g_free(errmsg);
 
-	purple_debug_info("msim", "msim_error: %s\n", full_errmsg);
+	purple_debug_info("msim", "msim_error (sesskey=%d): %s\n", 
+			session->sesskey, full_errmsg);
 
 	purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")), 
 			full_errmsg, NULL);
@@ -3154,6 +3162,13 @@
 	account = purple_connection_get_account(gc);
 	session = gc->proto_data;
 
+	/* libpurple/eventloop.h only defines these two */
+	if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) {
+		purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond);
+		purple_connection_error(gc, _("Invalid input condition"));
+		return;
+	}
+
 	g_return_if_fail(cond == PURPLE_INPUT_READ);
 	g_return_if_fail(MSIM_SESSION_VALID(session));