mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Cleanups:
* Remove obsolete string formatting function * Remove unused ADDRESS macro * Re-scope functions
This commit is contained in:
@@ -27,47 +27,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO TODO Replace these with something more robust and without macros.
|
||||
//
|
||||
#if ! BEAST_MSVC
|
||||
#define _vsnprintf(a,b,c,d) vsnprintf(a,b,c,d)
|
||||
#endif
|
||||
|
||||
std::string strprintf (const char* format, ...)
|
||||
{
|
||||
char buffer[50000];
|
||||
char* p = buffer;
|
||||
int limit = sizeof (buffer);
|
||||
int ret;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
va_list arg_ptr;
|
||||
va_start (arg_ptr, format);
|
||||
ret = _vsnprintf (p, limit, format, arg_ptr);
|
||||
va_end (arg_ptr);
|
||||
|
||||
if (ret >= 0 && ret < limit)
|
||||
break;
|
||||
|
||||
if (p != buffer)
|
||||
delete[] p;
|
||||
|
||||
limit *= 2;
|
||||
p = new char[limit];
|
||||
|
||||
if (p == nullptr)
|
||||
throw std::bad_alloc ();
|
||||
}
|
||||
|
||||
std::string str (p, p + ret);
|
||||
|
||||
if (p != buffer)
|
||||
delete[] p;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// NIKB NOTE: This function is only used by strUnHex (std::string const& strSrc)
|
||||
// which results in a pointless copy from std::string into std::vector. Should
|
||||
// we just scrap this function altogether?
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
extern std::string strprintf (const char* format, ...);
|
||||
|
||||
extern std::string urlEncode (std::string const& strSrc);
|
||||
|
||||
// NIKB TODO remove this function - it's only used for some logging in the UNL
|
||||
@@ -109,16 +107,9 @@ std::string strCopy (Blob const& vucSrc);
|
||||
|
||||
bool parseIpPort (std::string const& strSource, std::string& strIP, int& iPort);
|
||||
|
||||
inline std::string strGetEnv (std::string const& strKey)
|
||||
{
|
||||
return getenv (strKey.c_str ()) ? getenv (strKey.c_str ()) : "";
|
||||
}
|
||||
|
||||
bool parseUrl (std::string const& strUrl, std::string& strScheme,
|
||||
std::string& strDomain, int& iPort, std::string& strPath);
|
||||
|
||||
#define ADDRESS(p) strHex(uint64( ((char*) p) - ((char*) 0)))
|
||||
|
||||
/** Create a Parameters from a String.
|
||||
|
||||
Parameter strings have the format:
|
||||
|
||||
@@ -383,6 +383,20 @@ Config::Config ()
|
||||
START_UP = NORMAL;
|
||||
}
|
||||
|
||||
static
|
||||
std::string
|
||||
getEnvVar (char const* name)
|
||||
{
|
||||
std::string value;
|
||||
|
||||
auto const v = getenv (name);
|
||||
|
||||
if (v != nullptr)
|
||||
value = v;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void Config::setup (std::string const& strConf, bool bQuiet)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
@@ -418,35 +432,35 @@ void Config::setup (std::string const& strConf, bool bQuiet)
|
||||
CONFIG_FILE = CONFIG_DIR / strConfFile;
|
||||
DATA_DIR = CONFIG_DIR / strDbPath;
|
||||
|
||||
// Construct XDG config and data home.
|
||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
std::string strHome = getEnvVar ("HOME");
|
||||
std::string strXdgConfigHome = getEnvVar ("XDG_CONFIG_HOME");
|
||||
std::string strXdgDataHome = getEnvVar ("XDG_DATA_HOME");
|
||||
|
||||
if (boost::filesystem::exists (CONFIG_FILE)
|
||||
// Can we figure out XDG dirs?
|
||||
|| (!getenv ("HOME") && (!getenv ("XDG_CONFIG_HOME") || !getenv ("XDG_DATA_HOME"))))
|
||||
|| (strHome.empty () && (strXdgConfigHome.empty () || strXdgDataHome.empty ())))
|
||||
{
|
||||
// Current working directory is fine, put dbs in a subdir.
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct XDG config and data home.
|
||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
std::string strHome = strGetEnv ("HOME");
|
||||
std::string strXdgConfigHome = strGetEnv ("XDG_CONFIG_HOME");
|
||||
std::string strXdgDataHome = strGetEnv ("XDG_DATA_HOME");
|
||||
|
||||
if (strXdgConfigHome.empty ())
|
||||
{
|
||||
// $XDG_CONFIG_HOME was not set, use default based on $HOME.
|
||||
strXdgConfigHome = boost::str (boost::format ("%s/.config") % strHome);
|
||||
strXdgConfigHome = strHome + "/.config";
|
||||
}
|
||||
|
||||
if (strXdgDataHome.empty ())
|
||||
{
|
||||
// $XDG_DATA_HOME was not set, use default based on $HOME.
|
||||
strXdgDataHome = boost::str (boost::format ("%s/.local/share") % strHome);
|
||||
strXdgDataHome = strHome + "/.local/share";
|
||||
}
|
||||
|
||||
CONFIG_DIR = boost::str (boost::format ("%s/" SYSTEM_NAME) % strXdgConfigHome);
|
||||
CONFIG_FILE = CONFIG_DIR / strConfFile;
|
||||
DATA_DIR = boost::str (boost::format ("%s/" SYSTEM_NAME) % strXdgDataHome);
|
||||
CONFIG_DIR = strXdgConfigHome + "/" SYSTEM_NAME;
|
||||
CONFIG_FILE = CONFIG_DIR / strConfFile;
|
||||
DATA_DIR = strXdgDataHome + "/" SYSTEM_NAME;
|
||||
|
||||
boost::filesystem::create_directories (CONFIG_DIR, ec);
|
||||
|
||||
|
||||
@@ -903,7 +903,7 @@ struct RPCCallImp
|
||||
if (iStatus == 401)
|
||||
throw std::runtime_error ("incorrect rpcuser or rpcpassword (authorization failed)");
|
||||
else if ((iStatus >= 400) && (iStatus != 400) && (iStatus != 404) && (iStatus != 500)) // ?
|
||||
throw std::runtime_error (strprintf ("server returned HTTP error %d", iStatus));
|
||||
throw std::runtime_error (std::string ("server returned HTTP error %d") + std::to_string (iStatus));
|
||||
else if (strData.empty ())
|
||||
throw std::runtime_error ("no response from server");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user