From 3e3df32d6d5a426ff11ac1b3734374bf25046b7f Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sat, 13 Aug 2011 15:39:07 +0300 Subject: [PATCH] Service and corporation permissions added --- include/stg/admin_conf.h | 30 +++--- include/stg/admin_conf.inc.h | 26 ++--- .../plugins/store/files/file_store.cpp | 12 +++ tests/test_admin_conf.cpp | 95 ++++++++++++------- 4 files changed, 106 insertions(+), 57 deletions(-) diff --git a/include/stg/admin_conf.h b/include/stg/admin_conf.h index 32012f34..df6d9e22 100644 --- a/include/stg/admin_conf.h +++ b/include/stg/admin_conf.h @@ -23,20 +23,24 @@ struct PRIV userPasswd(0), userAddDel(0), adminChg(0), - tariffChg(0) - {}; - PRIV(uint16_t p) - : userStat((p & 0x0003) >> 0x00), - userConf((p & 0x000C) >> 0x02), - userCash((p & 0x0030) >> 0x04), - userPasswd((p & 0x00C0) >> 0x06), - userAddDel((p & 0x0300) >> 0x08), - adminChg((p & 0x0C00) >> 0x0A), - tariffChg((p & 0x3000) >> 0x0C) + tariffChg(0), + serviceChg(0), + corpChg(0) + {} + PRIV(uint32_t p) + : userStat((p & 0x00000003) >> 0x00), + userConf((p & 0x0000000C) >> 0x02), + userCash((p & 0x00000030) >> 0x04), + userPasswd((p & 0x000000C0) >> 0x06), + userAddDel((p & 0x00000300) >> 0x08), + adminChg((p & 0x00000C00) >> 0x0A), + tariffChg((p & 0x00003000) >> 0x0C), + serviceChg((p & 0x0000C000) >> 0x0E), + corpChg((p & 0x00030000) >> 0x10) {} - uint16_t ToInt() const; - void FromInt(uint16_t p); + uint32_t ToInt() const; + void FromInt(uint32_t p); uint16_t userStat; uint16_t userConf; @@ -45,6 +49,8 @@ struct PRIV uint16_t userAddDel; uint16_t adminChg; uint16_t tariffChg; + uint16_t serviceChg; + uint16_t corpChg; }; //----------------------------------------------------------------------------- struct ADMIN_CONF diff --git a/include/stg/admin_conf.inc.h b/include/stg/admin_conf.inc.h index 44897a08..f744936e 100644 --- a/include/stg/admin_conf.inc.h +++ b/include/stg/admin_conf.inc.h @@ -8,28 +8,32 @@ #define ADMIN_CONF_INC_H inline -uint16_t PRIV::ToInt() const +uint32_t PRIV::ToInt() const { -uint16_t p = (userStat << 0) | +uint32_t p = (userStat << 0) | (userConf << 2) | (userCash << 4) | (userPasswd << 6) | (userAddDel << 8) | (adminChg << 10) | - (tariffChg << 12); + (tariffChg << 12) | + (serviceChg << 14) | + (corpChg << 16); return p; } inline -void PRIV::FromInt(uint16_t p) +void PRIV::FromInt(uint32_t p) { -userStat = (p & 0x0003) >> 0x00; // 1+2 -userConf = (p & 0x000C) >> 0x02; // 4+8 -userCash = (p & 0x0030) >> 0x04; // 10+20 -userPasswd = (p & 0x00C0) >> 0x06; // 40+80 -userAddDel = (p & 0x0300) >> 0x08; // 100+200 -adminChg = (p & 0x0C00) >> 0x0A; // 400+800 -tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000 +userStat = (p & 0x00000003) >> 0x00; // 1+2 +userConf = (p & 0x0000000C) >> 0x02; // 4+8 +userCash = (p & 0x00000030) >> 0x04; // 10+20 +userPasswd = (p & 0x000000C0) >> 0x06; // 40+80 +userAddDel = (p & 0x00000300) >> 0x08; // 100+200 +adminChg = (p & 0x00000C00) >> 0x0A; // 400+800 +tariffChg = (p & 0x00003000) >> 0x0C; // 1000+2000 +serviceChg = (p & 0x0000C000) >> 0x0E; // 4000+8000 +corpChg = (p & 0x00030000) >> 0x10; // 10000+20000 } #endif diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 1a16ed91..6d8de6c2 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -1280,6 +1280,8 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login cf.WriteInt("UsrAddDel", ac.priv.userAddDel); cf.WriteInt("ChgTariff", ac.priv.tariffChg); cf.WriteInt("ChgAdmin", ac.priv.adminChg); + cf.WriteInt("ChgService", ac.priv.serviceChg); + cf.WriteInt("ChgCorp", ac.priv.corpChg); } return 0; @@ -1407,6 +1409,16 @@ else return -1; } +if (cf.ReadInt("ChgService", &a, 0) == 0) + ac->priv.serviceChg = a; +else + ac->priv.serviceChg = 0; + +if (cf.ReadInt("ChgCorp", &a, 0) == 0) + ac->priv.corpChg = a; +else + ac->priv.corpChg = 0; + return 0; } //----------------------------------------------------------------------------- diff --git a/tests/test_admin_conf.cpp b/tests/test_admin_conf.cpp index 7a54c480..dad51b18 100644 --- a/tests/test_admin_conf.cpp +++ b/tests/test_admin_conf.cpp @@ -6,12 +6,12 @@ namespace tut { struct priv_data { enum { - MIX2 = 0x06C6, // 2103210 - ONES = 0x1555, - MIX3 = 0x1B1B, // 3210321 - TWOS = 0x2AAA, - MIX1 = 0x24E4, // 0123012 - THREES = 0x3FFF + MIX2 = 0x0002C6C6, // 210321032 + ONES = 0x00015555, + MIX3 = 0x00031B1B, // 321032103 + TWOS = 0x0002AAAA, + MIX1 = 0x0000E4E4, // 012301230 + THREES = 0x0003FFFF }; }; @@ -35,6 +35,8 @@ namespace tut ensure("zero.userAddDel == 0", zero.userAddDel == 0); ensure("zero.adminChg == 0", zero.adminChg == 0); ensure("zero.tariffChg == 0", zero.tariffChg == 0); + ensure("zero.serviceChg == 0", zero.serviceChg == 0); + ensure("zero.corpChg == 0", zero.corpChg == 0); ensure("zero.ToInt() == 0", zero.ToInt() == 0); } @@ -43,13 +45,13 @@ namespace tut template<> void testobject::test<2>() { - set_test_name("Check uint16_t conversions"); + set_test_name("Check uint32_t conversions"); - for (uint16_t i = 0; i < 4; ++i) { + for (uint8_t i = 0; i < 4; ++i) { // 'i' is extra trash in high bits - PRIV priv1(ONES | (i << 0x0E)); // All 1 + PRIV priv1(ONES | (i << 0x12)); // All 1 ensure_equals("priv1.userStat == 1", priv1.userStat, 1); ensure_equals("priv1.userConf == 1", priv1.userConf, 1); @@ -58,10 +60,12 @@ namespace tut ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1); ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1); ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1); + ensure_equals("priv1.serviceChg == 1", priv1.serviceChg, 1); + ensure_equals("priv1.corpChg == 1", priv1.corpChg, 1); - ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast(ONES)); + ensure_equals("priv1.ToInt() == 0x00015555", priv1.ToInt(), static_cast(ONES)); - PRIV priv2(TWOS | (i << 0x0E)); // All 2 + PRIV priv2(TWOS | (i << 0x12)); // All 2 ensure_equals("priv2.userStat == 2", priv2.userStat, 2); ensure_equals("priv2.userConf == 2", priv2.userConf, 2); @@ -70,10 +74,12 @@ namespace tut ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2); ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2); ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2); + ensure_equals("priv2.serviceChg == 2", priv2.serviceChg, 2); + ensure_equals("priv2.corpChg == 2", priv2.corpChg, 2); - ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast(TWOS)); + ensure_equals("priv2.ToInt() = 0x0002AAAA", priv2.ToInt(), static_cast(TWOS)); - PRIV priv3(THREES | (i << 0x0E)); // All 3 + PRIV priv3(THREES | (i << 0x12)); // All 3 ensure_equals("priv3.userStat == 3", priv3.userStat, 3); ensure_equals("priv3.userConf == 3", priv3.userConf, 3); @@ -82,10 +88,12 @@ namespace tut ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3); ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3); ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3); + ensure_equals("priv3.serviceChg == 3", priv3.serviceChg, 3); + ensure_equals("priv3.corpChg == 3", priv3.corpChg, 3); - ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast(THREES)); + ensure_equals("priv3.ToInt() = 0x0003FFFF", priv3.ToInt(), static_cast(THREES)); - PRIV pm1(MIX1 | (i << 0x0E)); // 0123012 + PRIV pm1(MIX1 | (i << 0x12)); // 012301230 ensure_equals("pm1.userStat == 0", pm1.userStat, 0); ensure_equals("pm1.userConf == 1", pm1.userConf, 1); @@ -94,10 +102,12 @@ namespace tut ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0); ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1); ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2); + ensure_equals("pm1.serviceChg == 3", pm1.serviceChg, 3); + ensure_equals("pm1.corpChg == 0", pm1.corpChg, 0); - ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast(MIX1)); + ensure_equals("pm1.ToInt() = 0xE4E4", pm1.ToInt(), static_cast(MIX1)); - PRIV pm2(MIX2 | (i << 0x0E)); // 0123012 + PRIV pm2(MIX2 | (i << 0x12)); // 210321032 ensure_equals("pm2.userStat == 2", pm2.userStat, 2); ensure_equals("pm2.userConf == 1", pm2.userConf, 1); @@ -106,10 +116,12 @@ namespace tut ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2); ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1); ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0); + ensure_equals("pm2.serviceChg == 3", pm2.serviceChg, 3); + ensure_equals("pm2.corpChg == 2", pm2.corpChg, 2); - ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast(MIX2)); + ensure_equals("pm2.ToInt() = 0x0002C6C6", pm2.ToInt(), static_cast(MIX2)); - PRIV pm3(MIX3 | (i << 0x0E)); // 3210321 + PRIV pm3(MIX3 | (i << 0x12)); // 321032103 ensure_equals("pm3.userStat == 3", pm3.userStat, 3); ensure_equals("pm3.userConf == 2", pm3.userConf, 2); @@ -118,8 +130,10 @@ namespace tut ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3); ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2); ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1); + ensure_equals("pm3.serviceChg == 0", pm3.serviceChg, 0); + ensure_equals("pm3.corpChg == 3", pm3.corpChg, 3); - ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast(MIX3)); + ensure_equals("pm3.ToInt() = 0x00031B1B", pm3.ToInt(), static_cast(MIX3)); } @@ -129,14 +143,15 @@ namespace tut template<> void testobject::test<3>() { - set_test_name("Check explicit uint16_t conversions"); + set_test_name("Check explicit uint32_t conversions"); - for (uint16_t i = 0; i < 4; ++i) { + for (uint8_t i = 0; i < 4; ++i) { // 'i' is extra trash in high bits PRIV priv1; - priv1.FromInt(ONES | (i << 0x0E)); // All 1 + priv1.FromInt(ONES | (i << 0x12)); // All 1 + ensure_equals("priv1.userStat == 1", priv1.userStat, 1); ensure_equals("priv1.userConf == 1", priv1.userConf, 1); @@ -145,11 +160,13 @@ namespace tut ensure_equals("priv1.userAddDel == 1", priv1.userAddDel, 1); ensure_equals("priv1.adminChg == 1", priv1.adminChg, 1); ensure_equals("priv1.tariffChg == 1", priv1.tariffChg, 1); + ensure_equals("priv1.serviceChg == 1", priv1.serviceChg, 1); + ensure_equals("priv1.corpChg == 1", priv1.corpChg, 1); - ensure_equals("priv1.ToInt() == 0x1555", priv1.ToInt(), static_cast(ONES)); + ensure_equals("priv1.ToInt() == 0x00015555", priv1.ToInt(), static_cast(ONES)); PRIV priv2; - priv2.FromInt(TWOS | (i << 0x0E)); // All 2 + priv2.FromInt(TWOS | (i << 0x12)); // All 2 ensure_equals("priv2.userStat == 2", priv2.userStat, 2); ensure_equals("priv2.userConf == 2", priv2.userConf, 2); @@ -158,11 +175,13 @@ namespace tut ensure_equals("priv2.userAddDel == 2", priv2.userAddDel, 2); ensure_equals("priv2.adminChg == 2", priv2.adminChg, 2); ensure_equals("priv2.tariffChg == 2", priv2.tariffChg, 2); + ensure_equals("priv2.serviceChg == 2", priv2.serviceChg, 2); + ensure_equals("priv2.corpChg == 2", priv2.corpChg, 2); - ensure_equals("priv2.ToInt() = 0x2AAA", priv2.ToInt(), static_cast(TWOS)); + ensure_equals("priv2.ToInt() = 0x0002AAAA", priv2.ToInt(), static_cast(TWOS)); PRIV priv3; - priv3.FromInt(THREES | (i << 0x0E)); // All 3 + priv3.FromInt(THREES | (i << 0x12)); // All 3 ensure_equals("priv3.userStat == 3", priv3.userStat, 3); ensure_equals("priv3.userConf == 3", priv3.userConf, 3); @@ -171,11 +190,13 @@ namespace tut ensure_equals("priv3.userAddDel == 3", priv3.userAddDel, 3); ensure_equals("priv3.adminChg == 3", priv3.adminChg, 3); ensure_equals("priv3.tariffChg == 3", priv3.tariffChg, 3); + ensure_equals("priv3.serviceChg == 3", priv3.serviceChg, 3); + ensure_equals("priv3.corpChg == 3", priv3.corpChg, 3); - ensure_equals("priv2.ToInt() = 0x3FFF", priv3.ToInt(), static_cast(THREES)); + ensure_equals("priv3.ToInt() = 0x0003FFFF", priv3.ToInt(), static_cast(THREES)); PRIV pm1; - pm1.FromInt(MIX1 | (i << 0x0E)); // 0123012 + pm1.FromInt(MIX1 | (i << 0x12)); // 012301230 ensure_equals("pm1.userStat == 0", pm1.userStat, 0); ensure_equals("pm1.userConf == 1", pm1.userConf, 1); @@ -184,11 +205,13 @@ namespace tut ensure_equals("pm1.userAddDel == 0", pm1.userAddDel, 0); ensure_equals("pm1.adminChg == 1", pm1.adminChg, 1); ensure_equals("pm1.tariffChg == 2", pm1.tariffChg, 2); + ensure_equals("pm1.serviceChg == 3", pm1.serviceChg, 3); + ensure_equals("pm1.corpChg == 0", pm1.corpChg, 0); - ensure_equals("pm1.ToInt() = 0x24E4", pm1.ToInt(), static_cast(MIX1)); + ensure_equals("pm1.ToInt() = 0xE4E4", pm1.ToInt(), static_cast(MIX1)); PRIV pm2; - pm2.FromInt(MIX2 | (i << 0x0E)); // 0123012 + pm2.FromInt(MIX2 | (i << 0x12)); // 210321032 ensure_equals("pm2.userStat == 2", pm2.userStat, 2); ensure_equals("pm2.userConf == 1", pm2.userConf, 1); @@ -197,11 +220,13 @@ namespace tut ensure_equals("pm2.userAddDel == 2", pm2.userAddDel, 2); ensure_equals("pm2.adminChg == 1", pm2.adminChg, 1); ensure_equals("pm2.tariffChg == 0", pm2.tariffChg, 0); + ensure_equals("pm2.serviceChg == 3", pm2.serviceChg, 3); + ensure_equals("pm2.corpChg == 2", pm2.corpChg, 2); - ensure_equals("pm2.ToInt() = 0x06C6", pm2.ToInt(), static_cast(MIX2)); + ensure_equals("pm2.ToInt() = 0x0002C6C6", pm2.ToInt(), static_cast(MIX2)); PRIV pm3; - pm3.FromInt(MIX3 | (i << 0x0E)); // 3210321 + pm3.FromInt(MIX3 | (i << 0x12)); // 321032103 ensure_equals("pm3.userStat == 3", pm3.userStat, 3); ensure_equals("pm3.userConf == 2", pm3.userConf, 2); @@ -210,8 +235,10 @@ namespace tut ensure_equals("pm3.userAddDel == 3", pm3.userAddDel, 3); ensure_equals("pm3.adminChg == 2", pm3.adminChg, 2); ensure_equals("pm3.tariffChg == 1", pm3.tariffChg, 1); + ensure_equals("pm3.serviceChg == 0", pm3.serviceChg, 0); + ensure_equals("pm3.corpChg == 3", pm3.corpChg, 3); - ensure_equals("pm3.ToInt() = 0x1B1B", pm3.ToInt(), static_cast(MIX3)); + ensure_equals("pm3.ToInt() = 0x00031B1B", pm3.ToInt(), static_cast(MIX3)); } -- 2.43.2