changeset 17849:e49b259fc7dd

PEP publishing features are now only announced in disco#info when PEP is supported by the server.
author Andreas Monitzer <pidgin@monitzer.com>
date Fri, 15 Jun 2007 07:13:41 +0000
parents 5fc8a8a25008
children 2e41e74dabd0
files libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/pep.c libpurple/protocols/jabber/presence.c libpurple/protocols/jabber/usermood.c
diffstat 6 files changed, 48 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/disco.c	Wed Jun 13 16:03:11 2007 +0000
+++ b/libpurple/protocols/jabber/disco.c	Fri Jun 15 07:13:41 2007 +0000
@@ -37,9 +37,10 @@
 	JabberDiscoInfoCallback *callback;
 };
 
-#define SUPPORT_FEATURE(x) \
+#define SUPPORT_FEATURE(x) { \
 	feature = xmlnode_new_child(query, "feature"); \
-	xmlnode_set_attrib(feature, "var", x);
+	xmlnode_set_attrib(feature, "var", x); \
+}
 
 
 void jabber_disco_info_parse(JabberStream *js, xmlnode *packet) {
@@ -98,11 +99,12 @@
 			SUPPORT_FEATURE("http://jabber.org/protocol/xhtml-im")
 			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0199.html#ns")
                 
-            if(!node) { /* non-caps disco#info, add all extensions */
+            if(!node) { /* non-caps disco#info, add all enabled extensions */
                 GList *features;
                 for(features = jabber_features; features; features = features->next) {
                     JabberFeature *feat = (JabberFeature*)features->data;
-                    SUPPORT_FEATURE(feat->namespace);
+					if(feat->is_enabled == NULL || feat->is_enabled(js, feat->shortname, feat->namespace) == TRUE)
+						SUPPORT_FEATURE(feat->namespace);
                 }
             }
 		} else {
@@ -129,8 +131,8 @@
                     for(features = jabber_features; features; features = features->next) {
                         JabberFeature *feat = (JabberFeature*)features->data;
                         if(!strcmp(feat->shortname, ext)) {
-                            SUPPORT_FEATURE(feat->namespace);
-                            break;
+							SUPPORT_FEATURE(feat->namespace);
+							break;
                         }
                     }
                     if(features == NULL)
--- a/libpurple/protocols/jabber/jabber.c	Wed Jun 13 16:03:11 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Jun 15 07:13:41 2007 +0000
@@ -56,6 +56,8 @@
 #include "xdata.h"
 #include "pep.h"
 
+#include <assert.h>
+
 #define JABBER_CONNECT_STEPS (js->gsc ? 8 : 5)
 
 static PurplePlugin *my_protocol = NULL;
@@ -1094,10 +1096,16 @@
 	js->idle = idle ? time(NULL) - idle : idle;
 }
 
-void jabber_add_feature(const char *shortname, const char *namespace) {
-	JabberFeature *feat = g_new0(JabberFeature,1);
+void jabber_add_feature(const char *shortname, const char *namespace, JabberFeatureEnabled cb) {
+	JabberFeature *feat;
+	
+	assert(shortname != NULL);
+	assert(namespace != NULL);
+	
+	feat = g_new0(JabberFeature,1);
 	feat->shortname = g_strdup(shortname);
 	feat->namespace = g_strdup(namespace);
+	feat->is_enabled = cb;
 	
 	/* try to remove just in case it already exists in the list */
 	jabber_remove_feature(shortname);
@@ -1461,7 +1469,9 @@
 	act = purple_plugin_action_new(_("Search for Users..."),
 								 jabber_user_search_begin);
 	m = g_list_append(m, act);
-	
+
+	purple_debug_info("jabber", "jabber_actions: have pep: %s\n", js->pep?"YES":"NO");
+
 	if(js->pep)
 		jabber_pep_init_actions(&m);
 
--- a/libpurple/protocols/jabber/jabber.h	Wed Jun 13 16:03:11 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Fri Jun 15 07:13:41 2007 +0000
@@ -154,6 +154,18 @@
 	gboolean pep;
 } JabberStream;
 
+typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *shortname, const gchar *namespace);
+
+typedef struct _JabberFeature
+{
+	gchar *shortname;
+	gchar *namespace;
+	JabberFeatureEnabled *is_enabled;
+} JabberFeature;
+
+/* what kind of additional features as returned from disco#info are supported? */
+extern GList *jabber_features;
+
 void jabber_process_packet(JabberStream *js, xmlnode *packet);
 void jabber_send(JabberStream *js, xmlnode *data);
 void jabber_send_raw(JabberStream *js, const char *data, int len);
@@ -167,7 +179,7 @@
 
 char *jabber_parse_error(JabberStream *js, xmlnode *packet);
 
-void jabber_add_feature(const gchar *shortname, const gchar *namespace);
+void jabber_add_feature(const gchar *shortname, const gchar *namespace, JabberFeatureEnabled cb); /* cb may be NULL */
 void jabber_remove_feature(const gchar *shortname);
 
 /** PRPL functions */
@@ -189,13 +201,4 @@
 void jabber_register_commands(void);
 void jabber_init_plugin(PurplePlugin *plugin);
 
-typedef struct _JabberFeature
-{
-	gchar *shortname;
-	gchar *namespace;
-} JabberFeature;
-
-/* what kind of additional features as returned from disco#info are supported? */
-extern GList *jabber_features;
-
 #endif /* _PURPLE_JABBER_H_ */
--- a/libpurple/protocols/jabber/pep.c	Wed Jun 13 16:03:11 2007 +0000
+++ b/libpurple/protocols/jabber/pep.c	Fri Jun 15 07:13:41 2007 +0000
@@ -41,7 +41,7 @@
 
 void jabber_pep_register_handler(const char *shortname, const char *xmlns, JabberPEPHandler handlerfunc) {
 	gchar *notifyns = g_strdup_printf("%s+notify", xmlns);
-	jabber_add_feature(shortname, notifyns);
+	jabber_add_feature(shortname, notifyns, NULL); /* receiving PEPs is always supported */
 	g_free(notifyns);
 	g_hash_table_replace(pep_handlers, g_strdup(xmlns), handlerfunc);
 }
--- a/libpurple/protocols/jabber/presence.c	Wed Jun 13 16:03:11 2007 +0000
+++ b/libpurple/protocols/jabber/presence.c	Fri Jun 15 07:13:41 2007 +0000
@@ -187,8 +187,13 @@
         extlist[0] = '\0';
         for(feature = jabber_features; feature && remaining > 0; feature = feature->next) {
             JabberFeature *feat = (JabberFeature*)feature->data;
-            unsigned featlen = strlen(feat->shortname);
-            
+            unsigned featlen;
+
+			if(feat->is_enabled != NULL && feat->is_enabled(js, feat->shortname, feat->namespace) == FALSE)
+				continue; /* skip this feature */
+			
+			featlen = strlen(feat->shortname);
+
             /* cut off when we don't have any more space left in our buffer (too bad) */
             if(featlen > remaining)
                 break;
--- a/libpurple/protocols/jabber/usermood.c	Wed Jun 13 16:03:11 2007 +0000
+++ b/libpurple/protocols/jabber/usermood.c	Fri Jun 15 07:13:41 2007 +0000
@@ -133,8 +133,13 @@
 		g_free(moodtext);
 }
 
+static gboolean is_mood_supported(JabberStream *js, const gchar *shortname, const gchar *namespace) {
+	purple_debug_info("jabber", "is_mood_supported: have pep: %s\n", js->pep?"YES":"NO");
+	return js->pep;
+}
+
 void jabber_mood_init(void) {
-	jabber_add_feature("mood", "http://jabber.org/protocol/mood");
+	jabber_add_feature("mood", "http://jabber.org/protocol/mood", is_mood_supported);
 	jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
 }