X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/899b65fa18e88f77d584d79f71592a2b51a632c2..21baffc9c880ba71baaddad5c4cf2b32352823ff:/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index d9f87eca..f5a57a48 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -19,6 +19,7 @@ * Author : Maxim Mamontov */ +#include "configproto.h" #include "conn.h" @@ -26,6 +27,7 @@ #include "parser_admins.h" #include "parser_tariffs.h" #include "parser_users.h" +#include "parser_services.h" #include "parser_message.h" #include "parser_user_info.h" #include "parser_auth_by.h" @@ -53,6 +55,9 @@ CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l) m_admins(NULL), m_tariffs(NULL), m_users(NULL), + m_services(NULL), + m_corporations(NULL), + m_store(NULL), m_port(0), m_bindAddress("0.0.0.0"), m_running(false), @@ -78,7 +83,6 @@ int CONFIGPROTO::Prepare() sigaddset(&sigmask, SIGUSR1); sigaddset(&sigmask, SIGHUP); pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask); - m_listenSocket = socket(PF_INET, SOCK_STREAM, 0); if (m_listenSocket < 0) @@ -158,10 +162,7 @@ void CONFIGPROTO::Run() if (!m_running) break; if (res > 0) - { - printfd(__FILE__, "Something happend - received %d events.\n", res); HandleEvents(fds); - } CleanupConns(); } @@ -209,6 +210,8 @@ void CONFIGPROTO::RegisterParsers() assert(m_admins != NULL); assert(m_users != NULL); assert(m_tariffs != NULL); + assert(m_services != NULL); + assert(m_corporations != NULL); SP::GET_SERVER_INFO::FACTORY::Register(m_registry, *m_settings, *m_users, *m_tariffs); @@ -229,6 +232,12 @@ void CONFIGPROTO::RegisterParsers() SP::CHG_USER::FACTORY::Register(m_registry, *m_users, *m_store, *m_tariffs); SP::CHECK_USER::FACTORY::Register(m_registry, *m_users); + SP::GET_SERVICES::FACTORY::Register(m_registry, *m_services); + SP::GET_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::ADD_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::DEL_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::CHG_SERVICE::FACTORY::Register(m_registry, *m_services); + SP::SEND_MESSAGE::FACTORY::Register(m_registry, *m_users); SP::AUTH_BY::FACTORY::Register(m_registry, *m_users); @@ -248,7 +257,6 @@ int CONFIGPROTO::MaxFD() const void CONFIGPROTO::BuildFDSet(fd_set & fds) const { - printfd(__FILE__, "Building fd set for %d connections.\n", m_conns.size()); FD_ZERO(&fds); FD_SET(m_listenSocket, &fds); std::deque::const_iterator it; @@ -258,8 +266,6 @@ void CONFIGPROTO::BuildFDSet(fd_set & fds) const void CONFIGPROTO::CleanupConns() { - size_t old = m_conns.size(); - std::deque::iterator pos; for (pos = m_conns.begin(); pos != m_conns.end(); ++pos) if (((*pos)->IsDone() && !(*pos)->IsKeepAlive()) || !(*pos)->IsOk()) @@ -270,9 +276,6 @@ void CONFIGPROTO::CleanupConns() pos = std::remove(m_conns.begin(), m_conns.end(), static_cast(NULL)); m_conns.erase(pos, m_conns.end()); - - if (m_conns.size() < old) - printfd(__FILE__, "Cleaned up %d connections.\n", old - m_conns.size()); } void CONFIGPROTO::HandleEvents(const fd_set & fds) @@ -284,17 +287,12 @@ void CONFIGPROTO::HandleEvents(const fd_set & fds) std::deque::iterator it; for (it = m_conns.begin(); it != m_conns.end(); ++it) if (FD_ISSET((*it)->Sock(), &fds)) - { - printfd(__FILE__, "Reading data from %s:%d.\n", inet_ntostring((*it)->IP()).c_str(), (*it)->Port()); (*it)->Read(); - } } } void CONFIGPROTO::AcceptConnection() { - printfd(__FILE__, "Accepting new connection.\n"); - struct sockaddr_in outerAddr; socklen_t outerAddrLen(sizeof(outerAddr)); int sock = accept(m_listenSocket, reinterpret_cast(&outerAddr), &outerAddrLen); @@ -311,7 +309,7 @@ void CONFIGPROTO::AcceptConnection() try { - m_conns.push_back(new STG::Conn(m_registry, *m_admins, sock, outerAddr)); + m_conns.push_back(new STG::Conn(m_registry, *m_admins, sock, outerAddr, m_logger)); printfd(__FILE__, "New connection from %s:%d. Total connections: %d\n", inet_ntostring(m_conns.back()->IP()).c_str(), m_conns.back()->Port(), m_conns.size()); } catch (const STG::Conn::Error & error) @@ -320,9 +318,3 @@ void CONFIGPROTO::AcceptConnection() m_logger(std::string("Failed to create new client connection: '") + error.what() + "'."); } } -/* -void CONFIGPROTO::WriteLogAccessFailed(uint32_t ip) -{ - m_logger("Admin's connection failed. IP %s", inet_ntostring(ip).c_str()); -} -*/