diff options
Diffstat (limited to 'src/Client/CommandParser.cpp')
-rw-r--r-- | src/Client/CommandParser.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 044a64c..1c0403d 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -27,9 +27,11 @@ #include <Common/Requests/FSInfoRequest.h> #include <Common/Requests/DisconnectRequest.h> #include <Common/Requests/GroupListRequest.h> +#include <Common/Requests/GroupUserListRequest.h> #include <Common/Requests/StatusRequest.h> #include <Common/Requests/UserInfoRequest.h> #include <Common/Requests/UserListRequest.h> +#include <Common/Requests/UserGroupListRequest.h> #include <Common/Tokenizer.h> #include <iostream> @@ -49,8 +51,10 @@ const CommandParser::Command CommandParser::commands[] = { {{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &CommandParser::statusCommand}, {{"user_info", "user", 0}, "user_info uid", "Search for a user id", "Search for a user id.", &CommandParser::userInfoCommand}, {{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &CommandParser::listUsersCommand}, + {{"list_user_groups", "user_groups", 0}, "list_user_groups uid", "List user's groups", "List the groups that the user is member of.", &CommandParser::listUserGroupsCommand}, {{"list_groups", "groups", 0}, "list_groups", "Show the user group database", "Show the user group database.", &CommandParser::listGroupsCommand}, - {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, + {{"list_group_users", "group_users", 0}, "list_group_users gid", "List group's users", "List the users that are members of the group.", &CommandParser::listGroupUsersCommand}, + {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Close the connection and quit the client.", &CommandParser::exitCommand}, {{0}, 0, 0, 0, 0} }; @@ -292,6 +296,32 @@ void CommandParser::listUsersCommand(const std::vector<std::string>&) { boost::bind(&CommandManager::userListRequestFinished, CommandManager::get(), _1)); } +void CommandParser::listUserGroupsCommand(const std::vector<std::string> &args) { + if(args.size() == 1) { + Common::Logger::logf(Common::Logger::ERROR, "%s: No user id given.", args[0].c_str()); + printUsage("list_user_groups"); + return; + } + if(args.size() > 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); + printUsage("list_user_groups"); + return; + } + + char *endptr; + unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + Common::Logger::logf(Common::Logger::ERROR, "%s: Unable to parse user id.", args[0].c_str()); + printUsage("list_user_groups"); + return; + } + + ++CommandManager::get()->activeRequests; + + Common::RequestManager::get()->sendRequest<Common::Requests::UserGroupListRequest>(connection, + boost::bind(&CommandManager::userGroupListRequestFinished, CommandManager::get(), _1), uid); +} + void CommandParser::listGroupsCommand(const std::vector<std::string>&) { ++CommandManager::get()->activeRequests; @@ -299,6 +329,32 @@ void CommandParser::listGroupsCommand(const std::vector<std::string>&) { boost::bind(&CommandManager::groupListRequestFinished, CommandManager::get(), _1)); } +void CommandParser::listGroupUsersCommand(const std::vector<std::string> &args) { + if(args.size() == 1) { + Common::Logger::logf(Common::Logger::ERROR, "%s: No group id given.", args[0].c_str()); + printUsage("list_group_users"); + return; + } + if(args.size() > 2) { + Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); + printUsage("list_group_users"); + return; + } + + char *endptr; + unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + Common::Logger::logf(Common::Logger::ERROR, "%s: Unable to parse group id.", args[0].c_str()); + printUsage("list_group_users"); + return; + } + + ++CommandManager::get()->activeRequests; + + Common::RequestManager::get()->sendRequest<Common::Requests::GroupUserListRequest>(connection, + boost::bind(&CommandManager::groupUserListRequestFinished, CommandManager::get(), _1), gid); +} + void CommandParser::exitCommand(const std::vector<std::string>&) { ++CommandManager::get()->activeRequests; |