Create loginTimer according to time diff
This commit is contained in:
parent
f18383c3eb
commit
a385968812
3 changed files with 5 additions and 212 deletions
|
@ -1,89 +0,0 @@
|
|||
/**
|
||||
* libtransport -- C++ library for easy XMPP Transports development
|
||||
*
|
||||
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "Swiften/Swiften.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
struct UserInfo;
|
||||
class User;
|
||||
class UserManager;
|
||||
class Component;
|
||||
class StorageBackend;
|
||||
class UserRegistration;
|
||||
class RosterManager;
|
||||
class Buddy;
|
||||
|
||||
/// Basic logging class which logs various data into std::out (standard output).
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
/// Creates new Logger class instance.
|
||||
/// \param component component instance
|
||||
Logger(Component *component);
|
||||
|
||||
/// Logger destructor.
|
||||
~Logger();
|
||||
|
||||
/// Starts logging data related to StorageBackend class.
|
||||
/// \param storage storage class
|
||||
void setStorageBackend(StorageBackend *storage);
|
||||
|
||||
/// Starts logging data related to UserRegistration class.
|
||||
/// \param userRegistration userRegistration class
|
||||
void setUserRegistration(UserRegistration *userRegistration);
|
||||
|
||||
/// Starts logging data related to UserManager class.
|
||||
/// \param userManager userManager class
|
||||
void setUserManager(UserManager *userManager);
|
||||
|
||||
/// Starts logging data related to RosterManager class.
|
||||
/// \param rosterManager rosterManager class
|
||||
void setRosterManager(RosterManager *rosterManager);
|
||||
|
||||
private:
|
||||
// Component
|
||||
void handleConnected();
|
||||
void handleConnectionError(const Swift::ComponentError &error);
|
||||
void handleXMLIn(const std::string &data);
|
||||
void handleXMLOut(const std::string &data);
|
||||
|
||||
// StorageBackend
|
||||
void handleStorageError(const std::string &statement, const std::string &error);
|
||||
|
||||
// UserRegistration
|
||||
void handleUserRegistered(const UserInfo &user);
|
||||
void handleUserUnregistered(const UserInfo &user);
|
||||
void handleUserUpdated(const UserInfo &user);
|
||||
|
||||
// UserManager
|
||||
void handleUserCreated(User *user);
|
||||
void handleUserDestroyed(User *user);
|
||||
|
||||
// RosterManager
|
||||
void handleBuddySet(Buddy *buddy);
|
||||
void handleBuddyUnset(Buddy *buddy);
|
||||
};
|
||||
|
||||
}
|
122
src/logger.cpp
122
src/logger.cpp
|
@ -1,122 +0,0 @@
|
|||
/**
|
||||
* libtransport -- C++ library for easy XMPP Transports development
|
||||
*
|
||||
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#include "transport/logger.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/userregistration.h"
|
||||
#include "transport/buddy.h"
|
||||
#include "transport/rostermanager.h"
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
namespace Transport {
|
||||
|
||||
Logger::Logger(Component *component) {
|
||||
component->onConnected.connect(boost::bind(&Logger::handleConnected, this));
|
||||
component->onConnectionError.connect(boost::bind(&Logger::handleConnectionError, this, _1));
|
||||
component->onXMLIn.connect(boost::bind(&Logger::handleXMLIn, this, _1));
|
||||
component->onXMLOut.connect(boost::bind(&Logger::handleXMLOut, this, _1));
|
||||
}
|
||||
|
||||
Logger::~Logger(){
|
||||
}
|
||||
|
||||
void Logger::setStorageBackend(StorageBackend *storage) {
|
||||
// storage->onStorageError.connect(boost::bind(&Logger::handleStorageError, this, _1, _2));
|
||||
}
|
||||
|
||||
void Logger::setUserRegistration(UserRegistration *userRegistration) {
|
||||
userRegistration->onUserRegistered.connect(boost::bind(&Logger::handleUserRegistered, this, _1));
|
||||
userRegistration->onUserUnregistered.connect(boost::bind(&Logger::handleUserUnregistered, this, _1));
|
||||
userRegistration->onUserUpdated.connect(boost::bind(&Logger::handleUserUpdated, this, _1));
|
||||
}
|
||||
|
||||
void Logger::setUserManager(UserManager *userManager) {
|
||||
userManager->onUserCreated.connect(boost::bind(&Logger::handleUserCreated, this, _1));
|
||||
userManager->onUserDestroyed.connect(boost::bind(&Logger::handleUserDestroyed, this, _1));
|
||||
}
|
||||
|
||||
void Logger::setRosterManager(RosterManager *rosterManager) {
|
||||
rosterManager->onBuddySet.connect(boost::bind(&Logger::handleBuddySet, this, _1));
|
||||
rosterManager->onBuddyUnset.connect(boost::bind(&Logger::handleBuddyUnset, this, _1));
|
||||
}
|
||||
|
||||
void Logger::handleConnected() {
|
||||
std::cout << "[COMPONENT] Connected to Jabber Server!\n";
|
||||
}
|
||||
|
||||
void Logger::handleConnectionError(const Swift::ComponentError &error) {
|
||||
std::cout << "[COMPONENT] Connection Error!\n";
|
||||
switch (error.getType()) {
|
||||
case Swift::ComponentError::UnknownError: std::cout << "[COMPONENT] Disconnect reason: UnknownError\n"; break;
|
||||
case Swift::ComponentError::ConnectionError: std::cout << "[COMPONENT] Disconnect reason: ConnectionError\n"; break;
|
||||
case Swift::ComponentError::ConnectionReadError: std::cout << "[COMPONENT] Disconnect reason: ConnectionReadError\n"; break;
|
||||
case Swift::ComponentError::ConnectionWriteError: std::cout << "[COMPONENT] Disconnect reason: ConnectionWriteError\n"; break;
|
||||
case Swift::ComponentError::XMLError: std::cout << "[COMPONENT] Disconnect reason: XMLError\n"; break;
|
||||
case Swift::ComponentError::AuthenticationFailedError: std::cout << "[COMPONENT] Disconnect reason: AuthenticationFailedError\n"; break;
|
||||
case Swift::ComponentError::UnexpectedElementError: std::cout << "[COMPONENT] Disconnect reason: UnexpectedElementError\n"; break;
|
||||
};
|
||||
}
|
||||
|
||||
void Logger::handleXMLIn(const std::string &data) {
|
||||
std::cout << "[XML IN] " << data << "\n";
|
||||
}
|
||||
|
||||
void Logger::handleXMLOut(const std::string &data) {
|
||||
std::cout << "[XML OUT] " << data << "\n";
|
||||
}
|
||||
|
||||
void Logger::handleStorageError(const std::string &statement, const std::string &error) {
|
||||
std::cout << "[SQL ERROR] \"" << error << "\" during statement \"" << statement << "\"\n";
|
||||
}
|
||||
|
||||
void Logger::handleUserRegistered(const UserInfo &user) {
|
||||
std::cout << "[REGISTRATION] User \"" << user.jid << "\" registered as \"" << user.uin << "\"\n";
|
||||
}
|
||||
|
||||
void Logger::handleUserUnregistered(const UserInfo &user) {
|
||||
std::cout << "[REGISTRATION] User \"" << user.jid << "\" unregistered \"" << user.uin << "\"\n";
|
||||
}
|
||||
|
||||
void Logger::handleUserUpdated(const UserInfo &user) {
|
||||
std::cout << "[REGISTRATION] User \"" << user.jid << "\" updated \"" << user.uin << "\"\n";
|
||||
}
|
||||
|
||||
void Logger::handleUserCreated(User *user) {
|
||||
std::cout << "[USERMANAGER] User \"" << user->getJID().toString() << "\" (UIN: \"" << user->getUserInfo().uin << "\") connected and User class has been created\n";
|
||||
}
|
||||
|
||||
void Logger::handleUserDestroyed(User *user) {
|
||||
std::cout << "[USERMANAGER] User \"" << user->getJID().toBare().toString() << "\" (UIN: \"" << user->getUserInfo().uin << "\") disconnected and User class is going to be destroyed\n";
|
||||
}
|
||||
|
||||
void Logger::handleBuddySet(Buddy *buddy) {
|
||||
std::cout << "[ROSTERMANAGER] \"" << buddy->getRosterManager()->getUser()->getJID().toBare().toString() << "\": Buddy \"" << buddy->getSafeName() << "\" (ALIAS: \"" << buddy->getAlias() << "\") has been bound with this user's roster.\n";
|
||||
}
|
||||
|
||||
void Logger::handleBuddyUnset(Buddy *buddy) {
|
||||
std::cout << "[ROSTERMANAGER] \"" << buddy->getRosterManager()->getUser()->getJID().toBare().toString() << "\": Buddy \"" << buddy->getSafeName() << "\" (ALIAS: \"" << buddy->getAlias() << "\") has been unbound with this user's roster.\n";
|
||||
}
|
||||
|
||||
}
|
|
@ -1722,7 +1722,11 @@ NetworkPluginServer::Backend *NetworkPluginServer::getFreeClient(bool acceptUser
|
|||
unsigned long diff = CONFIG_INT(m_config, "service.login_delay");
|
||||
time_t now = time(NULL);
|
||||
if (diff && (now - m_lastLogin < diff)) {
|
||||
m_loginTimer->stop();
|
||||
m_loginTimer = m_component->getNetworkFactories()->getTimerFactory()->createTimer((diff - (now - m_lastLogin)) * 1000);
|
||||
m_loginTimer->onTick.connect(boost::bind(&NetworkPluginServer::loginDelayFinished, this));
|
||||
m_loginTimer->start();
|
||||
LOG4CXX_INFO(logger, "Postponing login because of service.login_delay setting");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1736,7 +1740,7 @@ NetworkPluginServer::Backend *NetworkPluginServer::getFreeClient(bool acceptUser
|
|||
c = *it;
|
||||
// if we're not reusing all backends and backend is full, stop accepting new users on this backend
|
||||
if (!CONFIG_BOOL(m_config, "service.reuse_old_backends")) {
|
||||
if (c->users.size() + 1 >= CONFIG_INT(m_config, "service.users_per_backend")) {
|
||||
if (!check && c->users.size() + 1 >= CONFIG_INT(m_config, "service.users_per_backend")) {
|
||||
c->acceptUsers = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue