#ifndef ADMIN_CONF_H
#define ADMIN_CONF_H
-#include <string>
-
#include "os_int.h"
+#include "resetable.h"
+
+#include <string>
#define ADM_LOGIN_LEN (32)
#define ADM_PASSWD_LEN (32)
std::string password;
};
//-----------------------------------------------------------------------------
+struct ADMIN_CONF_RES
+{
+ ADMIN_CONF_RES()
+ {}
+ ADMIN_CONF_RES(const ADMIN_CONF_RES & rhs)
+ : priv(rhs.priv),
+ login(rhs.login),
+ password(rhs.password)
+ {}
+ ADMIN_CONF_RES & operator=(const ADMIN_CONF_RES & rhs)
+ {
+ priv = rhs.priv;
+ login = rhs.login;
+ password = rhs.password;
+ }
+ RESETABLE<PRIV> priv;
+ RESETABLE<std::string> login;
+ RESETABLE<std::string> password;
+};
#include "admin_conf.inc.h"
#include "stg/servconf_types.h"
+#include "stg/admin_conf.h"
#include "stg/os_int.h"
#include <string>
int ServerInfo(SERVER_INFO::CALLBACK f, void * data);
- /*int GetAdmins(GET_ADMINS::CALLBACK f, void * data);
+ int GetAdmins(GET_ADMINS::CALLBACK f, void * data);
int GetAdmin(const std::string & login, GET_ADMIN::CALLBACK f, void * data);
- int ChgAdmin(const std::string & request, CHG_ADMIN::CALLBACK f, void * data);*/
+ int ChgAdmin(const std::string & login, const ADMIN_CONF_RES & conf, CHG_ADMIN::CALLBACK f, void * data);
+ int AddAdmin(const std::string & login, const ADMIN_CONF & conf, GET_ADMIN::CALLBACK f, void * data);
+ int DelAdmin(const std::string & login, DEL_ADMIN::CALLBACK f, void * data);
int GetUsers(GET_USERS::CALLBACK f, void * data);
int GetUser(const std::string & login, GET_USER::CALLBACK f, void * data);
#define ENC_MSG_LEN (8)
+struct ADMIN_CONF;
+
namespace STG
{
confData
};
+typedef void (* SIMPLE_CALLBACK)(bool result, const std::string & reason, void * data);
+
namespace AUTH_BY
{
namespace CHECK_USER
{
-typedef int (* CALLBACK)(bool result, const std::string & reason, void * data);
+typedef SIMPLE_CALLBACK CALLBACK;
} // namespace CHECK_USER
namespace CHG_USER
{
-typedef void (* CALLBACK)(bool result, const std::string & reason, void * data);
+typedef SIMPLE_CALLBACK CALLBACK;
}
namespace SEND_MESSAGE
{
-typedef void (* CALLBACK)(bool result, const std::string & reason, void * data);
+typedef SIMPLE_CALLBACK CALLBACK;
+
+}
+
+namespace GET_ADMIN
+{
+
+typedef ADMIN_CONF INFO;
+typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+}
+
+namespace GET_ADMINS
+{
+
+typedef std::vector<GET_ADMIN::INFO> INFO;
+typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+}
+
+namespace ADD_ADMIN
+{
+
+typedef SIMPLE_CALLBACK CALLBACK;
+
+}
+
+namespace DEL_ADMIN
+{
+
+typedef SIMPLE_CALLBACK CALLBACK;
+
+}
+
+namespace CHG_ADMIN
+{
+
+typedef SIMPLE_CALLBACK CALLBACK;
}
#include "auth_by.h"
-#include <cstddef>
-
#include <strings.h> // strcasecmp
using namespace STG;
-AUTH_BY::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+AUTH_BY::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
depth(0),
parsingAnswer(false)
{
error.clear();
}
}
-//-----------------------------------------------------------------------------
-void AUTH_BY::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
CALLBACK callback;
#include "check_user.h"
-#include <cstddef>
-
#include <strings.h>
using namespace STG;
-CHECK_USER::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+CHECK_USER::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
depth(0)
{
}
else
callback(false, "Invalid response.", data);
}
-//-----------------------------------------------------------------------------
-void CHECK_USER::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
CALLBACK callback;
#include "chg_user.h"
-#include <cstddef>
-
#include <strings.h>
using namespace STG;
-CHG_USER::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+CHG_USER::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
depth(0)
{
}
else
callback(false, "Invalid response.", data);
}
-//-----------------------------------------------------------------------------
-void CHG_USER::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
CALLBACK callback;
#include <map>
#include <utility>
-#include <cstddef>
#include <strings.h>
}
-GET_USER::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+GET_USER::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
depth(0),
parsingAnswer(false)
{
if (!TryParse(propertyParsers, ToLower(el), attr))
error = "Invalid parameter.";
}
-//-----------------------------------------------------------------------------
-void GET_USER::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
virtual ~PARSER();
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
PROPERTY_PARSERS propertyParsers;
#include "get_users.h"
-#include <cstddef>
-
#include <strings.h>
using namespace STG;
-GET_USERS::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+GET_USERS::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
+ userParser(&GET_USERS::PARSER::UserCallback, this),
depth(0),
parsingAnswer(false)
{
- userParser.SetCallback(&GET_USERS::PARSER::UserCallback, this);
}
//-----------------------------------------------------------------------------
int GET_USERS::PARSER::ParseStart(const char * el, const char ** attr)
info.push_back(userInfo);
}
//-----------------------------------------------------------------------------
-void GET_USERS::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
-//-----------------------------------------------------------------------------
void GET_USERS::PARSER::UserCallback(bool result, const std::string & error, const GET_USER::INFO & info, void * data)
{
GET_USERS::PARSER * parser = static_cast<GET_USERS::PARSER *>(data);
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
CALLBACK callback;
#include "send_message.h"
-#include <cstddef>
-
#include <strings.h>
using namespace STG;
-SEND_MESSAGE::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+SEND_MESSAGE::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
depth(0)
{
}
else
callback(false, "Invalid response.", data);
}
-//-----------------------------------------------------------------------------
-void SEND_MESSAGE::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
CALLBACK callback;
#include "stg/common.h"
#include <cstdio> // sprintf
-#include <cstddef>
#include <strings.h>
}
-SERVER_INFO::PARSER::PARSER()
- : callback(NULL),
- data(NULL),
+SERVER_INFO::PARSER::PARSER(CALLBACK f, void * d)
+ : callback(f),
+ data(d),
depth(0),
parsingAnswer(false)
{
parsingAnswer = false;
}
}
-//-----------------------------------------------------------------------------
-void SERVER_INFO::PARSER::SetCallback(CALLBACK f, void * d)
-{
-callback = f;
-data = d;
-}
class PARSER: public STG::PARSER
{
public:
- PARSER();
+ PARSER(CALLBACK f, void * data);
int ParseStart(const char * el, const char ** attr);
void ParseEnd(const char * el);
- void SetCallback(CALLBACK f, void * data);
private:
PROPERTY_PARSERS propertyParsers;
IMPL(const std::string & server, uint16_t port,
const std::string & login, const std::string & password);
+ int ServerInfo(SERVER_INFO::CALLBACK f, void * data);
+
+ int GetAdmins(GET_ADMINS::CALLBACK f, void * data);
+ int GetAdmin(const std::string & login, GET_ADMIN::CALLBACK f, void * data);
+ int ChgAdmin(const std::string & login, const ADMIN_CONF_RES & conf, CHG_ADMIN::CALLBACK f, void * data);
+ int AddAdmin(const std::string & login, const ADMIN_CONF & conf, GET_ADMIN::CALLBACK f, void * data);
+ int DelAdmin(const std::string & login, DEL_ADMIN::CALLBACK f, void * data);
+
int GetUsers(GET_USERS::CALLBACK f, void * data);
int GetUser(const std::string & login, GET_USER::CALLBACK f, void * data);
int ChgUser(const std::string & request, CHG_USER::CALLBACK f, void * data);
int AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data);
int SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data);
- int ServerInfo(SERVER_INFO::CALLBACK f, void * data);
int CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data);
const std::string & GetStrError() const;
static void End(void * data, const char * el);
private:
- GET_USERS::PARSER parserGetUsers;
- GET_USER::PARSER parserGetUser;
- AUTH_BY::PARSER parserAuthBy;
- SERVER_INFO::PARSER parserServerInfo;
- CHG_USER::PARSER parserChgUser;
- CHECK_USER::PARSER parserCheckUser;
- SEND_MESSAGE::PARSER parserSendMessage;
-
NETTRANSACT nt;
std::string errorMsg;
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::GetUser(const std::string & login, GET_USER::CALLBACK f, void * data)
{
-parserGetUser.SetCallback(f, data);
-return Exec("<GetUser login=\"" + login + "\"/>", parserGetUser);
+GET_USER::PARSER parser(f, data);
+return Exec("<GetUser login=\"" + login + "\"/>", parser);
}
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::AuthBy(const std::string & login, AUTH_BY::CALLBACK f, void * data)
{
-parserAuthBy.SetCallback(f, data);
-return Exec("<GetUserAuthBy login=\"" + login + "\"/>", parserAuthBy);
+AUTH_BY::PARSER parser(f, data);
+return Exec("<GetUserAuthBy login=\"" + login + "\"/>", parser);
}
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::GetUsers(GET_USERS::CALLBACK f, void * data)
{
-parserGetUsers.SetCallback(f, data);
-return Exec("<GetUsers/>", parserGetUsers);
+GET_USERS::PARSER parser(f, data);
+return Exec("<GetUsers/>", parser);
}
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::ServerInfo(SERVER_INFO::CALLBACK f, void * data)
{
-parserServerInfo.SetCallback(f, data);
-return Exec("<GetServerInfo/>", parserServerInfo);
+SERVER_INFO::PARSER parser(f, data);
+return Exec("<GetServerInfo/>", parser);
}
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::ChgUser(const std::string & request, CHG_USER::CALLBACK f, void * data)
{
-parserChgUser.SetCallback(f, data);
-return Exec(request, parserChgUser);
+CHG_USER::PARSER parser(f, data);
+return Exec(request, parser);
}
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::SendMessage(const std::string & request, SEND_MESSAGE::CALLBACK f, void * data)
{
-parserSendMessage.SetCallback(f, data);
-return Exec(request, parserSendMessage);
+SEND_MESSAGE::PARSER parser(f, data);
+return Exec(request, parser);
}
//-----------------------------------------------------------------------------
int SERVCONF::IMPL::CheckUser(const std::string & login, const std::string & password, CHECK_USER::CALLBACK f, void * data)
{
-parserCheckUser.SetCallback(f, data);
-return Exec("<CheckUser login=\"" + login + "\" password=\"" + password + "\"/>", parserCheckUser);
+CHECK_USER::PARSER parser(f, data);
+return Exec("<CheckUser login=\"" + login + "\" password=\"" + password + "\"/>", parser);
}
//-----------------------------------------------------------------------------
void SERVCONF::IMPL::Start(void * data, const char * el, const char ** attr)