diff libpurple/protocols/jabber/presence.c @ 25743:6d6e10476c52

Clean up jabber_presence_send * Split out a version that acts as part of the prpl_info struct from one called internally Fix jabber_caps_broadcast_change * "prpl-jabber" * Don't leak memory * Send a full presence stanza
author Paul Aurich <paul@darkrain42.org>
date Fri, 21 Nov 2008 04:18:19 +0000
parents 4040da08a733
children 416ff3d65c16
line wrap: on
line diff
--- a/libpurple/protocols/jabber/presence.c	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/presence.c	Fri Nov 21 04:18:19 2008 +0000
@@ -94,11 +94,31 @@
 	g_free(my_base_jid);
 }
 
-
-void jabber_presence_send(PurpleAccount *account, PurpleStatus *status)
+void jabber_set_status(PurpleAccount *account, PurpleStatus *status)
 {
-	PurpleConnection *gc = NULL;
-	JabberStream *js = NULL;
+	PurpleConnection *gc;
+	JabberStream *js;
+
+	if (!purple_account_is_connected(account))
+		return;
+	
+	if (!purple_status_is_active(status))
+		return;
+
+	if (purple_status_is_exclusive(status) && !purple_status_is_active(status)) {
+		/* An exclusive status can't be deactivated. You should just
+		 * activate some other exclusive status. */
+		return;
+	}
+
+	gc = purple_account_get_connection(account);
+	js = gc->proto_data;
+	jabber_presence_send(js, FALSE);
+}
+
+void jabber_presence_send(JabberStream *js, gboolean force)
+{
+	PurpleAccount *account;
 	xmlnode *presence, *x, *photo;
 	char *stripped = NULL;
 	JabberBuddyState state;
@@ -107,28 +127,11 @@
 	int length = -1;
 	gboolean allowBuzz;
 	PurplePresence *p;
-	PurpleStatus *tune;
-
-	if (purple_account_is_disconnected(account))
-		return;
-
-	p = purple_account_get_presence(account);
-	if (NULL == status) {
-		status = purple_presence_get_active_status(p);
-	}
+	PurpleStatus *status, *tune;
 
-	if (purple_status_is_exclusive(status)) {
-		/* An exclusive status can't be deactivated. You should just
-		 * activate some other exclusive status. */
-		if (!purple_status_is_active(status))
-			return;
-	} else {
-		/* Work with the exclusive status. */
-		status = purple_presence_get_active_status(p);
-	}
-
-	gc = purple_account_get_connection(account);
-	js = gc->proto_data;
+	account = purple_connection_get_account(js->gc);
+	p = purple_account_get_presence(account);
+	status = purple_presence_get_active_status(p);
 
 	/* we don't want to send presence before we've gotten our roster */
 	if(!js->roster_parsed) {
@@ -142,16 +145,18 @@
 	allowBuzz = purple_status_get_attr_boolean(status,"buzz");
 	/* changing the buzz state has to trigger a re-broadcasting of the presence for caps */
 
-	if (js->googletalk && stripped == NULL && purple_presence_is_status_primitive_active(p, PURPLE_STATUS_TUNE)) {
-		tune = purple_presence_get_status(p, "tune");
+	tune = purple_presence_get_status(p, "tune");
+	if (js->googletalk && !stripped && purple_status_is_active(tune)) {
 		stripped = jabber_google_presence_outgoing(tune);
 	}
 	
 #define CHANGED(a,b) ((!a && b) || (a && a[0] == '\0' && b && b[0] != '\0') || \
 					  (a && !b) || (a && a[0] != '\0' && b && b[0] == '\0') || (a && b && strcmp(a,b)))
 	/* check if there are any differences to the <presence> and send them in that case */
-	if (allowBuzz != js->allowBuzz || js->old_state != state || CHANGED(js->old_msg, stripped) ||
-		js->old_priority != priority || CHANGED(js->old_avatarhash, js->avatar_hash)) {
+	if (force || allowBuzz != js->allowBuzz || js->old_state != state ||
+		CHANGED(js->old_msg, stripped) || js->old_priority != priority ||
+		CHANGED(js->old_avatarhash, js->avatar_hash)) {
+		/* Need to update allowBuzz before creating the presence (with caps) */
 		js->allowBuzz = allowBuzz;
 
 		presence = jabber_presence_create_js(js, state, stripped, priority);
@@ -182,8 +187,7 @@
 	g_free(stripped);
 
 	/* next, check if there are any changes to the tune values */
-	tune = purple_presence_get_status(p, "tune");
-	if (tune && purple_status_is_active(tune)) {
+	if (purple_status_is_active(tune)) {
 		artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
 		title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
 		source = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);