27 request.
pushKV(
"method", strMethod);
28 request.
pushKV(
"params", params);
39 reply.
pushKV(
"result", result);
41 reply.
pushKV(
"error", error);
49 return reply.
write() +
"\n";
54 error.
pushKV(
"code", code);
55 error.
pushKV(
"message", message);
77 const size_t COOKIE_SIZE = 32;
78 uint8_t rand_pwd[COOKIE_SIZE];
89 file.open(filepath_tmp);
90 if (!file.is_open()) {
91 LogPrintf(
"Unable to open cookie authentication file %s for writing\n",
92 filepath_tmp.string());
100 LogPrintf(
"Unable to rename cookie authentication file %s to %s\n",
101 filepath_tmp.string(), filepath.string());
104 LogPrintf(
"Generated RPC authentication cookie %s\n", filepath.string());
107 *cookie_out = cookie;
117 if (!file.is_open()) {
120 std::getline(file, cookie);
124 *cookie_out = cookie;
132 }
catch (
const fs::filesystem_error &e) {
133 LogPrintf(
"%s: Unable to remove random auth cookie file: %s\n",
140 throw std::runtime_error(
"Batch must be an array");
142 std::vector<UniValue> batch(num);
143 for (
size_t i = 0; i < in.
size(); ++i) {
146 throw std::runtime_error(
"Batch member must be object");
148 size_t id = rec[
"id"].
get_int();
150 throw std::runtime_error(
"Batch member id larger than size");
173 if (!valMethod.
isStr()) {
189 }
else if (valParams.
isNull()) {
193 "Params must be an array or object");
std::string SanitizeString(const std::string &str, int rule)
Remove unsafe chars.
std::vector< UniValue > JSONRPCProcessBatchReply(const UniValue &in, size_t num)
Parse JSON-RPC batch reply into a vector.
#define LogPrint(category,...)
static void LogPrintf(const char *fmt, const Args &... args)
const std::string & get_str() const
void DeleteAuthCookie()
Delete RPC authentication cookie from disk.
const UniValue & find_value(const UniValue &obj, const std::string &name)
void GetRandBytes(uint8_t *buf, int num) noexcept
Overall design of the RNG and entropy sources.
static const std::string COOKIEAUTH_FILE
Default name for auth cookie file.
UniValue JSONRPCError(int code, const std::string &message)
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
bool pushKV(const std::string &key, const UniValue &val)
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
std::string JSONRPCReply(const UniValue &result, const UniValue &error, const UniValue &id)
bool RenameOver(fs::path src, fs::path dest)
std::string get_filesystem_error_message(const fs::filesystem_error &e)
void parse(const UniValue &valRequest)
const UniValue & get_obj() const
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
UniValue JSONRPCReplyObj(const UniValue &result, const UniValue &error, const UniValue &id)
bool GenerateAuthCookie(std::string *cookie_out)
Generate a new RPC authentication cookie and write it to disk.
std::string HexStr(const T itbegin, const T itend)
UniValue JSONRPCRequestObj(const std::string &strMethod, const UniValue ¶ms, const UniValue &id)
JSON-RPC protocol.
const UniValue NullUniValue
static fs::path GetAuthCookieFile(bool temp=false)
Get name of RPC authentication cookie file.
Standard JSON-RPC 2.0 errors.
bool error(const char *fmt, const Args &... args)
bool GetAuthCookie(std::string *cookie_out)
Read the RPC authentication cookie from disk.
static const std::string COOKIEAUTH_USER
Username used when cookie authentication is in use (arbitrary, only for recognizability in debugging/...