Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Allred
crown-core
Commits
8e39b284
Commit
8e39b284
authored
10 years ago
by
Gavin Andresen
Committed by
Wladimir J. van der Laan
10 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Refactor -alertnotify code
Refactor common -alertnotify code into static CAlert::Notify method.
parent
b9db91c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/alert.cpp
+21
-16
src/alert.cpp
src/alert.h
+1
-0
src/alert.h
src/main.cpp
+3
-8
src/main.cpp
with
25 additions
and
24 deletions
+25
-24
src/alert.cpp
View file @
8e39b284
...
...
@@ -235,25 +235,30 @@ bool CAlert::ProcessAlert(bool fThread)
if
(
AppliesToMe
())
{
uiInterface
.
NotifyAlertChanged
(
GetHash
(),
CT_NEW
);
std
::
string
strCmd
=
GetArg
(
"-alertnotify"
,
""
);
if
(
!
strCmd
.
empty
())
{
// Alert text should be plain ascii coming from a trusted source, but to
// be safe we first strip anything not in safeChars, then add single quotes around
// the whole string before passing it to the shell:
std
::
string
singleQuote
(
"'"
);
std
::
string
safeStatus
=
SanitizeString
(
strStatusBar
);
safeStatus
=
singleQuote
+
safeStatus
+
singleQuote
;
boost
::
replace_all
(
strCmd
,
"%s"
,
safeStatus
);
if
(
fThread
)
boost
::
thread
t
(
runCommand
,
strCmd
);
// thread runs free
else
runCommand
(
strCmd
);
}
Notify
(
strStatusBar
,
fThread
);
}
}
LogPrint
(
"alert"
,
"accepted alert %d, AppliesToMe()=%d
\n
"
,
nID
,
AppliesToMe
());
return
true
;
}
void
CAlert
::
Notify
(
const
std
::
string
&
strMessage
,
bool
fThread
)
{
std
::
string
strCmd
=
GetArg
(
"-alertnotify"
,
""
);
if
(
strCmd
.
empty
())
return
;
// Alert text should be plain ascii coming from a trusted source, but to
// be safe we first strip anything not in safeChars, then add single quotes around
// the whole string before passing it to the shell:
std
::
string
singleQuote
(
"'"
);
std
::
string
safeStatus
=
SanitizeString
(
strMessage
);
safeStatus
=
singleQuote
+
safeStatus
+
singleQuote
;
boost
::
replace_all
(
strCmd
,
"%s"
,
safeStatus
);
if
(
fThread
)
boost
::
thread
t
(
runCommand
,
strCmd
);
// thread runs free
else
runCommand
(
strCmd
);
}
This diff is collapsed.
Click to expand it.
src/alert.h
View file @
8e39b284
...
...
@@ -99,6 +99,7 @@ public:
bool
RelayTo
(
CNode
*
pnode
)
const
;
bool
CheckSignature
()
const
;
bool
ProcessAlert
(
bool
fThread
=
true
);
static
void
Notify
(
const
std
::
string
&
strMessage
,
bool
fThread
);
/*
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
View file @
8e39b284
...
...
@@ -1369,14 +1369,9 @@ void CheckForkWarningConditions()
{
if (!fLargeWorkForkFound)
{
std::string strCmd = GetArg("-alertnotify", "");
if (!strCmd.empty())
{
std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
pindexBestForkBase->phashBlock->ToString() + std::string("'");
boost::replace_all(strCmd, "%s", warning);
boost::thread t(runCommand, strCmd); // thread runs free
}
std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
pindexBestForkBase->phashBlock->ToString() + std::string("'");
CAlert::Notify(warning, true);
}
if (pindexBestForkTip)
{
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help