Permalink
Browse files

Add -alertnotify startup switch

  • Loading branch information...
Tranz5 committed Jul 12, 2014
1 parent 7530fd3 commit 74ba1c5df07b8c324aa2ab092d3076f31c804e50
Showing with 31 additions and 3 deletions.
  1. +29 −2 src/alert.cpp
  2. +1 −1 src/alert.h
  3. +1 −0 src/init.cpp
@@ -2,6 +2,9 @@
// Alert system
//
#include <algorithm>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
#include <map>
@@ -170,7 +173,7 @@ CAlert CAlert::getAlertByHash(const uint256 &hash)
return retval;
}
bool CAlert::ProcessAlert()
bool CAlert::ProcessAlert(bool fThread)
{
if (!CheckSignature())
return false;
@@ -234,9 +237,33 @@ bool CAlert::ProcessAlert()
// Add to mapAlerts
mapAlerts.insert(make_pair(GetHash(), *this));
// Notify UI if it applies to me
// Notify UI and -alertnotify if it applies to me
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("'");
// safeChars chosen to allow simple messages/URLs/email addresses, but avoid anything
// even possibly remotely dangerous like & or >
std::string safeChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 .,;_/:?@");
std::string safeStatus;
for (std::string::size_type i = 0; i < strStatusBar.size(); i++)
{
if (safeChars.find(strStatusBar[i]) != std::string::npos)
safeStatus.push_back(strStatusBar[i]);
}
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
if (fThread)
boost::thread t(runCommand, strCmd); // thread runs free
else
runCommand(strCmd);
}
}
printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
@@ -91,7 +91,7 @@ class CAlert : public CUnsignedAlert
bool AppliesToMe() const;
bool RelayTo(CNode* pnode) const;
bool CheckSignature() const;
bool ProcessAlert();
bool ProcessAlert(bool fThread = true);
/*
* Get copy of (active) alert object by hash. Returns a null alert if it is not found.
@@ -295,6 +295,7 @@ std::string HelpMessage()
" -newtxnotify=<cmd> " + _("Execute command when a new wallet transaction occurs (%s in cmd is replaced by TxID)") + "\n" +
" -confirmnotify=<cmd> " + _("Execute command when a wallet transaction is confirmed (%s in cmd is replaced by TxID)") + "\n" +
" -blockfoundnotify=<cmd>" + _("Execute command when a block is found (%s in cmd is replaced by block hash)") + "\n" +
" -alertnotify=<cmd> " + _("Execute command when a relevant alert is received (%s in cmd is replaced by message)") + "\n" +
" -upgradewallet " + _("Upgrade wallet to latest format") + "\n" +
" -keypool=<n> " + _("Set key pool size to <n> (default: 100)") + "\n" +
" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +

0 comments on commit 74ba1c5

Please sign in to comment.