-//
-// Alert system
-//
-
-#include <algorithm>
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/replace.hpp>
-#include <boost/foreach.hpp>
-#include <map>
+// Copyright (c) 2010 Satoshi Nakamoto
+// Copyright (c) 2009-2014 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "alert.h"
+
#include "key.h"
#include "net.h"
-#include "sync.h"
#include "ui_interface.h"
+#include "util.h"
+
+#include <algorithm>
+#include <map>
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/replace.hpp>
+#include <boost/foreach.hpp>
using namespace std;
map<uint256, CAlert> mapAlerts;
CCriticalSection cs_mapAlerts;
-static const char* pszMainKey = "04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284";
-static const char* pszTestKey = "04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a";
-
void CUnsignedAlert::SetNull()
{
nVersion = 1;
return strprintf(
"CAlert(\n"
" nVersion = %d\n"
- " nRelayUntil = %"PRI64d"\n"
- " nExpiration = %"PRI64d"\n"
+ " nRelayUntil = %d\n"
+ " nExpiration = %d\n"
" nID = %d\n"
" nCancel = %d\n"
" setCancel = %s\n"
nExpiration,
nID,
nCancel,
- strSetCancel.c_str(),
+ strSetCancel,
nMinVer,
nMaxVer,
- strSetSubVer.c_str(),
+ strSetSubVer,
nPriority,
- strComment.c_str(),
- strStatusBar.c_str());
+ strComment,
+ strStatusBar);
}
void CUnsignedAlert::print() const
{
- printf("%s", ToString().c_str());
+ LogPrintf("%s", ToString());
}
void CAlert::SetNull()
bool CAlert::CheckSignature() const
{
- CPubKey key(ParseHex(fTestNet ? pszTestKey : pszMainKey));
+ CPubKey key(Params().AlertKey());
if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
return error("CAlert::CheckSignature() : verify signature failed");
const CAlert& alert = (*mi).second;
if (Cancels(alert))
{
- printf("cancelling alert %d\n", alert.nID);
+ LogPrint("alert", "cancelling alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
else if (!alert.IsInEffect())
{
- printf("expiring alert %d\n", alert.nID);
+ LogPrint("alert", "expiring alert %d\n", alert.nID);
uiInterface.NotifyAlertChanged((*mi).first, CT_DELETED);
mapAlerts.erase(mi++);
}
const CAlert& alert = item.second;
if (alert.Cancels(*this))
{
- printf("alert already cancelled by %d\n", alert.nID);
+ LogPrint("alert", "alert already cancelled by %d\n", alert.nID);
return false;
}
}
// 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]);
- }
+ std::string safeStatus = SanitizeString(strStatusBar);
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
}
}
- printf("accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
+ LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}