FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sysadmin/src/HookUser.cpp at master · StarryInternet/sysadmin · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
StarryInternet
/
sysadmin
Public
Notifications
You must be signed in to change notification settings
Fork
8
Star
11
Code
Issues
10
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
sysadmin
/
src
/
HookUser.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (96 loc) · 2.52 KB
Breadcrumbs
sysadmin
/
src
/
HookUser.cpp
Copy path
File metadata and controls
112 lines (96 loc) · 2.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#
include
"
HookConfig.h
"
#
include
"
HookUser.h
"
#
include
"
KeyValueFormatter.h
"
#
include
"
ExternalRunner.h
"
#
include
<
algorithm
>
#
include
<
log4cxx/logger.h
>
namespace
{
log4cxx::LoggerPtr
spLogger
(log4cxx::Logger::getLogger(
"
HookUser
"
));
}
HookUser::HookUser
(std::string name,
HookType type,
std::vector<HookConfig> hooks,
HookFulfiller hookfulfiller,
std::shared_ptr<IExternalRunner> externalScript,
size_t
run_level)
: mName(name)
, mType(type)
, mHooks(hooks.begin(), hooks.end())
, mHookFulfiller(hookfulfiller)
, mExternalScript(externalScript)
, mRunLevel(run_level)
{
}
HookUser::HookUser
(
const
HookUser& source)
: mName(source.
mName
)
, mType(source.
mType
)
, mHooks(source.
mHooks
.begin(), source.mHooks.end())
, mHookFulfiller(source.
mHookFulfiller
)
, mExternalScript(source.
mExternalScript
)
, mRunLevel(source.
mRunLevel
)
{
}
HookUser& HookUser::
operator
=(HookUser source)
{
if
(
this
!= &source)
{
mName
= source.
mName
;
mType
= source.
mType
;
mHooks
.
swap
(source.
mHooks
);
mHookFulfiller
.
swap
(source.
mHookFulfiller
);
mExternalScript
= source.
mExternalScript
;
mRunLevel
= source.
mRunLevel
;
}
return
*
this
;
}
folly::Future<folly::Unit>
HookUser::ExecuteExternalProcess
()
const
{
return
mHookFulfiller
(
mHooks
).
thenValue
([
this
](
const
std::vector<ConfigPair::Key>& )
{
//
We don't pass anything to hooks being run
return
this
->
mExternalScript
->
Run
({});
}).
thenError
(folly::
tag_t
<HookUserError>{}, [](
const
auto
& err)
{
throw
ExternalRunnerError
(err.
what
());
});
}
bool
HookUser::HasHook
(
const
ConfigPair::Key& key)
const
{
for
(
const
auto
& hook :
mHooks
)
{
if
(key == hook.
mKey
|| (hook.
mKey
.
IsWildcard
() && key.
SubkeyMatches
(hook.
mKey
)))
{
return
true
;
}
}
return
false
;
}
size_t
HookUser::RunLevel
()
const
{
return
mRunLevel
;
}
std::string
HookUser::Name
()
const
{
return
mName
;
}
HookType
HookUser::GetType
()
const
{
return
mType
;
}
bool
operator
==(
const
HookUser& lhs,
const
HookUser& rhs)
{
return
lhs.
mHooks
== rhs.
mHooks
&& lhs.
mExternalScript
== rhs.
mExternalScript
;
}
bool
operator
!=(
const
HookUser& lhs,
const
HookUser& rhs)
{
return
!(lhs == rhs);
}
bool
operator
<(
const
HookUser& lhs,
const
HookUser& rhs)
{
return
lhs.
mRunLevel
< rhs.
mRunLevel
;
}
bool
operator
<=(
const
HookUser& lhs,
const
HookUser& rhs)
{
return
lhs.
mRunLevel
< rhs.
mRunLevel
;
}
Back
|
FazBrowse Home
|
New Git URL