Mercurial > pidgin
diff libpurple/protocols/jabber/usermood.c @ 20334:58a57a0ca807
applied changes from 1095e0c294d15e95c8909d270748c5253226bfe6
through a976c1dbb1135583dc67c67af14aa684fd4e18ee
applied changes from a976c1dbb1135583dc67c67af14aa684fd4e18ee
through 62ac0eb5b2ae2fda530b7230c8a903cc5ecd4513
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 19 Oct 2007 18:30:30 +0000 |
parents | ab38146f8f78 |
children | 787b3897ba9f 7821fa7b22db fc80a99f6f40 |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/usermood.c Fri Oct 19 18:28:33 2007 +0000 +++ b/libpurple/protocols/jabber/usermood.c Fri Oct 19 18:30:30 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) {