Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add -alertnotify startup switch
  • Loading branch information
Tranz5 committed Jul 12, 2014
1 parent 7530fd3 commit 74ba1c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/alert.cpp
Expand Up @@ -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>

Expand Down Expand Up @@ -170,7 +173,7 @@ CAlert CAlert::getAlertByHash(const uint256 &hash)
return retval;
}

bool CAlert::ProcessAlert()
bool CAlert::ProcessAlert(bool fThread)
{
if (!CheckSignature())
return false;
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/alert.h
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Expand Up @@ -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" +
Expand Down

0 comments on commit 74ba1c5

Please sign in to comment.