summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-06-24 00:04:28 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-06-24 00:04:28 +0200
commitdff7c00a0c2c3fcb64efd611d70398d711ad861b (patch)
tree93c1556c15987b37e8d2ba3421cb246006a02eac /src/Client
parent02b9e16833acbdaa820bd3b8b64d652a41a8ff58 (diff)
downloadmad-dff7c00a0c2c3fcb64efd611d70398d711ad861b.tar
mad-dff7c00a0c2c3fcb64efd611d70398d711ad861b.zip
NetworkUserBackend implementiert
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandParser.cpp3
-rw-r--r--src/Client/UserCommands.cpp194
-rw-r--r--src/Client/UserCommands.h4
3 files changed, 100 insertions, 101 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index f231082..842be7f 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -43,10 +43,11 @@ const CommandParser::Command CommandParser::commands[] = {
{{"reboot", 0}, "reboot *|host...", "Reboot host", "Reboot hosts. * will reboot all hosts.", &SystemCommands::rebootCommand},
{{"shutdown", "halt", 0}, "shutdown *|host...", "Shut hosts down", "Shut hosts down. * will shut down all hosts.", &SystemCommands::shutdownCommand},
{{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &SystemCommands::statusCommand},
- {{"user_info", "user", 0}, "user_info uid", "Search for a user id", "Search for a user id.", &UserCommands::userInfoCommand},
{{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &UserCommands::listUsersCommand},
+ {{"user_info", "user", 0}, "user_info uid|name", "Search for a user id", "Search for a user.", &UserCommands::userInfoCommand},
{{"list_user_groups", "user_groups", 0}, "list_user_groups uid", "List user's groups", "List the groups that the user is member of.", &UserCommands::listUserGroupsCommand},
{{"list_groups", "groups", 0}, "list_groups", "Show the user group database", "Show the user group database.", &UserCommands::listGroupsCommand},
+ {{"group_info", "group", 0}, "group_info gid|name", "Search for a group id", "Search for a group.", &UserCommands::groupInfoCommand},
{{"list_group_users", "group_users", 0}, "list_group_users gid", "List group's users", "List the users that are members of the group.", &UserCommands::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}
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index de5b7ea..fec2a33 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -23,11 +23,7 @@
#include <Common/RequestManager.h>
-#include <Common/Requests/GroupListRequest.h>
-#include <Common/Requests/GroupUserListRequest.h>
-#include <Common/Requests/UserInfoRequest.h>
-#include <Common/Requests/UserListRequest.h>
-#include <Common/Requests/UserGroupListRequest.h>
+#include <Common/UserManager.h>
#include <iostream>
@@ -35,6 +31,29 @@
namespace Mad {
namespace Client {
+void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args _UNUSED_PARAMETER_) {
+ try {
+ boost::shared_ptr<const std::map<unsigned long, Common::UserInfo> > users = commandParser->application->getUserManager()->getUserList();
+
+ if(users->empty()) {
+ std::cout << "User list is empty." << std::endl;
+ }
+ else {
+ std::cout << "Found " << users->size() << " user" << (users->size()==1 ? "" : "s") << ":" << std::endl;
+
+ for(std::map<unsigned long, Common::UserInfo>::const_iterator user = users->begin(); user != users->end(); ++user) {
+ std::cout << " " << user->second.getUid() << ", " << user->second.getGid() << ", "
+ << user->second.getUsername() << ", " << user->second.getFullName() << std::endl;
+ }
+ }
+
+ std::cout << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
+}
+
void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
if(args.size() == 1) {
std::cerr << args[0] << ": No user id given." << std::endl;
@@ -47,58 +66,23 @@ void UserCommands::userInfoCommand(CommandParser *commandParser, const std::vect
return;
}
- char *endptr;
- unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10);
- if(args[1].empty() || *endptr != '\0') {
- std::cerr << args[0] << ": Unable to parse user id." << std::endl;
- commandParser->printUsage("user_info");
- return;
- }
-
- boost::shared_ptr<Common::Requests::UserInfoRequest> request(new Common::Requests::UserInfoRequest(commandParser->application, uid));
- commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
- request->wait();
-
- std::pair<boost::shared_ptr<const Common::XmlPacket>, Core::Exception> result = request->getResult();
-
- if(!result.first || result.second) {
- std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl;
- }
- else {
- const Common::XmlPacket &packet = *result.first;
-
- std::cout << " " << packet.get<unsigned long>("uid") << ", " << packet.get<unsigned long>("gid") << ", "
- << packet.get<const std::string&>("username") << ", " << packet.get<const std::string&>("fullName") << std::endl << std::endl;
- }
-}
-
-void UserCommands::listUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args _UNUSED_PARAMETER_) {
- boost::shared_ptr<Common::Requests::UserListRequest> request(new Common::Requests::UserListRequest(commandParser->application));
-
- commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
- request->wait();
-
- std::pair<boost::shared_ptr<const Common::XmlPacket>, Core::Exception> result = request->getResult();
-
- if(!result.first || result.second) {
- std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl;
- }
- else {
- const Common::XmlPacket::List *users = result.first->getList("users");
-
- if(!users || users->isEmpty()) {
- std::cout << "User list is empty." << std::endl;
- }
- else {
- std::cout << "Found " << users->getSize() << " user" << (users->getSize()==1 ? "" : "s") << ":" << std::endl;
+ try {
+ char *endptr;
+ unsigned long uid = std::strtoul(args[1].c_str(), &endptr, 10);
+ boost::shared_ptr<const Common::UserInfo> userInfo;
- for(Common::XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user)
- std::cout << " " << user->get<unsigned long>("uid") << ", " << user->get<unsigned long>("gid")
- << ", " << user->get<const std::string&>("username") << ", " << user->get<const std::string&>("fullName") << std::endl;
+ if(args[1].empty() || *endptr != '\0') {
+ userInfo = commandParser->application->getUserManager()->getUserInfoByName(args[1]);
}
+ else
+ userInfo = commandParser->application->getUserManager()->getUserInfo(uid);
- std::cout << std::endl;
+ std::cout << " " << userInfo->getUid() << ", " << userInfo->getGid() << ", "
+ << userInfo->getUsername() << ", " << userInfo->getFullName() << std::endl << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
}
}
@@ -122,59 +106,77 @@ void UserCommands::listUserGroupsCommand(CommandParser *commandParser, const std
return;
}
- boost::shared_ptr<Common::Requests::UserGroupListRequest> request(new Common::Requests::UserGroupListRequest(commandParser->application, uid));
- commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
- request->wait();
+ try {
+ boost::shared_ptr<const std::set<unsigned long> > groups = commandParser->application->getUserManager()->getUserGroupList(uid);
- std::pair<boost::shared_ptr<const Common::XmlPacket>, Core::Exception> result = request->getResult();
-
- if(!result.first || result.second) {
- std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl;
- }
- else {
- const Common::XmlPacket::List *groups = result.first->getList("groups");
-
- if(!groups || groups->isEmpty()) {
+ if(groups->empty()) {
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;
+ std::cout << "User is member of " << groups->size() << " group" << (groups->size()==1 ? "" : "s") << ":" << std::endl;
- for(Common::XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group)
- std::cout << " " << group->get<unsigned long>("gid") << std::endl;
+ for(std::set<unsigned long>::const_iterator group = groups->begin(); group != groups->end(); ++group)
+ std::cout << " " << *group << std::endl;
}
std::cout << std::endl;
}
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
}
void UserCommands::listGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args _UNUSED_PARAMETER_) {
- boost::shared_ptr<Common::Requests::GroupListRequest> request(new Common::Requests::GroupListRequest(commandParser->application));
+ try {
+ boost::shared_ptr<const std::map<unsigned long, Common::GroupInfo> > groups = commandParser->application->getUserManager()->getGroupList();
- commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
- request->wait();
+ if(groups->empty()) {
+ std::cout << "Group list is empty." << std::endl;
+ }
+ else {
+ std::cout << "Found " << groups->size() << " group" << (groups->size()==1 ? "" : "s") << ":" << std::endl;
- std::pair<boost::shared_ptr<const Common::XmlPacket>, Core::Exception> result = request->getResult();
+ for(std::map<unsigned long, Common::GroupInfo>::const_iterator group = groups->begin(); group != groups->end(); ++group) {
+ std::cout << " " << group->second.getGid() << ", " << group->second.getName() << std::endl;
+ }
+ }
- if(!result.first || result.second) {
- std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl;
+ std::cout << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
}
- else {
- const Common::XmlPacket::List *groups = result.first->getList("groups");
+}
- if(!groups || groups->isEmpty()) {
- std::cout << "Group list is empty." << std::endl;
- }
- else {
- std::cout << "Found " << groups->getSize() << " group" << (groups->getSize()==1 ? "" : "s") << ":" << std::endl;
+void UserCommands::groupInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args) {
+ if(args.size() == 1) {
+ std::cerr << args[0] << ": No group id given." << std::endl;
+ commandParser->printUsage("group_info");
+ return;
+ }
+ if(args.size() > 2) {
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
+ commandParser->printUsage("group_info");
+ return;
+ }
+
+ try {
+ char *endptr;
+ unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10);
+ boost::shared_ptr<const Common::GroupInfo> groupInfo;
- for(Common::XmlPacket::List::const_iterator group = groups->begin(); group != groups->end(); ++group)
- std::cout << " " << group->get<unsigned long>("gid") << ", " << group->get<const std::string&>("name") << std::endl;
+ if(args[1].empty() || *endptr != '\0') {
+ groupInfo = commandParser->application->getUserManager()->getGroupInfoByName(args[1]);
}
+ else
+ groupInfo = commandParser->application->getUserManager()->getGroupInfo(gid);
- std::cout << std::endl;
+ std::cout << " " << groupInfo->getGid() << ", " << groupInfo->getName() << std::endl << std::endl;
+ }
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
}
}
@@ -198,31 +200,25 @@ void UserCommands::listGroupUsersCommand(CommandParser *commandParser, const std
return;
}
- boost::shared_ptr<Common::Requests::GroupUserListRequest> request(new Common::Requests::GroupUserListRequest(commandParser->application, gid));
- commandParser->application->getRequestManager()->sendRequest(commandParser->connection, request);
- request->wait();
+ try {
+ boost::shared_ptr<const std::set<unsigned long> > users = commandParser->application->getUserManager()->getGroupUserList(gid);
- std::pair<boost::shared_ptr<const Common::XmlPacket>, Core::Exception> result = request->getResult();
-
- if(!result.first || result.second) {
- std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl;
- }
- else {
- const Common::XmlPacket::List *users = result.first->getList("users");
-
- if(!users || users->isEmpty()) {
+ if(users->empty()) {
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;
+ std::cout << "The group has " << users->size() << " member" << (users->size()==1 ? "" : "s") << ":" << std::endl;
- for(Common::XmlPacket::List::const_iterator user = users->begin(); user != users->end(); ++user)
- std::cout << " " << user->get<unsigned long>("uid") << std::endl;
+ for(std::set<unsigned long>::const_iterator user = users->begin(); user != users->end(); ++user)
+ std::cout << " " << *user << std::endl;
}
std::cout << std::endl;
}
+ catch(Core::Exception e) {
+ std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl;
+ }
}
}
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index f3dd31c..0f56a40 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -33,10 +33,12 @@ class UserCommands {
UserCommands();
public:
- static void userInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void listUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void userInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void listUserGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+
static void listGroupsCommand(CommandParser *commandParser, const std::vector<std::string> &args);
+ static void groupInfoCommand(CommandParser *commandParser, const std::vector<std::string> &args);
static void listGroupUsersCommand(CommandParser *commandParser, const std::vector<std::string> &args);
};