annotate libpurple/protocols/jabber/usermood.c @ 19279:39779b201e7c

Initialize newmood to NULL, as there are codepaths by which we can check against whether it is NULL or not before setting it, and that's bad.
author Evan Schoenberg <evan.s@dreskin.net>
date Fri, 17 Aug 2007 02:26:42 +0000
parents 6842cc73b1b7
children d32ed28cf645
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
1 /*
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
3 *
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
4 * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com>
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
5 *
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
9 * (at your option) any later version.
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
10 *
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
14 * GNU General Public License for more details.
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
15 *
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
19 *
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
20 */
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
21
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
22 #include "usermood.h"
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
23 #include "pep.h"
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
24 #include <assert.h>
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
25 #include <string.h>
17846
2f067d8fb19a Fixed a few small mistakes I discovered while testing user mood in Adium.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17845
diff changeset
26 #include "internal.h"
17850
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
27 #include "request.h"
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
28
17851
460b4bf797e7 Minor syntactic sugar.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17850
diff changeset
29 static const char *moodstrings[] = {
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
30 "afraid",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
31 "amazed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
32 "angry",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
33 "annoyed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
34 "anxious",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
35 "aroused",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
36 "ashamed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
37 "bored",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
38 "brave",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
39 "calm",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
40 "cold",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
41 "confused",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
42 "contented",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
43 "cranky",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
44 "curious",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
45 "depressed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
46 "disappointed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
47 "disgusted",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
48 "distracted",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
49 "embarrassed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
50 "excited",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
51 "flirtatious",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
52 "frustrated",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
53 "grumpy",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
54 "guilty",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
55 "happy",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
56 "hot",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
57 "humbled",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
58 "humiliated",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
59 "hungry",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
60 "hurt",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
61 "impressed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
62 "in_awe",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
63 "in_love",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
64 "indignant",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
65 "interested",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
66 "intoxicated",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
67 "invincible",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
68 "jealous",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
69 "lonely",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
70 "mean",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
71 "moody",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
72 "nervous",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
73 "neutral",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
74 "offended",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
75 "playful",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
76 "proud",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
77 "relieved",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
78 "remorseful",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
79 "restless",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
80 "sad",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
81 "sarcastic",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
82 "serious",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
83 "shocked",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
84 "shy",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
85 "sick",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
86 "sleepy",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
87 "stressed",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
88 "surprised",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
89 "thirsty",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
90 "worried",
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
91 NULL
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
92 };
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
93
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
94 static void jabber_mood_cb(JabberStream *js, const char *from, xmlnode *items) {
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
95 /* it doesn't make sense to have more than one item here, so let's just pick the first one */
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
96 xmlnode *item = xmlnode_get_child(items, "item");
19279
39779b201e7c Initialize newmood to NULL, as there are codepaths by which we can check against whether it is NULL or not before setting it, and that's bad.
Evan Schoenberg <evan.s@dreskin.net>
parents: 17869
diff changeset
97 const char *newmood = NULL;
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
98 char *moodtext = NULL;
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
99 JabberBuddy *buddy = jabber_buddy_find(js, from, FALSE);
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
100 xmlnode *moodinfo, *mood;
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
101 /* ignore the mood of people not on our buddy list */
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
102 if (!buddy || !item)
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
103 return;
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
104
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
105 mood = xmlnode_get_child_with_namespace(item, "mood", "http://jabber.org/protocol/mood");
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
106 if (!mood)
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
107 return;
17856
f108b91e2fee Fixed a minor mistake which could leave the usermood to be parsed incompletely.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17853
diff changeset
108 for (moodinfo = mood->child; moodinfo; moodinfo = moodinfo->next) {
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
109 if (moodinfo->type == XMLNODE_TYPE_TAG) {
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
110 if (!strcmp(moodinfo->name, "text")) {
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
111 if (!moodtext) /* only pick the first one */
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
112 moodtext = xmlnode_get_data(moodinfo);
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
113 } else {
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
114 int i;
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
115 for (i = 0; moodstrings[i]; ++i) {
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
116 /* verify that the mood is known (valid) */
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
117 if (!strcmp(moodinfo->name, moodstrings[i])) {
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
118 newmood = moodstrings[i];
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
119 break;
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
120 }
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
121 }
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
122 }
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
123 if (newmood != NULL && moodtext != NULL)
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
124 break;
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
125 }
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
126 }
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
127 if (newmood != NULL) {
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
128 JabberBuddyResource *resource = jabber_buddy_find_resource(buddy, NULL);
17869
6842cc73b1b7 Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17856
diff changeset
129 if(!resource) { /* huh? */
6842cc73b1b7 Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17856
diff changeset
130 if (moodtext)
6842cc73b1b7 Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17856
diff changeset
131 g_free(moodtext);
6842cc73b1b7 Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17856
diff changeset
132 return;
6842cc73b1b7 Implemented XEP-0172: User Nickname, fixed some potential crashers in the other PEP callbacks.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17856
diff changeset
133 }
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
134 const char *status_id = jabber_buddy_state_get_status_id(resource->state);
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
135
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
136 purple_prpl_got_user_status(js->gc->account, from, status_id, "mood", _(newmood), "moodtext", moodtext?moodtext:"", NULL);
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
137 }
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
138 if (moodtext)
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
139 g_free(moodtext);
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
140 }
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
141
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
142 void jabber_mood_init(void) {
17853
7754d39d70c5 Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17852
diff changeset
143 jabber_add_feature("mood", "http://jabber.org/protocol/mood", jabber_pep_namespace_only_when_pep_enabled_cb);
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
144 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
145 }
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
146
17850
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
147 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) {
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
148 JabberStream *js = gc->proto_data;
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
149
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
150 jabber_mood_set(js, moodstrings[purple_request_fields_get_choice(fields, "mood")], purple_request_fields_get_string(fields, "text"));
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
151 }
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
152
17848
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
153 static void do_mood_set_mood(PurplePluginAction *action) {
17850
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
154 PurpleConnection *gc = (PurpleConnection *) action->context;
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
155
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
156 PurpleRequestFields *fields;
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
157 PurpleRequestFieldGroup *group;
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
158 PurpleRequestField *field;
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
159 int i;
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
160
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
161 fields = purple_request_fields_new();
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
162 group = purple_request_field_group_new(NULL);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
163 purple_request_fields_add_group(fields, group);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
164
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
165 field = purple_request_field_choice_new("mood",
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
166 _("Mood"), 0);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
167
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
168 for(i = 0; moodstrings[i]; ++i)
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
169 purple_request_field_choice_add(field, _(moodstrings[i]));
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
170
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
171 purple_request_field_set_required(field, TRUE);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
172 purple_request_field_group_add_field(group, field);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
173
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
174 field = purple_request_field_string_new("text",
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
175 _("Description"), NULL,
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
176 FALSE);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
177 purple_request_field_group_add_field(group, field);
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
178
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
179 purple_request_fields(gc, _("Edit User Mood"),
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
180 _("Edit User Mood"),
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
181 _("Please select your mood from the list."),
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
182 fields,
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
183 _("Set"), G_CALLBACK(do_mood_set_from_fields),
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
184 _("Cancel"), NULL,
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
185 purple_connection_get_account(gc), NULL, NULL,
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
186 gc);
17848
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
187
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
188 }
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
189
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
190 void jabber_mood_init_action(GList **m) {
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
191 PurplePluginAction *act = purple_plugin_action_new(_("Set Mood..."), do_mood_set_mood);
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
192 *m = g_list_append(*m, act);
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
193 }
5fc8a8a25008 Implemented a mood menu action (non-functional right now for some reason)
Andreas Monitzer <pidgin@monitzer.com>
parents: 17847
diff changeset
194
17850
2e41e74dabd0 Implemented setting the User Mood. Currently untested since it requires the fields request API, which isn't implemented in Adium yet.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17849
diff changeset
195 void jabber_mood_set(JabberStream *js, const char *mood, const char *text) {
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
196 xmlnode *publish, *moodnode;
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
197
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
198 assert(mood != NULL);
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
199
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
200 publish = xmlnode_new("publish");
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
201 xmlnode_set_attrib(publish,"node","http://jabber.org/protocol/mood");
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
202 moodnode = xmlnode_new_child(xmlnode_new_child(publish, "item"), "mood");
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
203 xmlnode_set_namespace(moodnode, "http://jabber.org/protocol/mood");
17847
267f614152c4 Removed the huge enum for the user mood states, since it's now passed as localized strings anyways
Andreas Monitzer <pidgin@monitzer.com>
parents: 17846
diff changeset
204 xmlnode_new_child(moodnode, mood);
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
205
17852
af833a3204bb Fixed usermood memory management and removed publishing empty <text/>s.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17851
diff changeset
206 if (text && text[0] != '\0') {
17845
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
207 xmlnode *textnode = xmlnode_new_child(moodnode, "text");
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
208 xmlnode_insert_data(textnode, text, -1);
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
209 }
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
210
2e0799b916b9 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <pidgin@monitzer.com>
parents: 17844
diff changeset
211 jabber_pep_publish(js, publish);
17852
af833a3204bb Fixed usermood memory management and removed publishing empty <text/>s.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17851
diff changeset
212 /* publish is freed by jabber_pep_publish -> jabber_iq_send -> jabber_iq_free
af833a3204bb Fixed usermood memory management and removed publishing empty <text/>s.
Andreas Monitzer <pidgin@monitzer.com>
parents: 17851
diff changeset
213 (yay for well-defined memory management rules) */
17842
a0cd74d7b51e forgot to add usermood.[hc]
Andreas Monitzer <pidgin@monitzer.com>
parents:
diff changeset
214 }