changeset 17888:cca457b9158b

disapproval of revision '217714a0fa711773c0d419f8cd82297ffc339507'
author Andreas Monitzer <pidgin@monitzer.com>
date Fri, 29 Jun 2007 21:44:42 +0000
parents 233af7fe561c
children 9686d549f084
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, 83 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Thu Jun 28 13:22:13 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Jun 29 21:44:42 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,6 +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	Thu Jun 28 13:22:13 2007 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Fri Jun 29 21:44:42 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	Thu Jun 28 13:22:13 2007 +0000
+++ b/libpurple/protocols/jabber/message.c	Fri Jun 29 21:44:42 2007 +0000
@@ -278,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;
@@ -363,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;
@@ -428,6 +451,9 @@
 		}
 	}
 	
+	if(jm->hasBuzz)
+		handle_buzz(jm);
+
 	switch(jm->type) {
 		case JABBER_MESSAGE_NORMAL:
 		case JABBER_MESSAGE_CHAT:
--- a/libpurple/protocols/jabber/message.h	Thu Jun 28 13:22:13 2007 +0000
+++ b/libpurple/protocols/jabber/message.h	Fri Jun 29 21:44:42 2007 +0000
@@ -40,6 +40,7 @@
 	} type;
 	time_t sent;
 	gboolean delayed;
+	gboolean hasBuzz;
 	char *id;
 	char *from;
 	char *to;