Changeset View
Changeset View
Standalone View
Standalone View
src/net_permissions.cpp
// Copyright (c) 2009-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 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 <net_permissions.h> | #include <net_permissions.h> | ||||
#include <netbase.h> | #include <netbase.h> | ||||
#include <util/error.h> | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
// The parse the following format "perm1,perm2@xxxxxx" | // The parse the following format "perm1,perm2@xxxxxx" | ||||
bool TryParsePermissionFlags(const std::string str, NetPermissionFlags &output, | bool TryParsePermissionFlags(const std::string str, NetPermissionFlags &output, | ||||
size_t &readen, std::string &error) { | size_t &readen, std::string &error) { | ||||
NetPermissionFlags flags = PF_NONE; | NetPermissionFlags flags = PF_NONE; | ||||
const auto atSeparator = str.find('@'); | const auto atSeparator = str.find('@'); | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | bool NetWhitebindPermissions::TryParse(const std::string str, | ||||
size_t offset; | size_t offset; | ||||
if (!TryParsePermissionFlags(str, flags, offset, error)) { | if (!TryParsePermissionFlags(str, flags, offset, error)) { | ||||
return false; | return false; | ||||
} | } | ||||
const std::string strBind = str.substr(offset); | const std::string strBind = str.substr(offset); | ||||
CService addrBind; | CService addrBind; | ||||
if (!Lookup(strBind.c_str(), addrBind, 0, false)) { | if (!Lookup(strBind.c_str(), addrBind, 0, false)) { | ||||
error = strprintf(_("Cannot resolve -%s address: '%s'").translated, | error = ResolveErrMsg("whitebind", strBind); | ||||
"whitebind", strBind); | |||||
return false; | return false; | ||||
} | } | ||||
if (addrBind.GetPort() == 0) { | if (addrBind.GetPort() == 0) { | ||||
error = strprintf( | error = strprintf( | ||||
_("Need to specify a port with -whitebind: '%s'").translated, | _("Need to specify a port with -whitebind: '%s'").translated, | ||||
strBind); | strBind); | ||||
return false; | return false; | ||||
} | } | ||||
Show All 30 Lines |