libpurple/protocols/jabber/usermood.c

changeset 21352
e10c4ea18f7c
parent 21175
c6d76b49c206
parent 21351
4c83d3121e8b
child 21630
591a79c1b295
equal deleted inserted replaced
21175:c6d76b49c206 21352:e10c4ea18f7c
24 #include "usermood.h" 24 #include "usermood.h"
25 #include "pep.h" 25 #include "pep.h"
26 #include <string.h> 26 #include <string.h>
27 #include "internal.h" 27 #include "internal.h"
28 #include "request.h" 28 #include "request.h"
29 #include "debug.h"
29 30
30 static const char *moodstrings[] = { 31 static const char *moodstrings[] = {
31 "afraid", 32 "afraid",
32 "amazed", 33 "amazed",
33 "angry", 34 "angry",
143 jabber_add_feature("mood", "http://jabber.org/protocol/mood", jabber_pep_namespace_only_when_pep_enabled_cb); 144 jabber_add_feature("mood", "http://jabber.org/protocol/mood", jabber_pep_namespace_only_when_pep_enabled_cb);
144 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb); 145 jabber_pep_register_handler("moodn", "http://jabber.org/protocol/mood", jabber_mood_cb);
145 } 146 }
146 147
147 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { 148 static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) {
148 JabberStream *js = gc->proto_data; 149 JabberStream *js;
149 150 int max_mood_idx;
150 jabber_mood_set(js, moodstrings[purple_request_fields_get_choice(fields, "mood")], purple_request_fields_get_string(fields, "text")); 151 int selected_mood = purple_request_fields_get_choice(fields, "mood");
152
153 if (!PURPLE_CONNECTION_IS_VALID(gc)) {
154 purple_debug_error("jabber", "Unable to set mood; account offline.\n");
155 return;
156 }
157
158 js = gc->proto_data;
159
160 /* This is ugly, but protects us from unexpected values. */
161 for (max_mood_idx = 0; moodstrings[max_mood_idx]; max_mood_idx++);
162
163 if (selected_mood < 0 || selected_mood >= max_mood_idx) {
164 purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood);
165 return;
166 }
167
168 jabber_mood_set(js, moodstrings[selected_mood], purple_request_fields_get_string(fields, "text"));
151 } 169 }
152 170
153 static void do_mood_set_mood(PurplePluginAction *action) { 171 static void do_mood_set_mood(PurplePluginAction *action) {
154 PurpleConnection *gc = (PurpleConnection *) action->context; 172 PurpleConnection *gc = (PurpleConnection *) action->context;
155 173

mercurial