Mercurial > pidgin
diff libpurple/protocols/jabber/usermood.c @ 21085:7821fa7b22db
propagate from branch 'im.pidgin.pidgin' (head ef97aa9259d77504bb07c2dff5ec0750d498e847)
to branch 'org.maemo.garage.pidgin.pidgin.request-with-ui-hint' (head e8b5729ce3e73070299b06e0fba894a819d5cbb4)
author | Gabriel Schulhof <nix@go-nix.ca> |
---|---|
date | Wed, 10 Oct 2007 23:20:18 +0000 |
parents | 285bb637a2b7 686a492e2b70 |
children | 84b9b98070e5 |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/usermood.c Tue Oct 09 21:00:59 2007 +0000 +++ b/libpurple/protocols/jabber/usermood.c Wed Oct 10 23:20:18 2007 +0000 @@ -26,6 +26,7 @@ #include <string.h> #include "internal.h" #include "request.h" +#include "debug.h" static const char *moodstrings[] = { "afraid", @@ -145,9 +146,26 @@ } static void do_mood_set_from_fields(PurpleConnection *gc, PurpleRequestFields *fields) { - JabberStream *js = gc->proto_data; - - jabber_mood_set(js, moodstrings[purple_request_fields_get_choice(fields, "mood")], purple_request_fields_get_string(fields, "text")); + JabberStream *js; + int max_mood_idx; + int selected_mood = purple_request_fields_get_choice(fields, "mood"); + + if (!PURPLE_CONNECTION_IS_VALID(gc)) { + purple_debug_error("jabber", "Unable to set mood; account offline.\n"); + return; + } + + js = gc->proto_data; + + /* This is ugly, but protects us from unexpected values. */ + for (max_mood_idx = 0; moodstrings[max_mood_idx]; max_mood_idx++); + + if (selected_mood < 0 || selected_mood >= max_mood_idx) { + purple_debug_error("jabber", "Invalid mood index (%d) selected.\n", selected_mood); + return; + } + + jabber_mood_set(js, moodstrings[selected_mood], purple_request_fields_get_string(fields, "text")); } static void do_mood_set_mood(PurplePluginAction *action) {