diff --git a/include/Swiften/Parser/PayloadParsers/StatsParser.cpp b/include/Swiften/Parser/PayloadParsers/StatsParser.cpp index 2c4e421b..1c795a8a 100644 --- a/include/Swiften/Parser/PayloadParsers/StatsParser.cpp +++ b/include/Swiften/Parser/PayloadParsers/StatsParser.cpp @@ -14,7 +14,7 @@ StatsParser::StatsParser() : level_(TopLevel), inItem_(false) { void StatsParser::handleStartElement(const std::string& element, const std::string& /*ns*/, const AttributeMap& attributes) { if (level_ == PayloadLevel) { - if (element == "item") { + if (element == "stat") { inItem_ = true; currentItem_ = StatsPayload::Item(); diff --git a/include/transport/statsresponder.h b/include/transport/statsresponder.h new file mode 100644 index 00000000..9c252d92 --- /dev/null +++ b/include/transport/statsresponder.h @@ -0,0 +1,51 @@ +/** + * libtransport -- C++ library for easy XMPP Transports development + * + * Copyright (C) 2011, Jan Kaluza + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#pragma once + +#include +#include "Swiften/Swiften.h" +#include "Swiften/Queries/SetResponder.h" +#include "Swiften/Elements/StatsPayload.h" + +namespace Transport { + +class Component; +class UserManager; +class NetworkPluginServer; +class StorageBackend; + +class StatsResponder : public Swift::Responder { + public: + StatsResponder(Component *component, UserManager *userManager, NetworkPluginServer *server, StorageBackend *storageBackend); + ~StatsResponder(); + + private: + virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr payload); + virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr payload); + + Component *m_component; + UserManager *m_userManager; + NetworkPluginServer *m_server; + StorageBackend *m_storageBackend; + time_t m_start; +}; + +} diff --git a/spectrum/src/main.cpp b/spectrum/src/main.cpp index 2c14f3a9..07a76ce8 100644 --- a/spectrum/src/main.cpp +++ b/spectrum/src/main.cpp @@ -8,6 +8,7 @@ #include "transport/userregistration.h" #include "transport/networkpluginserver.h" #include "transport/admininterface.h" +#include "transport/statsresponder.h" #include "transport/util.h" #include "Swiften/EventLoop/SimpleEventLoop.h" #include @@ -323,6 +324,8 @@ int main(int argc, char **argv) NetworkPluginServer plugin(&transport, &config, &userManager, &ftManager); AdminInterface adminInterface(&transport, &userManager, &plugin, storageBackend); + StatsResponder statsResponder(&transport, &userManager, &plugin, storageBackend); + statsResponder.start(); eventLoop_ = &eventLoop; diff --git a/src/statsresponder.cpp b/src/statsresponder.cpp new file mode 100644 index 00000000..bfa04aca --- /dev/null +++ b/src/statsresponder.cpp @@ -0,0 +1,78 @@ +/** + * XMPP - libpurple transport + * + * Copyright (C) 2009, Jan Kaluza + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA + */ + +#include "transport/statsresponder.h" + +#include +#include +#include "Swiften/Queries/IQRouter.h" +#include "transport/BlockPayload.h" +#include "Swiften/Swiften.h" +#include "transport/usermanager.h" +#include "transport/user.h" +#include "transport/buddy.h" +#include "transport/rostermanager.h" +#include "log4cxx/logger.h" + +using namespace log4cxx; + +using namespace Swift; +using namespace boost; + +namespace Transport { + +static LoggerPtr logger = Logger::getLogger("StatsResponder"); + +StatsResponder::StatsResponder(Component *component, UserManager *userManager, NetworkPluginServer *server, StorageBackend *storageBackend) : Swift::Responder(component->getIQRouter()) { + m_component = component; + m_userManager = userManager; + m_server = server; + m_storageBackend = storageBackend; + m_start = time(0); +} + +StatsResponder::~StatsResponder() { + +} + +bool StatsResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr stats) { + boost::shared_ptr response(new StatsPayload()); + + if (stats->getItems().empty()) { + response->addItem(StatsPayload::Item("uptime")); + } + else { + BOOST_FOREACH(const StatsPayload::Item &item, stats->getItems()) { + if (item.getName() == "uptime") { + response->addItem(StatsPayload::Item("uptime", "seconds", boost::lexical_cast(time(0) - m_start))); + } + } + } + + sendResponse(from, id, response); + + return true; +} + +bool StatsResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr stats) { + return false; +} + +}