summaryrefslogtreecommitdiffstats
path: root/src/Client
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-02-13 00:00:05 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-02-13 00:00:05 +0100
commit04363ca342914ba75e693edb876cbe535839fa79 (patch)
treed1309d7b0f6288a8250e972e5cab2546f2a77609 /src/Client
parent2ab1fbd763ad8692ea3ca29705a4fe821ccb1309 (diff)
downloadmad-04363ca342914ba75e693edb876cbe535839fa79.tar
mad-04363ca342914ba75e693edb876cbe535839fa79.zip
Einfache Abfrage der Benutzerdatenbank implementiert
Diffstat (limited to 'src/Client')
-rw-r--r--src/Client/CommandManager.cpp26
-rw-r--r--src/Client/CommandManager.h2
-rw-r--r--src/Client/CommandParser.cpp22
-rw-r--r--src/Client/CommandParser.h1
-rw-r--r--src/Client/Makefile.in9
-rw-r--r--src/Client/Requests/Makefile.in9
6 files changed, 54 insertions, 15 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index 4b24782..aacf939 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -23,6 +23,7 @@
#include <Net/Packets/FSInfoPacket.h>
#include <Net/Packets/HostListPacket.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <Net/Packets/UserListPacket.h>
#include <cmath>
#include <iostream>
@@ -205,5 +206,30 @@ void CommandManager::statusRequestFinished(const Common::Request<Net::Packets::H
requestFinished();
}
+void CommandManager::userListRequestFinished(const Common::Request<Net::Packets::UserListPacket> &request) {
+ try {
+ const Net::Packets::UserListPacket &packet = request.getResult();
+
+ const std::vector<Common::UserInfo> &users = packet.getUserInfo();
+
+ if(users.empty()) {
+ std::cout << "User list is empty." << std::endl;
+ }
+ else {
+ std::cout << "Found " << packet.getUserInfo().size() << " users:" << std::endl;
+
+ for(std::vector<Common::UserInfo>::const_iterator user = users.begin(); user != users.end(); ++user)
+ std::cout << " " << user->getUid() << ", " << user->getGid() << ", " << user->getUsername() << ", " << user->getFullName() << std::endl;
+ }
+
+ std::cout << std::endl;
+ }
+ catch(Common::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 ef20e8a..454c77e 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -29,6 +29,7 @@ namespace Packets {
class FSInfoPacket;
class HostStatusPacket;
class HostListPacket;
+class UserListPacket;
}
}
@@ -61,6 +62,7 @@ class CommandManager {
void disconnectRequestFinished(const Common::Request<> &request);
void fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
void statusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
+ void userListRequestFinished(const Common::Request<Net::Packets::UserListPacket> &request);
CommandManager() : activeRequests(0), disconnect(false) {}
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index efc9c4b..304a2ff 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -28,6 +28,7 @@
#include <Common/Requests/FSInfoRequest.h>
#include <Common/Requests/DisconnectRequest.h>
#include <Common/Requests/StatusRequest.h>
+#include <Common/Requests/UserListRequest.h>
#include <Common/Tokenizer.h>
#include <Net/Packets/HostListPacket.h>
#include <Net/Packets/HostStatusPacket.h>
@@ -40,13 +41,14 @@ namespace Mad {
namespace Client {
const CommandParser::Command CommandParser::commands[] = {
- {{"fsinfo", 0}, "fsinfo [host]", "Displays file system usage information", "Displays file system usage information of a host or the server (if no host is given).", &CommandParser::fsinfoCommand},
- {{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand},
- {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
- {{"reboot", 0}, "reboot *|host...", "Reboots host", "Reboots hosts. * will reboot all hosts.", &CommandParser::rebootCommand},
- {{"shutdown", "halt", 0}, "shutdown *|host...", "Shuts hosts down", "Shuts hosts down. * will shut down all hosts.", &CommandParser::shutdownCommand},
- {{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &CommandParser::statusCommand},
- {{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand},
+ {{"fsinfo", 0}, "fsinfo [host]", "Display file system usage information", "Display file system usage information of a host or the server (if no host is given).", &CommandParser::fsinfoCommand},
+ {{"help", "?", 0}, "help [command]", "Display usage information about commands", "Display usage information about a command. If no command is given, display a list of all available commands.", &CommandParser::helpCommand},
+ {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "List the currently active hosts", "List the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
+ {{"reboot", 0}, "reboot *|host...", "Reboot host", "Reboot hosts. * will reboot all hosts.", &CommandParser::rebootCommand},
+ {{"shutdown", "halt", 0}, "shutdown *|host...", "Shut hosts down", "Shut hosts down. * will shut down all hosts.", &CommandParser::shutdownCommand},
+ {{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &CommandParser::statusCommand},
+ {{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &CommandParser::listUsersCommand},
+ {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Closes the connection and quits the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
};
@@ -253,6 +255,12 @@ void CommandParser::statusCommand(const std::vector<std::string> &args) {
++CommandManager::get()->activeRequests;
}
+void CommandParser::listUsersCommand(const std::vector<std::string>&) {
+ ++CommandManager::get()->activeRequests;
+
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::UserListRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::userListRequestFinished))));
+}
+
void CommandParser::exitCommand(const std::vector<std::string>&) {
++CommandManager::get()->activeRequests;
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index e01449a..de65788 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -66,6 +66,7 @@ class CommandParser {
void rebootCommand(const std::vector<std::string> &args);
void shutdownCommand(const std::vector<std::string> &args);
void statusCommand(const std::vector<std::string> &args);
+ void listUsersCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
CommandParser() : connection(0) {}
diff --git a/src/Client/Makefile.in b/src/Client/Makefile.in
index 3d3ddda..20f85ee 100644
--- a/src/Client/Makefile.in
+++ b/src/Client/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -221,6 +221,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Requests
@@ -236,8 +237,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -385,7 +386,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in
index bba3c7f..842713e 100644
--- a/src/Client/Requests/Makefile.in
+++ b/src/Client/Requests/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -212,6 +212,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
@@ -225,8 +226,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -305,7 +306,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS