Changeset - 05e874df86a2
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-06-16 00:29:02
hanzz.k@gmail.com
Fixed UserRegisration crash
4 files changed with 22 insertions and 23 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -74,12 +74,13 @@ else()
 
	message("Network plugins   : no (install Google Protocol Buffers)")
 
	message("Libpurple plugin  : no (install libpurple and Google Protocol Buffers)")
 
	message("IRC plugin        : no (install libircclient-qt and Google Protocol Buffers)")
 
endif()
 

	
 
if(CMAKE_BUILD_TYPE MATCHES Debug)
 
	ADD_DEFINITIONS(-O0)
 
	ADD_DEFINITIONS(-ggdb)
 
	ADD_DEFINITIONS(-DDEBUG)
 
	ADD_DEFINITIONS(-Wall)
 
	ADD_DEFINITIONS(-W)
 
	ADD_DEFINITIONS(-Wcast-align)
 
	ADD_DEFINITIONS(-Wextra -Wno-sign-compare -Wno-unused-parameter)
 
@@ -105,16 +106,16 @@ include_directories(${EVENT_INCLUDE_DIRS})
 
include_directories(${SWIFTEN_INCLUDE_DIR})
 
include_directories(${Boost_INCLUDE_DIRS})
 

	
 

	
 
ADD_SUBDIRECTORY(src)
 
ADD_SUBDIRECTORY(include)
 
ADD_SUBDIRECTORY(examples)
 
#ADD_SUBDIRECTORY(examples)
 
ADD_SUBDIRECTORY(spectrum)
 
ADD_SUBDIRECTORY(backends)
 
ADD_SUBDIRECTORY(tests)
 
#ADD_SUBDIRECTORY(tests)
 

	
 
if(DOXYGEN_FOUND)
 
	message("Docs              : yes")
 
	ADD_SUBDIRECTORY(docs)
 
else(DOXYGEN_FOUND)
 
	message("Docs              : no (install doxygen)")
include/transport/userregistration.h
Show inline comments
 
@@ -18,26 +18,25 @@
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#pragma once
 

	
 
#include "Swiften/Swiften.h"
 
#include "Swiften/Queries/GetResponder.h"
 
#include "Swiften/Queries/SetResponder.h"
 
#include "Swiften/Queries/Responder.h"
 
#include "Swiften/Elements/InBandRegistrationPayload.h"
 

	
 
namespace Transport {
 

	
 
struct UserInfo;
 
class Component;
 
class StorageBackend;
 
class UserManager;
 
class Config;
 

	
 
/// Allows users to register the transport using service discovery.
 
class UserRegistration : Swift::GetResponder<Swift::InBandRegistrationPayload>, Swift::SetResponder<Swift::InBandRegistrationPayload> {
 
class UserRegistration : public Swift::Responder<Swift::InBandRegistrationPayload> {
 
	public:
 
		/// Creates new UserRegistration handler.
 
		/// \param component Component associated with this class
 
		/// \param userManager UserManager associated with this class
 
		/// \param storageBackend StorageBackend where the registered users will be stored
 
		UserRegistration(Component *component, UserManager *userManager, StorageBackend *storageBackend);
 
@@ -66,14 +65,14 @@ class UserRegistration : Swift::GetResponder<Swift::InBandRegistrationPayload>,
 

	
 
		/// Called when user's registration has been updated.
 
		/// \param userInfo UserInfo struct with informations about user
 
		boost::signal<void (const UserInfo &userInfo)> onUserUpdated;
 

	
 
	private:
 
		bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload);
 
		bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload);
 
		virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload);
 
		virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload);
 
		
 
		Component *m_component;
 
		StorageBackend *m_storageBackend;
 
		UserManager *m_userManager;
 
		Config *m_config;
 

	
src/sqlite3backend.cpp
Show inline comments
 
@@ -60,12 +60,13 @@ using namespace boost;
 
namespace Transport {
 

	
 
SQLite3Backend::SQLite3Backend(Config *config) {
 
	m_config = config;
 
	m_db = NULL;
 
	m_prefix = CONFIG_STRING(m_config, "database.prefix");
 
	std::cout << "SQLITE3 " << this << "\n";
 
}
 

	
 
SQLite3Backend::~SQLite3Backend(){
 
	if (m_db) {
 
		// Would be nice to use this:
 
		//
src/userregistration.cpp
Show inline comments
 
@@ -27,19 +27,17 @@
 
#include <boost/shared_ptr.hpp>
 

	
 
using namespace Swift;
 

	
 
namespace Transport {
 

	
 
UserRegistration::UserRegistration(Component *component, UserManager *userManager, StorageBackend *storageBackend) : Swift::GetResponder<Swift::InBandRegistrationPayload>(component->m_iqRouter), Swift::SetResponder<Swift::InBandRegistrationPayload>(component->m_iqRouter) {
 
UserRegistration::UserRegistration(Component *component, UserManager *userManager, StorageBackend *storageBackend) : Swift::Responder<Swift::InBandRegistrationPayload>(component->m_iqRouter) {
 
	m_component = component;
 
	m_config = m_component->m_config;
 
	m_storageBackend = storageBackend;
 
	m_userManager = userManager;
 
	Swift::GetResponder<Swift::InBandRegistrationPayload>::start();
 
	Swift::SetResponder<Swift::InBandRegistrationPayload>::start();
 
}
 

	
 
UserRegistration::~UserRegistration(){
 
}
 

	
 
bool UserRegistration::registerUser(const UserInfo &row) {
 
@@ -118,24 +116,24 @@ bool UserRegistration::unregisterUser(const std::string &barejid) {
 

	
 
	return true;
 
}
 

	
 
bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload) {
 
	if (CONFIG_STRING(m_config, "service.protocol") == "irc") {
 
		Swift::GetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
		sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	std::string barejid = from.toBare().toString();
 

	
 
// 	User *user = m_userManager->getUserByJID(barejid);
 
	if (!CONFIG_BOOL(m_config,"registration.enable_public_registration")) {
 
		std::list<std::string> const &x = CONFIG_LIST(m_config,"service.allowed_servers");
 
		if (std::find(x.begin(), x.end(), from.getDomain()) == x.end()) {
 
// 			Log("UserRegistration", "This user has no permissions to register an account");
 
			Swift::GetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
			sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
			return true;
 
		}
 
	}
 

	
 
// 	const char *_language = user ? user->getLang() : CONFIG_STRING(m_config, "registration.language").c_str();
 

	
 
@@ -207,31 +205,31 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
		boolean->setValue(0);
 
		form->addField(boolean);
 
	}
 

	
 
	reg->setForm(form);
 

	
 
	Swift::GetResponder<Swift::InBandRegistrationPayload>::sendResponse(from, id, reg);
 
	sendResponse(from, id, reg);
 

	
 
	return true;
 
}
 

	
 
bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::InBandRegistrationPayload> payload) {
 
	if (CONFIG_STRING(m_config, "service.protocol") == "irc") {
 
		Swift::GetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
		sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	std::string barejid = from.toBare().toString();
 

	
 
// 	AbstractUser *user = m_component->userManager()->getUserByJID(barejid);
 
	if (!CONFIG_BOOL(m_config,"registration.enable_public_registration")) {
 
		std::list<std::string> const &x = CONFIG_LIST(m_config,"service.allowed_servers");
 
		if (std::find(x.begin(), x.end(), from.getDomain()) == x.end()) {
 
// 			Log("UserRegistration", "This user has no permissions to register an account");
 
			Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
			sendError(from, id, ErrorPayload::BadRequest, ErrorPayload::Modify);
 
			return true;
 
		}
 
	}
 

	
 
	UserInfo res;
 
	bool registered = m_storageBackend->getUser(barejid, res);
 
@@ -281,43 +279,43 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
			}
 
		}
 
	}
 

	
 
	if (payload->isRemove()) {
 
		unregisterUser(barejid);
 
		Swift::SetResponder<Swift::InBandRegistrationPayload>::sendResponse(from, id, InBandRegistrationPayload::ref());
 
		sendResponse(from, id, InBandRegistrationPayload::ref());
 
		return true;
 
	}
 

	
 
	if (!payload->getUsername() || !payload->getPassword()) {
 
		Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	// Register or change password
 
	if (payload->getUsername()->empty() ||
 
		(payload->getPassword()->empty() && CONFIG_STRING(m_config, "service.protocol") != "twitter" && CONFIG_STRING(m_config, "service.protocol") != "bonjour")
 
// 		|| localization.getLanguages().find(language) == localization.getLanguages().end()
 
	)
 
	{
 
		Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	if (CONFIG_STRING(m_config, "service.protocol") == "xmpp") {
 
		// User tries to register himself.
 
		if ((Swift::JID(*payload->getUsername()).toBare() == from.toBare())) {
 
			Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
			sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
			return true;
 
		}
 

	
 
		// User tries to register someone who's already registered.
 
		UserInfo user_row;
 
		bool registered = m_storageBackend->getUser(Swift::JID(*payload->getUsername()).toBare().toString(), user_row);
 
		if (registered) {
 
			Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
			sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
			return true;
 
		}
 
	}
 

	
 
	std::string username = *payload->getUsername();
 
// 	m_component->protocol()->prepareUsername(username);
 
@@ -327,21 +325,21 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
		newUsername = CONFIG_STRING(m_config, "registration.username_mask");
 
// 		replace(newUsername, "$username", username.c_str());
 
	}
 

	
 
// 	if (!m_component->protocol()->isValidUsername(newUsername)) {
 
// 		Log("UserRegistration", "This is not valid username: "<< newUsername);
 
// 		Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
// 		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
// 		return true;
 
// 	}
 

	
 
// #if GLIB_CHECK_VERSION(2,14,0)
 
// 	if (!CONFIG_STRING(m_config, "registration.reg_allowed_usernames").empty() &&
 
// 		!g_regex_match_simple(CONFIG_STRING(m_config, "registration.reg_allowed_usernames"), newUsername.c_str(),(GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_EXTENDED), (GRegexMatchFlags) 0)) {
 
// 		Log("UserRegistration", "This is not valid username: "<< newUsername);
 
// 		Swift::SetResponder<Swift::InBandRegistrationPayload>::sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
// 		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
// 		return true;
 
// 	}
 
// #endif
 
	if (!registered) {
 
		res.jid = barejid;
 
		res.uin = username;
 
@@ -359,11 +357,11 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
		res.language = language;
 
		res.encoding = encoding;
 
		m_storageBackend->setUser(res);
 
		onUserUpdated(res);
 
	}
 

	
 
	Swift::SetResponder<Swift::InBandRegistrationPayload>::sendResponse(from, id, InBandRegistrationPayload::ref());
 
	sendResponse(from, id, InBandRegistrationPayload::ref());
 
	return true;
 
}
 

	
 
}
0 comments (0 inline, 0 general)