Changeset - e0f560a64814
[Not reviewed]
0 5 0
Jan Kaluza - 13 years ago 2012-11-13 12:37:42
hanzz.k@gmail.com
Added database.vip_statement, database.vip_only and database.vip_message variables
5 files changed with 58 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/config.cpp
Show inline comments
 
@@ -99,6 +99,8 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		("service.enable_xhtml", value<bool>()->default_value(true), "")
 
		("service.max_room_list_size", value<int>()->default_value(100), "")
 
		("service.jid_escaping", value<bool>()->default_value(true), "")
 
		("service.vip_only", value<bool>()->default_value(false), "")
 
		("service.vip_message", value<std::string>()->default_value(""), "")
 
		("vhosts.vhost", value<std::vector<std::string> >()->multitoken(), "")
 
		("identity.name", value<std::string>()->default_value("Spectrum 2 Transport"), "Name showed in service discovery.")
 
		("identity.category", value<std::string>()->default_value("gateway"), "Disco#info identity category. 'gateway' by default.")
 
@@ -125,6 +127,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description
 
		("database.port", value<int>()->default_value(0), "Database port.")
 
		("database.prefix", value<std::string>()->default_value(""), "Prefix of tables in database")
 
		("database.encryption_key", value<std::string>()->default_value(""), "Encryption key.")
 
		("database.vip_statement", value<std::string>()->default_value(""), "Encryption key.")
 
		("logging.config", value<std::string>()->default_value(""), "Path to log4cxx config file which is used for Spectrum 2 instance")
 
		("logging.backend_config", value<std::string>()->default_value(""), "Path to log4cxx config file which is used for backends")
 
		("backend.default_avatar", value<std::string>()->default_value(""), "Full path to default avatar")
src/mysqlbackend.cpp
Show inline comments
 
@@ -443,6 +443,23 @@ bool MySQLBackend::getUser(const std::string &barejid, UserInfo &user) {
 
		}
 
	}
 

	
 
	if (!CONFIG_STRING(m_config, "database.vip_statement").empty()) {
 
		std::string query = CONFIG_STRING(m_config, "database.vip_statement");
 
		boost::replace_all(query, "$jid", barejid);
 
		LOG4CXX_INFO(logger, "Executing '" << query << "' to find out if user " << barejid << " is VIP");
 
		if (exec(query)) {
 
			MYSQL_RES *result = mysql_store_result(&m_conn);
 
			if (result) {
 
				LOG4CXX_INFO(logger, "User " << barejid << " is VIP");
 
				user.vip = 1;
 
			}
 
			else {
 
				LOG4CXX_INFO(logger, "User " << barejid << " is not VIP");
 
				user.vip = 0;
 
			}
 
		}
 
	}
 

	
 
	return ret;
 
}
 

	
src/tests/basictest.h
Show inline comments
 
@@ -225,6 +225,7 @@ class BasicTest : public Swift::XMPPParserClient {
 
		user.jid = "user@localhost";
 
		user.uin = "legacyname";
 
		user.password = "password";
 
		user.vip = 0;
 
		storage->setUser(user);
 
	}
 

	
src/tests/usermanager.cpp
Show inline comments
 
@@ -27,6 +27,7 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST(connectUserTransportDisabled);
 
	CPPUNIT_TEST(connectUserRegistrationNeeded);
 
	CPPUNIT_TEST(connectUserRegistrationNeededRegistered);
 
	CPPUNIT_TEST(connectUserVipOnlyNonVip);
 
	CPPUNIT_TEST(handleProbePresence);
 
	CPPUNIT_TEST(disconnectUser);
 
	CPPUNIT_TEST_SUITE_END();
 
@@ -71,6 +72,26 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT(!streamEnded);
 
	}
 

	
 
	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());
 
		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;
src/usermanager.cpp
Show inline comments
 
@@ -277,6 +277,22 @@ void UserManager::handlePresence(Swift::Presence::ref presence) {
 
			return;
 
		}
 

	
 
		if (CONFIG_BOOL(m_component->getConfig(), "service.vip_only") && res.vip == false) {
 
			if (!CONFIG_STRING(m_component->getConfig(), "service.vip_message").empty()) {
 
				boost::shared_ptr<Swift::Message> msg(new Swift::Message());
 
				msg->setBody(CONFIG_STRING(m_component->getConfig(), "service.vip_message"));
 
				msg->setTo(presence->getFrom());
 
				msg->setFrom(m_component->getJID());
 
				m_component->getStanzaChannel()->sendMessage(msg);
 
			}
 

	
 
			LOG4CXX_WARN(logger, "Non VIP user " << userkey << " tried to login");
 
			if (m_component->inServerMode()) {
 
				m_userRegistry->onPasswordInvalid(presence->getFrom());
 
			}
 
			return;
 
		}
 

	
 
		bool transport_enabled = true;
 
		if (m_storageBackend) {
 
			std::string value = "1";
0 comments (0 inline, 0 general)