void * data;
bool * result;
};
+//-----------------------------------------------------------------------------
+struct AuthByCbData
+{
+ void * data;
+ bool * result;
+};
//---------------------------------------------------------------------------
struct HelpParams
{
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");
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;
}
//-----------------------------------------------------------------------------
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;
+}
+//-----------------------------------------------------------------------------
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,
{"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}};
req.ud[c - 700] = " ";
break;
+ case 800:
+ req.authBy = true;
+
case '?':
case ':':
//printf ("Unknown option \n");
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)
REQUEST()
: chgTariff(false),
createUser(false),
- deleteUser(false)
+ deleteUser(false),
+ authBy(false)
{
for (int i = 0; i < DIR_NUM; i++)
{
string message;
bool createUser;
bool deleteUser;
+bool authBy;
RESETABLE<string> usrMsg;
RESETABLE<double> credit;
./configproto.cpp \
./parser.cpp \
./parser_tariff.cpp \
- ./parser_admin.cpp
+ ./parser_admin.cpp \
+ ./parser_auth_by.cpp
LIBS += -lexpat \
$(LIB_THREAD)
parserDelUser(),
parserCheckUser(),
parserSendMessage(),
+ parserAuthBy(),
parserGetAdmins(),
parserAddAdmin(),
parserDelAdmin(),
dataParser.push_back(&parserDelUser);
dataParser.push_back(&parserCheckUser);
dataParser.push_back(&parserSendMessage);
+dataParser.push_back(&parserAuthBy);
dataParser.push_back(&parserGetTariffs);
dataParser.push_back(&parserAddTariff);
#include "stg/logger.h"
#include "parser.h"
+#include "parser_auth_by.h"
+
#define STG_HEADER "SG04"
#define OK_HEADER "OKHD"
#define ERR_HEADER "ERHD"
PARSER_DEL_USER parserDelUser;
PARSER_CHECK_USER parserCheckUser;
PARSER_SEND_MESSAGE parserSendMessage;
+ PARSER_AUTH_BY parserAuthBy;
PARSER_GET_ADMINS parserGetAdmins;
PARSER_ADD_ADMIN parserAddAdmin;
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);
}
#include <expat.h>
#include <list>
+#include <vector>
#include <string>
#include "stg/os_int.h"
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
{
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:
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);
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);
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;
RecvUserDataCb_t RecvUserDataCb;
RecvUserDataCb_t RecvGetUserDataCb;
+ RecvAuthByDataCb_t RecvAuthByCb;
RecvServerInfoDataCb_t RecvServerInfoDataCb;
RecvChgUserCb_t RecvChgUserCb;
RecvCheckUserCb_t RecvCheckUserCb;
RecvSendMessageCb_t RecvSendMessageCb;
void * getUserDataDataCb;
+ void * getUserAuthByDataCb;
void * getUsersDataDataCb;
void * getServerInfoDataCb;
void * chgUserDataCb;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
+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),
RecvCheckUserCb(NULL),
RecvSendMessageCb(NULL),
getUserDataDataCb(NULL),
+ getUserAuthByDataCb(NULL),
getUsersDataDataCb(NULL),
getServerInfoDataCb(NULL),
chgUserDataCb(NULL),
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();
getUserDataDataCb = data;
}
//-----------------------------------------------------------------------------
+void SERVCONF::SetGetUserAuthByRecvCb(RecvAuthByDataCb_t f, void * data)
+{
+RecvAuthByCb = f;
+getUserAuthByDataCb = data;
+}
+//-----------------------------------------------------------------------------
void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
{
RecvServerInfoDataCb = f;