]> git.stg.codes - stg.git/commitdiff
Added ability to list authorizers for user.
authorMaxim Mamontov <faust.madf@gmail.com>
Fri, 26 Jul 2013 17:25:54 +0000 (20:25 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Fri, 26 Jul 2013 17:25:54 +0000 (20:25 +0300)
projects/sgconf/common_sg.cpp
projects/sgconf/common_sg.h
projects/sgconf/main.cpp
projects/sgconf/request.h
projects/stargazer/plugins/configuration/sgconfig/Makefile
projects/stargazer/plugins/configuration/sgconfig/configproto.cpp
projects/stargazer/plugins/configuration/sgconfig/configproto.h
projects/stargazer/plugins/configuration/sgconfig/parser.cpp
stglibs/srvconf.lib/include/stg/servconf.h
stglibs/srvconf.lib/parser.cpp
stglibs/srvconf.lib/servconf.cpp

index 3d0151602d18c948c45c95177dd701cdc696320d..bb4f59674a5d993bfe68dec37c53eb839e36241d 100644 (file)
@@ -52,6 +52,12 @@ struct GetUserCbData
     void * data;
     bool * result;
 };
     void * data;
     bool * result;
 };
+//-----------------------------------------------------------------------------
+struct AuthByCbData
+{
+    void * data;
+    bool * result;
+};
 //---------------------------------------------------------------------------
 struct HelpParams
 {
 //---------------------------------------------------------------------------
 struct HelpParams
 {
@@ -122,6 +128,9 @@ printf("sgconf set -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> --
 printf("To get userdata<0...9> use:\n");
 printf("sgconf get -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> --ud0 [--ud1 ...]\n\n");
 
 printf("To get userdata<0...9> use:\n");
 printf("sgconf get -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> --ud0 [--ud1 ...]\n\n");
 
+printf("To get user's authorizers list use:\n");
+printf("sgconf get -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> --authorized-by\n");
+
 printf("To send message use:\n");
 printf("sgconf set -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> -m <message>\n\n");
 
 printf("To send message use:\n");
 printf("sgconf set -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> -m <message>\n\n");
 
@@ -406,6 +415,22 @@ for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++)
         cout << strReqParams[i].name << "=" << str << endl;
         }
     }
         cout << strReqParams[i].name << "=" << str << endl;
         }
     }
+*result = true;
+}
+//-----------------------------------------------------------------------------
+void RecvAuthByData(const std::vector<std::string> & list, void * d)
+{
+AuthByCbData * abcbd;
+abcbd = (AuthByCbData *)d;
+
+bool * result = abcbd->result;
+
+REQUEST * req = (REQUEST *)abcbd->data;
+
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+    cout << *it << "\n";
+cout << endl;
+
 *result = true;
 }
 //-----------------------------------------------------------------------------
 *result = true;
 }
 //-----------------------------------------------------------------------------
@@ -497,3 +522,42 @@ else
 return 0;
 }
 //-----------------------------------------------------------------------------
 return 0;
 }
 //-----------------------------------------------------------------------------
+int ProcessAuthBy(const std::string &server,
+                  int port,
+                  const std::string &admLogin,
+                  const std::string &admPasswd,
+                  const std::string &login,
+                  void * data)
+{
+SERVCONF sc;
+
+bool result = false;
+
+sc.SetServer(server.c_str());  // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ
+sc.SetPort(port);           // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ
+sc.SetAdmLogin(admLogin.c_str());    // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉΠɠÐÁÒÏÌØ ÁÄÍÉÎÁ
+sc.SetAdmPassword(admPasswd.c_str());
+
+// TODO Good variable name :)
+AuthByCbData abcbd;
+
+abcbd.data = data;
+abcbd.result = &result;
+
+sc.SetGetUserAuthByRecvCb(RecvAuthByData, &abcbd);
+sc.GetUserAuthBy(login.c_str());
+
+if (result)
+    {
+    printf("Ok\n");
+    return 0;
+    }
+else
+    {
+    printf("Error\n");
+    return -1;
+    }
+
+return 0;
+}
+//-----------------------------------------------------------------------------
index a654748a68f744ea558ef309d5d2702d21447c4e..a5cbffad86289f16be34308ad61f6e1575346932 100644 (file)
@@ -52,6 +52,13 @@ int ProcessGetUser(const std::string &server,
                    const std::string &login,
                    void * data);
 
                    const std::string &login,
                    void * data);
 
+int ProcessAuthBy(const std::string &server,
+                  int port,
+                  const std::string &admLogin,
+                  const std::string &admPasswd,
+                  const std::string &login,
+                  void * data);
+
 int ProcessSetUser(const std::string &server,
                    int port,
                    const std::string &admLogin,
 int ProcessSetUser(const std::string &server,
                    int port,
                    const std::string &admLogin,
index 2aaacbc01d2e5e4d723f32d1d42f37de7a376008..ce5a20722707c37940a485abdd1fff0add7ff0d1 100644 (file)
@@ -108,7 +108,8 @@ struct option long_options_get[] = {
 {"email",       0, 0, 'L'},  //emaiL
 {"phone",       0, 0, 'P'},  //phone
 {"group",       0, 0, 'G'},  //Group
 {"email",       0, 0, 'L'},  //emaiL
 {"phone",       0, 0, 'P'},  //phone
 {"group",       0, 0, 'G'},  //Group
-{"ip",         0, 0, 'I'},  //IP-address of user
+{"ip",          0, 0, 'I'},  //IP-address of user
+{"authorized-by",0, 0, 800}, //always online
 
 {0, 0, 0, 0}};
 
 
 {0, 0, 0, 0}};
 
@@ -846,6 +847,9 @@ while (1)
             req.ud[c - 700] = " ";
             break;
 
             req.ud[c - 700] = " ";
             break;
 
+        case 800:
+            req.authBy = true;
+
         case '?':
         case ':':
             //printf ("Unknown option \n");
         case '?':
         case ':':
             //printf ("Unknown option \n");
@@ -873,7 +877,10 @@ if (missedOptionArg || !CheckParametersGet(&req))
     exit(PARAMETER_PARSING_ERR_CODE);
     }
 
     exit(PARAMETER_PARSING_ERR_CODE);
     }
 
-return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req);
+if (req.authBy)
+    return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req);
+else
+    return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req);
 }
 //-----------------------------------------------------------------------------
 int mainSet(int argc, char **argv)
 }
 //-----------------------------------------------------------------------------
 int mainSet(int argc, char **argv)
index daddec1d3401f6d2eec33d1a2678a98823bd922a..6122212732aa5206359a6eb8342c717de401c61a 100644 (file)
@@ -49,7 +49,8 @@ struct REQUEST
 REQUEST()
     : chgTariff(false),
       createUser(false),
 REQUEST()
     : chgTariff(false),
       createUser(false),
-      deleteUser(false)
+      deleteUser(false),
+      authBy(false)
 {
     for (int i = 0; i < DIR_NUM; i++)
         {
 {
     for (int i = 0; i < DIR_NUM; i++)
         {
@@ -75,6 +76,7 @@ RESETABLE<double>   setCash;
 string              message;
 bool                createUser;
 bool                deleteUser;
 string              message;
 bool                createUser;
 bool                deleteUser;
+bool                authBy;
 
 RESETABLE<string>   usrMsg;
 RESETABLE<double>   credit;
 
 RESETABLE<string>   usrMsg;
 RESETABLE<double>   credit;
index b6f4938a632095cfcdf505f4fb950e39d65845e6..83e267d15992fdc5ef690d7f3750b42e7d39e65e 100644 (file)
@@ -11,7 +11,8 @@ SRCS = ./stgconfig.cpp \
        ./configproto.cpp \
        ./parser.cpp \
        ./parser_tariff.cpp \
        ./configproto.cpp \
        ./parser.cpp \
        ./parser_tariff.cpp \
-       ./parser_admin.cpp
+       ./parser_admin.cpp \
+       ./parser_auth_by.cpp
 
 LIBS += -lexpat \
        $(LIB_THREAD)
 
 LIBS += -lexpat \
        $(LIB_THREAD)
index 22facc612adf4b55a9b02f22d3f3ac8d20a323c2..015c24602fb5391345a8826ad926cd64293af434 100644 (file)
@@ -107,6 +107,7 @@ CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
       parserDelUser(),
       parserCheckUser(),
       parserSendMessage(),
       parserDelUser(),
       parserCheckUser(),
       parserSendMessage(),
+      parserAuthBy(),
       parserGetAdmins(),
       parserAddAdmin(),
       parserDelAdmin(),
       parserGetAdmins(),
       parserAddAdmin(),
       parserDelAdmin(),
@@ -130,6 +131,7 @@ dataParser.push_back(&parserAddUser);
 dataParser.push_back(&parserDelUser);
 dataParser.push_back(&parserCheckUser);
 dataParser.push_back(&parserSendMessage);
 dataParser.push_back(&parserDelUser);
 dataParser.push_back(&parserCheckUser);
 dataParser.push_back(&parserSendMessage);
+dataParser.push_back(&parserAuthBy);
 
 dataParser.push_back(&parserGetTariffs);
 dataParser.push_back(&parserAddTariff);
 
 dataParser.push_back(&parserGetTariffs);
 dataParser.push_back(&parserAddTariff);
index b8b01f024da3f1f0d8daf32ce7ea50231678ec13..ccb8a4d723353c08bc6ad09b4e18117bea7ae3e6 100644 (file)
@@ -41,6 +41,8 @@
 #include "stg/logger.h"
 #include "parser.h"
 
 #include "stg/logger.h"
 #include "parser.h"
 
+#include "parser_auth_by.h"
+
 #define  STG_HEADER     "SG04"
 #define  OK_HEADER      "OKHD"
 #define  ERR_HEADER     "ERHD"
 #define  STG_HEADER     "SG04"
 #define  OK_HEADER      "OKHD"
 #define  ERR_HEADER     "ERHD"
@@ -107,6 +109,7 @@ private:
     PARSER_DEL_USER             parserDelUser;
     PARSER_CHECK_USER           parserCheckUser;
     PARSER_SEND_MESSAGE         parserSendMessage;
     PARSER_DEL_USER             parserDelUser;
     PARSER_CHECK_USER           parserCheckUser;
     PARSER_SEND_MESSAGE         parserSendMessage;
+    PARSER_AUTH_BY              parserAuthBy;
 
     PARSER_GET_ADMINS           parserGetAdmins;
     PARSER_ADD_ADMIN            parserAddAdmin;
 
     PARSER_GET_ADMINS           parserGetAdmins;
     PARSER_ADD_ADMIN            parserAddAdmin;
index 8e11a157ccd4a86addebffd3da8f0b49ebfa5ed8..b6c491721f78c53a3c01d5edad0b163cc5ef57f3 100644 (file)
@@ -286,6 +286,13 @@ answerList->push_back(s);
 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
 answerList->push_back(s);
 
 strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
 answerList->push_back(s);
 
+s = "<AuthorizedBy>";
+std::vector<std::string> list(u->GetAuthorizers());
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+    s += "<Auth name=\"" + *it + "\">";
+s += "</AuthorizedBy>";
+answerList->push_back(s);
+
 strprintf(&s, "</user>");
 answerList->push_back(s);
 }
 strprintf(&s, "</user>");
 answerList->push_back(s);
 }
index 67c2f248dbae85c49b08fb1cf7f4eaa0189170e2..dbbe20013daa4087224221ea5c94e4c8c500d0d8 100644 (file)
@@ -30,6 +30,7 @@
 #include <expat.h>
 
 #include <list>
 #include <expat.h>
 
 #include <list>
+#include <vector>
 #include <string>
 
 #include "stg/os_int.h"
 #include <string>
 
 #include "stg/os_int.h"
@@ -101,6 +102,7 @@ typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data);
 typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
 typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
 typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
 typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
 typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
 typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
+typedef void(*RecvAuthByDataCb_t)(const std::vector<std::string> & list, void * data);
 //-----------------------------------------------------------------------------
 struct ADMINDATA
 {
 //-----------------------------------------------------------------------------
 struct ADMINDATA
 {
@@ -224,6 +226,23 @@ private:
     bool error;
 };
 //-----------------------------------------------------------------------------
     bool error;
 };
 //-----------------------------------------------------------------------------
+class PARSER_AUTH_BY: public PARSER
+{
+public:
+    PARSER_AUTH_BY();
+    int  ParseStart(const char *el, const char **attr);
+    void ParseEnd(const char *el);
+    void ParseServerInfo(const char *el, const char **attr);
+    bool GetError();
+    void SetRecvCb(RecvAuthByDataCb_t, void * data);
+private:
+    RecvAuthByDataCb_t RecvAuthByDataCb;
+    void * authByDataCb;
+    int depth;
+    bool error;
+    std::vector<std::string> list;
+};
+//-----------------------------------------------------------------------------
 class SERVCONF
 {
 public:
 class SERVCONF
 {
 public:
@@ -235,6 +254,7 @@ public:
     void SetAdmPassword(const char * password);
 
     void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
     void SetAdmPassword(const char * password);
 
     void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
+    void SetGetUserAuthByRecvCb(RecvAuthByDataCb_t, void * data);
     void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
     void SetChgUserCb(RecvChgUserCb_t, void * data);
     void SetCheckUserCb(RecvCheckUserCb_t, void * data);
     void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
     void SetChgUserCb(RecvChgUserCb_t, void * data);
     void SetCheckUserCb(RecvCheckUserCb_t, void * data);
@@ -244,6 +264,7 @@ public:
     int GetUsers();
     int GetUser(const char * login);
     int ChgUser(const char * request);
     int GetUsers();
     int GetUser(const char * login);
     int ChgUser(const char * request);
+    int GetUserAuthBy(const char * login);
     // TODO: Remove this shit!
     int MsgUser(const char * request);
     int SendMessage(const char * login, const char * message, int prio);
     // TODO: Remove this shit!
     int MsgUser(const char * request);
     int SendMessage(const char * login, const char * message, int prio);
@@ -260,6 +281,7 @@ private:
 
     PARSER_GET_USERS parserGetUsers;
     PARSER_GET_USER parserGetUser;
 
     PARSER_GET_USERS parserGetUsers;
     PARSER_GET_USER parserGetUser;
+    PARSER_AUTH_BY parserAuthBy;
     PARSER_GET_SERVER_INFO  parserServerInfo;
     PARSER_CHG_USER parserChgUser;
     PARSER_CHECK_USER parserCheckUser;
     PARSER_GET_SERVER_INFO  parserServerInfo;
     PARSER_CHG_USER parserChgUser;
     PARSER_CHECK_USER parserCheckUser;
@@ -274,12 +296,14 @@ private:
 
     RecvUserDataCb_t RecvUserDataCb;
     RecvUserDataCb_t RecvGetUserDataCb;
 
     RecvUserDataCb_t RecvUserDataCb;
     RecvUserDataCb_t RecvGetUserDataCb;
+    RecvAuthByDataCb_t RecvAuthByCb;
     RecvServerInfoDataCb_t RecvServerInfoDataCb;
     RecvChgUserCb_t RecvChgUserCb;
     RecvCheckUserCb_t RecvCheckUserCb;
     RecvSendMessageCb_t RecvSendMessageCb;
 
     void * getUserDataDataCb;
     RecvServerInfoDataCb_t RecvServerInfoDataCb;
     RecvChgUserCb_t RecvChgUserCb;
     RecvCheckUserCb_t RecvCheckUserCb;
     RecvSendMessageCb_t RecvSendMessageCb;
 
     void * getUserDataDataCb;
+    void * getUserAuthByDataCb;
     void * getUsersDataDataCb;
     void * getServerInfoDataCb;
     void * chgUserDataCb;
     void * getUsersDataDataCb;
     void * getServerInfoDataCb;
     void * chgUserDataCb;
index a87266eb5cb57d37fd6cb81f002134cbdde1e547..625373594e0b86b12fb1bf92632e396ae19171a9 100644 (file)
@@ -822,6 +822,58 @@ if (strcmp(attr[0], "value") == 0)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
+PARSER_AUTH_BY::PARSER_AUTH_BY()
+    : RecvAuthByDataCb(NULL),
+      authByDataCb(NULL),
+      depth(0),
+      error(false),
+      list()
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+    {
+    if (strcasecmp(el, "AuthorizedBy") != 0)
+        {
+        list.erase(list.begin(), list.end());
+        //printf("%s\n", el);
+        }
+    }
+else
+    {
+    if (depth == 2)
+        {
+        if (strcasecmp(el, "Auth") == 0)
+            {
+            if (attr && attr[0])
+                list.push_back(attr[0]);
+            return 0;
+            }
+        }
+    }
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_AUTH_BY::ParseEnd(const char *)
+{
+depth--;
+if (depth == 0)
+    {
+    RecvAuthByDataCb(list, authByDataCb);
+    }
+}
+//-----------------------------------------------------------------------------
+void PARSER_AUTH_BY::SetRecvCb(RecvAuthByDataCb_t f, void * data)
+{
+RecvAuthByDataCb = f;
+authByDataCb = data;
+}
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 PARSER_CHG_USER::PARSER_CHG_USER()
     : RecvChgUserCb(NULL),
       chgUserCbData(NULL),
 PARSER_CHG_USER::PARSER_CHG_USER()
     : RecvChgUserCb(NULL),
       chgUserCbData(NULL),
index ab386cf753dfab06b631806d5faea58d63776050..0ca3028c9e881209cf4d881696c6aedc0ae9a41e 100644 (file)
@@ -101,6 +101,7 @@ SERVCONF::SERVCONF()
       RecvCheckUserCb(NULL),
       RecvSendMessageCb(NULL),
       getUserDataDataCb(NULL),
       RecvCheckUserCb(NULL),
       RecvSendMessageCb(NULL),
       getUserDataDataCb(NULL),
+      getUserAuthByDataCb(NULL),
       getUsersDataDataCb(NULL),
       getServerInfoDataCb(NULL),
       chgUserDataCb(NULL),
       getUsersDataDataCb(NULL),
       getServerInfoDataCb(NULL),
       chgUserDataCb(NULL),
@@ -142,6 +143,37 @@ currParser = &parserGetUser;
 nt.Reset();
 nt.SetRxCallback(this, AnsRecv);
 
 nt.Reset();
 nt.SetRxCallback(this, AnsRecv);
 
+if ((ret = nt.Connect()) != st_ok)
+    {
+    errorMsg = nt.GetError();
+    return ret;
+    }
+if ((ret = nt.Transact(request)) != st_ok)
+    {
+    errorMsg = nt.GetError();
+    return ret;
+    }
+if ((ret = nt.Disconnect()) != st_ok)
+    {
+    errorMsg = nt.GetError();
+    return ret;
+    }
+
+return st_ok;
+}
+//-----------------------------------------------------------------------------
+int SERVCONF::GetUserAuthBy(const char * l)
+{
+char request[255];
+snprintf(request, 255, "<GetUserAuthBy login=\"%s\"/>", l);
+int ret;
+
+currParser = &parserAuthBy;
+((PARSER_AUTH_BY*)currParser)->SetRecvCb(RecvAuthByCb, getUserAuthByDataCb);
+
+nt.Reset();
+nt.SetRxCallback(this, AnsRecv);
+
 if ((ret = nt.Connect()) != st_ok)
     {
     errorMsg = nt.GetError();
 if ((ret = nt.Connect()) != st_ok)
     {
     errorMsg = nt.GetError();
@@ -368,6 +400,12 @@ RecvGetUserDataCb = f;            //GET_USER
 getUserDataDataCb = data;
 }
 //-----------------------------------------------------------------------------
 getUserDataDataCb = data;
 }
 //-----------------------------------------------------------------------------
+void SERVCONF::SetGetUserAuthByRecvCb(RecvAuthByDataCb_t f, void * data)
+{
+RecvAuthByCb = f;
+getUserAuthByDataCb = data;
+}
+//-----------------------------------------------------------------------------
 void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
 {
 RecvServerInfoDataCb = f;
 void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
 {
 RecvServerInfoDataCb = f;