gluxi-dev
view src/base/rolelist.cpp @ 138:e6c403cb7823
[project @ 139]
Security: Fix Incorrect role calculation for visitors
| author | Dmitry Nezhevenko <dion@inhex.net> |
|---|---|
| date | Sun, 25 Nov 2007 21:50:56 +0000 |
| parents | 06065938863b |
| children | 3c6cb76e0ed6 |
line source
1 #include "rolelist.h"
3 #include <QtDebug>
5 RoleList::RoleList()
6 {
7 }
9 RoleList::~RoleList()
10 {
11 }
13 void RoleList::insert(const QString& key, const int value)
14 {
15 if (keys().indexOf(key)>=0)
16 {
17 qDebug() << "RoleList: Key already exists";
18 remove(key);
19 }
21 if (value>=ROLE_MEMBER)
22 QMap<QString, int>::insert(key,value);
23 qDebug() << "RoleList: NEW " << key << value;
24 }
26 void RoleList::insert(const QString& key, const QString& from)
27 {
28 if (from.isEmpty())
29 return;
30 int value=(*this)[from];
31 QMap<QString, int>::insert(key,value);
32 }
34 void RoleList::insert(const QString& key, const QString& role, const QString& affiliation)
35 {
36 insert(key,calc(role,affiliation));
37 }
39 void RoleList::update(const QString& key, int value)
40 {
41 qDebug() << "RoleList::update: " << key << value;
42 if (get(key)>=value)
43 return;
44 remove(key);
45 insert(key,value);
46 }
48 int RoleList::calc(const QString& role, const QString& affiliation)
49 {
51 QString r=role.toUpper();
52 QString a=affiliation.toUpper();
53 if (a.startsWith("OWNER"))
54 return(ROLE_OWNER);
55 if (a.startsWith("ADMIN"))
56 return(ROLE_ADMIN);
57 if (r.startsWith("MODER"))
58 return(ROLE_MODERATOR);
59 if (a.startsWith("MEMBER"))
60 return(ROLE_MEMBER);
61 if (r.startsWith("PARTICIPANT"))
62 return(ROLE_PARTICIPANT);
63 return 0;
64 }
66 int RoleList::operator[](const QString&key)
67 {
68 return get(key);
69 }
71 int RoleList::get(const QString& key)
72 {
73 return QMap<QString, int>::value(key,0);
74 }
