diff options
author | James Booth <boothj5@gmail.com> | 2014-10-12 01:32:15 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-10-12 01:32:15 +0100 |
commit | da373e9097797102ff8fea50cd9cfcca24021d32 (patch) | |
tree | 04ccca6782e77d36d107929077bf6d4512a2ab77 /src/command | |
parent | 77684cda007391ba57cfbaea22bde071bee2925d (diff) | |
download | profani-tty-da373e9097797102ff8fea50cd9cfcca24021d32.tar.gz |
Added validation to /role and /affiliation
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/command.c | 11 | ||||
-rw-r--r-- | src/command/commands.c | 52 |
2 files changed, 34 insertions, 29 deletions
diff --git a/src/command/command.c b/src/command/command.c index 7d35c609..7e868938 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -311,14 +311,13 @@ static struct cmd_t command_defs[] = NULL } } }, { "/room", - cmd_room, parse_args_with_freetext, 1, 5, NULL, - { "/room accept|destroy|config|info", "Room configuration.", - { "/room accept|destroy|config|info", - "--------------------------------", + cmd_room, parse_args, 1, 1, NULL, + { "/room accept|destroy|config", "Room configuration.", + { "/room accept|destroy|config", + "---------------------------", "accept - Accept default room configuration.", "destroy - Reject default room configuration.", "config - Edit room configuration.", - "info - Show room details.", NULL } } }, { "/kick", @@ -331,7 +330,7 @@ static struct cmd_t command_defs[] = NULL } } }, { "/ban", - cmd_ban, parse_args, 1, 2, NULL, + cmd_ban, parse_args_with_freetext, 1, 2, NULL, { "/ban jid [reason]", "Ban users from chat rooms.", { "/ban jid [reason]", "-----------------", diff --git a/src/command/commands.c b/src/command/commands.c index 3e8d58d3..32d36f58 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2244,18 +2244,9 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) return TRUE; } - char *room = ui_current_recipient(); - char *affiliation = args[1]; - if (!affiliation) { - iq_room_affiliation_list(room, "owner"); - iq_room_affiliation_list(room, "admin"); - iq_room_affiliation_list(room, "member"); - iq_room_affiliation_list(room, "outcast"); - return TRUE; - } - - if ((g_strcmp0(affiliation, "owner") != 0) && + if ((affiliation != NULL) && + (g_strcmp0(affiliation, "owner") != 0) && (g_strcmp0(affiliation, "admin") != 0) && (g_strcmp0(affiliation, "member") != 0) && (g_strcmp0(affiliation, "none") != 0) && @@ -2264,10 +2255,16 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) return TRUE; } + char *room = ui_current_recipient(); ProfWin *window = wins_get_by_recipient(room); if (g_strcmp0(cmd, "list") == 0) { - if (g_strcmp0(affiliation, "none") == 0) { + if (!affiliation) { + iq_room_affiliation_list(room, "owner"); + iq_room_affiliation_list(room, "admin"); + iq_room_affiliation_list(room, "member"); + iq_room_affiliation_list(room, "outcast"); + } else if (g_strcmp0(affiliation, "none") == 0) { win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with no affiliation."); } else { iq_room_affiliation_list(room, affiliation); @@ -2276,6 +2273,11 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) } if (g_strcmp0(cmd, "set") == 0) { + if (!affiliation) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + char *jid = args[2]; if (jid == NULL) { cons_show("Usage: %s", help.usage); @@ -2287,6 +2289,7 @@ cmd_affiliation(gchar **args, struct cmd_help_t help) } } + cons_show("Usage: %s", help.usage); return TRUE; } @@ -2312,17 +2315,9 @@ cmd_role(gchar **args, struct cmd_help_t help) return TRUE; } - char *room = ui_current_recipient(); - char *role = args[1]; - if (!role) { - iq_room_role_list(room, "moderator"); - iq_room_role_list(room, "participant"); - iq_room_role_list(room, "visitor"); - return TRUE; - } - - if ((g_strcmp0(role, "visitor") != 0) && + if ((role != NULL ) && + (g_strcmp0(role, "visitor") != 0) && (g_strcmp0(role, "participant") != 0) && (g_strcmp0(role, "moderator") != 0) && (g_strcmp0(role, "none") != 0)) { @@ -2330,10 +2325,15 @@ cmd_role(gchar **args, struct cmd_help_t help) return TRUE; } + char *room = ui_current_recipient(); ProfWin *window = wins_get_by_recipient(room); if (g_strcmp0(cmd, "list") == 0) { - if (g_strcmp0(role, "none") == 0) { + if (!role) { + iq_room_role_list(room, "moderator"); + iq_room_role_list(room, "participant"); + iq_room_role_list(room, "visitor"); + } else if (g_strcmp0(role, "none") == 0) { win_save_print(window, '!', NULL, 0, 0, "", "Cannot list users with no role."); } else { iq_room_role_list(room, role); @@ -2342,6 +2342,11 @@ cmd_role(gchar **args, struct cmd_help_t help) } if (g_strcmp0(cmd, "set") == 0) { + if (!role) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + char *nick = args[2]; if (nick == NULL) { cons_show("Usage: %s", help.usage); @@ -2353,6 +2358,7 @@ cmd_role(gchar **args, struct cmd_help_t help) } } + cons_show("Usage: %s", help.usage); return TRUE; } |