cpw.darkrain42.xmpp.bosh: fa942689: Clean up jabber_presence_send

paul at darkrain42.org paul at darkrain42.org
Sat Jan 17 23:57:11 EST 2009


-----------------------------------------------------------------
Revision: fa942689cc6670bf10e0e38f4e805994d055f2a2
Ancestor: da702f886f1200f900bee02d615b4588ba021589
Author: paul at darkrain42.org
Date: 2008-11-21T04:18:19
Branch: im.pidgin.cpw.darkrain42.xmpp.bosh
URL: http://d.pidgin.im/viewmtn/revision/info/fa942689cc6670bf10e0e38f4e805994d055f2a2

Modified 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

ChangeLog: 

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

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/buddy.c	b687d1cce701f26584534067479bb48e29893101
+++ libpurple/protocols/jabber/buddy.c	a8624944c1428d7549119a7382a955a2aa86b3a7
@@ -493,9 +493,6 @@ void jabber_set_buddy_icon(PurpleConnect
 
 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 @@ void jabber_set_buddy_icon(PurpleConnect
 	/* 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);
 }
 
 /*
============================================================
--- libpurple/protocols/jabber/caps.c	f311a1db924ae3f3c6c682f1b306e6d9c0ff47e0
+++ libpurple/protocols/jabber/caps.c	c50c6220a1a11a768d2bf91c5ad0cf9b1ab15f06
@@ -867,16 +867,19 @@ const gchar* jabber_caps_get_own_hash(Ja
 	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);
 }
 
============================================================
--- libpurple/protocols/jabber/disco.c	5780a5e11050b0bf71ec9b88ef7bcb9491326f39
+++ libpurple/protocols/jabber/disco.c	7839516bbd42b283d0de037730cc2827fec7f692
@@ -298,7 +298,7 @@ jabber_disco_finish_server_info_result_c
 	}
 
 	/* 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 */
============================================================
--- libpurple/protocols/jabber/libxmpp.c	86de7e5afa868b456ad92c14cc8dcdc290c7928e
+++ libpurple/protocols/jabber/libxmpp.c	8d8f47112f6c4ca93dd53e589d4044df2f95a0fa
@@ -69,7 +69,7 @@ static PurplePluginProtocolInfo prpl_inf
 	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 */
============================================================
--- libpurple/protocols/jabber/presence.c	5956307bffa04bd8c71f10a7ce181436ae6b5667
+++ libpurple/protocols/jabber/presence.c	bde8803486ca3321b0fce379fffddba34f0e29b1
@@ -94,11 +94,31 @@ void jabber_presence_fake_to_self(Jabber
 	g_free(my_base_jid);
 }
 
+void jabber_set_status(PurpleAccount *account, PurpleStatus *status)
+{
+	PurpleConnection *gc;
+	JabberStream *js;
 
-void jabber_presence_send(PurpleAccount *account, PurpleStatus *status)
+	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)
 {
-	PurpleConnection *gc = NULL;
-	JabberStream *js = NULL;
+	PurpleAccount *account;
 	xmlnode *presence, *x, *photo;
 	char *stripped = NULL;
 	JabberBuddyState state;
@@ -107,29 +127,12 @@ void jabber_presence_send(PurpleAccount 
 	int length = -1;
 	gboolean allowBuzz;
 	PurplePresence *p;
-	PurpleStatus *tune;
+	PurpleStatus *status, *tune;
 
-	if (purple_account_is_disconnected(account))
-		return;
-
+	account = purple_connection_get_account(js->gc);
 	p = purple_account_get_presence(account);
-	if (NULL == status) {
-		status = purple_presence_get_active_status(p);
-	}
+	status = purple_presence_get_active_status(p);
 
-	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;
-
 	/* we don't want to send presence before we've gotten our roster */
 	if(!js->roster_parsed) {
 		purple_debug_info("jabber", "attempt to send presence before roster retrieved\n");
@@ -142,16 +145,18 @@ void jabber_presence_send(PurpleAccount 
 	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 @@ void jabber_presence_send(PurpleAccount 
 	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);
============================================================
--- libpurple/protocols/jabber/presence.h	a77bd82d513655a2ba4eef03d8c9f2d70e7e7e3d
+++ libpurple/protocols/jabber/presence.h	d7898e323604f549d5d7e45e634fb42c1e2c5cda
@@ -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);
============================================================
--- libpurple/protocols/jabber/roster.c	a384763565f91ecfa641f97f9ba59f697fa9169a
+++ libpurple/protocols/jabber/roster.c	902db55cf63902b43d6d30046db76ab92359851c
@@ -261,7 +261,7 @@ void jabber_roster_parse(JabberStream *j
 	if(!js->roster_parsed) {
 		js->roster_parsed = TRUE;
 
-		jabber_presence_send(js->gc->account, NULL);
+		jabber_presence_send(js, TRUE);
 	}
 }
 


More information about the Commits mailing list