Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
daa47546
Commit
daa47546
authored
Oct 19, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Permission: move code to ParsePermission() and a table
parent
c5194d0a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
16 deletions
+22
-16
Permission.cxx
src/Permission.cxx
+22
-16
No files found.
src/Permission.cxx
View file @
daa47546
...
...
@@ -35,15 +35,32 @@
static
constexpr
char
PERMISSION_PASSWORD_CHAR
=
'@'
;
#define PERMISSION_SEPERATOR ","
#define PERMISSION_READ_STRING "read"
#define PERMISSION_ADD_STRING "add"
#define PERMISSION_CONTROL_STRING "control"
#define PERMISSION_ADMIN_STRING "admin"
static
constexpr
struct
{
const
char
*
name
;
unsigned
value
;
}
permission_names
[]
=
{
{
"read"
,
PERMISSION_READ
},
{
"add"
,
PERMISSION_ADD
},
{
"control"
,
PERMISSION_CONTROL
},
{
"admin"
,
PERMISSION_ADMIN
},
{
nullptr
,
0
},
};
static
std
::
map
<
std
::
string
,
unsigned
>
permission_passwords
;
static
unsigned
permission_default
;
gcc_pure
static
unsigned
ParsePermission
(
const
char
*
p
)
{
for
(
auto
i
=
permission_names
;
i
->
name
!=
nullptr
;
++
i
)
if
(
strcmp
(
p
,
i
->
name
)
==
0
)
return
i
->
value
;
FormatFatalError
(
"unknown permission
\"
%s
\"
"
,
p
);
}
static
unsigned
parsePermissions
(
const
char
*
string
)
{
assert
(
string
!=
nullptr
);
...
...
@@ -54,18 +71,7 @@ static unsigned parsePermissions(const char *string)
tokens
=
g_strsplit
(
string
,
PERMISSION_SEPERATOR
,
0
);
for
(
unsigned
i
=
0
;
tokens
[
i
]
!=
NULL
;
++
i
)
{
char
*
temp
=
tokens
[
i
];
if
(
strcmp
(
temp
,
PERMISSION_READ_STRING
)
==
0
)
{
permission
|=
PERMISSION_READ
;
}
else
if
(
strcmp
(
temp
,
PERMISSION_ADD_STRING
)
==
0
)
{
permission
|=
PERMISSION_ADD
;
}
else
if
(
strcmp
(
temp
,
PERMISSION_CONTROL_STRING
)
==
0
)
{
permission
|=
PERMISSION_CONTROL
;
}
else
if
(
strcmp
(
temp
,
PERMISSION_ADMIN_STRING
)
==
0
)
{
permission
|=
PERMISSION_ADMIN
;
}
else
{
FormatFatalError
(
"unknown permission
\"
%s
\"
"
,
temp
);
}
permission
|=
ParsePermission
(
temp
);
}
g_strfreev
(
tokens
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment