changeset 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 6adbaf3d25e3 416ff3d65c16
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/caps.c libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/libxmpp.c libpurple/protocols/jabber/presence.c libpurple/protocols/jabber/presence.h libpurple/protocols/jabber/roster.c
diffstat 7 files changed, 62 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Fri Nov 21 04:18:19 2008 +0000
@@ -493,9 +493,6 @@
 
 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
 {
-	PurplePresence *gpresence;
-	PurpleStatus *status;
-	
 	if(((JabberStream*)gc->proto_data)->pep) {
 		/* XEP-0084: User Avatars */
 		if(img) {
@@ -625,9 +622,7 @@
 	/* publish vCard for those poor older clients */
 	jabber_set_info(gc, purple_account_get_user_info(gc->account));
 
-	gpresence = purple_account_get_presence(gc->account);
-	status = purple_presence_get_active_status(gpresence);
-	jabber_presence_send(gc->account, status);
+	jabber_presence_send(gc->proto_data, FALSE);
 }
 
 /*
--- a/libpurple/protocols/jabber/caps.c	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/caps.c	Fri Nov 21 04:18:19 2008 +0000
@@ -867,16 +867,19 @@
 	return js->caps_hash;
 }
 
-void jabber_caps_broadcast_change() {
-	GList *active_accounts = purple_accounts_get_all_active();
-	for (active_accounts = purple_accounts_get_all_active(); active_accounts; active_accounts = active_accounts->next) {
-		PurpleAccount *account = active_accounts->data;
-		if (!strcmp(account->protocol_id, "jabber")) {
-			PurpleConnection *conn = account->gc;
-			JabberStream *js = conn->proto_data;
-			xmlnode *presence = jabber_presence_create_js(js, JABBER_BUDDY_STATE_UNKNOWN, 0, 0);
-			jabber_send(js, presence);
+void jabber_caps_broadcast_change()
+{
+	GList *node, *accounts = purple_accounts_get_all_active();
+
+	for (node = accounts; node; node = node->next) {
+		PurpleAccount *account = node->data;
+		const char *prpl_id = purple_account_get_protocol_id(account);
+		if (!strcmp("prpl-jabber", prpl_id)) {
+			PurpleConnection *gc = purple_account_get_connection(account);
+			jabber_presence_send(gc->proto_data, TRUE);
 		}
 	}
+
+	g_list_free(accounts);
 }
 
--- a/libpurple/protocols/jabber/disco.c	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/disco.c	Fri Nov 21 04:18:19 2008 +0000
@@ -298,7 +298,7 @@
 	}
 
 	/* Send initial presence; this will trigger receipt of presence for contacts on the roster */
-	jabber_presence_send(js->gc->account, NULL);
+	jabber_presence_send(js, TRUE);
 
 	if (js->server_caps & JABBER_CAP_ADHOC) {
 		/* The server supports ad-hoc commands, so let's request the list */
--- a/libpurple/protocols/jabber/libxmpp.c	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Fri Nov 21 04:18:19 2008 +0000
@@ -69,7 +69,7 @@
 	jabber_set_info,				/* set_info */
 	jabber_send_typing,				/* send_typing */
 	jabber_buddy_get_info,			/* get_info */
-	jabber_presence_send,			/* set_status */
+	jabber_set_status,				/* set_status */
 	jabber_idle_set,				/* set_idle */
 	NULL,							/* change_passwd */
 	jabber_roster_add_buddy,		/* add_buddy */
--- 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);
--- a/libpurple/protocols/jabber/presence.h	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/presence.h	Fri Nov 21 04:18:19 2008 +0000
@@ -26,7 +26,17 @@
 #include "jabber.h"
 #include "xmlnode.h"
 
-void jabber_presence_send(PurpleAccount *account, PurpleStatus *status);
+void jabber_set_status(PurpleAccount *account, PurpleStatus *status);
+
+/**
+ *	Send a full presence stanza.
+ *
+ *	@param js       A JabberStream object.
+ *	@param force    Force sending the presence stanza, irrespective of whether
+ *	                the contents seem to have changed.
+ */
+void jabber_presence_send(JabberStream *js, gboolean force);
+
 xmlnode *jabber_presence_create(JabberBuddyState state, const char *msg, int priority); /* DEPRECATED */
 xmlnode *jabber_presence_create_js(JabberStream *js, JabberBuddyState state, const char *msg, int priority);
 void jabber_presence_parse(JabberStream *js, xmlnode *packet);
--- a/libpurple/protocols/jabber/roster.c	Fri Nov 21 00:35:44 2008 +0000
+++ b/libpurple/protocols/jabber/roster.c	Fri Nov 21 04:18:19 2008 +0000
@@ -261,7 +261,7 @@
 	if(!js->roster_parsed) {
 		js->roster_parsed = TRUE;
 
-		jabber_presence_send(js->gc->account, NULL);
+		jabber_presence_send(js, TRUE);
 	}
 }