comparison libpurple/protocols/jabber/jabber.c @ 32777:3b1070cb4f29

jabber: Validate user moods, and make the /mood cmd behave flexibly. A user in Pidgin running "/mood ?" or "/mood -" would result in invalid XML being sent to the server (similar to #14342, except '<-/>' or '<?/>'). Prevent this by ensuring the user is specifying something from the list. The /mood command will also now try to treat its entire arguments as a single string, and set that as the mood -- I figure this is what a user would expect?
author Paul Aurich <paul@darkrain42.org>
date Wed, 23 May 2012 05:01:14 +0000
parents ec6371d4cae8
children
comparison
equal deleted inserted replaced
32776:804239d704ff 32777:3b1070cb4f29
3573 { 3573 {
3574 PurpleAccount *account = purple_conversation_get_account(conv); 3574 PurpleAccount *account = purple_conversation_get_account(conv);
3575 JabberStream *js = purple_connection_get_protocol_data(purple_account_get_connection(account)); 3575 JabberStream *js = purple_connection_get_protocol_data(purple_account_get_connection(account));
3576 3576
3577 if (js->pep) { 3577 if (js->pep) {
3578 /* if no argument was given, unset mood */ 3578 gboolean ret;
3579
3579 if (!args || !args[0]) { 3580 if (!args || !args[0]) {
3580 jabber_mood_set(js, NULL, NULL); 3581 /* No arguments; unset mood */
3581 } else if (!args[1]) { 3582 ret = jabber_mood_set(js, NULL, NULL);
3582 jabber_mood_set(js, args[0], NULL);
3583 } else { 3583 } else {
3584 jabber_mood_set(js, args[0], args[1]); 3584 /* At least one argument. Relying on the list of arguments
3585 } 3585 * being NULL-terminated.
3586 3586 */
3587 return PURPLE_CMD_RET_OK; 3587 ret = jabber_mood_set(js, args[0], args[1]);
3588 if (!ret) {
3589 /* Let's try again */
3590 char *tmp = g_strjoin(" ", args[0], args[1], NULL);
3591 ret = jabber_mood_set(js, "undefined", tmp);
3592 g_free(tmp);
3593 }
3594 }
3595
3596 if (ret) {
3597 return PURPLE_CMD_RET_OK;
3598 } else {
3599 purple_conversation_write(conv, NULL,
3600 _("Failed to specify mood"),
3601 PURPLE_MESSAGE_ERROR, time(NULL));
3602 return PURPLE_CMD_RET_FAILED;
3603 }
3588 } else { 3604 } else {
3589 /* account does not support PEP, can't set a mood */ 3605 /* account does not support PEP, can't set a mood */
3590 purple_conversation_write(conv, NULL, 3606 purple_conversation_write(conv, NULL,
3591 _("Account does not support PEP, can't set mood"), 3607 _("Account does not support PEP, can't set mood"),
3592 PURPLE_MESSAGE_ERROR, time(NULL)); 3608 PURPLE_MESSAGE_ERROR, time(NULL));
3711 3727
3712 id = purple_cmd_register("mood", "ws", PURPLE_CMD_P_PRPL, 3728 id = purple_cmd_register("mood", "ws", PURPLE_CMD_P_PRPL,
3713 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM | 3729 PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_IM |
3714 PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, 3730 PURPLE_CMD_FLAG_PRPL_ONLY | PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS,
3715 "prpl-jabber", jabber_cmd_mood, 3731 "prpl-jabber", jabber_cmd_mood,
3716 _("mood: Set current user mood"), NULL); 3732 _("mood &lt;mood&gt; [text]: Set current user mood"), NULL);
3717 commands = g_slist_prepend(commands, GUINT_TO_POINTER(id)); 3733 commands = g_slist_prepend(commands, GUINT_TO_POINTER(id));
3718 3734
3719 g_hash_table_insert(jabber_cmds, plugin, commands); 3735 g_hash_table_insert(jabber_cmds, plugin, commands);
3720 } 3736 }
3721 3737