summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-05-29 18:02:12 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-05-29 18:02:12 +0200
commitcb8e66c1b1f1c8076053d71347d0b1f96ca0bca1 (patch)
treee8340c2830b5d4614cfb44bbb309003a3eb6525c /src/Client
parent9bb64c7c90e6481ed3689a2b9380496da4ce09ff (diff)
downloadmad-cb8e66c1b1f1c8076053d71347d0b1f96ca0bca1.tar
mad-cb8e66c1b1f1c8076053d71347d0b1f96ca0bca1.zip
Requests UserGroupList und GroupUserList implementiert
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandManager.cpp58
-rw-r--r--src/Client/CommandManager.h2
-rw-r--r--src/Client/CommandParser.cpp58
-rw-r--r--src/Client/CommandParser.h2
4 files changed, 117 insertions, 3 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index b427db7..603f679 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -235,7 +235,7 @@ void CommandManager::userListRequestFinished(const Common::Request &request) {
std::cout << "User list is empty." << std::endl;
}
else {
- std::cout << "Found " << users.getSize() << " users:" << std::endl;
+ std::cout << "Found " << users.getSize() << " user" << (users.getSize()==1 ? "" : "s") << ":" << std::endl;
for(size_t i = 0; i < users.getSize(); ++i)
@@ -251,6 +251,33 @@ void CommandManager::userListRequestFinished(const Common::Request &request) {
requestFinished();
}
+void CommandManager::userGroupListRequestFinished(const Common::Request &request) {
+ try {
+ const Common::XmlPacket &packet = request.getResult();
+
+ const Common::XmlPacket::Element &groups = packet["groups"];
+
+ if(groups.isEmpty()) {
+ std::cout << "The user isn't member of any group." << std::endl;
+ }
+ else {
+
+ std::cout << "User is member of " << groups.getSize() << " group" << (groups.getSize()==1 ? "" : "s") << ":" << std::endl;
+
+
+ for(size_t i = 0; i < groups.getSize(); ++i)
+ std::cout << " " << (unsigned long)groups[i]["gid"] << std::endl;
+ }
+
+ std::cout << std::endl;
+ }
+ catch(Net::Exception &exception) {
+ Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
+ }
+
+ requestFinished();
+}
+
void CommandManager::groupListRequestFinished(const Common::Request &request) {
try {
const Common::XmlPacket &packet = request.getResult();
@@ -261,7 +288,7 @@ void CommandManager::groupListRequestFinished(const Common::Request &request) {
std::cout << "Group list is empty." << std::endl;
}
else {
- std::cout << "Found " << groups.getSize() << " groups:" << std::endl;
+ std::cout << "Found " << groups.getSize() << " group" << (groups.getSize()==1 ? "" : "s") << ":" << std::endl;
for(size_t i = 0; i < groups.getSize(); ++i)
@@ -277,5 +304,32 @@ void CommandManager::groupListRequestFinished(const Common::Request &request) {
requestFinished();
}
+void CommandManager::groupUserListRequestFinished(const Common::Request &request) {
+ try {
+ const Common::XmlPacket &packet = request.getResult();
+
+ const Common::XmlPacket::Element &users = packet["users"];
+
+ if(users.isEmpty()) {
+ std::cout << "The group doesn't have any members." << std::endl;
+ }
+ else {
+
+ std::cout << "The group has " << users.getSize() << " member" << (users.getSize()==1 ? "" : "s") << ":" << std::endl;
+
+
+ for(size_t i = 0; i < users.getSize(); ++i)
+ std::cout << " " << (unsigned long)users[i]["uid"] << std::endl;
+ }
+
+ std::cout << std::endl;
+ }
+ catch(Net::Exception &exception) {
+ Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
+ }
+
+ requestFinished();
+}
+
}
}
diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h
index 3cfc502..137ec8e 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -60,7 +60,9 @@ class CommandManager {
void statusRequestFinished(const Common::Request &request);
void userInfoRequestFinished(const Common::Request &request);
void userListRequestFinished(const Common::Request &request);
+ void userGroupListRequestFinished(const Common::Request &request);
void groupListRequestFinished(const Common::Request &request);
+ void groupUserListRequestFinished(const Common::Request &request);
CommandManager() : activeRequests(0), disconnect(false) {}
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;
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 727181e..692eb7e 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -65,7 +65,9 @@ class CommandParser {
void statusCommand(const std::vector<std::string> &args);
void userInfoCommand(const std::vector<std::string> &args);
void listUsersCommand(const std::vector<std::string> &args);
+ void listUserGroupsCommand(const std::vector<std::string> &args);
void listGroupsCommand(const std::vector<std::string> &args);
+ void listGroupUsersCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
CommandParser() : connection(0) {}