summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/ConnectionManager.cpp3
-rw-r--r--src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp71
-rw-r--r--src/Core/RequestHandlers/DaemonCommandRequestHandler.h49
-rw-r--r--src/Core/RequestHandlers/Makefile.am4
-rw-r--r--src/Core/RequestHandlers/Makefile.in12
-rw-r--r--src/Core/Requests/CommandRequest.cpp47
-rw-r--r--src/Core/Requests/CommandRequest.h45
-rw-r--r--src/Core/Requests/Makefile.am4
-rw-r--r--src/Core/Requests/Makefile.in7
9 files changed, 230 insertions, 12 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index 272c04b..faf6e29 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -21,6 +21,7 @@
#include "ConfigManager.h"
#include <Common/Logger.h>
#include <Common/RequestHandlers/StatusRequestHandler.h>
+#include "RequestHandlers/DaemonCommandRequestHandler.h"
#include "RequestHandlers/DaemonListRequestHandler.h"
#include "RequestHandlers/DaemonStatusRequestHandler.h"
#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
@@ -67,6 +68,8 @@ ConnectionManager::ConnectionManager() {
Common::RequestManager::init(true);
Common::RequestManager::getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>(Net::Packet::STATUS);
+ Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_REBOOT);
+ Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>(Net::Packet::DAEMON_COMMAND_SHUTDOWN);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonListRequestHandler>(Net::Packet::LIST_DAEMONS);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>(Net::Packet::DAEMON_STATUS);
Common::RequestManager::getRequestManager()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH);
diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp
new file mode 100644
index 0000000..9ae0bdd
--- /dev/null
+++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.cpp
@@ -0,0 +1,71 @@
+/*
+ * DaemonCommandRequestHandler.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DaemonCommandRequestHandler.h"
+#include "../ConnectionManager.h"
+#include <Common/Logger.h>
+#include <Core/Requests/CommandRequest.h>
+#include <Net/Packets/ErrorPacket.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+void DaemonCommandRequestHandler::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::DAEMON_COMMAND_SHUTDOWN && packet.getType() != Net::Packet::DAEMON_COMMAND_REBOOT) {
+ Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ signalFinished().emit();
+ return;
+ }
+
+ // TODO Require authentication
+
+ con = connection;
+ requestId = packet.getRequestId();
+
+ std::string daemonName((char*)packet.getData(), packet.getLength());
+
+ try {
+ Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName);
+ Common::RequestManager::getRequestManager()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(
+ new Requests::CommandRequest(packet.getType() == Net::Packet::DAEMON_COMMAND_REBOOT, sigc::mem_fun(this, &DaemonCommandRequestHandler::requestFinished))
+ ));
+ }
+ catch(Common::Exception &e) {
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e));
+ }
+}
+
+void DaemonCommandRequestHandler::requestFinished(const Common::Request<> &request) {
+ try {
+ request.getResult();
+ con->send(Net::Packet(Net::Packet::OK, requestId));
+ }
+ catch(Common::Exception &e) {
+ con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, requestId, e));
+ }
+
+ signalFinished().emit();
+}
+
+}
+}
+}
diff --git a/src/Core/RequestHandlers/DaemonCommandRequestHandler.h b/src/Core/RequestHandlers/DaemonCommandRequestHandler.h
new file mode 100644
index 0000000..bb021ed
--- /dev/null
+++ b/src/Core/RequestHandlers/DaemonCommandRequestHandler.h
@@ -0,0 +1,49 @@
+/*
+ * DaemonCommandRequestHandler.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_REQUESTHANDLERS_DAEMONCOMMANDREQUESTHANDLER_H_
+#define MAD_CORE_REQUESTHANDLERS_DAEMONCOMMANDREQUESTHANDLER_H_
+
+#include <Common/RequestHandler.h>
+#include <Common/Request.h>
+#include <stdint.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+class DaemonCommandRequestHandler : public Common::RequestHandler {
+ private:
+ Net::Connection *con;
+ uint16_t requestId;
+
+ void requestFinished(const Common::Request<> &request);
+
+ protected:
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+
+ public:
+ DaemonCommandRequestHandler() {}
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTHANDLERS_DAEMONCOMMANDREQUESTHANDLER_H_ */
diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am
index 3c52634..484df59 100644
--- a/src/Core/RequestHandlers/Makefile.am
+++ b/src/Core/RequestHandlers/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequesthandlers.la
-librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp
+librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp
-noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h
+noinst_HEADERS = DaemonCommandRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h
diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in
index a450ea0..e0dc6f2 100644
--- a/src/Core/RequestHandlers/Makefile.in
+++ b/src/Core/RequestHandlers/Makefile.in
@@ -48,9 +48,10 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequesthandlers_la_LIBADD =
-am_librequesthandlers_la_OBJECTS = DaemonListRequestHandler.lo \
- DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \
- IdentifyRequestHandler.lo LogRequestHandler.lo
+am_librequesthandlers_la_OBJECTS = DaemonCommandRequestHandler.lo \
+ DaemonListRequestHandler.lo DaemonStatusRequestHandler.lo \
+ GSSAPIAuthRequestHandler.lo IdentifyRequestHandler.lo \
+ LogRequestHandler.lo
librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -189,8 +190,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequesthandlers.la
-librequesthandlers_la_SOURCES = DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp
-noinst_HEADERS = DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h
+librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp IdentifyRequestHandler.cpp LogRequestHandler.cpp
+noinst_HEADERS = DaemonCommandRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h IdentifyRequestHandler.h LogRequestHandler.h
all: all-am
.SUFFIXES:
@@ -242,6 +243,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonCommandRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonListRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@
diff --git a/src/Core/Requests/CommandRequest.cpp b/src/Core/Requests/CommandRequest.cpp
new file mode 100644
index 0000000..35d4dd2
--- /dev/null
+++ b/src/Core/Requests/CommandRequest.cpp
@@ -0,0 +1,47 @@
+/*
+ * CommandRequest.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "CommandRequest.h"
+#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+
+namespace Mad {
+namespace Core {
+namespace Requests {
+
+void CommandRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+ connection->send(Net::Packet(reboot ? Net::Packet::COMMAND_REBOOT : Net::Packet::COMMAND_SHUTDOWN, requestId));
+}
+
+void CommandRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() == Net::Packet::ERROR) {
+ finishWithError(Net::Packets::ErrorPacket(packet).getException());
+ return;
+ }
+ else if(packet.getType() != Net::Packet::OK) {
+ finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET));
+ return; // TODO Logging
+ }
+
+ finish();
+}
+
+}
+}
+}
diff --git a/src/Core/Requests/CommandRequest.h b/src/Core/Requests/CommandRequest.h
new file mode 100644
index 0000000..181fa4d
--- /dev/null
+++ b/src/Core/Requests/CommandRequest.h
@@ -0,0 +1,45 @@
+/*
+ * CommandRequest.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_REQUESTS_COMMANDREQUEST_H_
+#define MAD_CORE_REQUESTS_COMMANDREQUEST_H_
+
+#include <Common/Request.h>
+
+namespace Mad {
+namespace Core {
+namespace Requests {
+
+class CommandRequest : public Common::Request<> {
+ private:
+ bool reboot;
+
+ protected:
+ virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+
+ public:
+ CommandRequest(bool reboot0, slot_type slot) : Common::Request<>(slot), reboot(reboot0) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTS_COMMANDREQUEST_H_ */
diff --git a/src/Core/Requests/Makefile.am b/src/Core/Requests/Makefile.am
index d220dd6..2d08477 100644
--- a/src/Core/Requests/Makefile.am
+++ b/src/Core/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DaemonStatusRequest.cpp
+librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp
-noinst_HEADERS = DaemonStatusRequest.h
+noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h
diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in
index 23458f1..22ac701 100644
--- a/src/Core/Requests/Makefile.in
+++ b/src/Core/Requests/Makefile.in
@@ -48,7 +48,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
-am_librequests_la_OBJECTS = DaemonStatusRequest.lo
+am_librequests_la_OBJECTS = CommandRequest.lo DaemonStatusRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -187,8 +187,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DaemonStatusRequest.cpp
-noinst_HEADERS = DaemonStatusRequest.h
+librequests_la_SOURCES = CommandRequest.cpp DaemonStatusRequest.cpp
+noinst_HEADERS = CommandRequest.h DaemonStatusRequest.h
all: all-am
.SUFFIXES:
@@ -240,6 +240,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CommandRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DaemonStatusRequest.Plo@am__quote@
.cpp.o: