Refactor -alertnotify code
Refactor common -alertnotify code into static CAlert::Notify method.
This commit is contained in:
parent
7c6cbff0e5
commit
e01a7939d3
3 changed files with 26 additions and 25 deletions
|
@ -233,25 +233,30 @@ bool CAlert::ProcessAlert(bool fThread)
|
||||||
if(AppliesToMe())
|
if(AppliesToMe())
|
||||||
{
|
{
|
||||||
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
|
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
|
||||||
std::string strCmd = GetArg("-alertnotify", "");
|
Notify(strStatusBar, fThread);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
|
LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -101,7 +101,8 @@ public:
|
||||||
bool AppliesToMe() const;
|
bool AppliesToMe() const;
|
||||||
bool RelayTo(CNode* pnode) const;
|
bool RelayTo(CNode* pnode) const;
|
||||||
bool CheckSignature() const;
|
bool CheckSignature() const;
|
||||||
bool ProcessAlert(bool fThread = true);
|
bool ProcessAlert(bool fThread = true); // fThread means run -alertnotify in a free-running thread
|
||||||
|
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.
|
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -1178,14 +1178,9 @@ void CheckForkWarningConditions()
|
||||||
{
|
{
|
||||||
if (!fLargeWorkForkFound)
|
if (!fLargeWorkForkFound)
|
||||||
{
|
{
|
||||||
std::string strCmd = GetArg("-alertnotify", "");
|
std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") +
|
||||||
if (!strCmd.empty())
|
pindexBestForkBase->phashBlock->ToString() + std::string("'");
|
||||||
{
|
CAlert::Notify(warning, true);
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (pindexBestForkTip)
|
if (pindexBestForkTip)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue