const int TO_KOI8 = 0;
const int FROM_KOI8 = 1;
//-----------------------------------------------------------------------------
-struct GetUserCbData
+struct GetUserData
{
- void * data;
- bool * result;
+ REQUEST & request;
+ bool result;
};
//---------------------------------------------------------------------------
struct HelpParams
string * value;
};
//-----------------------------------------------------------------------------
-void RecvUserData(USERDATA * ud, void * d)
+void GetUserCallback(const PARSER_GET_USER::INFO & info, void * d)
{
-GetUserCbData * gucbd;
-gucbd = (GetUserCbData *)d;
-
-bool * result = gucbd->result;
+GetUserData * data = static_cast<GetUserData *>(d);
REQUEST * req = (REQUEST *)gucbd->data;
-if (ud->login == "")
+if (info.login == "")
{
- *result = false;
+ data->result = false;
return;
}
-if (!req->cash.res_empty())
- cout << "cash=" << ud->cash << endl;
+if (!data->request.cash.res_empty())
+ cout << "cash=" << info.cash << endl;
-if (!req->credit.res_empty())
- cout << "credit=" << ud->credit << endl;
+if (!data->requst.credit.res_empty())
+ cout << "credit=" << info.credit << endl;
-if (!req->creditExpire.res_empty())
+if (!data->requst.creditExpire.res_empty())
{
char buf[32];
struct tm brokenTime;
- time_t tt = ud->creditExpire;
+ time_t tt = info.creditExpire;
brokenTime.tm_wday = 0;
brokenTime.tm_yday = 0;
cout << "creditExpire=" << buf << endl;
}
-if (!req->down.res_empty())
- cout << "down=" << ud->down << endl;
+if (!data->requst.down.res_empty())
+ cout << "down=" << info.down << endl;
+
+if (!data->requst.passive.res_empty())
+ cout << "passive=" << info.passive << endl;
-if (!req->passive.res_empty())
- cout << "passive=" << ud->passive << endl;
+if (!data->requst.disableDetailStat.res_empty())
+ cout << "disableDetailStat=" << info.disableDetailStat << endl;
-if (!req->disableDetailStat.res_empty())
- cout << "disableDetailStat=" << ud->disableDetailStat << endl;
+if (!data->requst.alwaysOnline.res_empty())
+ cout << "alwaysOnline=" << info.alwaysOnline << endl;
-if (!req->alwaysOnline.res_empty())
- cout << "alwaysOnline=" << ud->alwaysOnline << endl;
+if (!data->requst.prepaidTraff.res_empty())
+ cout << "prepaidTraff=" << info.prepaidTraff << endl;
-if (!req->prepaidTraff.res_empty())
- cout << "prepaidTraff=" << ud->prepaidTraff << endl;
+for (int i = 0; i < DIR_NUM; i++)
+ {
+ if (!data->requst.up[i].res_empty())
+ cout << "session upload for dir" << i << "=" << info.stat.su[i] << endl;
+ if (!data->requst.down[i].res_empty())
+ cout << "session download for dir" << i << "=" << info.stat.sd[i] << endl;
+ }
for (int i = 0; i < DIR_NUM; i++)
{
- if (!req->u[i].res_empty())
- cout << "u" << i << "=" << ud->stat.mu[i] << endl;
- if (!req->d[i].res_empty())
- cout << "d" << i << "=" << ud->stat.md[i] << endl;
+ if (!data->requst.monthUp[i].res_empty())
+ cout << "month upload for dir" << i << "=" << info.stat.mu[i] << endl;
+ if (!data->requst.monthDown[i].res_empty())
+ cout << "month download for dir" << i << "=" << info.stat.md[i] << endl;
}
for (int i = 0; i < USERDATA_NUM; i++)
{
- if (!req->ud[i].res_empty())
+ if (!data->requst.ud[i].res_empty())
{
string str;
- ConvertFromKOI8(ud->userData[i], &str);
+ ConvertFromKOI8(info.userData[i], &str);
cout << "userdata" << i << "=" << str << endl;
}
}
StringReqParams strReqParams[] =
{
- {"note", req->note, &ud->note},
- {"name", req->name, &ud->name},
- {"address", req->address, &ud->address},
- {"email", req->email, &ud->email},
- {"phone", req->phone, &ud->phone},
- {"group", req->group, &ud->group},
- {"tariff", req->tariff, &ud->tariff},
- {"password", req->usrPasswd, &ud->password},
- {"ip", req->ips, &ud->ips} // IP-address of user
+ {"note", data->requst.note, &info.note},
+ {"name", data->requst.name, &info.name},
+ {"address", data->requst.address, &info.address},
+ {"email", data->requst.email, &info.email},
+ {"phone", data->requst.phone, &info.phone},
+ {"group", data->requst.group, &info.group},
+ {"tariff", data->requst.tariff, &info.tariff},
+ {"password", data->requst.usrPasswd, &info.password},
+ {"ip", data->requst.ips, &info.ips} // IP-address of user
};
for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++)
{
cout << strReqParams[i].name << "=" << str << endl;
}
}
-*result = true;
+data->result = true;
}
//-----------------------------------------------------------------------------
void RecvAuthByData(const PARSER_AUTH_BY::INFO & list, void *)
bool result = false;
-sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ
-sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ
-sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ
+sc.SetServer(server.c_str());
+sc.SetPort(port);
+sc.SetAdmLogin(admLogin.c_str());
sc.SetAdmPassword(admPasswd.c_str());
// TODO Good variable name :)
const std::string &admLogin,
const std::string &admPasswd,
const std::string &login,
- void * data)
+ REQUEST & request)
{
SERVCONF sc;
bool result = false;
-sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ
-sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ
-sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ
+sc.SetServer(server.c_str());
+sc.SetPort(port);
+sc.SetAdmLogin(admLogin.c_str());
sc.SetAdmPassword(admPasswd.c_str());
// TODO Good variable name :)
GetUserCbData gucbd;
-gucbd.data = data;
+gucbd.data = &request;
gucbd.result = &result;
-sc.SetGetUserDataRecvCb(RecvUserData, &gucbd);
+sc.SetGetUserCallback(GetUserCallback, &gucbd);
sc.GetUser(login.c_str());
if (result)
const std::string &admLogin,
const std::string &admPasswd,
const std::string &login,
- void * data)
+ REQUEST & request)
{
SERVCONF sc;
const std::string &admLogin,
const std::string &admPasswd,
const std::string &login,
- void * data);
+ REQUEST & request);
int ProcessAuthBy(const std::string &server,
int port,
const std::string &admLogin,
const std::string &admPasswd,
const std::string &login,
- void * data);
+ REQUEST & request);
int ProcessSetUser(const std::string &server,
int port,
{"passive", 0, 0, 'i'}, //passive
{"disable-stat",0, 0, 'S'}, //disable detail stat
{"always-online",0, 0, 'O'}, //always online
-{"u0", 0, 0, 500}, //U0
-{"u1", 0, 0, 501}, //U1
-{"u2", 0, 0, 502}, //U2
-{"u3", 0, 0, 503}, //U3
-{"u4", 0, 0, 504}, //U4
-{"u5", 0, 0, 505}, //U5
-{"u6", 0, 0, 506}, //U6
-{"u7", 0, 0, 507}, //U7
-{"u8", 0, 0, 508}, //U8
-{"u9", 0, 0, 509}, //U9
-{"d0", 0, 0, 600}, //D0
-{"d1", 0, 0, 601}, //D1
-{"d2", 0, 0, 602}, //D2
-{"d3", 0, 0, 603}, //D3
-{"d4", 0, 0, 604}, //D4
-{"d5", 0, 0, 605}, //D5
-{"d6", 0, 0, 606}, //D6
-{"d7", 0, 0, 607}, //D7
-{"d8", 0, 0, 608}, //D8
-{"d9", 0, 0, 609}, //D9
-
-{"ud0", 0, 0, 700}, //UserData0
-{"ud1", 0, 0, 701}, //UserData1
-{"ud2", 0, 0, 702}, //UserData2
-{"ud3", 0, 0, 703}, //UserData3
-{"ud4", 0, 0, 704}, //UserData4
-{"ud5", 0, 0, 705}, //UserData5
-{"ud6", 0, 0, 706}, //UserData6
-{"ud7", 0, 0, 707}, //UserData7
-{"ud8", 0, 0, 708}, //UserData8
-{"ud9", 0, 0, 709}, //UserData9
+{"session-upload-dir", 1, 0, 500}, //SU0
+{"session-download-dir", 1, 0, 501}, //SD0
+{"month-upload-dir", 1, 0, 502}, //MU0
+{"month-download-dir", 1, 0, 503}, //MD0
+
+{"user-data", 1, 0, 700}, //UserData0
{"prepaid", 0, 0, 'e'}, //prepaid traff
{"create", 0, 0, 'n'}, //create
{"passive", 1, 0, 'i'}, //passive
{"disable-stat",1, 0, 'S'}, //disable detail stat
{"always-online",1, 0, 'O'}, //always online
-{"u0", 1, 0, 500}, //U0
-{"u1", 1, 0, 501}, //U1
-{"u2", 1, 0, 502}, //U2
-{"u3", 1, 0, 503}, //U3
-{"u4", 1, 0, 504}, //U4
-{"u5", 1, 0, 505}, //U5
-{"u6", 1, 0, 506}, //U6
-{"u7", 1, 0, 507}, //U7
-{"u8", 1, 0, 508}, //U8
-{"u9", 1, 0, 509}, //U9
-{"d0", 1, 0, 600}, //D0
-{"d1", 1, 0, 601}, //D1
-{"d2", 1, 0, 602}, //D2
-{"d3", 1, 0, 603}, //D3
-{"d4", 1, 0, 604}, //D4
-{"d5", 1, 0, 605}, //D5
-{"d6", 1, 0, 606}, //D6
-{"d7", 1, 0, 607}, //D7
-{"d8", 1, 0, 608}, //D8
-{"d9", 1, 0, 609}, //D9
-
-{"ud0", 1, 0, 700}, //UserData
-{"ud1", 1, 0, 701}, //UserData1
-{"ud2", 1, 0, 702}, //UserData2
-{"ud3", 1, 0, 703}, //UserData3
-{"ud4", 1, 0, 704}, //UserData4
-{"ud5", 1, 0, 705}, //UserData5
-{"ud6", 1, 0, 706}, //UserData6
-{"ud7", 1, 0, 707}, //UserData7
-{"ud8", 1, 0, 708}, //UserData8
-{"ud9", 1, 0, 709}, //UserData9
+{"session-upload", 1, 0, 500}, //U0
+{"session-download", 1, 0, 501}, //U1
+{"month-upload", 1, 0, 502}, //U2
+{"month-download", 1, 0, 503}, //U3
+
+{"user-data", 1, 0, 700}, //UserData
{"prepaid", 1, 0, 'e'}, //prepaid traff
{"create", 1, 0, 'n'}, //create
case 'G': //Group
req.group = " ";
break;
-
+
case 'I': //IP-address of user
req.ips = " ";
break;
break;
case 500: //U
+ //printf("U%d\n", c - 500);
+ req.sessionUp[optarg] = 1;
+ break;
case 501:
+ //printf("U%d\n", c - 500);
+ req.sessionDown[optarg] = 1;
+ break;
case 502:
- case 503:
- case 504:
- case 505:
- case 506:
- case 507:
- case 508:
- case 509:
//printf("U%d\n", c - 500);
- req.u[c - 500] = 1;
+ req.monthUp[optarg] = 1;
break;
-
- case 600: //D
- case 601:
- case 602:
- case 603:
- case 604:
- case 605:
- case 606:
- case 607:
- case 608:
- case 609:
- //printf("D%d\n", c - 600);
- req.d[c - 600] = 1;
+ case 503:
+ //printf("U%d\n", c - 500);
+ req.monthDown[optarg] = 1;
break;
case 700: //UserData
- case 701:
- case 702:
- case 703:
- case 704:
- case 705:
- case 706:
- case 707:
- case 708:
- case 709:
//printf("UD%d\n", c - 700);
- req.ud[c - 700] = " ";
+ req.ud[optarg] = " ";
break;
case 800:
}
if (req.authBy)
- return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req);
+ 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);
+ return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req);
}
//-----------------------------------------------------------------------------
int mainSet(int argc, char **argv)
break;
case 500: //U
+ //printf("U%d\n", c - 500);
+ req.sesionUpload[optarg] = ParseTraff(argv[optind++]);
+ break;
case 501:
+ //printf("U%d\n", c - 500);
+ req.sessionDownload[optarg] = ParseTraff(argv[optind++]);
+ break;
case 502:
- case 503:
- case 504:
- case 505:
- case 506:
- case 507:
- case 508:
- case 509:
//printf("U%d\n", c - 500);
- req.u[c - 500] = ParseTraff(optarg);
+ req.monthUpload[optarg] = ParseTraff(argv[optind++]);
break;
-
- case 600: //D
- case 601:
- case 602:
- case 603:
- case 604:
- case 605:
- case 606:
- case 607:
- case 608:
- case 609:
- //printf("D%d\n", c - 600);
- req.d[c - 600] = ParseTraff(optarg);
+ case 503:
+ //printf("U%d\n", c - 500);
+ req.monthDownload[optarg] = ParseTraff(argv[optind++]);
break;
case 700: //UserData
- case 701:
- case 702:
- case 703:
- case 704:
- case 705:
- case 706:
- case 707:
- case 708:
- case 709:
- ParseAnyString(optarg, &str);
+ ParseAnyString(argv[optind++], &str);
//printf("UD%d\n", c - 700);
- req.ud[c - 700] = str;
+ req.userData[optarg] = str;
break;
case '?':
{
for (int i = 0; i < DIR_NUM; i++)
{
- u[i].reset();
- d[i].reset();
+ sessionUp[i].reset();
+ sessionDown[i].reset();
+ monthUp[i].reset();
+ monthDown[i].reset();
}
for (int i = 0; i < USERDATA_NUM; i++)
- ud[i].reset();
+ userData[i].reset();
}
RESETABLE<string> server;
RESETABLE<bool> alwaysOnline;
RESETABLE<double> prepaidTraff;
-RESETABLE<int64_t> u[DIR_NUM];
-RESETABLE<int64_t> d[DIR_NUM];
+RESETABLE<int64_t> sessionUp[DIR_NUM];
+RESETABLE<int64_t> sessionDown[DIR_NUM];
-RESETABLE<string> ud[USERDATA_NUM];
+RESETABLE<int64_t> monthUp[DIR_NUM];
+RESETABLE<int64_t> monthDown[DIR_NUM];
+
+RESETABLE<string> userData[USERDATA_NUM];
RESETABLE<string> note;
RESETABLE<string> name;
class BASE_PROPERTY_PARSER
{
public:
- virtual bool Parse(const char ** attr) = 0;
+ virtual ~BASE_PROPERTY_PARSER() {}
+ virtual void Parse(const char ** attr) = 0;
};
template <typename T>
-class PROPERTY_PARSER
+class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
{
public:
typedef T (* FUNC)(const char **);
void SetAdmLogin(const char * login);
void SetAdmPassword(const char * password);
- void SetGetUsers(PARSER_GET_USERS::CALLBACK f, void * data);
+ void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data);
void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data);
void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data);
void SetChgUserCb(RecvChgUserCb_t, void * data);
PARSER_CHECK_USER::CALLBACK checkUserCallback;
RecvSendMessageCb_t RecvSendMessageCb;
+ void * getUsersData;
void * getUserData;
void * authByData;
- void * getUsersData;
void * serverInfoData;
void * chgUserDataCb;
void * checkUserData;
#include "stg/common.h"
+#include <utility>
#include <cstddef>
#include <strings.h>
{
double value = 0;
if (checkValue(attr))
- if (strtodouble2(attr[1], value) == EINVAL)
+ if (strtodouble2(attr[1], value))
return 0;
return value;
}
template <>
-STAT getValue<STAT>(const char ** attr)
+PARSER_GET_USER::STAT getValue<PARSER_GET_USER::STAT>(const char ** attr)
{
-STAT value;
+PARSER_GET_USER::STAT value;
if (!attr)
return value;
std::map<std::string, long long &> props;
for (size_t i = 0; i < DIR_NUM; ++i)
{
- props.insert("su" + x2str(i), value.su[i]);
- props.insert("sd" + x2str(i), value.sd[i]);
- props.insert("mu" + x2str(i), value.mu[i]);
- props.insert("md" + x2str(i), value.md[i]);
+ props.insert(std::pair<std::string, long long &>("su" + x2str(i), value.su[i]));
+ props.insert(std::pair<std::string, long long &>("sd" + x2str(i), value.sd[i]));
+ props.insert(std::pair<std::string, long long &>("mu" + x2str(i), value.mu[i]));
+ props.insert(std::pair<std::string, long long &>("md" + x2str(i), value.md[i]));
}
size_t pos = 0;
while (attr[pos])
std::string getEncodedValue(const char ** attr)
{
+std::string value;
if (checkValue(attr))
- return Decode21str(attr[1]);
-return "";
+ Decode21str(value, attr[1]);
+return value;
}
+template <typename T>
+void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool encoded = false);
+
template <typename T>
void addParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, bool /*encoded*/)
{
- parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue<T>));
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, getValue<T>)));
}
template <>
void addParser<std::string>(PROPERTY_PARSERS & parsers, const std::string & name, std::string & value, bool encoded)
{
if (encoded)
- parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getEncodedValue));
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<std::string>(value, getEncodedValue)));
else
- parsers.insert(ToLower(name), new PROPERTY_PARSER(value, getValue<T>));
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<std::string>(value, getValue<std::string>)));
}
void tryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
{
if (strcasecmp(el, "user") == 0)
if (strcasecmp(attr[1], "error") == 0)
- user.login = "";
+ info.login = "";
}
//-----------------------------------------------------------------------------
void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
: currParser(NULL),
parseDepth(0),
error(0),
- RecvUserDataCb(NULL),
- RecvGetUserDataCb(NULL),
+ getUsersCallback(NULL),
+ getUserCallback(NULL),
authByCallback(NULL),
serverInfoCallback(NULL),
RecvChgUserCb(NULL),
checkUserCallback(NULL),
RecvSendMessageCb(NULL),
- getUserDataDataCb(NULL),
+ getUsersData(NULL),
+ getUserData(NULL),
authByData(NULL),
- getUsersDataDataCb(NULL),
serverInfoData(NULL),
chgUserDataCb(NULL),
checkUserData(NULL),