]> git.stg.codes - stg.git/commitdiff
Solved some TODOs.
authorMaxim Mamontov <faust.madf@gmail.com>
Tue, 23 Sep 2014 15:17:37 +0000 (18:17 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Fri, 9 Jan 2015 21:35:38 +0000 (23:35 +0200)
Conflicts:
projects/stargazer/plugins/configuration/sgconfig/parser_user_info.cpp
projects/stargazer/plugins/configuration/sgconfig/parser_user_info.h

16 files changed:
projects/stargazer/plugins/configuration/sgconfig/configproto.cpp
projects/stargazer/plugins/configuration/sgconfig/conn.cpp
projects/stargazer/plugins/configuration/sgconfig/conn.h
projects/stargazer/plugins/configuration/sgconfig/parser_admins.cpp
projects/stargazer/plugins/configuration/sgconfig/parser_admins.h
projects/stargazer/plugins/configuration/sgconfig/parser_auth_by.h
projects/stargazer/plugins/configuration/sgconfig/parser_message.cpp
projects/stargazer/plugins/configuration/sgconfig/parser_message.h
projects/stargazer/plugins/configuration/sgconfig/parser_server_info.cpp
projects/stargazer/plugins/configuration/sgconfig/parser_server_info.h
projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.cpp
projects/stargazer/plugins/configuration/sgconfig/parser_tariffs.h
projects/stargazer/plugins/configuration/sgconfig/parser_users.cpp
projects/stargazer/plugins/configuration/sgconfig/parser_users.h
stglibs/common.lib/common.cpp
stglibs/common.lib/include/stg/common.h

index d9f87eca5884786abaffca61a9c5ef621cdb05b8..fc1649005b3f73ea33e73030a403b83d9e0d3812 100644 (file)
@@ -158,10 +158,7 @@ void CONFIGPROTO::Run()
         if (!m_running)
             break;
         if (res > 0)
-        {
-            printfd(__FILE__, "Something happend - received %d events.\n", res);
             HandleEvents(fds);
-        }
 
         CleanupConns();
     }
@@ -248,7 +245,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<STG::Conn *>::const_iterator it;
@@ -258,8 +254,6 @@ void CONFIGPROTO::BuildFDSet(fd_set & fds) const
 
 void CONFIGPROTO::CleanupConns()
 {
-    size_t old = m_conns.size();
-
     std::deque<STG::Conn *>::iterator pos;
     for (pos = m_conns.begin(); pos != m_conns.end(); ++pos)
         if (((*pos)->IsDone() && !(*pos)->IsKeepAlive()) || !(*pos)->IsOk())
@@ -270,9 +264,6 @@ void CONFIGPROTO::CleanupConns()
 
     pos = std::remove(m_conns.begin(), m_conns.end(), static_cast<STG::Conn *>(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 +275,12 @@ void CONFIGPROTO::HandleEvents(const fd_set & fds)
         std::deque<STG::Conn *>::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<sockaddr *>(&outerAddr), &outerAddrLen);
@@ -311,7 +297,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 +306,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());
-}
-*/
index abcc677b34916619eea4811c8c8144102ba0d399..8bba49be567369c9864594baddf311dae360e44b 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "stg/admins.h"
 #include "stg/admin.h"
+#include "stg/logger.h"
 #include "stg/blowfish.h"
 #include "stg/bfstream.h"
 #include "stg/common.h"
@@ -44,7 +45,8 @@ const char Conn::OK_LOGINS[] = "OKLS";
 const char Conn::ERR_LOGINS[] = "ERLS";
 
 Conn::Conn(const BASE_PARSER::REGISTRY & registry,
-           ADMINS & admins, int sock, const sockaddr_in& addr)
+           ADMINS & admins, int sock, const sockaddr_in& addr,
+           PLUGIN_LOGGER & logger)
     : m_registry(registry),
       m_admins(admins),
       m_admin(NULL),
@@ -57,6 +59,7 @@ Conn::Conn(const BASE_PARSER::REGISTRY & registry,
       m_buffer(m_header),
       m_bufferSize(sizeof(m_header)),
       m_stream(NULL),
+      m_logger(logger),
       m_dataState(false, *this)
 {
     if (m_xmlParser == NULL)
@@ -80,16 +83,14 @@ bool Conn::Read()
     ssize_t res = read(m_sock, m_buffer, m_bufferSize);
     if (res < 0)
     {
-        printfd(__FILE__, "Failed to read data from %s:%d: '%s'.\n", inet_ntostring(IP()).c_str(), Port(), strerror(errno));
         m_state = ERROR;
-        // TODO: log it
+        Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'");
         return false;
     }
     if (res == 0 && m_state != DATA) // EOF is ok for data.
     {
-        printfd(__FILE__, "Failed to read data from %s:%d: 'EOF'.\n", inet_ntostring(IP()).c_str(), Port());
         m_state = ERROR;
-        // TODO: log it
+        Log(__FILE__, "Failed to read data from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Unexpected EOF.");
         return false;
     }
     m_bufferSize -= res;
@@ -101,7 +102,8 @@ bool Conn::WriteAnswer(const void* buffer, size_t size)
     ssize_t res = write(m_sock, buffer, size);
     if (res < 0)
     {
-        // TODO: log it
+        m_state = ERROR;
+        Log(__FILE__, "Failed to write data to " + inet_ntostring(IP()) + ":" + x2str(Port()) + ". Reason: '" + strerror(errno) + "'.");
         return false;
     }
     return true;
@@ -109,7 +111,7 @@ bool Conn::WriteAnswer(const void* buffer, size_t size)
 
 BASE_PARSER * Conn::GetParser(const std::string & tag) const
 {
-    BASE_PARSER::REGISTRY::const_iterator it = m_registry.find(tag);
+    BASE_PARSER::REGISTRY::const_iterator it = m_registry.find(ToLower(tag));
     if (it == m_registry.end())
         return NULL;
     return it->second->create(*m_admin);
@@ -117,7 +119,6 @@ BASE_PARSER * Conn::GetParser(const std::string & tag) const
 
 bool Conn::HandleBuffer(size_t size)
 {
-    printfd(__FILE__, "Got %d bytes. State: %s.\n", size, (m_state == DATA ? "DATA" : (m_state == HEADER ? "HEADER" : (m_state == LOGIN ? "LOGIN" : (m_state == CRYPTO_LOGIN ? "CRYPTO_LOGIN" : (m_state == DONE ? "DONE" : "ERROR"))))));
     if (m_state == DATA)
         return HandleData(size);
 
@@ -139,9 +140,8 @@ bool Conn::HandleHeader()
 {
     if (strncmp(m_header, STG_HEADER, sizeof(m_header)) != 0)
     {
-        printfd(__FILE__, "Wrong header from %s:%d.\n", inet_ntostring(IP()).c_str(), Port());
+        Log(__FILE__, "Received invalid header from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ".");
         WriteAnswer(ERR_HEADER, sizeof(ERR_HEADER) - 1); // Without \0
-        // TODO: log it
         m_state = ERROR;
         return false;
     }
@@ -155,9 +155,9 @@ bool Conn::HandleLogin()
 {
     if (m_admins.Find(m_login, &m_admin)) // ADMINS::Find returns true on error.
     {
-        printfd(__FILE__, "Wrong login ('%s') from %s:%d.\n", m_login, inet_ntostring(IP()).c_str(), Port());
+        std::string login(m_login, strnlen(m_login, sizeof(m_login)));
+        Log(__FILE__, "Received invalid login '" + ToPrintable(login) + "' from " + inet_ntostring(IP()) + ":" + x2str(Port()) + ".");
         WriteAnswer(ERR_LOGIN, sizeof(ERR_LOGIN) - 1); // Without \0
-        // TODO: log it
         m_state = ERROR;
         return false;
     }
@@ -177,9 +177,8 @@ bool Conn::HandleCryptoLogin()
 
     if (strncmp(m_login, login, sizeof(login)) != 0)
     {
-        printfd(__FILE__, "Wrong password from %s:%d: '%s' != '%s'.\n", inet_ntostring(IP()).c_str(), Port(), login, m_login);
+        Log(__FILE__, "Attempt to connect with wrong password from " + m_admin->GetLogin() + "@" + inet_ntostring(IP()) + ":" + x2str(Port()) + ".");
         WriteAnswer(ERR_LOGINS, sizeof(ERR_LOGINS) - 1); // Without \0
-        // TODO: log it
         m_state = ERROR;
         return false;
     }
@@ -209,7 +208,7 @@ bool Conn::DataCallback(const void * block, size_t size, void * data)
 
     if (XML_Parse(state.conn.m_xmlParser, xml, length, state.final) == XML_STATUS_ERROR)
     {
-        // TODO: log it
+        state.conn.Log(__FILE__, "Received invalid XML from " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + ".");
         printfd(__FILE__, "XML parse error at line %d, %d: %s. Is final: %d\n",
                   static_cast<int>(XML_GetCurrentLineNumber(state.conn.m_xmlParser)),
                   static_cast<int>(XML_GetCurrentColumnNumber(state.conn.m_xmlParser)),
@@ -223,7 +222,7 @@ bool Conn::DataCallback(const void * block, size_t size, void * data)
     {
         if (!state.conn.WriteResponse())
         {
-            // TODO: log it
+            state.conn.Log(__FILE__, "Failed to write response to " + state.conn.m_admin->GetLogin() + "@" + inet_ntostring(state.conn.IP()) + ":" + x2str(state.conn.Port()) + ".");
             state.conn.m_state = ERROR;
             return false;
         }
@@ -243,13 +242,10 @@ void Conn::ParseXMLStart(void * data, const char * el, const char ** attr)
 
     if (conn.m_parser == NULL)
     {
-        printfd(__FILE__, "Failed to find a suitable parser for '%s'.\n", el);
-        // TODO: log it
+        conn.Log(__FILE__, "Received unknown command '" + std::string(el) + "' from " + conn.m_admin->GetLogin() + "@" + inet_ntostring(conn.IP()) + ":" + x2str(conn.Port()) + ".");
         conn.m_state = ERROR;
         return;
     }
-    else
-        printfd(__FILE__, "Using parser '%s'.\n", conn.m_parser->GetTag().c_str());
 
     conn.m_parser->Start(data, el, attr);
 }
@@ -261,7 +257,7 @@ void Conn::ParseXMLEnd(void * data, const char * el)
 
     if (conn.m_parser == NULL)
     {
-        // TODO: log it
+        // No need to log it.
         conn.m_state = ERROR;
         return;
     }
@@ -277,7 +273,7 @@ bool Conn::WriteResponse()
         answer = m_parser->GetAnswer();
     else
         answer = "<Error result=\"Unknown command.\"/>";
-    printfd(__FILE__, "Writing %d bytes of answer: '%s'\n", answer.length(), answer.c_str());
+    printfd(__FILE__, "Writing %d bytes of answer.\n", answer.length());
     stream.Put(answer.c_str(), answer.length() + 1 /* including \0 */, true /* final */);
     return stream.IsOk();
 }
@@ -288,3 +284,9 @@ bool Conn::WriteCallback(const void * block, size_t size, void * data)
     Conn & conn = *static_cast<Conn *>(data);
     return WriteAll(conn.m_sock, block, size);;
 }
+
+void Conn::Log(const char * file, const std::string & message)
+{
+    printfd(file, "%s\n", message.c_str());
+    m_logger(message);
+}
index 8f76b7e94635b672f241341b97ba539638384f61..e3cb3f0c6e72a26274929c5dd9b49b598315e50a 100644 (file)
@@ -39,6 +39,7 @@ class USERS;
 class TARIFFS;
 class ADMIN;
 class BASE_PARSER;
+class PLUGIN_LOGGER;
 
 namespace STG
 {
@@ -54,7 +55,8 @@ class Conn
         };
 
         Conn(const BASE_PARSER::REGISTRY & registry,
-             ADMINS & admins, int sock, const sockaddr_in& addr);
+             ADMINS & admins, int sock, const sockaddr_in& addr,
+             PLUGIN_LOGGER & logger);
         ~Conn();
 
         int Sock() const { return m_sock; }
@@ -100,6 +102,7 @@ class Conn
         char m_cryptoLogin[ADM_LOGIN_LEN]; // Without \0
         char m_data[1024];
         STG::DECRYPT_STREAM * m_stream;
+        PLUGIN_LOGGER &  m_logger;
 
         BASE_PARSER * GetParser(const std::string & tag) const;
 
@@ -113,6 +116,8 @@ class Conn
         bool WriteAnswer(const void* buffer, size_t size);
         bool WriteResponse();
 
+        void Log(const char * file, const std::string & message);
+
         struct DataState
         {
             DataState(bool f, Conn & c) : final(f), conn(c) {}
index 740d86a7d3f83b29d9ab67b0f4ccebc629b4b769..0db867bb3e680e1132e59a7c7a1aaaac29a0891f 100644 (file)
@@ -22,7 +22,6 @@
 #include "parser_admins.h"
 
 #include "stg/admins.h"
-#include "stg/common.h"
 
 #include <strings.h> // strcasecmp
 
index c68789c2d5409e5a5444f19e25d979f530d34fd7..3b99e6422fc269043c068c04d0b1c8327d767151 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "parser.h"
 
+#include "stg/common.h"
 #include "stg/resetable.h"
 
 #include <string>
@@ -45,7 +46,7 @@ class GET_ADMINS: public BASE_PARSER
                 FACTORY(const ADMINS & admins) : m_admins(admins) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_ADMINS(admin, m_admins); }
                 static void Register(REGISTRY & registry, const ADMINS & admins)
-                { registry[tag] = new FACTORY(admins); }
+                { registry[ToLower(tag)] = new FACTORY(admins); }
             private:
                 const ADMINS & m_admins;
         };
@@ -70,7 +71,7 @@ class ADD_ADMIN: public BASE_PARSER
                 FACTORY(ADMINS & admins) : m_admins(admins) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_ADMIN(admin, m_admins); }
                 static void Register(REGISTRY & registry, ADMINS & admins)
-                { registry[tag] = new FACTORY(admins); }
+                { registry[ToLower(tag)] = new FACTORY(admins); }
             private:
                 ADMINS & m_admins;
         };
@@ -97,7 +98,7 @@ class DEL_ADMIN: public BASE_PARSER
                 FACTORY(ADMINS & admins) : m_admins(admins) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_ADMIN(admin, m_admins); }
                 static void Register(REGISTRY & registry, ADMINS & admins)
-                { registry[tag] = new FACTORY(admins); }
+                { registry[ToLower(tag)] = new FACTORY(admins); }
             private:
                 ADMINS & m_admins;
         };
@@ -124,7 +125,7 @@ class CHG_ADMIN: public BASE_PARSER
                 FACTORY(ADMINS & admins) : m_admins(admins) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_ADMIN(admin, m_admins); }
                 static void Register(REGISTRY & registry, ADMINS & admins)
-                { registry[tag] = new FACTORY(admins); }
+                { registry[ToLower(tag)] = new FACTORY(admins); }
             private:
                 ADMINS & m_admins;
         };
index d36ca1c446e325acbb71e1b0dbfae4bfc05da0ee..9a2e81a81bc7eaa345fc8e3b1f8aab08e109c8fa 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "parser.h"
 
+#include "stg/common.h"
+
 #include <string>
 
 class ADMIN;
@@ -42,7 +44,7 @@ class AUTH_BY : public BASE_PARSER
                 FACTORY(const USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new AUTH_BY(admin, m_users); }
                 static void Register(REGISTRY & registry, const USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 const USERS & m_users;
         };
index c93ac43764ec4b1aed02c2f5656270fa0483610a..06489a4246214166b28da83fbcf32e877fa7545c 100644 (file)
@@ -22,7 +22,6 @@
 #include "parser_message.h"
 
 #include "stg/users.h"
-#include "stg/common.h"
 
 extern volatile time_t stgTime; // So sad...
 
index 6a5f8f4e6ce098b17b973eda35d2c83abb538403..4caa354c47edcc4e6b1ed54f895e489498bcb761 100644 (file)
@@ -25,6 +25,7 @@
 #include "parser.h"
 
 #include "stg/message.h"
+#include "stg/common.h"
 
 #include <vector>
 #include <string>
@@ -46,7 +47,7 @@ class SEND_MESSAGE: public BASE_PARSER
                 FACTORY(USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new SEND_MESSAGE(admin, m_users); }
                 static void Register(REGISTRY & registry, USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 USERS & m_users;
         };
index 0cb215d0afcde4d8072fb5eeb9f415965c460ea2..1873b9bbc14db47a86629848aaf9415d5be96a4f 100644 (file)
@@ -24,7 +24,6 @@
 #include "stg/settings.h"
 #include "stg/users.h"
 #include "stg/tariffs.h"
-#include "stg/common.h"
 #include "stg/version.h"
 #include "stg/const.h"
 
index 1b76659f82c9f2b164d00856828b7e90e5035ccb..094caf383ea348c1a290f8bd83675c3bc86ae8d2 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "parser.h"
 
+#include "stg/common.h"
+
 class ADMIN;
 class SETTINGS;
 class USERS;
@@ -43,7 +45,7 @@ class GET_SERVER_INFO: public BASE_PARSER {
                     : m_settings(settings), m_users(users), m_tariffs(tariffs) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_SERVER_INFO(admin, m_settings, m_users, m_tariffs); }
                 static void Register(REGISTRY & registry, const SETTINGS & settings, const USERS & users, const TARIFFS & tariffs)
-                { registry[tag] = new FACTORY(settings, users, tariffs); }
+                { registry[ToLower(tag)] = new FACTORY(settings, users, tariffs); }
             private:
                 const SETTINGS & m_settings;
                 const USERS & m_users;
index 4763e97fd47a945411acd6d0ad382cf0ed27bbfa..cc32b6fcca41a022ec4a44c56089a216faa3de68 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "stg/tariffs.h"
 #include "stg/users.h"
-#include "stg/common.h"
 #include "stg/resetable.h"
 
 #include <cstdio> // snprintf
index 5dad5eff1902b37f1953c3fa1ffdd1ed92fe4513..6425cca12910ee047d100c3df71476f0d94a1245 100644 (file)
@@ -25,6 +25,7 @@
 #include "parser.h"
 
 #include "stg/tariff_conf.h"
+#include "stg/common.h"
 
 #include <string>
 
@@ -46,7 +47,7 @@ class GET_TARIFFS: public BASE_PARSER
                 FACTORY(const TARIFFS & tariffs) : m_tariffs(tariffs) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_TARIFFS(admin, m_tariffs); }
                 static void Register(REGISTRY & registry, const TARIFFS & tariffs)
-                { registry[tag] = new FACTORY(tariffs); }
+                { registry[ToLower(tag)] = new FACTORY(tariffs); }
             private:
                 const TARIFFS & m_tariffs;
         };
@@ -71,7 +72,7 @@ class ADD_TARIFF: public BASE_PARSER
                 FACTORY(TARIFFS & tariffs) : m_tariffs(tariffs) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_TARIFF(admin, m_tariffs); }
                 static void Register(REGISTRY & registry, TARIFFS & tariffs)
-                { registry[tag] = new FACTORY(tariffs); }
+                { registry[ToLower(tag)] = new FACTORY(tariffs); }
             private:
                 TARIFFS & m_tariffs;
         };
@@ -98,7 +99,7 @@ class DEL_TARIFF: public BASE_PARSER
                 FACTORY(TARIFFS & tariffs, const USERS & users) : m_tariffs(tariffs), m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_TARIFF(admin, m_users, m_tariffs); }
                 static void Register(REGISTRY & registry, TARIFFS & tariffs, const USERS & users)
-                { registry[tag] = new FACTORY(tariffs, users); }
+                { registry[ToLower(tag)] = new FACTORY(tariffs, users); }
             private:
                 TARIFFS & m_tariffs;
                 const USERS & m_users;
@@ -127,7 +128,7 @@ class CHG_TARIFF: public BASE_PARSER
                 FACTORY(TARIFFS & tariffs) : m_tariffs(tariffs) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_TARIFF(admin, m_tariffs); }
                 static void Register(REGISTRY & registry, TARIFFS & tariffs)
-                { registry[tag] = new FACTORY(tariffs); }
+                { registry[ToLower(tag)] = new FACTORY(tariffs); }
             private:
                 TARIFFS & m_tariffs;
         };
index f596bfbfd9f0fc87d4a6109ccb3ed8b4170f73ee..cd66ec9e037741a95368ceb03f9512acb9cc4e82 100644 (file)
@@ -26,7 +26,6 @@
 #include "stg/user_property.h"
 #include "stg/user_conf.h"
 #include "stg/user_stat.h"
-#include "stg/common.h"
 
 #include <cstdio>
 #include <cassert>
index 4d03b7e8042219accd812290712125381f03ceac..0ef1cb95106678f029302e1512db5dca3ba01eb1 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "stg/user_conf.h"
 #include "stg/user_stat.h"
+#include "stg/common.h"
 #include "stg/resetable.h"
 
 #include <string>
@@ -50,7 +51,7 @@ class GET_USERS: public BASE_PARSER
                 FACTORY(USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_USERS(admin, m_users); }
                 static void Register(REGISTRY & registry, USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 USERS & m_users;
         };
@@ -78,7 +79,7 @@ class GET_USER: public BASE_PARSER
                 FACTORY(const USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new GET_USER(admin, m_users); }
                 static void Register(REGISTRY & registry, const USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 const USERS & m_users;
         };
@@ -105,7 +106,7 @@ class ADD_USER: public BASE_PARSER
                 FACTORY(USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new ADD_USER(admin, m_users); }
                 static void Register(REGISTRY & registry, USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 USERS & m_users;
         };
@@ -134,7 +135,7 @@ class CHG_USER: public BASE_PARSER
                 {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHG_USER(admin, m_users, m_store, m_tariffs); }
                 static void Register(REGISTRY & registry, USERS & users, STORE & store, const TARIFFS & tariffs)
-                { registry[tag] = new FACTORY(users, store, tariffs); }
+                { registry[ToLower(tag)] = new FACTORY(users, store, tariffs); }
             private:
                 USERS & m_users;
                 STORE & m_store;
@@ -180,7 +181,7 @@ class DEL_USER: public BASE_PARSER
                 FACTORY(USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new DEL_USER(admin, m_users); }
                 static void Register(REGISTRY & registry, USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 USERS & m_users;
         };
@@ -209,7 +210,7 @@ class CHECK_USER: public BASE_PARSER
                 FACTORY(const USERS & users) : m_users(users) {}
                 virtual BASE_PARSER * create(const ADMIN & admin) { return new CHECK_USER(admin, m_users); }
                 static void Register(REGISTRY & registry, const USERS & users)
-                { registry[tag] = new FACTORY(users); }
+                { registry[ToLower(tag)] = new FACTORY(users); }
             private:
                 const USERS & m_users;
         };
index 5bd66c8798d879ec5193c8a3a36e9845c45d6539..1068cfa12ed085351486dd462b844cc7603a4d73 100644 (file)
@@ -1047,3 +1047,16 @@ while (done < size)
     }
 return true;
 }
+
+std::string ToPrintable(const std::string & src)
+{
+    std::string dest;
+
+    for (size_t i = 0; i < src.size(); ++i)
+        if (std::isprint(src[i]))
+            dest += src[i];
+        else
+            dest += "\\" + x2str(src[i]);
+
+    return dest;
+}
index 0791f0938e9e89c327ba255f07f2b1f97f9a358d..fe3b3af29377975fff95360eb7d8606078cf2334 100644 (file)
@@ -142,6 +142,8 @@ bool WaitPackets(int sd);
 bool ReadAll(int sd, void * dest, size_t size);
 bool WriteAll(int sd, const void * source, size_t size);
 
+std::string ToPrintable(const std::string & src);
+
 //-----------------------------------------------------------------------------
 int str2x(const std::string & str, int32_t & x);
 int str2x(const std::string & str, uint32_t & x);