Changeset - 7ba8909d719f
[Not reviewed]
0 9 0
Jan Kaluza - 9 years ago 2016-02-15 12:21:04
jkaluza@redhat.com
Use value_or instead of get_value_or
9 files changed with 16 insertions and 16 deletions:
0 comments (0 inline, 0 general)
libtransport/AdminInterface.cpp
Show inline comments
 
@@ -55,25 +55,25 @@ AdminInterface::AdminInterface(Component *component, UserManager *userManager, N
 
	m_server = server;
 
	m_userRegistration = userRegistration;
 
	m_start = time(NULL);
 

	
 
	m_component->getFrontend()->onMessageReceived.connect(bind(&AdminInterface::handleMessageReceived, this, _1));
 
}
 

	
 
AdminInterface::~AdminInterface() {
 
}
 

	
 
void AdminInterface::handleQuery(Swift::Message::ref message) {
 
#if HAVE_SWIFTEN_3
 
	std::string msg = message->getBody().value_or("");
 
	std::string msg = message->getBody().get_value_or("");
 
#else
 
	std::string msg = message->getBody();
 
#endif
 
	LOG4CXX_INFO(logger, "Message from admin received: '" << msg << "'");
 
	message->setTo(message->getFrom());
 
	message->setFrom(m_component->getJID());
 

	
 
	if (msg == "status") {
 
		int users = m_userManager->getUserCount();
 
		int backends = m_server->getBackendCount();
 
		message->setBody("Running (" + boost::lexical_cast<std::string>(users) + " users connected using " + boost::lexical_cast<std::string>(backends) + " backends)");
 
	}
 
@@ -381,25 +381,25 @@ void AdminInterface::handleMessageReceived(Swift::Message::ref message) {
 
	if (!message->getTo().getNode().empty())
 
		return;
 

	
 
	std::vector<std::string> const &x = CONFIG_VECTOR(m_component->getConfig(),"service.admin_jid");
 
	if (std::find(x.begin(), x.end(), message->getFrom().toBare().toString()) == x.end()) {
 
	    LOG4CXX_WARN(logger, "Message not from admin user, but from " << message->getFrom().toBare().toString());
 
	    return;
 
	
 
	}
 
	
 
	// Ignore empty messages
 
#if HAVE_SWIFTEN_3
 
	if (message->getBody().value_or("").empty()) {
 
	if (message->getBody().get_value_or("").empty()) {
 
		return;
 
	}
 
#else
 
	if (message->getBody().empty()) {
 
		return;
 
	}
 
#endif
 

	
 
	handleQuery(message);
 

	
 
	m_component->getFrontend()->sendMessage(message);
 
}
libtransport/NetworkPluginServer.cpp
Show inline comments
 
@@ -962,25 +962,25 @@ void NetworkPluginServer::handleQueryPayload(Backend *b, const std::string &data
 
	}
 

	
 
	if (!m_adminInterface) {
 
		return;
 
	}
 

	
 
	boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
	msg->setBody(payload.config());
 
	m_adminInterface->handleQuery(msg);
 

	
 
	pbnetwork::BackendConfig response;
 
#if HAVE_SWIFTEN_3
 
	response.set_config(msg->getBody().value_or(""));
 
	response.set_config(msg->getBody().get_value_or(""));
 
#else
 
	response.set_config(msg->getBody());
 
#endif
 

	
 
	std::string message;
 
	response.SerializeToString(&message);
 

	
 
	WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_QUERY);
 

	
 
	send(b->connection, message);
 
}
 

	
 
@@ -1688,25 +1688,25 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
 
				return;
 
			}
 
			send(c->connection, message);
 
		}
 
	}
 

	
 
	boost::shared_ptr<Swift::AttentionPayload> attentionPayload = msg->getPayload<Swift::AttentionPayload>();
 
	if (attentionPayload) {
 
		pbnetwork::ConversationMessage m;
 
		m.set_username(conv->getConversationManager()->getUser()->getJID().toBare());
 
		m.set_buddyname(conv->getLegacyName());
 
#if HAVE_SWIFTEN_3
 
		m.set_message(msg->getBody().value_or(""));
 
		m.set_message(msg->getBody().get_value_or(""));
 
#else
 
		m.set_message(msg->getBody());
 
#endif
 

	
 
		std::string message;
 
		m.SerializeToString(&message);
 

	
 
		WRAP(message, pbnetwork::WrapperMessage_Type_TYPE_ATTENTION);
 

	
 
		Backend *c = (Backend *) conv->getConversationManager()->getUser()->getData();
 
		send(c->connection, message);
 
		return;
 
@@ -1728,25 +1728,25 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
 
		return;
 
	}
 
	
 

	
 
	std::string xhtml;
 
	boost::shared_ptr<Swift::XHTMLIMPayload> xhtmlPayload = msg->getPayload<Swift::XHTMLIMPayload>();
 
	if (xhtmlPayload) {
 
		xhtml = xhtmlPayload->getBody();
 
	}
 

	
 
	// Send normal message
 
#if HAVE_SWIFTEN_3
 
	std::string body = msg->getBody().value_or("");
 
	std::string body = msg->getBody().get_value_or("");
 
#else
 
	std::string body = msg->getBody();
 
#endif
 
	if (!body.empty() || !xhtml.empty()) {
 
		pbnetwork::ConversationMessage m;
 
		m.set_username(conv->getConversationManager()->getUser()->getJID().toBare());
 
		m.set_buddyname(conv->getLegacyName());
 
		m.set_message(body);
 
		m.set_xhtml(xhtml);
 
		boost::shared_ptr<Swift::DeliveryReceiptRequest> receiptPayload = msg->getPayload<Swift::DeliveryReceiptRequest>();
 
		if (receiptPayload && !msg->getID().empty()) {
 
			m.set_id(msg->getID());
libtransport/UserManager.cpp
Show inline comments
 
@@ -366,25 +366,25 @@ void UserManager::handleRemoveTimeout(const std::string jid, User *u, bool recon
 
void UserManager::handleMessageReceived(Swift::Message::ref message) {
 
	if (message->getType() == Swift::Message::Error) {
 
		return;
 
	}
 

	
 
	// Do not count chatstate notification...
 
	boost::shared_ptr<Swift::ChatState> statePayload = message->getPayload<Swift::ChatState>();
 
	if (!statePayload) {
 
		messageToBackendSent();
 
	}
 

	
 
#if HAVE_SWIFTEN_3
 
	std::string body = message->getBody().value_or("");
 
	std::string body = message->getBody().get_value_or("");
 
#else
 
	std::string body = message->getBody();
 
#endif
 
	if (body.empty() && !statePayload && message->getSubject().empty()) {
 
		return;
 
	}
 

	
 
	User *user = getUser(message->getFrom().toBare().toString());
 
	if (!user){
 
		return;
 
	}
 

	
spectrum/src/frontends/slack/SlackSession.cpp
Show inline comments
 
@@ -142,25 +142,25 @@ void SlackSession::sendMessage(boost::shared_ptr<Swift::Message> message) {
 
		}
 
		channel = m_slackChannel;
 
		from = Buddy::JIDToLegacyName(message->getFrom(), m_user);
 

	
 
		Buddy *b;
 
		if (m_user && (b = m_user->getRosterManager()->getBuddy(from)) != NULL) {
 
			from = b->getAlias() + " (" + from + ")";
 
		}
 
	}
 

	
 
	LOG4CXX_INFO(logger, m_uinfo.jid << "Sending message to Slack channel " << channel << " from " << from);
 
#if HAVE_SWIFTEN_3
 
	std::string body = message->getBody().value_or("");
 
	std::string body = message->getBody().get_value_or("");
 
#else
 
	std::string body = message->getBody();
 
#endif
 
	m_rtm->getAPI()->sendMessage(from, channel, body);
 
}
 

	
 
void SlackSession::setPurpose(const std::string &purpose, const std::string &channel) {
 
	std::string ch = channel;
 
	if (ch.empty()) {
 
		ch = m_slackChannel;
 
	}
 
	if (ch.empty()) {
spectrum/src/frontends/slack/SlackUserManager.cpp
Show inline comments
 
@@ -101,25 +101,25 @@ std::string SlackUserManager::handleOAuth2Code(const std::string &code, const st
 

	
 
std::string SlackUserManager::getOAuth2URL(const std::vector<std::string> &args) {
 
	return static_cast<SlackUserRegistration *>(m_userRegistration)->createOAuth2URL(args);
 
}
 

	
 
void SlackUserManager::handleUserCreated(User *user) {
 
	LOG4CXX_INFO(logger, "handleUserCreated");
 
	static_cast<SlackUser *>(user)->getSession()->handleConnected();
 
}
 

	
 
bool SlackUserManager::handleAdminMessage(Swift::Message::ref message) {
 
#if HAVE_SWIFTEN_3
 
	std::string body = message->getBody().value_or("");
 
	std::string body = message->getBody().get_value_or("");
 
#else
 
	std::string body = message->getBody();
 
#endif
 

	
 
	if (body.find("list_rooms") == 0) {
 
		std::vector<std::string> args;
 
		boost::split(args, body, boost::is_any_of(" "));
 
		if (args.size() == 2) {
 
			UserInfo uinfo;
 
			if (!m_storageBackend->getUser(args[1], uinfo)) {
 
				message->setBody("Error: Unknown user");
 
				return true;
tests/libtransport/conversationmanager.cpp
Show inline comments
 
@@ -5,25 +5,25 @@
 
#include <Swiften/Server/Server.h>
 
#include <Swiften/Network/DummyNetworkFactories.h>
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include <Swiften/Elements/VCardUpdate.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#define get_value_or(X) substr()
 
#endif
 

	
 
class ConversationManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(ConversationManagerTest);
 
	CPPUNIT_TEST(conversationSize);
 
	CPPUNIT_TEST(handleNormalMessages);
 
	CPPUNIT_TEST(handleNormalMessagesInitiatedFromXMPP);
 
	CPPUNIT_TEST(handleNormalMessagesHeadline);
 
	CPPUNIT_TEST(handleGroupchatMessages);
 
	CPPUNIT_TEST(handleGroupchatMessagesAlias);
 
	CPPUNIT_TEST(handleGroupchatMessagesBouncer);
 
	CPPUNIT_TEST(handleGroupchatMessagesBouncerLeave);
tests/libtransport/user.cpp
Show inline comments
 
@@ -4,25 +4,25 @@
 
#include <Swiften/EventLoop/DummyEventLoop.h>
 
#include <Swiften/Server/Server.h>
 
#include <Swiften/Network/DummyNetworkFactories.h>
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#define get_value_or(X) substr()
 
#endif
 

	
 
class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserTest);
 
	CPPUNIT_TEST(sendCurrentPresence);
 
    CPPUNIT_TEST(handlePresence);
 
	CPPUNIT_TEST(handlePresenceJoinRoom);
 
	CPPUNIT_TEST(handlePresenceJoinRoomTwoResources);
 
	CPPUNIT_TEST(handlePresenceLeaveRoom);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResources);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomTwoResourcesOneDisconnects);
 
	CPPUNIT_TEST(handlePresenceLeaveRoomBouncer);
 
@@ -422,25 +422,25 @@ class UserTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 

	
 
	void handleDisconnected() {
 
		User *user = userManager->getUser("user@localhost");
 
		user->handleDisconnected("Connection error", Swift::SpectrumErrorPayload::CONNECTION_ERROR_AUTHENTICATION_FAILED);
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT(streamEnded);
 
		user = userManager->getUser("user@localhost");
 
		CPPUNIT_ASSERT(!user);
 

	
 
		CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
		Swift::Message *m = dynamic_cast<Swift::Message *>(getStanza(received[0]));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Connection error"), m->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Connection error"), m->getBody().get_value_or(""));
 

	
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::StreamError *>(received[1].get()));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Connection error"), dynamic_cast<Swift::StreamError *>(received[1].get())->getText());
 

	
 
		disconnected = true;
 
	}
 

	
 
	void handleDisconnectedReconnect() {
 
		readyToConnect = false;
 
		User *user = userManager->getUser("user@localhost");
 
		user->handleDisconnected("Connection error");
 
		loop->processEvents();
tests/libtransport/usermanager.cpp
Show inline comments
 
@@ -4,25 +4,25 @@
 
#include <Swiften/EventLoop/DummyEventLoop.h>
 
#include <Swiften/Server/Server.h>
 
#include <Swiften/Network/DummyNetworkFactories.h>
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#define get_value_or(X) substr()
 
#endif
 

	
 
class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserManagerTest);
 
	CPPUNIT_TEST(connectUser);
 
	CPPUNIT_TEST(connectTwoResources);
 
	CPPUNIT_TEST(connectUserTransportDisabled);
 
	CPPUNIT_TEST(connectUserRegistrationNeeded);
 
	CPPUNIT_TEST(connectUserRegistrationNeededRegistered);
 
	CPPUNIT_TEST(connectUserVipOnlyNonVip);
 
	CPPUNIT_TEST(handleProbePresence);
 
	CPPUNIT_TEST(disconnectUser);
 
@@ -72,25 +72,25 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	}
 

	
 
	void connectUserVipOnlyNonVip() {
 
		addUser();
 
		std::istringstream ifs("service.server_mode = 1\nservice.jid_escaping=0\nservice.jid=localhost\nservice.vip_only=1\nservice.vip_message=Ahoj\n");
 
		cfg->load(ifs);
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		loop->processEvents();
 

	
 
		CPPUNIT_ASSERT_EQUAL(3, (int) received.size());
 
		CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Ahoj"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("Ahoj"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().get_value_or(""));
 
		CPPUNIT_ASSERT_EQUAL(std::string("user@localhost/resource"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getTo().toString());
 
		CPPUNIT_ASSERT_EQUAL(std::string("localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getFrom().toString());
 

	
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		CPPUNIT_ASSERT(streamEnded);
 
		std::istringstream ifs2("service.server_mode = 1\nservice.jid_escaping=1\nservice.jid=localhost\nservice.more_resources=1\n");
 
		cfg->load(ifs2);
 
	}
 

	
 
	void handleProbePresence() {
 
		UserInfo info;
 
		info.id = 1;
tests/libtransport/userregistration.cpp
Show inline comments
 
@@ -4,25 +4,25 @@
 
#include <Swiften/EventLoop/DummyEventLoop.h>
 
#include <Swiften/Server/Server.h>
 
#include <Swiften/Network/DummyNetworkFactories.h>
 
#include <Swiften/Network/DummyConnectionServer.h>
 
#include "Swiften/Server/ServerStanzaChannel.h"
 
#include "Swiften/Server/ServerFromClientSession.h"
 
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
 
#include "basictest.h"
 

	
 
using namespace Transport;
 

	
 
#if !HAVE_SWIFTEN_3
 
#define value_or(X) substr()
 
#define get_value_or(X) substr()
 
#endif
 

	
 
class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserRegistrationTest);
 
	CPPUNIT_TEST(getForm);
 
	CPPUNIT_TEST(getFormRegistered);
 
	CPPUNIT_TEST(registerUser);
 
	CPPUNIT_TEST(registerUserWithoutRR);
 
	CPPUNIT_TEST(unregisterUser);
 
	CPPUNIT_TEST(unregisterEmptyPayload);
 
	CPPUNIT_TEST(registerUserNotify);
 
	CPPUNIT_TEST(unregisterUserNotify);
 
@@ -195,25 +195,25 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
			received.clear();
 
			injectIQ(iq);
 
			loop->processEvents();
 

	
 
			CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
 
			CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
 
			CPPUNIT_ASSERT_EQUAL(std::string("localhost"), getStanza(received[0])->getPayload<Swift::RosterPayload>()->getItems()[0].getJID().toString());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("registered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().value_or(""));
 
			CPPUNIT_ASSERT_EQUAL(std::string("registered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().get_value_or(""));
 

	
 
			UserInfo user;
 
			CPPUNIT_ASSERT_EQUAL(true, storage->getUser("user@localhost", user));
 

	
 
			CPPUNIT_ASSERT_EQUAL(std::string("legacyname"), user.uin);
 
			CPPUNIT_ASSERT_EQUAL(std::string("password"), user.password);
 
		}
 

	
 
		void unregisterUserNotify() {
 
			registerUserNotify();
 
			received.clear();
 

	
 
@@ -233,25 +233,25 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 

	
 
			iq = Swift::IQ::createResult(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID(), boost::shared_ptr<Swift::Payload>(new Swift::RosterPayload()));
 
			received.clear();
 
			injectIQ(iq);
 
			loop->processEvents();
 

	
 
			CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Set, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
 
			CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::RosterPayload>());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Message *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(std::string("unregistered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().value_or(""));
 
			CPPUNIT_ASSERT_EQUAL(std::string("unregistered: user@localhost"), dynamic_cast<Swift::Message *>(getStanza(received[1]))->getBody().get_value_or(""));
 

	
 

	
 
			UserInfo user;
 
			CPPUNIT_ASSERT_EQUAL(false, storage->getUser("user@localhost", user));
 
		}
 

	
 
		void changePassword() {
 
			registerUser();
 
			received.clear();
 

	
 
			Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
 
			reg->setUsername("legacyname");
0 comments (0 inline, 0 general)