Example #1
0
static void cmd_unignore(const char *data)
{
	IGNORE_REC *rec;
	GSList *tmp;
	char *key;

	if (is_numeric(data, ' ')) {
		/* with index number */
		tmp = g_slist_nth(ignores, atoi(data)-1);
		rec = tmp == NULL ? NULL : tmp->data;
	} else {
		/* with mask */
		char *chans[2] = { "*", NULL };

		if (ischannel(*data)) chans[0] = (char *) data;
		rec = ignore_find("*", ischannel(*data) ? NULL : data, chans);
	}

	if (rec == NULL)
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORE_NOT_FOUND, data);
	else {
		key = ignore_get_key(rec);
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED, key);
		g_free(key);

		rec->level = 0;
		rec->except_level = 0;
		ignore_update_rec(rec);
	}
}
Example #2
0
static void sig_ignore_destroyed(IGNORE_REC *rec)
{
	char *key;

	key = ignore_get_key(rec);
	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_UNIGNORED, key);
	g_free(key);
}
Example #3
0
static void ignore_print(int index, IGNORE_REC *rec)
{
	char *key, *levels;

	key = ignore_get_key(rec);
	levels = ignore_get_levels(rec->level, rec->except_level);
	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
		    IRCTXT_IGNORE_LINE, index,
		    key != NULL ? key : "",
		    levels != NULL ? levels : "",
		    rec->regexp ? " -regexp" : "",
		    rec->fullword ? " -word" : "",
		    rec->replies ? " -replies" : "");
        g_free(key);
	g_free(levels);
}
Example #4
0
static void ignore_print(int index, IGNORE_REC *rec)
{
	GString *options;
	char *key, *levels;

	key = ignore_get_key(rec);
	levels = bits2level(rec->level);

	options = g_string_new(NULL);
	if (rec->exception) g_string_append(options, "-except ");
	if (rec->regexp) {
		g_string_append(options, "-regexp ");
		if (rec->pattern == NULL)
			g_string_append(options, "[INVALID! -pattern missing] ");
#ifdef HAVE_REGEX_H
		else if (!rec->regexp_compiled)
			g_string_append(options, "[INVALID!] ");
#endif
	}
	if (rec->fullword) g_string_append(options, "-full ");
	if (rec->replies) g_string_append(options, "-replies ");
	if (rec->servertag != NULL)
		g_string_append_printf(options, "-network %s ", rec->servertag);
	if (rec->pattern != NULL)
		g_string_append_printf(options, "-pattern %s ", rec->pattern);

	if (options->len > 1) g_string_truncate(options, options->len-1);

	if (index >= 0) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
			    TXT_IGNORE_LINE, index, key != NULL ? key : "",
			    levels != NULL ? levels : "", options->str);
	} else {
		printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
			    options->len > 0 ? TXT_IGNORED_OPTIONS : TXT_IGNORED,
			    key != NULL ? key : "",
			    levels != NULL ? levels : "", options->str);
	}
	g_string_free(options, TRUE);
        g_free(key);
	g_free(levels);
}
Example #5
0
static void cmd_ignore(const char *data)
{
	/* /IGNORE [-regexp | -word] [-pattern <pattern>] [-except]
	           [-replies] [-channels <channel>] <mask> <levels>
	   OR

           /IGNORE [-regexp | -word] [-pattern <pattern>] [-except] [-replies]
	           <channels> <levels> */
        GHashTable *optlist;
	IGNORE_REC *rec;
	char *patternarg, *chanarg, *mask, *levels, *key;
	char **channels;
	void *free_arg;
	int new_ignore;

	if (*data == '\0') {
		cmd_ignore_show();
		return;
	}

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
			    "ignore", &optlist, &mask, &levels))
		return;

	patternarg = g_hash_table_lookup(optlist, "pattern");
        chanarg = g_hash_table_lookup(optlist, "channels");

	if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	if (ischannel(*mask)) {
		chanarg = mask;
		mask = "";
	}
	channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
		g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);

	rec = ignore_find(NULL, mask, channels);
	new_ignore = rec == NULL;

	if (rec == NULL) {
		rec = g_new0(IGNORE_REC, 1);

		rec->mask = *mask == '\0' ? NULL : g_strdup(mask);
		rec->channels = channels;
	} else {
                g_free_and_null(rec->pattern);
		g_strfreev(channels);
	}

	if (g_hash_table_lookup(optlist, "except") != NULL) {
                rec->except_level = combine_level(rec->except_level, levels);
	} else {
		ignore_split_levels(levels, &rec->level, &rec->except_level);
	}

	rec->pattern = (patternarg == NULL || *patternarg == '\0') ?
		NULL : g_strdup(patternarg);
	rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
	rec->fullword = g_hash_table_lookup(optlist, "word") != NULL;
	rec->replies = g_hash_table_lookup(optlist, "replies") != NULL;

	if (rec->level == 0 && rec->except_level == 0) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED,
			    rec->mask == NULL ? "" : rec->mask);
	} else {
		key = ignore_get_key(rec);
		levels = ignore_get_levels(rec->level, rec->except_level);
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORED, key, levels);
		g_free(key);
		g_free(levels);
	}

	if (new_ignore)
		ignore_add_rec(rec);
	else
		ignore_update_rec(rec);

	cmd_params_free(free_arg);
}
Example #6
0
static void cmd_ignore(const char *data)
{
	/* /IGNORE [-regexp | -word] [-pattern <pattern>] [-except]
	           [-channels <channel>] <mask> <levels>
	   OR

           /IGNORE [-regexp | -word] [-pattern <pattern>] [-except]
	           <channels> <levels> */
	char *params, *args, *patternarg, *chanarg, *mask, *levels, *key;
	char **channels;
	IGNORE_REC *rec;
	int new_ignore;

	if (*data == '\0') {
		cmd_ignore_show();
		return;
	}

	args = "pattern channels";
	params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST,
				&args, &patternarg, &chanarg, &mask, &levels);
	if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	if (ischannel(*mask)) {
		chanarg = mask;
		mask = "";
	}
	channels = *chanarg == '\0' ? NULL :
		g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);

	rec = ignore_find(NULL, mask, channels);
	new_ignore = rec == NULL;

	if (rec == NULL) {
		rec = g_new0(IGNORE_REC, 1);

		rec->mask = *mask == '\0' ? NULL : g_strdup(mask);
		rec->channels = channels;
	} else {
                g_free_and_null(rec->pattern);
		g_strfreev(channels);
	}

	if (stristr(args, "-except") != NULL) {
                rec->except_level = combine_level(rec->except_level, levels);
	} else {
		ignore_split_levels(levels, &rec->level, &rec->except_level);
	}

	rec->pattern = *patternarg == '\0' ? NULL : g_strdup(patternarg);
	rec->regexp = stristr(args, "-regexp") != NULL;
	rec->fullword = stristr(args, "-word") != NULL;
	rec->replies = stristr(args, "-replies") != NULL;

	if (rec->level == 0 && rec->except_level == 0) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED,
			    rec->mask == NULL ? "" : rec->mask);
	} else {
		key = ignore_get_key(rec);
		levels = ignore_get_levels(rec->level, rec->except_level);
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORED, key, levels);
		g_free(key);
		g_free(levels);
	}

	if (new_ignore)
		ignore_add_rec(rec);
	else
		ignore_update_rec(rec);

	g_free(params);
}