Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Classes | Namespaces | Functions | Variables
util.cpp File Reference
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include "util.h"
#include "sync.h"
#include "version.h"
#include "ui_interface.h"
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
#include <openssl/rand.h>
#include <stdarg.h>
Include dependency graph for util.cpp:

Go to the source code of this file.

Classes

class  CInit
 

Namespaces

 boost
 
 boost::program_options
 

Functions

std::string boost::program_options::to_internal (const std::string &)
 
void locking_callback (int mode, int i, const char *file, int line)
 
void RandAddSeed ()
 
void RandAddSeedPerfmon ()
 
uint64 GetRand (uint64 nMax)
 
int GetRandInt (int nMax)
 
uint256 GetRandHash ()
 
int OutputDebugStringF (const char *pszFormat,...)
 
string vstrprintf (const char *format, va_list ap)
 
string real_strprintf (const char *format, int dummy,...)
 
string real_strprintf (const std::string &format, int dummy,...)
 Overload strprintf for std::string, to be able to use it with _ (translation). More...
 
bool error (const char *format,...)
 
void ParseString (const string &str, char c, vector< string > &v)
 
string FormatMoney (int64 n, bool fPlus)
 
bool ParseMoney (const string &str, int64 &nRet)
 
bool ParseMoney (const char *pszIn, int64 &nRet)
 
string SanitizeString (const string &str)
 
bool IsHex (const string &str)
 
vector< unsigned char > ParseHex (const char *psz)
 
vector< unsigned char > ParseHex (const string &str)
 
void ParseParameters (int argc, const char *const argv[])
 
std::string GetArg (const std::string &strArg, const std::string &strDefault)
 Return string argument or default value. More...
 
int64 GetArg (const std::string &strArg, int64 nDefault)
 Return integer argument or default value. More...
 
bool GetBoolArg (const std::string &strArg, bool fDefault)
 Return boolean argument or default value. More...
 
bool SoftSetArg (const std::string &strArg, const std::string &strValue)
 Set an argument if it doesn't already have a value. More...
 
bool SoftSetBoolArg (const std::string &strArg, bool fValue)
 Set a boolean argument if it doesn't already have a value. More...
 
string EncodeBase64 (const unsigned char *pch, size_t len)
 
string EncodeBase64 (const string &str)
 
vector< unsigned char > DecodeBase64 (const char *p, bool *pfInvalid)
 
string DecodeBase64 (const string &str)
 
string EncodeBase32 (const unsigned char *pch, size_t len)
 
string EncodeBase32 (const string &str)
 
vector< unsigned char > DecodeBase32 (const char *p, bool *pfInvalid)
 
string DecodeBase32 (const string &str)
 
bool WildcardMatch (const char *psz, const char *mask)
 
bool WildcardMatch (const string &str, const string &mask)
 
void LogException (std::exception *pex, const char *pszThread)
 
void PrintException (std::exception *pex, const char *pszThread)
 
void PrintExceptionContinue (std::exception *pex, const char *pszThread)
 
boost::filesystem::path GetDefaultDataDir ()
 
const boost::filesystem::path & GetDataDir (bool fNetSpecific)
 
boost::filesystem::path GetConfigFile ()
 
void ReadConfigFile (map< string, string > &mapSettingsRet, map< string, vector< string > > &mapMultiSettingsRet)
 
boost::filesystem::path GetPidFile ()
 
void CreatePidFile (const boost::filesystem::path &path, pid_t pid)
 
bool RenameOver (boost::filesystem::path src, boost::filesystem::path dest)
 
void FileCommit (FILE *fileout)
 
int GetFilesize (FILE *file)
 
bool TruncateFile (FILE *file, unsigned int length)
 
int RaiseFileDescriptorLimit (int nMinFD)
 
void AllocateFileRange (FILE *file, unsigned int offset, unsigned int length)
 
void ShrinkDebugFile ()
 
int64 GetTime ()
 
void SetMockTime (int64 nMockTimeIn)
 
int64 GetTimeOffset ()
 
int64 GetAdjustedTime ()
 
void AddTimeData (const CNetAddr &ip, int64 nTime)
 
void seed_insecure_rand (bool fDeterministic)
 Seed insecure_rand using the random pool. More...
 
string FormatVersion (int nVersion)
 
string FormatFullVersion ()
 
std::string FormatSubVersion (const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
 
boost::filesystem::path GetTempPath ()
 
void runCommand (std::string strCommand)
 
void RenameThread (const char *name)
 
bool NewThread (void(*pfn)(void *), void *parg)
 

Variables

map< string, string > mapArgs
 
map< string, vector< string > > mapMultiArgs
 
bool fDebug = false
 
bool fDebugNet = false
 
bool fPrintToConsole = false
 
bool fPrintToDebugger = false
 
bool fDaemon = false
 
bool fServer = false
 
bool fCommandLine = false
 
string strMiscWarning
 
bool fTestNet = false
 
bool fBloomFilters = true
 
bool fNoListen = false
 
bool fLogTimestamps = false
 
CMedianFilter< int64vTimeOffsets (200, 0)
 
volatile bool fReopenDebugLog = false
 
bool fCachedPath [2] = {false, false}
 
class CInit instance_of_cinit
 
uint32_t insecure_rand_Rz = 11
 MWC RNG of George Marsaglia This is intended to be fast. More...
 
uint32_t insecure_rand_Rw = 11
 

Function Documentation

void AddTimeData ( const CNetAddr ip,
int64  nTime 
)

Definition at line 1322 of file util.cpp.

void AllocateFileRange ( FILE *  file,
unsigned int  offset,
unsigned int  length 
)

Definition at line 1216 of file util.cpp.

void CreatePidFile ( const boost::filesystem::path &  path,
pid_t  pid 
)

Definition at line 1136 of file util.cpp.

vector<unsigned char> DecodeBase32 ( const char *  p,
bool *  pfInvalid 
)

Definition at line 832 of file util.cpp.

string DecodeBase32 ( const string &  str)

Definition at line 949 of file util.cpp.

vector<unsigned char> DecodeBase64 ( const char *  p,
bool *  pfInvalid 
)

Definition at line 679 of file util.cpp.

string DecodeBase64 ( const string &  str)

Definition at line 762 of file util.cpp.

string EncodeBase32 ( const unsigned char *  pch,
size_t  len 
)

Definition at line 768 of file util.cpp.

string EncodeBase32 ( const string &  str)

Definition at line 827 of file util.cpp.

string EncodeBase64 ( const unsigned char *  pch,
size_t  len 
)

Definition at line 628 of file util.cpp.

string EncodeBase64 ( const string &  str)

Definition at line 674 of file util.cpp.

bool error ( const char *  format,
  ... 
)

Definition at line 358 of file util.cpp.

void FileCommit ( FILE *  fileout)

Definition at line 1158 of file util.cpp.

string FormatFullVersion ( )

Definition at line 1404 of file util.cpp.

string FormatMoney ( int64  n,
bool  fPlus 
)

Definition at line 389 of file util.cpp.

std::string FormatSubVersion ( const std::string &  name,
int  nClientVersion,
const std::vector< std::string > &  comments 
)

Definition at line 1410 of file util.cpp.

string FormatVersion ( int  nVersion)

Definition at line 1396 of file util.cpp.

int64 GetAdjustedTime ( )

Definition at line 1317 of file util.cpp.

std::string GetArg ( const std::string &  strArg,
const std::string &  strDefault 
)

Return string argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. "1")
Returns
command-line argument or default value

Definition at line 586 of file util.cpp.

int64 GetArg ( const std::string &  strArg,
int64  nDefault 
)

Return integer argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(e.g. 1)
Returns
command-line argument (0 if invalid number) or default value

Definition at line 593 of file util.cpp.

bool GetBoolArg ( const std::string &  strArg,
bool  fDefault = false 
)

Return boolean argument or default value.

Parameters
strArgArgument to get (e.g. "-foo")
default(true or false)
Returns
command-line argument or default value

Definition at line 600 of file util.cpp.

boost::filesystem::path GetConfigFile ( )

Definition at line 1094 of file util.cpp.

const boost::filesystem::path& GetDataDir ( bool  fNetSpecific)

Definition at line 1060 of file util.cpp.

boost::filesystem::path GetDefaultDataDir ( )

Definition at line 1031 of file util.cpp.

int GetFilesize ( FILE *  file)

Definition at line 1174 of file util.cpp.

boost::filesystem::path GetPidFile ( )

Definition at line 1128 of file util.cpp.

uint64 GetRand ( uint64  nMax)

Definition at line 175 of file util.cpp.

uint256 GetRandHash ( )

Definition at line 195 of file util.cpp.

int GetRandInt ( int  nMax)

Definition at line 190 of file util.cpp.

boost::filesystem::path GetTempPath ( )

Definition at line 1438 of file util.cpp.

int64 GetTime ( )

Definition at line 1298 of file util.cpp.

int64 GetTimeOffset ( )

Definition at line 1312 of file util.cpp.

bool IsHex ( const string &  str)

Definition at line 490 of file util.cpp.

void locking_callback ( int  mode,
int  i,
const char *  file,
int  line 
)

Definition at line 91 of file util.cpp.

void LogException ( std::exception *  pex,
const char *  pszThread 
)

Definition at line 1008 of file util.cpp.

bool NewThread ( void(*)(void *)  pfn,
void *  parg 
)

Definition at line 1491 of file util.cpp.

int OutputDebugStringF ( const char *  pszFormat,
  ... 
)

Definition at line 237 of file util.cpp.

vector<unsigned char> ParseHex ( const char *  psz)

Definition at line 500 of file util.cpp.

vector<unsigned char> ParseHex ( const string &  str)

Definition at line 521 of file util.cpp.

bool ParseMoney ( const string &  str,
int64 nRet 
)

Definition at line 413 of file util.cpp.

bool ParseMoney ( const char *  pszIn,
int64 nRet 
)

Definition at line 418 of file util.cpp.

void ParseParameters ( int  argc,
const char *const  argv[] 
)

Definition at line 541 of file util.cpp.

void ParseString ( const string &  str,
char  c,
vector< string > &  v 
)

Definition at line 369 of file util.cpp.

void PrintException ( std::exception *  pex,
const char *  pszThread 
)

Definition at line 1014 of file util.cpp.

void PrintExceptionContinue ( std::exception *  pex,
const char *  pszThread 
)

Definition at line 1023 of file util.cpp.

int RaiseFileDescriptorLimit ( int  nMinFD)

Definition at line 1195 of file util.cpp.

void RandAddSeed ( )

Definition at line 140 of file util.cpp.

void RandAddSeedPerfmon ( )

Definition at line 148 of file util.cpp.

void ReadConfigFile ( map< string, string > &  mapSettingsRet,
map< string, vector< string > > &  mapMultiSettingsRet 
)

Definition at line 1101 of file util.cpp.

string real_strprintf ( const char *  format,
int  dummy,
  ... 
)

Definition at line 340 of file util.cpp.

string real_strprintf ( const std::string &  format,
int  dummy,
  ... 
)

Overload strprintf for std::string, to be able to use it with _ (translation).

This will not support GCC format type warnings (-Wformat) so be careful.

Definition at line 349 of file util.cpp.

bool RenameOver ( boost::filesystem::path  src,
boost::filesystem::path  dest 
)

Definition at line 1147 of file util.cpp.

void RenameThread ( const char *  name)

Definition at line 1467 of file util.cpp.

void runCommand ( std::string  strCommand)

Definition at line 1460 of file util.cpp.

string SanitizeString ( const string &  str)

Definition at line 461 of file util.cpp.

void seed_insecure_rand ( bool  fDeterministic = false)

Seed insecure_rand using the random pool.

Parameters
DeterministicUse a determinstic seed

Definition at line 1377 of file util.cpp.

void SetMockTime ( int64  nMockTimeIn)

Definition at line 1305 of file util.cpp.

void ShrinkDebugFile ( )

Definition at line 1258 of file util.cpp.

bool SoftSetArg ( const std::string &  strArg,
const std::string &  strValue 
)

Set an argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
strValueValue (e.g. "1")
Returns
true if argument gets set, false if it already had a value

Definition at line 611 of file util.cpp.

bool SoftSetBoolArg ( const std::string &  strArg,
bool  fValue 
)

Set a boolean argument if it doesn't already have a value.

Parameters
strArgArgument to set (e.g. "-foo")
fValueValue (e.g. false)
Returns
true if argument gets set, false if it already had a value

Definition at line 619 of file util.cpp.

bool TruncateFile ( FILE *  file,
unsigned int  length 
)

Definition at line 1184 of file util.cpp.

string vstrprintf ( const char *  format,
va_list  ap 
)

Definition at line 309 of file util.cpp.

bool WildcardMatch ( const char *  psz,
const char *  mask 
)

Definition at line 956 of file util.cpp.

bool WildcardMatch ( const string &  str,
const string &  mask 
)

Definition at line 980 of file util.cpp.

Variable Documentation

bool fBloomFilters = true

Definition at line 82 of file util.cpp.

bool fCachedPath[2] = {false, false}

Definition at line 87 of file util.cpp.

bool fCommandLine = false

Definition at line 79 of file util.cpp.

bool fDaemon = false

Definition at line 77 of file util.cpp.

bool fDebug = false

Definition at line 73 of file util.cpp.

bool fDebugNet = false

Definition at line 74 of file util.cpp.

bool fLogTimestamps = false

Definition at line 84 of file util.cpp.

bool fNoListen = false

Definition at line 83 of file util.cpp.

bool fPrintToConsole = false

Definition at line 75 of file util.cpp.

bool fPrintToDebugger = false

Definition at line 76 of file util.cpp.

volatile bool fReopenDebugLog = false

Definition at line 86 of file util.cpp.

bool fServer = false

Definition at line 78 of file util.cpp.

bool fTestNet = false

Definition at line 81 of file util.cpp.

uint32_t insecure_rand_Rw = 11

Definition at line 1376 of file util.cpp.

uint32_t insecure_rand_Rz = 11

MWC RNG of George Marsaglia This is intended to be fast.

It has a period of 2^59.3, though the least significant 16 bits only have a period of about 2^30.1.

Returns
random value

Definition at line 1375 of file util.cpp.

class CInit instance_of_cinit
map<string, string> mapArgs

Definition at line 71 of file util.cpp.

map<string, vector<string> > mapMultiArgs

Definition at line 72 of file util.cpp.

string strMiscWarning

Definition at line 80 of file util.cpp.

CMedianFilter<int64> vTimeOffsets(200, 0)