Changeset - 8d64493eef2a
[Not reviewed]
0 3 0
Jan Kaluza - 9 years ago 2016-01-23 21:58:48
jkaluza@redhat.com
Fix #86 - Use utf8 aware to_lower function
3 files changed with 32 insertions and 8 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -77,24 +77,24 @@ endif()
 

	
 
# FIND BOOST
 
if (WIN32)
 
	set(Boost_USE_STATIC_LIBS      ON)
 
	set(Boost_USE_MULTITHREADED      ON)
 
	set(Boost_USE_STATIC_RUNTIME    OFF)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals locale REQUIRED)
 
else(WIN32)
 
	LIST_CONTAINS(contains -lboost_program_options ${SWIFTEN_LIBRARY})
 
	if(contains)
 
		message(STATUS "Using non-multithreaded boost")
 
		set(Boost_USE_MULTITHREADED 0)
 
	endif(contains)
 
	set(Boost_FIND_QUIETLY ON)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread-mt signals)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread-mt signals locale)
 
	if (NOT Boost_FOUND)
 
		set(Boost_FIND_QUIETLY OFF)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals locale REQUIRED)
 
	endif()
 
endif(WIN32)
 

	
 
message( STATUS "Found Boost: ${Boost_VERSION}, ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}")
 

	
 
if (${Boost_VERSION} GREATER 104999)
libtransport/RosterManager.cpp
Show inline comments
 
@@ -31,24 +31,28 @@
 
#include "Swiften/Elements/RosterItemPayload.h"
 
#include "Swiften/Elements/RosterItemExchangePayload.h"
 
#include "Swiften/Elements/Nickname.h"
 
#include <boost/foreach.hpp>
 
#include <boost/make_shared.hpp>
 
#include <boost/algorithm/string.hpp>
 
#include <boost/locale.hpp>
 

	
 
#include <map>
 
#include <iterator>
 

	
 
namespace Transport {
 

	
 
DEFINE_LOGGER(logger, "RosterManager");
 

	
 
RosterManager::RosterManager(User *user, Component *component){
 
	m_rosterStorage = NULL;
 
	m_user = user;
 
	m_component = component;
 

	
 
	boost::locale::generator gen;
 
	std::locale::global(gen("en_GB.UTF8"));
 
}
 

	
 
RosterManager::~RosterManager() {
 
	if (m_rosterStorage) {
 
		m_rosterStorage->storeBuddies();
 
	}
 
@@ -68,13 +72,13 @@ RosterManager::~RosterManager() {
 
	if (m_rosterStorage)
 
		delete m_rosterStorage;
 
}
 

	
 
void RosterManager::removeBuddy(const std::string &_name) {
 
	std::string name = _name;
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	Buddy *buddy = getBuddy(name);
 
	if (!buddy) {
 
		LOG4CXX_WARN(logger, m_user->getJID().toString() << ": Tried to remove unknown buddy " << name);
 
		return;
 
	}
 

	
 
@@ -115,26 +119,26 @@ void RosterManager::sendBuddySubscribePresence(Buddy *buddy) {
 

	
 
void RosterManager::handleBuddyChanged(Buddy *buddy) {
 
}
 

	
 
void RosterManager::setBuddy(Buddy *buddy) {
 
	std::string name = buddy->getName();
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	LOG4CXX_INFO(logger, "Associating buddy " << name << " with " << m_user->getJID().toString());
 
	m_buddies[name] = buddy;
 
	onBuddySet(buddy);
 

	
 
	doAddBuddy(buddy);
 

	
 
	if (m_rosterStorage)
 
		m_rosterStorage->storeBuddy(buddy);
 
}
 

	
 
void RosterManager::unsetBuddy(Buddy *buddy) {
 
	std::string name = buddy->getName();
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	m_buddies.erase(name);
 
	if (m_rosterStorage)
 
		m_rosterStorage->removeBuddyFromQueue(buddy);
 
	onBuddyUnset(buddy);
 
}
 

	
 
@@ -143,13 +147,13 @@ void RosterManager::storeBuddy(Buddy *buddy) {
 
		m_rosterStorage->storeBuddy(buddy);
 
	}
 
}
 

	
 
Buddy *RosterManager::getBuddy(const std::string &_name) {
 
	std::string name = _name;
 
	boost::algorithm::to_lower(name);
 
	name = boost::locale::to_lower(name);
 
	return m_buddies[name];
 
}
 

	
 

	
 
void RosterManager::handleSubscription(Swift::Presence::ref presence) {
 
	std::string legacyName = Buddy::JIDToLegacyName(presence->getTo(), m_user);
 
@@ -346,13 +350,13 @@ void RosterManager::setStorageBackend(StorageBackend *storageBackend) {
 

	
 
	for (std::list<BuddyInfo>::const_iterator it = roster.begin(); it != roster.end(); it++) {
 
		Buddy *buddy = m_component->getFactory()->createBuddy(this, *it);
 
		if (buddy) {
 
			LOG4CXX_INFO(logger, m_user->getJID().toString() << ": Adding cached buddy " << buddy->getName() << " fom database");
 
			std::string name = buddy->getName();
 
			boost::algorithm::to_lower(name);
 
			name = boost::locale::to_lower(name);
 
			m_buddies[name] = buddy;
 
			onBuddySet(buddy);
 
		}
 
	}
 

	
 
	m_rosterStorage = storage;
tests/libtransport/rostermanager.cpp
Show inline comments
 
@@ -12,12 +12,13 @@
 

	
 
using namespace Transport;
 

	
 
class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(RosterManagerTest);
 
	CPPUNIT_TEST(setBuddy);
 
	CPPUNIT_TEST(setBuddyUTF8);
 
	CPPUNIT_TEST(setBuddyNoAlias);
 
	CPPUNIT_TEST(sendCurrentPresences);
 
	CPPUNIT_TEST(sendUnavailablePresences);
 
	CPPUNIT_TEST(sendCurrentPresence);
 
	CPPUNIT_TEST(sendBuddySubscribePresence);
 
	CPPUNIT_TEST(removeBuddy);
 
@@ -82,12 +83,31 @@ class RosterManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
 
		Swift::RosterItemPayload item = payload1->getItems()[0];
 
		CPPUNIT_ASSERT_EQUAL(std::string("buddy1"), Buddy::JIDToLegacyName(item.getJID(), user));
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), item.getName());
 
	}
 

	
 
	void setBuddyUTF8() {
 
		User *user = userManager->getUser("user@localhost");
 
		CPPUNIT_ASSERT(user);
 

	
 
		std::vector<std::string> grp;
 
		grp.push_back("group1");
 
		LocalBuddy *buddy = new LocalBuddy(user->getRosterManager(), -1, "Катя антонова", "", grp, BUDDY_JID_ESCAPING);
 
		user->getRosterManager()->setBuddy(buddy);
 

	
 
		CPPUNIT_ASSERT(user->getRosterManager()->getBuddy("катя антонова"));
 

	
 
		Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
 
		CPPUNIT_ASSERT(payload1);
 
		CPPUNIT_ASSERT_EQUAL(1, (int) payload1->getItems().size());
 
		Swift::RosterItemPayload item = payload1->getItems()[0];
 
		CPPUNIT_ASSERT_EQUAL(std::string("Катя антонова"), Buddy::JIDToLegacyName(item.getJID(), user));
 
		CPPUNIT_ASSERT_EQUAL(std::string(""), item.getName());
 
	}
 

	
 
	void setBuddy() {
 
		User *user = userManager->getUser("user@localhost");
 
		add2Buddies();
 
		CPPUNIT_ASSERT_EQUAL(4, (int) received.size());
 

	
 
		Swift::RosterPayload::ref payload1 = getStanza(received[0])->getPayload<Swift::RosterPayload>();
0 comments (0 inline, 0 general)