Exemplo n.º 1
0
	virtual void Initialize() {
		try {
			log4cplus::helpers::Properties props(properties_file_name_.c_str());
			if (!props.size())
				MLB::Utility::ThrowException("No property name/value pairs "
					"loaded from property file --- does file exist?");
			property_configuration_.
				reset(new log4cplus::PropertyConfigurator(props));
			property_configuration_->configure();
			return;
		}
		catch (const std::exception &except) {
			//	If the ctor parameter was empty, we'll try to use a default
			//	log4cpp configuration. Otherwise, we throw...
			if ((!empty_file_name_) && require_properties_file_)
				Rethrow(except, "Unable to parse log4cplus properties file '" +
					properties_file_name_ + std::string(": ") + except.what());
		}
		try {
			// Try a default configuration...
			log4cplus::BasicConfigurator default_configuration;
			default_configuration.configure();
		}
		catch (const std::exception &except) {
			Rethrow(except, "Unable to configure log4cplus using the defaults: " +
				std::string(except.what()));
		}
	}
Exemplo n.º 2
0
	LogHandlerLog4Cpp(const std::string &application_name,
		const std::string &properties_file_name = "",
		bool require_properties_file = true) :
		 application_name_(application_name)
		,properties_file_name_(properties_file_name)
		,require_properties_file_(require_properties_file) {
		try {
			if (properties_file_name_.empty())
				properties_file_name_ = application_name + ".properties";
			log4cpp::PropertyConfigurator::configure(properties_file_name_);
			return;
		}
		catch (const std::exception &except) {
			//	If the ctor parameter was empty, we'll try to use a default
			//	log4cpp configuration. Otherwise, we throw...
			if ((!properties_file_name.empty()) && require_properties_file)
				Rethrow(except, "Unable to parse log4cpp properties file '" +
					properties_file_name + std::string(": ") + except.what());
		}
		try {
			// Try a default configuration...
			log4cpp::Category &root_ref = log4cpp::Category::getRoot();
			root_ref.setPriority(log4cpp::Priority::DEBUG);
		}
		catch (const std::exception &except) {
			Rethrow(except, "Unable to configure log4cpp using the defaults: " +
				std::string(except.what()));
		}
	}
Exemplo n.º 3
0
bool
Ledger::setup (Config const& config)
{
    bool ret = true;

    fees_.base = config.FEE_DEFAULT;
    fees_.units = config.TRANSACTION_FEE_BASE;
    fees_.reserve = config.FEE_ACCOUNT_RESERVE;
    fees_.increment = config.FEE_OWNER_RESERVE;

    try
    {
        if (auto const sle = read(keylet::fees()))
        {
            // VFALCO NOTE Why getFieldIndex and not isFieldPresent?

            if (sle->getFieldIndex (sfBaseFee) != -1)
                fees_.base = sle->getFieldU64 (sfBaseFee);

            if (sle->getFieldIndex (sfReferenceFeeUnits) != -1)
                fees_.units = sle->getFieldU32 (sfReferenceFeeUnits);

            if (sle->getFieldIndex (sfReserveBase) != -1)
                fees_.reserve = sle->getFieldU32 (sfReserveBase);

            if (sle->getFieldIndex (sfReserveIncrement) != -1)
                fees_.increment = sle->getFieldU32 (sfReserveIncrement);
        }
    }
    catch (SHAMapMissingNode &)
    {
        ret = false;
    }
    catch (std::exception const&)
    {
        Rethrow();
    }

    try
    {
        rules_ = Rules(*this, config.features);
    }
    catch (SHAMapMissingNode &)
    {
        ret = false;
    }
    catch (std::exception const&)
    {
        Rethrow();
    }

    return ret;
}
Exemplo n.º 4
0
    void run ()
    {
        try
        {
            Throw<std::runtime_error>("Throw test");
        }
        catch (std::runtime_error const& e)
        {
            BEAST_EXPECT(std::string(e.what()) == "Throw test");

            try
            {
                Rethrow();
            }
            catch (std::runtime_error const& e)
            {
                BEAST_EXPECT(std::string(e.what()) == "Throw test");
            }
            catch (...)
            {
                BEAST_EXPECT(false);
            }
        }
        catch (...)
        {
            BEAST_EXPECT(false);
        }
    }
Exemplo n.º 5
0
//	////////////////////////////////////////////////////////////////////////////
TimeVal &TimeVal::AddMicroseconds(int usecs_to_add)
{
	int secs_to_add = usecs_to_add / 1000000;
	int new_usec    = tv_usec + (usecs_to_add % 1000000);

	if (new_usec >= 1000000) {
		secs_to_add += new_usec / 1000000;
		new_usec    %= 1000000;
	}
	else if (new_usec < 0) {
		secs_to_add += -1 + (new_usec / 1000000);
		new_usec     = 1000000 + (new_usec % 1000000);
	}

	if (secs_to_add) {
		try {
			AddSeconds(secs_to_add);
		}
		catch (const std::exception &except) {
			Rethrow(except, "Unable to add the requested number of microseconds "
				"(" + AnyToString(usecs_to_add) + "): " +
				std::string(except.what()));
		}
	}

	tv_usec = new_usec;

	return(*this);
}
Exemplo n.º 6
0
void
msig::operator()(Env& env, JTx& jt) const
{
    auto const mySigners = signers;
    jt.signer = [mySigners, &env](Env&, JTx& jt)
    {
        jt[sfSigningPubKey.getJsonName()] = "";
        boost::optional<STObject> st;
        try
        {
            st = parse(jt.jv);
        }
        catch(parse_error const&)
        {
            env.test.log << pretty(jt.jv) << std::endl;
            Rethrow();
        }
        auto& js = jt[sfSigners.getJsonName()];
        js.resize(mySigners.size());
        for(std::size_t i = 0; i < mySigners.size(); ++i)
        {
            auto const& e = mySigners[i];
            auto& jo = js[i][sfSigner.getJsonName()];
            jo[jss::Account] = e.acct.human();
            jo[jss::SigningPubKey] = strHex(e.sig.pk().slice());

            Serializer ss {buildMultiSigningData (*st, e.acct.id())};
            auto const sig = ripple::sign (
                *publicKeyType(e.sig.pk().slice()), e.sig.sk(), ss.slice());
            jo[sfTxnSignature.getJsonName()] =
                strHex(Slice{ sig.data(), sig.size() });
        }
    };
}
Exemplo n.º 7
0
//	////////////////////////////////////////////////////////////////////////////
void LogHandlerFileBase::OpenFile(const char *file_name)
{
	if ((file_name == NULL) || (!(*file_name)))
		ThrowException("Specified log file name is NULL or an empty string.");

	try {
		OpenFileImpl(file_name);
	}
	catch (const std::exception &except) {
		Rethrow(except, "Unable to open log file '" + std::string(file_name) +
			std::string("': ") + except.what());
	}
}
Exemplo n.º 8
0
	void TEST_ArchiveType(const DataType &datum, const std::string &data_name,
	const std::string &archive_name, int flags = boost::archive::no_header)
{
	std::cout << data_name << ": " << std::setw(9) << archive_name <<
		" ---> " << std::flush;

	try {
		std::string datum_saved;
		try {
			try {
				std::ostringstream output_stream;
				SaveArchive        s_archive(output_stream, flags);
				s_archive & boost::serialization::make_nvp("MLBTest", datum);
				datum_saved.assign(output_stream.str());
			}
			catch (const std::exception &except) {
				ThrowException("Serialization save attempt failed: " +
					std::string(except.what()));
			}
			DataType datum_loaded;
			try {
				std::istringstream input_stream(datum_saved);
				LoadArchive        l_archive(input_stream, flags);
				l_archive & boost::serialization::make_nvp("MLBTest", datum_loaded);
			}
			catch (const std::exception &except) {
				ThrowException("Serialization load attempt failed: " +
					std::string(except.what()));
			}
			if ((datum < datum_loaded) || (datum_loaded < datum)) {
				std::ostringstream o_str;
				o_str <<
					"Comparison of original data (" << datum << ") with loaded "
					"result of serialization (" << datum_loaded << ") revealed "
					"differences.";
				ThrowException(o_str.str());
			}
		}
		catch (const std::exception &except) {
			Rethrow(except, "Failure in regression test for boost::serialization "
				"of type '" + data_name + "' with serialization archive type '" +
				archive_name + "': " + std::string(except.what()));
		}
		std::cout << "OK (serialized size = " <<
			static_cast<unsigned int>(datum_saved.size()) << ")" << std::endl;
	}
	catch (const std::exception &except) {
		std::cout << "FAILED: " << except.what() << std::endl;
		throw;
	}
}
Exemplo n.º 9
0
//	////////////////////////////////////////////////////////////////////////////
void ParseFromString(const char *in_date, time_t &out_secs,
	long &out_fractional, long fractional_places)
{
	if (in_date == NULL)
		ThrowInvalidArgument("Specified date string pointer is 'NULL'.");

	try {
		size_t date_length = strlen(in_date);
		char   date_buffer[Length_TimeSpec + 9 + 1];
		if (date_length < 8)
			ThrowInvalidArgument("Unknown date format.");
		if (date_length == 8) {
			char *end_ptr;
			strtoul(in_date, &end_ptr, 10);
			if (end_ptr != (in_date + 8))
				ThrowInvalidArgument("Invalid undelimited date string --- "
					"only numeric characters are valid.");
			strcat(nstrcat(strcat(nstrcat(strcat(nstrcpy(date_buffer, in_date, 4),
				"-"), in_date + 4, 2), "-"), in_date + 6, 2),
				" 00:00:00.000000000");
			ParseFromString_Basic(date_buffer, out_secs, out_fractional,
				fractional_places);
		}
		else {
			if ((!isdigit(in_date[0])) || (!isdigit(in_date[1])) ||
				(!isdigit(in_date[2])) || (!isdigit(in_date[3])) ||
				(!isdigit(in_date[5])) || (!isdigit(in_date[6])) ||
				(!isdigit(in_date[8])) || (!isdigit(in_date[9])))
				ThrowInvalidArgument("Invalid delimited date string --- "
					"expected format for date portion is 'yyyy-mm-dd'.");
			if (((in_date[4] != '-') && (in_date[4] != '/')) ||
				 ((in_date[7] != '-') && (in_date[7] != '/')))
				ThrowInvalidArgument("Invalid delimited date string --- "
					"expected format for date portion is 'yyyy-mm-dd'.");
			if (date_length == 10) {
				strcat(strcpy(date_buffer, in_date), " 00:00:00.000000000");
				ParseFromString_Basic(date_buffer, out_secs, out_fractional,
					fractional_places);
			}
			else if (date_length <= Length_TimeSpec) {
				if (((date_length < 20) && (date_length != 13) &&
					(date_length != 16) && (date_length != 19)))
					ThrowInvalidArgument("Unknown date format.");
				if (((in_date[10] != ' ') && (in_date[10] != '.')) ||
					(!isdigit(in_date[11])) || (!isdigit(in_date[12])))
					ThrowInvalidArgument("Invalid delimited date/time string.");
				if (date_length == 13)
					ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
						":00:00.000000000"), out_secs, out_fractional,
						fractional_places);
				else {
					if (((in_date[13] != ':') && (in_date[13] != '.')) ||
						(!isdigit(in_date[14])) || (!isdigit(in_date[15])))
						ThrowInvalidArgument("Invalid delimited date/time string.");
					if (date_length == 16)
						ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
							":00.000000000"), out_secs, out_fractional,
							fractional_places);
					else {
						if (((in_date[16] != ':') && (in_date[16] != '.')) ||
							(!isdigit(in_date[17])) || (!isdigit(in_date[18])))
							ThrowInvalidArgument("Invalid delimited date/time string.");
						else if (date_length == 19)
							ParseFromString_Basic(strcat(strcpy(date_buffer, in_date),
								".000000000"), out_secs, out_fractional,
								fractional_places);
						else if (in_date[19] != '.')
							ThrowInvalidArgument("Invalid delimited date/time string.");
						else
							ParseFromString_Basic(nstrcat(strcpy(date_buffer, in_date),
								"000000000", Length_TimeSpec - date_length), out_secs,
								out_fractional, fractional_places);
					}
				}
			}
			else
				ThrowInvalidArgument("Date/time string length exceeds maximum "
					"permissible (" + AnyToString(Length_TimeSpec) +
					" characters).");
		}
	}
	catch (const std::exception &except) {
		Rethrow(except, "Unable to parse date/time string '" +
			std::string(in_date) + "': " + std::string(except.what()));
	}
}