FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sysadmin/src/HookConfig.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
/
HookConfig.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
163 lines (138 loc) · 4.68 KB
Breadcrumbs
sysadmin
/
src
/
HookConfig.cpp
Copy path
File metadata and controls
163 lines (138 loc) · 4.68 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#
include
"
HookConfig.h
"
#
include
<
log4cxx/logger.h
>
namespace
{
log4cxx::LoggerPtr
spLogger
(log4cxx::Logger::getLogger(
"
FullHooksConfig
"
));
}
#
define
DECODE_REQUIRED
(
NODE, TARGET, KEY, TYPE
) \
if
((
NODE
)[
KEY
]) \
{ \
(
TARGET
) = (
NODE
)[
KEY
].
as
<
TYPE
>(); \
} \
else
\
{ \
LOG4CXX_WARN
(spLogger,
"
Could not decode key:
"
<<
KEY
); \
return
false
; \
}
#
define
DECODE_OPTIONAL
(
NODE, TARGET, KEY, TYPE, DEFAULT
) \
if
((
NODE
)[
KEY
]) \
{ \
(
TARGET
) = (
NODE
)[
KEY
].
as
<
TYPE
>(); \
} \
else
\
{ \
(
TARGET
) = (
DEFAULT
); \
}
#
define
DECODE_REQUIRED_SEQUENCE
(
NODE, TARGET, KEY, TYPE
) \
if
((
NODE
)[
KEY
] && (
NODE
)[
KEY
].IsSequence()) \
{ \
(
TARGET
) = (
NODE
)[
KEY
].
as
<
TYPE
>(); \
} \
else
\
{ \
return
false
; \
}
#
define
DECODE_OPTIONAL_SEQUENCE
(
NODE, TARGET, KEY, TYPE
) \
if
((
NODE
)[
KEY
] && (
NODE
)[
KEY
].IsSequence()) \
{ \
(
TARGET
) = (
NODE
)[
KEY
].
as
<
TYPE
>(); \
}
bool
operator
==(
const
HookConfig& lhs,
const
HookConfig& rhs)
{
return
lhs.
mKey
== rhs.
mKey
&& lhs.
mOptional
== rhs.
mOptional
;
}
bool
operator
!=(
const
HookConfig& lhs,
const
HookConfig& rhs)
{
return
(lhs == rhs);
}
namespace
YAML
{
Node convert<HookConfig>::encode(
const
HookConfig& )
{
return
Node
();
}
bool
convert<HookConfig>::decode(
const
Node& node, HookConfig& config)
{
try
{
config.
mKey
=
ConfigPair::Key
(node.
as
<std::string>());
config.
mOptional
=
false
;
return
true
;
}
catch
(
const
YAML
::Exception&)
{
for
(
const
auto
& ci : node)
{
config.
mKey
=
ConfigPair::Key
(ci.
first
.
as
<std::string>());
config.
mOptional
=
true
;
return
true
;
}
}
return
false
;
}
Node convert<TemplateConfig>::encode(
const
TemplateConfig& )
{
return
Node
();
}
bool
convert<TemplateConfig>::decode(
const
Node& node, TemplateConfig& config)
{
DECODE_REQUIRED
(node, config.
mName
,
"
name
"
, std::string);
DECODE_REQUIRED
(node, config.
mPath
,
"
template_location
"
, std::string);
DECODE_REQUIRED
(node, config.
mDestination
,
"
destination
"
, std::string);
DECODE_REQUIRED_SEQUENCE
(node, config.
mHooks
,
"
hooks
"
, std::vector<HookConfig>);
DECODE_OPTIONAL_SEQUENCE
(node, config.
mArguments
,
"
arguments
"
, std::vector<std::string>);
return
true
;
}
Node convert<ServiceConfig>::encode(
const
ServiceConfig& )
{
return
Node
();
}
HookOptions::RunOptions
DecodeRunOptions
(
const
std::string& optionstr)
{
if
(optionstr ==
"
detach
"
)
{
return
HookOptions::RunOptions::
DETACH
;
}
if
(optionstr ==
"
default
"
)
{
return
HookOptions::RunOptions::
DEFAULT
;
}
if
(optionstr ==
"
ignore
"
)
{
return
HookOptions::RunOptions::
IGNORE
;
}
return
HookOptions::RunOptions::
INVALID
;
}
bool
convert<ServiceConfig>::decode(
const
Node& node, ServiceConfig& config)
{
DECODE_REQUIRED
(node, config.
mName
,
"
name
"
, std::string);
DECODE_REQUIRED
(node, config.
mPath
,
"
script
"
, std::string);
DECODE_REQUIRED_SEQUENCE
(node, config.
mHooks
,
"
hooks
"
, std::vector<HookConfig>);
DECODE_OPTIONAL
(node, config.
mRunLevel
,
"
runlevel
"
,
size_t
,
1
);
DECODE_OPTIONAL_SEQUENCE
(node, config.
mArguments
,
"
arguments
"
, std::vector<std::string>);
if
(node[
"
options
"
])
{
config.
mRunOptions
=
DecodeRunOptions
(node[
"
options
"
].
as
<std::string>());
if
(config.
mRunOptions
== HookOptions::RunOptions::
INVALID
)
{
return
false
;
}
}
else
{
config.
mRunOptions
=
DecodeRunOptions
(
"
default
"
);
}
return
true
;
}
Node convert<FullHooksConfig>::encode(
const
FullHooksConfig& )
{
return
Node
();
}
bool
convert<FullHooksConfig>::decode(
const
Node& node, FullHooksConfig& config)
{
DECODE_OPTIONAL_SEQUENCE
(node, config.
mServices
,
"
services
"
, std::vector<ServiceConfig>);
DECODE_OPTIONAL_SEQUENCE
(node, config.
mTemplates
,
"
templates
"
, std::vector<TemplateConfig>);
DECODE_REQUIRED
(node, config.
mTemplaterPath
,
"
templater_path
"
, std::string);
return
true
;
}
}
Back
|
FazBrowse Home
|
New Git URL