Ejemplo n.º 1
0
int command_ignore(char *text, int len)
{
	char name[MAX_USERNAME_LENGTH];
	int i;
	Uint8 ch='\0';
	int result;

	while (isspace(*text))
		text++;

	for (i = 0; i < MAX_USERNAME_LENGTH - 1; i++)
	{
		ch = text[i];
		if (ch == ' ' || ch == '\0')
		{
			ch = '\0';
			break;
		}
		name[i] = ch;
	}
	name[i] = '\0';

	if (i >= MAX_USERNAME_LENGTH - 1 && text[i] != '\0') // This is the max chrs of name but isn't a null terminator
	{
		char str[100];
		safe_snprintf (str, sizeof(str), "%s %s", name_too_long, not_added_to_ignores);
		LOG_TO_CONSOLE (c_red1, str);
		return 1;
	}
	if (i < 3)
	{
		char str[100];
		safe_snprintf (str, sizeof(str), "%s %s", name_too_short, not_added_to_ignores);
		LOG_TO_CONSOLE (c_red1, name_too_short);
		return 1;
	}

	result = add_to_ignore_list (name, save_ignores);
	if (result == -1)
	{
		char str[100];
		safe_snprintf (str, sizeof(str), already_ignoring, name);
		LOG_TO_CONSOLE (c_red1, str);
		return 1;
	}
	if(result == -2)
	{
		LOG_TO_CONSOLE (c_red1, ignore_list_full);
	}
	else
	{
		char str[100];
		safe_snprintf (str, sizeof(str), added_to_ignores, name);
		LOG_TO_CONSOLE (c_green1, str);
	}
	return 1;
}
Ejemplo n.º 2
0
void load_ignores_list(char * file_name)
{
	int f_size;
	FILE *f = NULL;
	char * ignore_list_mem;
	int i,j;
	char name[64];
	Uint8 ch;
	size_t ret;

	f = open_file_config(file_name, "rb");
	if(f == NULL){return;}
	fseek(f,0,SEEK_END);
	f_size = ftell(f);
	if (f_size <= 0)
	{
		fclose(f);
		return;
	}

	//ok, allocate memory for it
	ignore_list_mem=(char *)calloc(f_size, 1);
	fseek (f, 0, SEEK_SET);
	ret = fread (ignore_list_mem, 1, f_size, f);
	fclose (f);
	if (ret != f_size)
	{
		free (ignore_list_mem);
		LOG_ERROR("%s() read failed for file [%s]\n", __FUNCTION__, file_name);
		return;
	}

	j=0;
	i=0;
	while (i<f_size)
	{
		ch = ignore_list_mem[i];
		if (ch == '\n' || ch == '\r')
		{
			if (j > 0 && add_to_ignore_list(name, 0) == -1)
				// ignore list full
				break;
			j = 0;
			i++;
		}
		else
		{
			name[j++] = ch;
			name[j] = '\0';
			i++;
		}
	}

	free(ignore_list_mem);
}