changeset 17842:a0cd74d7b51e

forgot to add usermood.[hc]
author Andreas Monitzer <pidgin@monitzer.com>
date Tue, 12 Jun 2007 00:00:53 +0000
parents df5bb342b10e
children 8338e171a43b
files libpurple/protocols/jabber/message.c libpurple/protocols/jabber/usermood.c libpurple/protocols/jabber/usermood.h
diffstat 3 files changed, 260 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/message.c	Mon Jun 11 23:33:39 2007 +0000
+++ b/libpurple/protocols/jabber/message.c	Tue Jun 12 00:00:53 2007 +0000
@@ -306,7 +306,7 @@
 
 	jm->from = g_strdup(xmlnode_get_attrib(packet, "from"));
 	jm->to = g_strdup(xmlnode_get_attrib(packet, "to"));
-	jm->id = g_strdup(xmlnode_get_attrib(packet, "id"));
+    jm->id = g_strdup(xmlnode_get_attrib(packet, "id"));
 
 	for(child = packet->child; child; child = child->next) {
         const char *xmlns = xmlnode_get_namespace(child);
@@ -357,7 +357,7 @@
 		} else if(!strcmp(child->name, "event") && !strcmp(xmlns,"http://jabber.org/protocol/pubsub#event")) {
             xmlnode *items;
             jm->type = JABBER_MESSAGE_EVENT;
-            for(items = child->child; child; child = child->next)
+            for(items = child->child; items; items = items->next)
                 jm->eventitems = g_list_append(jm->eventitems, items);
 		} else if(!strcmp(child->name, "error")) {
 			const char *code = xmlnode_get_attrib(child, "code");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/jabber/usermood.c	Tue Jun 12 00:00:53 2007 +0000
@@ -0,0 +1,160 @@
+/*
+ * purple - Jabber Protocol Plugin
+ *
+ * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "usermood.h"
+#include "pep.h"
+
+#include <string.h>
+
+static char *moodstrings[] = {
+    "afraid",
+    "amazed",
+    "angry",
+    "annoyed",
+    "anxious",
+    "aroused",
+    "ashamed",
+    "bored",
+    "brave",
+    "calm",
+    "cold",
+    "confused",
+    "contented",
+    "cranky",
+    "curious",
+    "depressed",
+    "disappointed",
+    "disgusted",
+    "distracted",
+    "embarrassed",
+    "excited",
+    "flirtatious",
+    "frustrated",
+    "grumpy",
+    "guilty",
+    "happy",
+    "hot",
+    "humbled",
+    "humiliated",
+    "hungry",
+    "hurt",
+    "impressed",
+    "in_awe",
+    "in_love",
+    "indignant",
+    "interested",
+    "intoxicated",
+    "invincible",
+    "jealous",
+    "lonely",
+    "mean",
+    "moody",
+    "nervous",
+    "neutral",
+    "offended",
+    "playful",
+    "proud",
+    "relieved",
+    "remorseful",
+    "restless",
+    "sad",
+    "sarcastic",
+    "serious",
+    "shocked",
+    "shy",
+    "sick",
+    "sleepy",
+    "stressed",
+    "surprised",
+    "thirsty",
+    "worried",
+    NULL
+};
+
+static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) {
+    /* it doesn't make sense to have more than one item here, so let's just pick the first one */
+    xmlnode *item = xmlnode_get_child(items, "item");
+    jabber_mood newmood = unknown;
+    char *moodtext = NULL;
+    JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE);
+    /* ignore the mood of people not on our buddy list */
+    if(!buddy)
+        return;
+    
+    if(item) {
+        xmlnode *mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood");
+        if(mood) {
+            xmlnode *moodinfo;
+            for(moodinfo = mood->child; moodinfo != mood->lastchild; moodinfo = moodinfo->next) {
+                if(moodinfo->type == XMLNODE_TYPE_TAG) {
+                    if(!strcmp(moodinfo->name, "text")) {
+                        if(!moodtext) /* only pick the first one */
+                            moodtext = xmlnode_get_data(moodinfo);
+                    } else {
+                        int i;
+                        for(i = 0; moodstrings[i]; ++i) {
+                            if(!strcmp(moodinfo->name, moodstrings[i])) {
+                                newmood = (jabber_mood)(i+1); /* 0 is "unknown", so we have to add 1 */
+                                break;
+                            }
+                        }
+                    }
+                    if(newmood != unknown && moodtext != NULL)
+                       break;
+                }
+            }
+        }
+    }
+    if(newmood != unknown) {
+        JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL);
+        const char *status_id = jabber_buddy_state_get_status_id(resource->state);
+        
+        purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", newmood, "moodtext", moodtext?moodtext:"", NULL);
+    }
+    if(moodtext)
+        g_free(moodtext);
+}
+
+void jabber_mood_init(void) {
+    jabber_add_feature("mood", "http://jabber.org/protocol/mood");
+    jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
+}
+
+void jabber_set_mood(JabberStream *js, jabber_mood mood, const char *text) {
+    xmlnode *publish, *moodnode;
+    if(mood == unknown)
+        return;
+    
+    publish = xmlnode_new("publish");
+    xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood");
+    moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood");
+    xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood");
+    xmlnode_new_child(moodnode, moodstrings[mood-1]);
+
+    if(text) {
+        xmlnode *textnode = xmlnode_new_child(moodnode, "text");
+        xmlnode_insert_data(textnode, text, -1);
+    }
+    
+    jabber_pep_publish(js, publish);
+    
+    xmlnode_free(publish);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/jabber/usermood.h	Tue Jun 12 00:00:53 2007 +0000
@@ -0,0 +1,98 @@
+/*
+ * purple - Jabber Protocol Plugin
+ *
+ * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef _PURPLE_JABBER_USERMOOD_H_
+#define _PURPLE_JABBER_USERMOOD_H_
+
+#include "jabber.h"
+
+/* Implementation of XEP-0107 */
+
+typedef enum _jabber_mood { /* wtf */
+    unknown = 0,
+    afraid,
+    amazed,
+    angry,
+    annoyed,
+    anxious,
+    aroused,
+    ashamed,
+    bored,
+    brave,
+    calm,
+    cold,
+    confused,
+    contented,
+    cranky,
+    curious,
+    depressed,
+    disappointed,
+    disgusted,
+    distracted,
+    embarrassed,
+    excited,
+    flirtatious,
+    frustrated,
+    grumpy,
+    guilty,
+    happy,
+    hot,
+    humbled,
+    humiliated,
+    hungry,
+    hurt,
+    impressed,
+    in_awe,
+    in_love,
+    indignant,
+    interested,
+    intoxicated,
+    invincible,
+    jealous,
+    lonely,
+    mean,
+    moody,
+    nervous,
+    neutral,
+    offended,
+    playful,
+    proud,
+    relieved,
+    remorseful,
+    restless,
+    sad,
+    sarcastic,
+    serious,
+    shocked,
+    shy,
+    sick,
+    sleepy,
+    stressed,
+    surprised,
+    thirsty,
+    worried
+} jabber_mood;
+
+void jabber_mood_init(void);
+
+void jabber_set_mood(JabberStream *js, jabber_mood mood, const char *text /* might be NULL */);
+
+#endif /* _PURPLE_JABBER_USERMOOD_H_ */