aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2014-10-07 13:11:48 -0400
committerWladimir J. van der Laan <laanwj@gmail.com>2014-10-08 12:17:57 +0200
commit25b49b5b45a7b43460c6da4d4cd5d6bc613cfab9 (patch)
tree22936f13496b19e987ce84e06a0fb295840d11a6
parent5b9f78d69ccf189bebe894b1921e34417103a046 (diff)
downloadbitcoin-25b49b5b45a7b43460c6da4d4cd5d6bc613cfab9.tar.xz
Refactor -alertnotify code
Refactor common -alertnotify code into static CAlert::Notify method.
-rw-r--r--src/alert.cpp37
-rw-r--r--src/alert.h1
-rw-r--r--src/main.cpp11
3 files changed, 25 insertions, 24 deletions
diff --git a/src/alert.cpp b/src/alert.cpp
index 99164d63e5..3cd0b03388 100644
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -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);
+}
diff --git a/src/alert.h b/src/alert.h
index 296d48891a..9e68b0f38d 100644
--- a/src/alert.h
+++ b/src/alert.h
@@ -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.
diff --git a/src/main.cpp b/src/main.cpp
index d1726904b6..fce341876e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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)
{