Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/misc.cpp
// Copyright (c) 2010 Satoshi Nakamoto | // Copyright (c) 2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2016 The Bitcoin Core developers | // Copyright (c) 2009-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <base58.h> | #include <base58.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <clientversion.h> | #include <clientversion.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <core_io.h> | #include <core_io.h> | ||||
#include <dstencode.h> | #include <dstencode.h> | ||||
#include <httpserver.h> | |||||
#include <init.h> | #include <init.h> | ||||
#include <logging.h> | |||||
#include <net.h> | #include <net.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <rpc/misc.h> | #include <rpc/misc.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <timedata.h> | #include <timedata.h> | ||||
#include <util.h> | #include <util.h> | ||||
▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | #else | ||||
RPC_INVALID_PARAMETER, | RPC_INVALID_PARAMETER, | ||||
"mallocinfo is only available when compiled with glibc 2.10+"); | "mallocinfo is only available when compiled with glibc 2.10+"); | ||||
#endif | #endif | ||||
} else { | } else { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode); | throw JSONRPCError(RPC_INVALID_PARAMETER, "unknown mode " + mode); | ||||
} | } | ||||
} | } | ||||
static void EnableOrDisableLogCategories(UniValue cats, bool enable) { | |||||
cats = cats.get_array(); | |||||
for (size_t i = 0; i < cats.size(); ++i) { | |||||
std::string cat = cats[i].get_str(); | |||||
bool success; | |||||
if (enable) { | |||||
success = GetLogger().EnableCategory(cat); | |||||
} else { | |||||
success = GetLogger().DisableCategory(cat); | |||||
} | |||||
if (!success) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"unknown logging category " + cat); | |||||
} | |||||
} | |||||
} | |||||
UniValue logging(const Config &config, const JSONRPCRequest &request) { | |||||
deadalnix: Presumably, this should be static? | |||||
if (request.fHelp || request.params.size() > 2) { | |||||
throw std::runtime_error( | |||||
"logging [include,...] <exclude>\n" | |||||
"Gets and sets the logging configuration.\n" | |||||
"When called without an argument, returns the list of categories " | |||||
"that are currently being debug logged.\n" | |||||
"When called with arguments, adds or removes categories from debug " | |||||
"logging.\n" | |||||
"The valid logging categories are: " + | |||||
ListLogCategories() + | |||||
"\n" | |||||
"libevent logging is configured on startup and cannot be modified " | |||||
"by this RPC during runtime.\n" | |||||
"Arguments:\n" | |||||
"1. \"include\" (array of strings) add debug logging for these " | |||||
"categories.\n" | |||||
"2. \"exclude\" (array of strings) remove debug logging for these " | |||||
"categories.\n" | |||||
"\nResult:\n" | |||||
"<categories> (string): a list of the logging categories that are " | |||||
"active.\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("logging", "\"[\\\"all\\\"]\" \"[\\\"http\\\"]\"") + | |||||
HelpExampleRpc("logging", "[\"all\"], \"[libevent]\"")); | |||||
} | |||||
uint32_t original_log_categories = GetLogger().GetCategoryMask(); | |||||
if (request.params.size() > 0 && request.params[0].isArray()) { | |||||
EnableOrDisableLogCategories(request.params[0], true); | |||||
} | |||||
if (request.params.size() > 1 && request.params[1].isArray()) { | |||||
EnableOrDisableLogCategories(request.params[1], false); | |||||
} | |||||
uint32_t updated_log_categories = GetLogger().GetCategoryMask(); | |||||
uint32_t changed_log_categories = | |||||
original_log_categories ^ updated_log_categories; | |||||
/* Update libevent logging if BCLog::LIBEVENT has changed. | |||||
* If the library version doesn't allow it, UpdateHTTPServerLogging() | |||||
* returns false, in which case we should clear the BCLog::LIBEVENT flag. | |||||
* Throw an error if the user has explicitly asked to change only the | |||||
* libevent flag and it failed. | |||||
*/ | |||||
if (changed_log_categories & BCLog::LIBEVENT) { | |||||
if (!UpdateHTTPServerLogging( | |||||
GetLogger().WillLogCategory(BCLog::LIBEVENT))) { | |||||
GetLogger().DisableCategory(BCLog::LIBEVENT); | |||||
if (changed_log_categories == BCLog::LIBEVENT) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"libevent logging cannot be updated when " | |||||
"using libevent before v2.1.1."); | |||||
} | |||||
} | |||||
} | |||||
UniValue result(UniValue::VOBJ); | |||||
std::vector<CLogCategoryActive> vLogCatActive = ListActiveLogCategories(); | |||||
for (const auto &logCatActive : vLogCatActive) { | |||||
result.pushKV(logCatActive.category, logCatActive.active); | |||||
} | |||||
return result; | |||||
} | |||||
static UniValue echo(const Config &config, const JSONRPCRequest &request) { | static UniValue echo(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp) { | if (request.fHelp) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"echo|echojson \"message\" ...\n" | "echo|echojson \"message\" ...\n" | ||||
"\nSimply echo back the input arguments. This command is for " | "\nSimply echo back the input arguments. This command is for " | ||||
"testing.\n" | "testing.\n" | ||||
"\nThe difference between echo and echojson is that echojson has " | "\nThe difference between echo and echojson is that echojson has " | ||||
"argument conversion enabled in the client-side table in" | "argument conversion enabled in the client-side table in" | ||||
Show All 27 Lines | static const ContextFreeRPCCommand commands[] = { | ||||
{ "util", "createmultisig", createmultisig, {"nrequired","keys"} }, | { "util", "createmultisig", createmultisig, {"nrequired","keys"} }, | ||||
{ "util", "verifymessage", verifymessage, {"address","signature","message"} }, | { "util", "verifymessage", verifymessage, {"address","signature","message"} }, | ||||
{ "util", "signmessagewithprivkey", signmessagewithprivkey, {"privkey","message"} }, | { "util", "signmessagewithprivkey", signmessagewithprivkey, {"privkey","message"} }, | ||||
/* Not shown in help */ | /* Not shown in help */ | ||||
{ "hidden", "setmocktime", setmocktime, {"timestamp"}}, | { "hidden", "setmocktime", setmocktime, {"timestamp"}}, | ||||
{ "hidden", "echo", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | { "hidden", "echo", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | ||||
{ "hidden", "echojson", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | { "hidden", "echojson", echo, {"arg0","arg1","arg2","arg3","arg4","arg5","arg6","arg7","arg8","arg9"}}, | ||||
{ "hidden", "getinfo", getinfo_deprecated, {}}, | { "hidden", "getinfo", getinfo_deprecated, {}}, | ||||
{ "hidden", "logging", logging, {"include", "exclude"}}, | |||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterMiscRPCCommands(CRPCTable &t) { | void RegisterMiscRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } | ||||
} | } |
Presumably, this should be static?