Ejemplo n.º 1
0
 int main(void)
 {
 	bool stringeq(const char s1[], const char s2[] );
 	char const s1[] = "compare string";
 	char const s2[] = "string";
 	
 	printf("%i\n", stringeq(s1, s2));
 	printf("%i\n", stringeq(s2, s2));
 	printf("%i\n", stringeq(s1, "compare string"));
 	
 	return 0;
 }
Ejemplo n.º 2
0
int read_config_node_local_config(config_t * config)
{
	config_setting_t * config_node_setting = config_lookup(config, "config_node");
	if (config_node_setting == NULL)
	{
		message(LOG_WARNING, FACILITY_CONFIG, "Config node section is missing, using and config node this node");

		zfs_config.config_node.node_id = zfs_config.this_node.node_id;
		zfs_config.config_node.host_port = zfs_config.this_node.host_port;
		xstringdup(&zfs_config.config_node.node_name, &zfs_config.this_node.node_name);

		return CONFIG_TRUE;
	}

	config_setting_t * setting_node_id = config_setting_get_member(config_node_setting, "id");
	config_setting_t * setting_node_name = config_setting_get_member(config_node_setting, "name");
	config_setting_t * setting_node_host = config_setting_get_member(config_node_setting, "host");

	if (setting_node_id == NULL || setting_node_name == NULL || setting_node_host == NULL)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local config node section name, node id or host name is missing, please add them to local config.\n");
		return CONFIG_FALSE;
	}

	if (config_setting_type(setting_node_id) != CONFIG_TYPE_INT)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local node section key id has wrong type, it should be int.\n");
		return CONFIG_FALSE;
	}

	if (config_setting_type(setting_node_name) != CONFIG_TYPE_STRING)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local node section key name has wrong type, it should be string.\n");
		return CONFIG_FALSE;
	}

	if (config_setting_type(setting_node_host) != CONFIG_TYPE_STRING)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local node section key name has wrong type, it should be string.\n");
		return CONFIG_FALSE;
	}

	zfs_config.config_node.node_id = config_setting_get_int(setting_node_id);
	if (!is_valid_node_id(zfs_config.config_node.node_id))
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Node in config node id is invalid, please fix is.\n");
		return CONFIG_FALSE;
	}

	if (zfs_config.this_node.node_id == zfs_config.config_node.node_id)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Node in config node id is same as this node id.\n");
		return CONFIG_FALSE;
	}

	const char * local_node_name = config_setting_get_string(setting_node_name);
	if (!is_valid_node_name(local_node_name))
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Node name in config node is invalid.\n");
		return CONFIG_FALSE;
	}

	xmkstring(&zfs_config.config_node.node_name, local_node_name);
	if (stringeq(&zfs_config.config_node.node_name, &zfs_config.this_node.node_name))
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Node name in config node is same as this node name.\n");
		return CONFIG_FALSE;
	}


	const char * local_node_host = config_setting_get_string(setting_node_host);
	if (!is_valid_host_name(local_node_host))
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Host name in config node is invalid.\n");
		return CONFIG_FALSE;
	}

	xmkstring(&(zfs_config.config_node.host_name), local_node_host);

	/*read port configuration*/
	zfs_config.config_node.host_port = read_tcp_port_setting(config_node_setting);


	return CONFIG_TRUE;
}