Ejemplo n.º 1
0
extern "C" struct dnet_node *dnet_parse_config(const char *file, int mon)
{
	dnet_node *node = NULL;
	config_data *data = NULL;

	try {
		data = static_cast<config_data *>(dnet_config_data_create());
		if (!data)
			throw std::bad_alloc();

		data->config_path = file;

		auto parser = data->parse_config();
		const config root = parser->root();
		const config logger = root.at("logger");
		const config options = root.at("options");
		const config backends = root.at("backends");

		parse_logger(data, logger);
		parse_options(data, options);
		parse_backends(data, backends);

		if (data->daemon_mode && !mon)
			dnet_background();

		if (!data->cfg_addr_num)
			throw config_error("no local address specified, exiting");

		node = dnet_server_node_create(data);
		if (!node)
			throw config_error("failed to create node");

		static_assert(sizeof(dnet_addr) == sizeof(address), "Size of dnet_addr and size of address must be equal");
		if (data->remotes.size() != 0) {
			int err = dnet_add_state(node, reinterpret_cast<const dnet_addr *>(data->remotes.data()), data->remotes.size(), 0);
			if (err < 0)
				BH_LOG(*node->log, DNET_LOG_WARNING, "Failed to connect to remote nodes: %d", err);
		}

	} catch (std::exception &exc) {
		if (data && data->cfg_state.log) {
			dnet_backend_log(data->cfg_state.log, DNET_LOG_ERROR,
				"cnf: failed to read config file '%s': %s", file, exc.what());
		} else {
			fprintf(stderr, "cnf: %s\n", exc.what());
			fflush(stderr);
		}

		if (node)
			dnet_server_node_destroy(node);
		else if (data)
			dnet_config_data_destroy(data);

		return NULL;
	}

	return node;
}
	stop_on_close_encounter_param(const config &cfg)
	{
		if(!cfg.count("close_approach"))
			dmin = 0.;
		else
			dmin = atof(cfg.at("close_approach").c_str());
	}
Ejemplo n.º 3
0
/**
 *	@brief	Analyze the PE with each selected plugin.
 *
 *	@param	io::OutputFormatter& formatter The object which will recieve the output.
 *	@param	const std::vector<std::string>& selected The names of the selected plugins.
 *	@param	const config& conf The configuration of the plugins.
 *	@param	const mana::PE& pe The PE to analyze.
 */
void handle_plugins_option(io::OutputFormatter& formatter,
						   const std::vector<std::string>& selected,
						   const config& conf,
						   const mana::PE& pe)
{
	bool all_plugins = std::find(selected.begin(), selected.end(), "all") != selected.end();
	std::vector<plugin::pIPlugin> plugins = plugin::PluginManager::get_instance().get_plugins();
	io::pNode plugins_node(new io::OutputTreeNode("Plugins", io::OutputTreeNode::LIST));

	for (std::vector<plugin::pIPlugin>::iterator it = plugins.begin() ; it != plugins.end() ; ++it)
	{
		// Verify that the plugin was selected
		if (!all_plugins && std::find(selected.begin(), selected.end(), *(*it)->get_id()) == selected.end()) {
			continue;
		}

		// Forward relevant configuration elements to the plugin.
		if (conf.count(*(*it)->get_id())) {
			(*it)->set_config(conf.at(*(*it)->get_id()));
		}

		plugin::pResult res = (*it)->analyze(pe);
		if (!res)
		{
			PRINT_WARNING << "Plugin " << *(*it)->get_id() << " returned a NULL result!" << std::endl;
			continue;
		}

		io::pNode output = res->get_output();
		if (!output || !res->get_information()->size()) {
			continue;
		}
		plugins_node->append(output);
	}

	formatter.add_data(plugins_node, *pe.get_path());
}