changeset 17612:b8de63d3bf89

Added buzz support using a private extension. Maybe I should write a XEP about that.
author Andreas Monitzer <pidgin@monitzer.com>
date Wed, 27 Jun 2007 03:23:52 +0000
parents feac55968392
children 7c79957207c3
files libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/libxmpp.c libpurple/protocols/jabber/message.c libpurple/protocols/jabber/message.h
diffstat 4 files changed, 88 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Mon Jun 25 20:07:31 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Wed Jun 27 03:23:52 2007 +0000
@@ -2046,6 +2046,57 @@
 	return PURPLE_CMD_RET_OK;
 }
 
+static PurpleCmdRet jabber_cmd_buzz(PurpleConversation *conv,
+		const char *cmd, char **args, char **error, void *data)
+{
+	JabberStream *js = conv->account->gc->proto_data;
+	xmlnode *msg, *buzz;
+	JabberBuddy *jb;
+	JabberBuddyResource *jbr;
+	char *to;
+	GList *iter;
+
+	if(!args || !args[0])
+		return PURPLE_CMD_RET_FAILED;
+	
+	jb = jabber_buddy_find(js, args[0], FALSE);
+	if(!jb) {
+		*error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), args[0]);
+		return PURPLE_CMD_RET_FAILED;
+	}
+	
+	jbr = jabber_buddy_find_resource(jb, NULL);
+	if(!jbr) {
+		*error = g_strdup_printf(_("Unable to buzz, because user %s might be offline."), args[0]);
+		return PURPLE_CMD_RET_FAILED;
+	}
+	if(!jbr->caps) {
+		*error = g_strdup_printf(_("Unable to buzz, because there is nothing known about user %s."), args[0]);
+		return PURPLE_CMD_RET_FAILED;
+	}
+	for(iter = jbr->caps->features; iter; iter = g_list_next(iter)) {
+		if(!strcmp(iter->data, "http://pidgin.im/xmpp/buzz")) {
+			msg = xmlnode_new("message");
+			to = g_strdup_printf("%s/%s", args[0], jbr->name);
+			xmlnode_set_attrib(msg,"to",to);
+			g_free(to);
+			
+			/* avoid offline storage */
+			xmlnode_set_attrib(msg,"type","headline");
+			
+			buzz = xmlnode_new_child(msg,"buzz");
+			xmlnode_set_namespace(buzz,"http://pidgin.im/xmpp/buzz");
+			
+			jabber_send(js,msg);
+			xmlnode_free(msg);
+			
+			return PURPLE_CMD_RET_OK;
+		}
+	}
+	*error = g_strdup_printf(_("Unable to buzz, because the user %s does not support it."), args[0]);
+	return PURPLE_CMD_RET_FAILED;
+}
+
 gboolean jabber_offline_message(const PurpleBuddy *buddy)
 {
 	return TRUE;
@@ -2129,7 +2180,10 @@
 					  "prpl-jabber", jabber_cmd_ping,
 					  _("ping &lt;jid&gt;:	Ping a user/component/server."),
 					  NULL);
-
+	purple_cmd_register("buzz", "s", PURPLE_CMD_P_PRPL,
+					  PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY,
+					  "prpl-jabber", jabber_cmd_buzz,
+					  _("buzz: Buzz a user to get their attention"), NULL);
 }
 
 void
--- a/libpurple/protocols/jabber/libxmpp.c	Mon Jun 25 20:07:31 2007 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Wed Jun 27 03:23:52 2007 +0000
@@ -239,6 +239,7 @@
 
 		jabber_add_feature("avatarmeta", AVATARNAMESPACEMETA, jabber_pep_namespace_only_when_pep_enabled_cb);
 		jabber_add_feature("avatardata", AVATARNAMESPACEDATA, jabber_pep_namespace_only_when_pep_enabled_cb);
+		jabber_add_feature("buzz", "http://pidgin.im/xmpp/buzz", NULL);
 		
 		jabber_pep_register_handler("avatar", AVATARNAMESPACEMETA, jabber_buddy_avatar_update_metadata);
 }
--- a/libpurple/protocols/jabber/message.c	Mon Jun 25 20:07:31 2007 +0000
+++ b/libpurple/protocols/jabber/message.c	Wed Jun 27 03:23:52 2007 +0000
@@ -148,9 +148,13 @@
 static void handle_headline(JabberMessage *jm)
 {
 	char *title;
-	GString *body = g_string_new("");
+	GString *body;
 	GList *etc;
+	
+	if(!jm->xhtml && !jm->body)
+		return; /* ignore headlines without any content */
 
+	body = g_string_new("");
 	title = g_strdup_printf(_("Message from %s"), jm->from);
 
 	if(jm->xhtml)
@@ -274,6 +278,27 @@
 	g_free(buf);
 }
 
+static void handle_buzz(JabberMessage *jm) {
+	PurpleBuddy *buddy;
+	PurpleAccount *account;
+	PurpleConversation *c;
+	char *username, *str;
+	
+	account = purple_connection_get_account(jm->js->gc);
+	c = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, jm->from);
+	
+	if ((buddy = purple_find_buddy(account, jm->from)) != NULL)
+		username = g_markup_escape_text(purple_buddy_get_alias(buddy), -1);
+	else
+		username = g_markup_escape_text(jm->from, -1);
+	
+	str = g_strdup_printf(_("%s just sent you a Buzz!"), username);
+	
+	purple_conversation_write(c, NULL, str, PURPLE_MESSAGE_SYSTEM|PURPLE_MESSAGE_NOTIFY, time(NULL));
+	g_free(username);
+	g_free(str);
+}
+
 void jabber_message_parse(JabberStream *js, xmlnode *packet)
 {
 	JabberMessage *jm;
@@ -359,6 +384,8 @@
 			jm->type = JABBER_MESSAGE_EVENT;
 			for(items = xmlnode_get_child(child,"items"); items; items = items->next)
 				jm->eventitems = g_list_append(jm->eventitems, items);
+		} else if(!strcmp(child->name, "buzz") && !strcmp(xmlns,"http://pidgin.im/xmpp/buzz")) {
+			jm->hasBuzz = TRUE;
 		} else if(!strcmp(child->name, "error")) {
 			const char *code = xmlnode_get_attrib(child, "code");
 			char *code_txt = NULL;
@@ -423,6 +450,9 @@
 			}
 		}
 	}
+	
+	if(jm->hasBuzz)
+		handle_buzz(jm);
 
 	switch(jm->type) {
 		case JABBER_MESSAGE_NORMAL:
--- a/libpurple/protocols/jabber/message.h	Mon Jun 25 20:07:31 2007 +0000
+++ b/libpurple/protocols/jabber/message.h	Wed Jun 27 03:23:52 2007 +0000
@@ -40,6 +40,7 @@
 	} type;
 	time_t sent;
 	gboolean delayed;
+	gboolean hasBuzz;
 	char *id;
 	char *from;
 	char *to;