changeset 26694:83e6e710cbf3

Add a new signal which is emitted (after the account is connected) if the associated account actions are changed. This is necessary since XMPP's account actions are not known when setting the account to connected. Also added support for push updates as specified in XEP-0050 2.3. Refs #7233.
author Paul Aurich <paul@darkrain42.org>
date Sun, 26 Apr 2009 06:45:55 +0000
parents 46b1d6eca6ef
children 3c35dcebefe7
files ChangeLog ChangeLog.API doc/account-signals.dox finch/gntblist.c libpurple/account.c libpurple/protocols/jabber/adhoccommands.c libpurple/protocols/jabber/adhoccommands.h libpurple/protocols/jabber/message.c libpurple/prpl.c libpurple/prpl.h pidgin/gtkblist.c
diffstat 11 files changed, 115 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Apr 26 06:26:55 2009 +0000
+++ b/ChangeLog	Sun Apr 26 06:45:55 2009 +0000
@@ -26,6 +26,8 @@
 	* Fix crash on connection with recent gstreamer0.10-plugins-bad.
 	* Don't create a new conversation window for incoming messages of
 	  type 'headline'.
+	* The Ad-Hoc commands associated with our server are now always shown at
+	  login.
 
 	IRC:
 	* Correctly handle WHOIS for users who are joined to a large number of
--- a/ChangeLog.API	Sun Apr 26 06:26:55 2009 +0000
+++ b/ChangeLog.API	Sun Apr 26 06:45:55 2009 +0000
@@ -9,6 +9,7 @@
 		* PURPLE_CONTACT
 		* PURPLE_BUDDY
 		* PURPLE_CHAT
+		* account-actions-changed (see account-signals.dox)
 		* purple_buddy_destroy
 		* purple_buddy_get_protocol_data
 		* purple_buddy_set_protocol_data
@@ -32,6 +33,7 @@
 		* purple_network_get_stun_ip
 		* purple_network_get_turn_ip
 		* purple_prpl_get_media_caps
+		* purple_prpl_got_account_actions
 		* purple_prpl_initiate_media
 		* purple_request_field_get_group
 		* purple_request_field_get_ui_data
--- a/doc/account-signals.dox	Sun Apr 26 06:26:55 2009 +0000
+++ b/doc/account-signals.dox	Sun Apr 26 06:45:55 2009 +0000
@@ -9,6 +9,7 @@
   @signal account-setting-info
   @signal account-set-info
   @signal account-status-changed
+  @signal account-actions-changed
   @signal account-alias-changed
   @signal account-authorization-requested
   @signal account-authorization-denied
@@ -97,6 +98,15 @@
   @param new     The status after change.
  @endsignaldef
 
+ @signaldef account-actions-changed
+  @signalproto
+void (*account_actions_changed)(PurpleAccount *account);
+  @endsignalproto
+  @signaldesc
+   Emitted when the account actions are changed after initial connection.
+  @param account The account whose actions changed.
+ @endsignaldef
+
  @signaldef account-alias-changed
   @signalproto
 void (*account_alias_changed)(PurpleAccount *account, const char *old);
--- a/finch/gntblist.c	Sun Apr 26 06:26:55 2009 +0000
+++ b/finch/gntblist.c	Sun Apr 26 06:45:55 2009 +0000
@@ -3123,6 +3123,8 @@
 				PURPLE_CALLBACK(reconstruct_accounts_menu), NULL);
 	purple_signal_connect(purple_connections_get_handle(), "signed-off", finch_blist_get_handle(),
 				PURPLE_CALLBACK(reconstruct_accounts_menu), NULL);
+	purple_signal_connect(purple_accounts_get_handle(), "account-actions-changed", finch_blist_get_handle(),
+				PURPLE_CALLBACK(reconstruct_accounts_menu), NULL);
 	purple_signal_connect(purple_blist_get_handle(), "buddy-status-changed", finch_blist_get_handle(),
 				PURPLE_CALLBACK(buddy_status_changed), ggblist);
 	purple_signal_connect(purple_blist_get_handle(), "buddy-idle-changed", finch_blist_get_handle(),
--- a/libpurple/account.c	Sun Apr 26 06:26:55 2009 +0000
+++ b/libpurple/account.c	Sun Apr 26 06:45:55 2009 +0000
@@ -2742,6 +2742,10 @@
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
 										PURPLE_SUBTYPE_STATUS));
 
+	purple_signal_register(handle, "account-actions-changed",
+						 purple_marshal_VOID__POINTER, NULL, 1,
+						 purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_ACCOUNT));
+
 	purple_signal_register(handle, "account-alias-changed",
 						 purple_marshal_VOID__POINTER_POINTER, NULL, 2,
 						 purple_value_new(PURPLE_TYPE_SUBTYPE,
--- a/libpurple/protocols/jabber/adhoccommands.c	Sun Apr 26 06:26:55 2009 +0000
+++ b/libpurple/protocols/jabber/adhoccommands.c	Sun Apr 26 06:45:55 2009 +0000
@@ -39,30 +39,18 @@
 	GList *actionslist;
 } JabberAdHocActionInfo;
 
-void jabber_adhoc_disco_result_cb(JabberStream *js, const char *from,
-                                  JabberIqType type, const char *id,
-                                  xmlnode *packet, gpointer data)
+static void
+jabber_adhoc_got_buddy_list(JabberStream *js, const char *from, xmlnode *query)
 {
-	const char *node;
-	xmlnode *query, *item;
-	JabberID *jabberid;
+	JabberID *jid;
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr = NULL;
-
-	if (type == JABBER_IQ_ERROR)
-		return;
+	xmlnode *item;
 
-	query = xmlnode_get_child_with_namespace(packet,"query","http://jabber.org/protocol/disco#items");
-	if(!query)
-		return;
-	node = xmlnode_get_attrib(query,"node");
-	if(!node || strcmp(node, "http://jabber.org/protocol/commands"))
-		return;
-
-	if((jabberid = jabber_id_new(from))) {
-		if(jabberid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
-			jbr = jabber_buddy_find_resource(jb, jabberid->resource);
-		jabber_id_free(jabberid);
+	if ((jid = jabber_id_new(from))) {
+		if (jid->resource && (jb = jabber_buddy_find(js, from, TRUE)))
+			jbr = jabber_buddy_find_resource(jb, jid->resource);
+		jabber_id_free(jid);
 	}
 
 	if(!jbr)
@@ -96,11 +84,31 @@
 	}
 }
 
+void
+jabber_adhoc_disco_result_cb(JabberStream *js, const char *from,
+                             JabberIqType type, const char *id,
+                             xmlnode *packet, gpointer data)
+{
+	xmlnode *query;
+	const char *node;
+
+	if (type == JABBER_IQ_ERROR)
+		return;
+
+	query = xmlnode_get_child_with_namespace(packet, "query", "http://jabber.org/protocol/disco#items");
+	if (!query)
+		return;
+	node = xmlnode_get_attrib(query, "node");
+	if (!purple_strequal(node, "http://jabber.org/protocol/commands"))
+		return;
+
+	jabber_adhoc_got_buddy_list(js, from, query);
+}
+
 static void jabber_adhoc_parse(JabberStream *js, const char *from,
                                JabberIqType type, const char *id,
                                xmlnode *packet, gpointer data);
 
-
 static void do_adhoc_action_cb(JabberStream *js, xmlnode *result, const char *actionhandle, gpointer user_data) {
 	xmlnode *command;
 	GList *action;
@@ -224,11 +232,8 @@
 }
 
 static void
-jabber_adhoc_server_got_list_cb(JabberStream *js, const char *from,
-                                JabberIqType type, const char *id,
-                                xmlnode *packet, gpointer data)
+jabber_adhoc_got_server_list(JabberStream *js, const char *from, xmlnode *query)
 {
-	xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", "http://jabber.org/protocol/disco#items");
 	xmlnode *item;
 
 	if(!query)
@@ -258,6 +263,29 @@
 
 		js->commands = g_list_append(js->commands,cmd);
 	}
+
+	if (js->state == JABBER_STREAM_CONNECTED)
+		purple_prpl_got_account_actions(purple_connection_get_account(js->gc));
+}
+
+static void
+jabber_adhoc_server_got_list_cb(JabberStream *js, const char *from,
+                                JabberIqType type, const char *id,
+                                xmlnode *packet, gpointer data)
+{
+	xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", "http://jabber.org/protocol/disco#items");
+
+	jabber_adhoc_got_server_list(js, from, query);
+
+}
+
+void jabber_adhoc_got_list(JabberStream *js, const char *from, xmlnode *query)
+{
+	if (purple_strequal(from, js->user->domain)) {
+		jabber_adhoc_got_server_list(js, from, query);
+	} else {
+		jabber_adhoc_got_buddy_list(js, from, query);
+	}
 }
 
 void jabber_adhoc_server_get_list(JabberStream *js) {
--- a/libpurple/protocols/jabber/adhoccommands.h	Sun Apr 26 06:26:55 2009 +0000
+++ b/libpurple/protocols/jabber/adhoccommands.h	Sun Apr 26 06:45:55 2009 +0000
@@ -34,6 +34,8 @@
 
 void jabber_adhoc_execute_action(PurpleBlistNode *node, gpointer data);
 
+void jabber_adhoc_got_list(JabberStream *js, const char *from, xmlnode *query);
+
 void jabber_adhoc_server_get_list(JabberStream *js);
 
 void jabber_adhoc_init_server_commands(JabberStream *js, GList **m);
--- a/libpurple/protocols/jabber/message.c	Sun Apr 26 06:26:55 2009 +0000
+++ b/libpurple/protocols/jabber/message.c	Sun Apr 26 06:45:55 2009 +0000
@@ -24,6 +24,7 @@
 #include "notify.h"
 #include "server.h"
 #include "util.h"
+#include "adhoccommands.h"
 #include "buddy.h"
 #include "chat.h"
 #include "data.h"
@@ -780,6 +781,12 @@
 			} else {
 				jm->etc = g_list_append(jm->etc, child);
 			}
+		} else if (g_str_equal(child->name, "query")) {
+			const char *node = xmlnode_get_attrib(child, "node");
+			if (purple_strequal(xmlns, "http://jabber.org/protocol/disco#items")
+					&& purple_strequal(node, "http://jabber.org/protocol/commands")) {
+				jabber_adhoc_got_list(js, jm->from, child);
+			}
 		}
 	}
 
--- a/libpurple/prpl.c	Sun Apr 26 06:26:55 2009 +0000
+++ b/libpurple/prpl.c	Sun Apr 26 06:45:55 2009 +0000
@@ -182,6 +182,17 @@
 }
 
 void
+purple_prpl_got_account_actions(PurpleAccount *account)
+{
+
+	g_return_if_fail(account != NULL);
+	g_return_if_fail(purple_account_is_connected(account));
+
+	purple_signal_emit(purple_accounts_get_handle(), "account-actions-changed",
+	                   account);
+}
+
+void
 purple_prpl_got_user_idle(PurpleAccount *account, const char *name,
 		gboolean idle, time_t idle_time)
 {
--- a/libpurple/prpl.h	Sun Apr 26 06:26:55 2009 +0000
+++ b/libpurple/prpl.h	Sun Apr 26 06:45:55 2009 +0000
@@ -661,6 +661,20 @@
 								  const char *status_id, ...) G_GNUC_NULL_TERMINATED;
 
 /**
+ * Notifies Purple that our account's actions have changed. This is only
+ * called after the initial connection. Emits the account-actions-changed
+ * signal.
+ *
+ * This is meant to be called from protocol plugins.
+ *
+ * @param account   The account.
+ *
+ * @see account-actions-changed
+ * @since 2.6.0
+ */
+void purple_prpl_got_account_actions(PurpleAccount *account);
+
+/**
  * Notifies Purple that a buddy's idle state and time have changed.
  *
  * This is meant to be called from protocol plugins.
--- a/pidgin/gtkblist.c	Sun Apr 26 06:26:55 2009 +0000
+++ b/pidgin/gtkblist.c	Sun Apr 26 06:45:55 2009 +0000
@@ -4652,6 +4652,12 @@
 }
 
 static void
+account_actions_changed(PurpleAccount *account, gpointer data)
+{
+	pidgin_blist_update_accounts_menu();
+}
+
+static void
 account_status_changed(PurpleAccount *account, PurpleStatus *old,
 					   PurpleStatus *new, PidginBuddyList *gtkblist)
 {
@@ -5837,6 +5843,8 @@
 	purple_signal_connect(handle, "account-error-changed", gtkblist,
 	                      PURPLE_CALLBACK(update_account_error_state),
 	                      gtkblist);
+	purple_signal_connect(handle, "account-actions-changed", gtkblist,
+	                      PURPLE_CALLBACK(account_actions_changed), NULL);
 
 	handle = pidgin_account_get_handle();
 	purple_signal_connect(handle, "account-modified", gtkblist,