X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/ede91934442fd804d7b818971a44e3ad795cb01f..d1d9452a687184ac6b992fadc77e89c8a308e388:/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp?ds=inline diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp index f232fb23..d93b3448 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp @@ -37,7 +37,7 @@ if (!priv->adminChg) return; } -string s; +std::string s; //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); @@ -45,17 +45,16 @@ answerList->push_back(""); ADMIN_CONF ac; int h = admins->OpenSearch(); -unsigned int p; while (admins->SearchNext(h, &ac) == 0) { //memcpy(&p, &ac.priv, sizeof(unsigned int)); - p = (ac.priv.userStat << 0) + - (ac.priv.userConf << 2) + - (ac.priv.userCash << 4) + - (ac.priv.userPasswd << 6) + - (ac.priv.userAddDel << 8) + - (ac.priv.adminChg << 10) + - (ac.priv.tariffChg << 12); + unsigned int p = (ac.priv.userStat << 0) + + (ac.priv.userConf << 2) + + (ac.priv.userCash << 4) + + (ac.priv.userPasswd << 6) + + (ac.priv.userAddDel << 8) + + (ac.priv.adminChg << 10) + + (ac.priv.tariffChg << 12); strprintf(&s, "", ac.login.c_str(), p); answerList->push_back(s); } @@ -93,32 +92,18 @@ void PARSER_DEL_ADMIN::CreateAnswer() //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); -if (admins->Del(adminToDel, *currAdmin) == 0) +if (admins->Del(adminToDel, currAdmin) == 0) { answerList->push_back(""); } else { - string s; + std::string s; strprintf(&s, "", admins->GetStrError().c_str()); answerList->push_back(s); } } //----------------------------------------------------------------------------- -int PARSER_DEL_ADMIN::CheckAttr(const char **attr) -{ -/* - * attr[0] = "login" (word login) - * attr[1] = login, value of login - * attr[2] = NULL */ - -if (strcasecmp(attr[0], "login") == 0 && attr[1] && !attr[2]) - { - return 0; - } -return -1; -} -//----------------------------------------------------------------------------- // ADD ADMIN //----------------------------------------------------------------------------- int PARSER_ADD_ADMIN::ParseStart(void *, const char *el, const char **attr) @@ -149,13 +134,13 @@ void PARSER_ADD_ADMIN::CreateAnswer() //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); -if (admins->Add(adminToAdd, *currAdmin) == 0) +if (admins->Add(adminToAdd, currAdmin) == 0) { answerList->push_back(""); } else { - string s; + std::string s; strprintf(&s, "", admins->GetStrError().c_str()); answerList->push_back(s); } @@ -212,49 +197,44 @@ void PARSER_CHG_ADMIN::CreateAnswer() { answerList->erase(answerList->begin(), answerList->end()); -ADMIN_CONF conf; -conf.login = login; -if (!login.res_empty()) + +if (!login.empty()) { - string s; - //if (admins->FindAdmin(login.data()) != NULL) - // { - if (!password.res_empty()) - conf.password = password.data(); + ADMIN * origAdmin = NULL; - if (!privAsString.res_empty()) - { - int p = 0; - if (str2x(privAsString.data().c_str(), p) < 0) - { - strprintf(&s, "" ); - answerList->push_back(s); - return; - } - //memcpy(&conf.priv, &p, sizeof(conf.priv)); - conf.priv.userStat = (p & 0x0003) >> 0x00; // 1+2 - conf.priv.userConf = (p & 0x000C) >> 0x02; // 4+8 - conf.priv.userCash = (p & 0x0030) >> 0x04; // 10+20 - conf.priv.userPasswd = (p & 0x00C0) >> 0x06; // 40+80 - conf.priv.userAddDel = (p & 0x0300) >> 0x08; // 100+200 - conf.priv.adminChg = (p & 0x0C00) >> 0x0A; // 400+800 - conf.priv.tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000 - } + if (admins->Find(login.data(), &origAdmin)) + { + answerList->push_back(std::string(""); + return; + } - if (admins->Change(conf, *currAdmin) != 0) - { - strprintf(&s, "", admins->GetStrError().c_str()); - answerList->push_back(s); - } - else + ADMIN_CONF conf(origAdmin->GetConf()); + + if (!password.empty()) + conf.password = password.data(); + + if (!privAsString.empty()) + { + int p = 0; + if (str2x(privAsString.data().c_str(), p) < 0) { - answerList->push_back(""); + answerList->push_back(""); + return; } - return; - // } - //strprintf(&s, "", admins->GetStrError().c_str()); - //answerList->push_back(s); - //return; + + conf.priv.FromInt(p); + } + + if (admins->Change(conf, currAdmin) != 0) + { + std::string s; + strprintf(&s, "", admins->GetStrError().c_str()); + answerList->push_back(s); + } + else + { + answerList->push_back(""); + } } else {