Changeset - d3ccb9f195c8
[Not reviewed]
0 3 0
HanzZ - 14 years ago 2011-06-26 23:00:05
hanzz.k@gmail.com
Better spectrum_manager
3 files changed with 30 insertions and 5 deletions:
0 comments (0 inline, 0 general)
spectrum/src/main.cpp
Show inline comments
 
@@ -5,6 +5,7 @@
 
#include "transport/sqlite3backend.h"
 
#include "transport/userregistration.h"
 
#include "transport/networkpluginserver.h"
 
#include "transport/admininterface.h"
 
#include "Swiften/EventLoop/SimpleEventLoop.h"
 
 
using namespace Transport;
 
@@ -72,6 +73,8 @@ int main(int argc, char **argv)
 
	}
 
	logger.setUserManager(&userManager);
 
 
	AdminInterface adminInterface(&transport, storageBackend);
 
 
	NetworkPluginServer plugin(&transport, &config, &userManager);
 
 
	eventLoop.run();
spectrum_manager/src/main.cpp
Show inline comments
 
@@ -10,6 +10,7 @@
 
using namespace Transport;
 
 
static int finished;
 
static std::string *m;
 
 
static void handleDisconnected(Swift::Client *client, const boost::optional<Swift::ClientError> &) {
 
	std::cout << "[ DISCONNECTED ] " << client->getJID().getDomain() << "\n";
 
@@ -19,7 +20,16 @@ static void handleDisconnected(Swift::Client *client, const boost::optional<Swif
 
}
 
 
static void handleConnected(Swift::Client *client) {
 
	std::cout << "[      OK      ] " << client->getJID().getDomain() << "\n";
 
	boost::shared_ptr<Swift::Message> message(new Swift::Message());
 
	message->setTo(client->getJID().getDomain());
 
	message->setFrom(client->getJID());
 
	message->setBody(*m);
 
 
	client->sendMessage(message);
 
}
 
 
static void handleMessageReceived(Swift::Client *client, Swift::Message::ref message) {
 
	std::cout << "[      OK      ] " << client->getJID().getDomain() << ": " << message->getBody() <<  "\n";
 
	if (--finished == 0) {
 
		exit(0);
 
	}
 
@@ -29,7 +39,7 @@ int main(int argc, char **argv)
 
{
 
	ManagerConfig config;
 
 
	boost::program_options::options_description desc("Usage: spectrum_manager <config_file.cfg>\nAllowed options");
 
	boost::program_options::options_description desc("Usage: spectrum_manager <config_file.cfg> <command>\nAllowed options");
 
	desc.add_options()
 
		("help,h", "help")
 
		;
 
@@ -55,7 +65,7 @@ int main(int argc, char **argv)
 
		return 1;
 
	}
 
 
	if (argc != 2) {
 
	if (argc != 3) {
 
		std::cout << desc << "\n";
 
		return 1;
 
	}
 
@@ -69,6 +79,9 @@ int main(int argc, char **argv)
 
	Swift::SimpleEventLoop eventLoop;
 
	Swift::BoostNetworkFactories networkFactories(&eventLoop);
 
 
	std::string message = argv[2];
 
	m = &message;
 
 
	std::vector<std::string> servers = CONFIG_VECTOR(&config, "servers.server");
 
	for (std::vector<std::string>::const_iterator it = servers.begin(); it != servers.end(); it++) {
 
		finished++;
 
@@ -76,7 +89,7 @@ int main(int argc, char **argv)
 
		client->setAlwaysTrustCertificates();
 
 		client->onConnected.connect(boost::bind(&handleConnected, client));
 
		client->onDisconnected.connect(bind(&handleDisconnected, client, _1));
 
// 		client->onMessageReceived.connect(bind(&handleMessageReceived, _1));
 
		client->onMessageReceived.connect(bind(&handleMessageReceived, client, _1));
 
		Swift::ClientOptions opt;
 
		opt.allowPLAINWithoutTLS = true;
 
		client->connect(opt);
src/admininterface.cpp
Show inline comments
 
@@ -46,10 +46,19 @@ AdminInterface::~AdminInterface() {
 
void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
	if (!message->getTo().getNode().empty())
 
		return;
 
	if (message->getFrom().getNode() != CONFIG_STRING(m_component->getConfig(), "service.admin_username"))
 

	
 
	if (message->getFrom().getNode() != CONFIG_STRING(m_component->getConfig(), "service.admin_username")) {
 
		LOG4CXX_WARN(logger, "Message not from admin user, but from " << message->getFrom().getNode());
 
		return;
 
	}
 

	
 
	LOG4CXX_INFO(logger, "Message from admin received");
 
	message->setTo(message->getFrom());
 
	message->setFrom(m_component->getJID());
 

	
 
	message->setBody("Unknown command");
 

	
 
	m_component->getStanzaChannel()->sendMessage(message);
 
}
 

	
 
}
0 comments (0 inline, 0 general)