From: Maxim Mamontov <faust.madf@gmail.com>
Date: Fri, 20 Sep 2013 21:17:50 +0000 (+0300)
Subject: Moved AUTH_BY parser from global scope.
X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/82c7b78d7b7cf797f0663c96f44b092103802035

Moved AUTH_BY parser from global scope.
---

diff --git a/projects/sgconf/common_sg.cpp b/projects/sgconf/common_sg.cpp
index 1db7c9c4..f3688649 100644
--- a/projects/sgconf/common_sg.cpp
+++ b/projects/sgconf/common_sg.cpp
@@ -43,6 +43,8 @@
 #include <langinfo.h>
 #include <iconv.h>
 
+using namespace STG;
+
 const int usageConf = 0;
 const int usageInfo = 1;
 
@@ -302,7 +304,7 @@ data->reason = reason;
 }
 //-----------------------------------------------------------------------------
 void RecvAuthByData(bool result, const std::string & reason,
-                    const PARSER_AUTH_BY::INFO & list, void * d)
+                    const AUTH_BY::INFO & list, void * d)
 {
 ResultData * data = static_cast<ResultData *>(d);
 data->result = result;
diff --git a/stglibs/srvconf.lib/include/stg/parser.h b/stglibs/srvconf.lib/include/stg/parser.h
index f8c3af0c..8d695a3a 100644
--- a/stglibs/srvconf.lib/include/stg/parser.h
+++ b/stglibs/srvconf.lib/include/stg/parser.h
@@ -22,6 +22,9 @@
 #ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
 #define __STG_STGLIBS_SRVCONF_PARSER_H__
 
+namespace STG
+{
+
 class PARSER
 {
 public:
@@ -30,4 +33,6 @@ public:
     virtual void ParseEnd(const char *el) = 0;
 };
 
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_auth_by.h b/stglibs/srvconf.lib/include/stg/parser_auth_by.h
deleted file mode 100644
index 00c997d5..00000000
--- a/stglibs/srvconf.lib/include/stg/parser_auth_by.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- *    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*
- *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
-#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
-
-#include "parser.h"
-
-#include <vector>
-#include <string>
-
-class PARSER_AUTH_BY: public PARSER
-{
-public:
-    typedef std::vector<std::string> INFO;
-    typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
-
-    PARSER_AUTH_BY();
-    int  ParseStart(const char *el, const char **attr);
-    void ParseEnd(const char *el);
-    void SetCallback(CALLBACK f, void * data);
-private:
-    CALLBACK callback;
-    void * data;
-    int depth;
-    bool parsingAnswer;
-    INFO info;
-    std::string error;
-};
-
-#endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_check_user.h b/stglibs/srvconf.lib/include/stg/parser_check_user.h
index e0bea221..4e1f498c 100644
--- a/stglibs/srvconf.lib/include/stg/parser_check_user.h
+++ b/stglibs/srvconf.lib/include/stg/parser_check_user.h
@@ -26,6 +26,9 @@
 
 #include <string>
 
+namespace STG
+{
+
 class PARSER_CHECK_USER: public PARSER
 {
 public:
@@ -43,4 +46,6 @@ private:
     void ParseAnswer(const char * el, const char ** attr);
 };
 
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_chg_user.h b/stglibs/srvconf.lib/include/stg/parser_chg_user.h
index cc6e9f18..75431ae1 100644
--- a/stglibs/srvconf.lib/include/stg/parser_chg_user.h
+++ b/stglibs/srvconf.lib/include/stg/parser_chg_user.h
@@ -26,6 +26,9 @@
 
 #include <string>
 
+namespace STG
+{
+
 class PARSER_CHG_USER: public PARSER
 {
 public:
@@ -43,4 +46,6 @@ private:
     void ParseAnswer(const char * el, const char ** attr);
 };
 
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_get_user.h b/stglibs/srvconf.lib/include/stg/parser_get_user.h
index 7f6faaad..a6fadeb8 100644
--- a/stglibs/srvconf.lib/include/stg/parser_get_user.h
+++ b/stglibs/srvconf.lib/include/stg/parser_get_user.h
@@ -33,6 +33,9 @@
 
 #include <ctime>
 
+namespace STG
+{
+
 class PARSER_GET_USER: public PARSER
 {
 public:
@@ -92,4 +95,6 @@ private:
     void ParseUserParams(const char *el, const char **attr);
 };
 
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_get_users.h b/stglibs/srvconf.lib/include/stg/parser_get_users.h
index 35fcd126..a8b8ac85 100644
--- a/stglibs/srvconf.lib/include/stg/parser_get_users.h
+++ b/stglibs/srvconf.lib/include/stg/parser_get_users.h
@@ -29,6 +29,9 @@
 
 #include <vector>
 
+namespace STG
+{
+
 class PARSER_GET_USERS: public PARSER
 {
 public:
@@ -54,4 +57,6 @@ private:
     static void UserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * data);
 };
 
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_send_message.h b/stglibs/srvconf.lib/include/stg/parser_send_message.h
index 9b3ca5ef..912d507e 100644
--- a/stglibs/srvconf.lib/include/stg/parser_send_message.h
+++ b/stglibs/srvconf.lib/include/stg/parser_send_message.h
@@ -26,6 +26,9 @@
 
 #include <string>
 
+namespace STG
+{
+
 class PARSER_SEND_MESSAGE: public PARSER
 {
 public:
@@ -43,4 +46,6 @@ private:
     void ParseAnswer(const char * el, const char ** attr);
 };
 
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/parser_server_info.h b/stglibs/srvconf.lib/include/stg/parser_server_info.h
index ff31ae71..cb57bffd 100644
--- a/stglibs/srvconf.lib/include/stg/parser_server_info.h
+++ b/stglibs/srvconf.lib/include/stg/parser_server_info.h
@@ -29,6 +29,9 @@
 
 #include <string>
 
+namespace STG
+{
+
 class PARSER_SERVER_INFO: public PARSER
 {
 public:
@@ -58,4 +61,6 @@ private:
     std::string error;
 };
 
+}
+
 #endif
diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h
index 32ee1cd4..e55cff2c 100644
--- a/stglibs/srvconf.lib/include/stg/servconf.h
+++ b/stglibs/srvconf.lib/include/stg/servconf.h
@@ -24,10 +24,9 @@
  $Author: faust $
  */
 
-#ifndef SERVCONF_H
-#define SERVCONF_H
+#ifndef __STG_STGLIBS_SERVCONF_H__
+#define __STG_STGLIBS_SERVCONF_H__
 
-#include "stg/parser_auth_by.h"
 #include "stg/parser_server_info.h"
 #include "stg/parser_check_user.h"
 #include "stg/parser_get_user.h"
@@ -35,10 +34,15 @@
 #include "stg/parser_chg_user.h"
 #include "stg/parser_send_message.h"
 
+#include "stg/servconf_types.h"
+
 #include "stg/os_int.h"
 
 #include <string>
 
+namespace STG
+{
+
 class SERVCONF
 {
 public:
@@ -49,7 +53,7 @@ public:
     int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data);
     int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data);
     int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data);
-    int AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data);
+    int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data);
     int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data);
     int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data);
     int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data);
@@ -60,6 +64,7 @@ private:
     class IMPL;
     IMPL * pImpl;
 };
-//-----------------------------------------------------------------------------
 
-#endif  /* _SERVCONF_H_ */
+} // namespace STG
+
+#endif
diff --git a/stglibs/srvconf.lib/include/stg/servconf_types.h b/stglibs/srvconf.lib/include/stg/servconf_types.h
index d7fb8478..7ffc5811 100644
--- a/stglibs/srvconf.lib/include/stg/servconf_types.h
+++ b/stglibs/srvconf.lib/include/stg/servconf_types.h
@@ -21,6 +21,9 @@
 #ifndef __STG_STGLIBS_SRVCONF_TYPES_H__
 #define __STG_STGLIBS_SRVCONF_TYPES_H__
 
+#include <string>
+#include <vector>
+
 #define  STG_HEADER     "SG04"
 #define  OK_HEADER      "OKHD"
 #define  ERR_HEADER     "ERHD"
@@ -31,6 +34,9 @@
 
 #define  ENC_MSG_LEN    (8)
 
+namespace STG
+{
+
 enum status
 {
 st_ok = 0,
@@ -55,4 +61,13 @@ confLoginCipher,
 confData
 };
 
+namespace AUTH_BY
+{
+
+typedef std::vector<std::string> INFO;
+typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+} // namespace AUTH_BY
+} // namespace STG
+
 #endif
diff --git a/stglibs/srvconf.lib/netunit.cpp b/stglibs/srvconf.lib/netunit.cpp
index 73f0f485..aabb7780 100644
--- a/stglibs/srvconf.lib/netunit.cpp
+++ b/stglibs/srvconf.lib/netunit.cpp
@@ -44,6 +44,8 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 
+using namespace STG;
+
 namespace
 {
 
diff --git a/stglibs/srvconf.lib/parser_auth_by.cpp b/stglibs/srvconf.lib/parser_auth_by.cpp
index 06981aae..b3904a1b 100644
--- a/stglibs/srvconf.lib/parser_auth_by.cpp
+++ b/stglibs/srvconf.lib/parser_auth_by.cpp
@@ -18,13 +18,15 @@
  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
  */
 
-#include "stg/parser_auth_by.h"
+#include "parser_auth_by.h"
 
 #include <cstddef>
 
 #include <strings.h> // strcasecmp
 
-PARSER_AUTH_BY::PARSER_AUTH_BY()
+using namespace STG;
+
+AUTH_BY::PARSER::PARSER()
     : callback(NULL),
       data(NULL),
       depth(0),
@@ -32,7 +34,7 @@ PARSER_AUTH_BY::PARSER_AUTH_BY()
 {
 }
 //-----------------------------------------------------------------------------
-int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
+int AUTH_BY::PARSER::ParseStart(const char *el, const char **attr)
 {
 depth++;
 if (depth == 1)
@@ -66,7 +68,7 @@ else
 return 0;
 }
 //-----------------------------------------------------------------------------
-void PARSER_AUTH_BY::ParseEnd(const char * /*el*/)
+void AUTH_BY::PARSER::ParseEnd(const char * /*el*/)
 {
 depth--;
 if (depth == 0)
@@ -78,7 +80,7 @@ if (depth == 0)
     }
 }
 //-----------------------------------------------------------------------------
-void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * d)
+void AUTH_BY::PARSER::SetCallback(AUTH_BY::CALLBACK f, void * d)
 {
 callback = f;
 data = d;
diff --git a/stglibs/srvconf.lib/parser_auth_by.h b/stglibs/srvconf.lib/parser_auth_by.h
new file mode 100644
index 00000000..4e94267c
--- /dev/null
+++ b/stglibs/srvconf.lib/parser_auth_by.h
@@ -0,0 +1,55 @@
+/*
+ *    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+
+#include "stg/parser.h"
+
+#include "stg/servconf_types.h"
+
+#include <vector>
+#include <string>
+
+namespace STG
+{
+namespace AUTH_BY
+{
+
+class PARSER: public STG::PARSER
+{
+public:
+    PARSER();
+    int  ParseStart(const char *el, const char **attr);
+    void ParseEnd(const char *el);
+    void SetCallback(CALLBACK f, void * data);
+private:
+    CALLBACK callback;
+    void * data;
+    int depth;
+    bool parsingAnswer;
+    INFO info;
+    std::string error;
+};
+
+} // namespace AUTH_BY
+} // namespace STG
+
+#endif
diff --git a/stglibs/srvconf.lib/parser_check_user.cpp b/stglibs/srvconf.lib/parser_check_user.cpp
index eed03f30..8c150357 100644
--- a/stglibs/srvconf.lib/parser_check_user.cpp
+++ b/stglibs/srvconf.lib/parser_check_user.cpp
@@ -25,6 +25,8 @@
 
 #include <strings.h>
 
+using namespace STG;
+
 PARSER_CHECK_USER::PARSER_CHECK_USER()
     : callback(NULL),
       data(NULL),
diff --git a/stglibs/srvconf.lib/parser_chg_user.cpp b/stglibs/srvconf.lib/parser_chg_user.cpp
index 53ce941d..084b0cc8 100644
--- a/stglibs/srvconf.lib/parser_chg_user.cpp
+++ b/stglibs/srvconf.lib/parser_chg_user.cpp
@@ -25,6 +25,8 @@
 
 #include <strings.h>
 
+using namespace STG;
+
 PARSER_CHG_USER::PARSER_CHG_USER()
     : callback(NULL),
       data(NULL),
diff --git a/stglibs/srvconf.lib/parser_get_user.cpp b/stglibs/srvconf.lib/parser_get_user.cpp
index 43d720e8..0127eda2 100644
--- a/stglibs/srvconf.lib/parser_get_user.cpp
+++ b/stglibs/srvconf.lib/parser_get_user.cpp
@@ -29,6 +29,8 @@
 
 #include <strings.h>
 
+using namespace STG;
+
 template <>
 bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
 {
diff --git a/stglibs/srvconf.lib/parser_get_users.cpp b/stglibs/srvconf.lib/parser_get_users.cpp
index 2f380c82..80465afc 100644
--- a/stglibs/srvconf.lib/parser_get_users.cpp
+++ b/stglibs/srvconf.lib/parser_get_users.cpp
@@ -25,6 +25,8 @@
 
 #include <strings.h>
 
+using namespace STG;
+
 PARSER_GET_USERS::PARSER_GET_USERS()
     : callback(NULL),
       data(NULL),
diff --git a/stglibs/srvconf.lib/parser_send_message.cpp b/stglibs/srvconf.lib/parser_send_message.cpp
index c1955fce..08b60462 100644
--- a/stglibs/srvconf.lib/parser_send_message.cpp
+++ b/stglibs/srvconf.lib/parser_send_message.cpp
@@ -25,6 +25,8 @@
 
 #include <strings.h>
 
+using namespace STG;
+
 PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
     : callback(NULL),
       data(NULL),
diff --git a/stglibs/srvconf.lib/parser_server_info.cpp b/stglibs/srvconf.lib/parser_server_info.cpp
index 645f6099..38a373b8 100644
--- a/stglibs/srvconf.lib/parser_server_info.cpp
+++ b/stglibs/srvconf.lib/parser_server_info.cpp
@@ -28,6 +28,8 @@
 
 #include <strings.h>
 
+using namespace STG;
+
 namespace
 {
 
diff --git a/stglibs/srvconf.lib/servconf.cpp b/stglibs/srvconf.lib/servconf.cpp
index c45dfb9b..a7663f0e 100644
--- a/stglibs/srvconf.lib/servconf.cpp
+++ b/stglibs/srvconf.lib/servconf.cpp
@@ -21,7 +21,7 @@
 #include "stg/servconf.h"
 
 #include "netunit.h"
-#include "stg/servconf_types.h"
+#include "parser_auth_by.h"
 
 #include "stg/common.h"
 
@@ -30,6 +30,8 @@
 
 #include <expat.h>
 
+using namespace STG;
+
 class SERVCONF::IMPL
 {
 public:
@@ -39,7 +41,7 @@ public:
     int GetUsers(PARSER_GET_USERS::CALLBACK f, void * data);
     int GetUser(const std::string & login, PARSER_GET_USER::CALLBACK f, void * data);
     int ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f, void * data);
-    int AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data);
+    int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data);
     int SendMessage(const std::string & request, PARSER_SEND_MESSAGE::CALLBACK f, void * data);
     int ServerInfo(PARSER_SERVER_INFO::CALLBACK f, void * data);
     int CheckUser(const std::string & login, const std::string & password, PARSER_CHECK_USER::CALLBACK f, void * data);
@@ -51,7 +53,7 @@ public:
 private:
     PARSER_GET_USERS parserGetUsers;
     PARSER_GET_USER parserGetUser;
-    PARSER_AUTH_BY parserAuthBy;
+    AUTH_BY::PARSER parserAuthBy;
     PARSER_SERVER_INFO  parserServerInfo;
     PARSER_CHG_USER parserChgUser;
     PARSER_CHECK_USER parserCheckUser;
@@ -67,22 +69,6 @@ private:
     static bool AnsRecv(void * data, const std::string & chunk, bool final);
 };
 
-/*namespace
-{
-
-void ElementStart(void * data, const char * el, const char ** attr)
-{
-static_cast<SERVCONF::IMPL *>(data)->Start(el, attr);
-}
-
-void ElementEnd(void * data, const char * el)
-{
-static_cast<SERVCONF::IMPL *>(data)->End(el);
-}
-
-} // namespace anonymous
-*/
-
 bool SERVCONF::IMPL::AnsRecv(void * data, const std::string & chunk, bool final)
 {
 SERVCONF::IMPL * sc = static_cast<SERVCONF::IMPL *>(data);
@@ -125,7 +111,7 @@ int SERVCONF::ChgUser(const std::string & request, PARSER_CHG_USER::CALLBACK f,
     return pImpl->ChgUser(request, f, data);
 }
 
-int SERVCONF::AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data)
+int SERVCONF::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data)
 {
     return pImpl->AuthBy(login, f, data);
 }
@@ -165,7 +151,7 @@ parserGetUser.SetCallback(f, data);
 return Exec("<GetUser login=\"" + login + "\"/>", parserGetUser);
 }
 //-----------------------------------------------------------------------------
-int SERVCONF::IMPL::AuthBy(const std::string & login, PARSER_AUTH_BY::CALLBACK f, void * data)
+int SERVCONF::IMPL::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data)
 {
 parserAuthBy.SetCallback(f, data);
 return Exec("<GetUserAuthBy login=\"" + login + "\"/>", parserAuthBy);