#include <boost/program_options/parsers.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
+
+#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/foreach.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
using namespace std;
+namespace bt = boost::posix_time;
map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs;
CMedianFilter<int64> vTimeOffsets(200,0);
bool fReopenDebugLog = false;
+// Extended DecodeDumpTime implementation, see this page for details:
+// http://stackoverflow.com/questions/3786201/parsing-of-date-time-from-string-boost
+const std::locale formats[] = {
+ std::locale(std::locale::classic(),new bt::time_input_facet("%Y-%m-%dT%H:%M:%SZ")),
+ std::locale(std::locale::classic(),new bt::time_input_facet("%Y-%m-%d %H:%M:%S")),
+ std::locale(std::locale::classic(),new bt::time_input_facet("%Y/%m/%d %H:%M:%S")),
+ std::locale(std::locale::classic(),new bt::time_input_facet("%d.%m.%Y %H:%M:%S")),
+ std::locale(std::locale::classic(),new bt::time_input_facet("%Y-%m-%d"))
+};
+
+const size_t formats_n = sizeof(formats)/sizeof(formats[0]);
+
+std::time_t pt_to_time_t(const bt::ptime& pt)
+{
+ bt::ptime timet_start(boost::gregorian::date(1970,1,1));
+ bt::time_duration diff = pt - timet_start;
+ return diff.ticks()/bt::time_duration::rep_type::ticks_per_second;
+}
+
// Init OpenSSL library multithreading support
static CCriticalSection** ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line)
char* p = buffer;
int limit = sizeof(buffer);
int ret;
- loop
+ while (true)
{
+#ifndef _MSC_VER
va_list arg_ptr;
va_copy(arg_ptr, ap);
+#else
+ va_list arg_ptr = ap;
+#endif;
#ifdef WIN32
ret = _vsnprintf(p, limit, format, arg_ptr);
#else
return;
string::size_type i1 = 0;
string::size_type i2;
- loop
+ while (true)
{
i2 = str.find(c, i1);
if (i2 == str.npos)
int64 n_abs = (n > 0 ? n : -n);
int64 quotient = n_abs/COIN;
int64 remainder = n_abs%COIN;
- string str = strprintf("%"PRI64d".%08"PRI64d, quotient, remainder);
+ string str = strprintf("%"PRI64d".%06"PRI64d, quotient, remainder);
// Right-trim excess zeros before the decimal point:
int nTrim = 0;
{
// convert hex dump to vector
vector<unsigned char> vch;
- loop
+ while (true)
{
while (isspace(*psz))
psz++;
}
+int64 DecodeDumpTime(const std::string& s)
+{
+ bt::ptime pt;
+
+ for(size_t i=0; i<formats_n; ++i)
+ {
+ std::istringstream is(s);
+ is.imbue(formats[i]);
+ is >> pt;
+ if(pt != bt::ptime()) break;
+ }
+
+ return pt_to_time_t(pt);
+}
+
+std::string EncodeDumpTime(int64 nTime) {
+ return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
+}
+
+std::string EncodeDumpString(const std::string &str) {
+ std::stringstream ret;
+ BOOST_FOREACH(unsigned char c, str) {
+ if (c <= 32 || c >= 128 || c == '%') {
+ ret << '%' << HexStr(&c, &c + 1);
+ } else {
+ ret << c;
+ }
+ }
+ return ret.str();
+}
+
+std::string DecodeDumpString(const std::string &str) {
+ std::stringstream ret;
+ for (unsigned int pos = 0; pos < str.length(); pos++) {
+ unsigned char c = str[pos];
+ if (c == '%' && pos+2 < str.length()) {
+ c = (((str[pos+1]>>6)*9+((str[pos+1]-'0')&15)) << 4) |
+ ((str[pos+2]>>6)*9+((str[pos+2]-'0')&15));
+ pos += 2;
+ }
+ ret << c;
+ }
+ return ret.str();
+}
+
bool WildcardMatch(const char* psz, const char* mask)
{
- loop
+ while (true)
{
switch (*mask)
{
return pathPidFile;
}
+#ifndef WIN32
void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
{
FILE* file = fopen(path.string().c_str(), "w");
fclose(file);
}
}
+#endif
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
{
static int64 nTimeOffset = 0;
+int64 GetTimeOffset()
+{
+ return nTimeOffset;
+}
+
int64 GetAdjustedTime()
{
- return GetTime() + nTimeOffset;
+ return GetTime() + GetTimeOffset();
}
void AddTimeData(const CNetAddr& ip, int64 nTime)