Esempio n. 1
0
int quitmsg_is_split(const char *msg)
{
	char *params, *host1, *host2, *p;
	int ok;

	g_return_val_if_fail(msg != NULL, FALSE);

	/* must have only two words */
	p = strchr(msg, ' ');
	if (p == NULL || strchr(p+1, ' ') != NULL) return FALSE;

	/* check that it looks ok.. */
	if (!match_wildcards("*.* *.*", msg) ||
	    match_wildcards("*..*", msg) || strstr(msg, "))") != NULL)
		return FALSE;

	/* get the two hosts */
	ok = FALSE;
	params = cmd_get_params(msg, 2 | PARAM_FLAG_NOQUOTES, &host1, &host2);
	if (g_strcasecmp(host1, host2) != 0) { /* hosts can't be same.. */
		/* check that domain length is 2 or 3 */
		p = strrchr(host1, '.');
		if (p != NULL && (strlen(p+1) == 2 || strlen(p+1) == 3)) {
			p = strrchr(host2, '.');
			if (p != NULL && (strlen(p+1) == 2 || strlen(p+1) == 3)) {
				/* it looks just like a netsplit to me. */
				ok = TRUE;
			}
		}
	}
	g_free(params);

	return ok;
}
Esempio n. 2
0
File: nicklist.c Progetto: GPF/irssi
/* Find nick mask, wildcards allowed */
NICK_REC *nicklist_find_mask(CHANNEL_REC *channel, const char *mask)
{
	NICK_REC *nickrec;
	char *nick, *host;

	g_return_val_if_fail(IS_CHANNEL(channel), NULL);
	g_return_val_if_fail(mask != NULL, NULL);

	nick = g_strdup(mask);
	host = strchr(nick, '!');
	if (host != NULL) *host++ = '\0';

	if (strchr(nick, '*') || strchr(nick, '?')) {
		g_free(nick);
		return nicklist_find_wildcards(channel, mask);
	}

	nickrec = g_hash_table_lookup(channel->nicks, nick);

	if (host != NULL) {
		while (nickrec != NULL) {
			if (nickrec->host != NULL &&
			    match_wildcards(host, nickrec->host))
				break; /* match */
			nickrec = nickrec->next;
		}
	}
	g_free(nick);
	return nickrec;
}
Esempio n. 3
0
static void hilight_nick_cache(GHashTable *list, CHANNEL_REC *channel,
                               NICK_REC *nick)
{
    GSList *tmp;
    HILIGHT_REC *match;
    char *nickmask;
    int len, best_match;

    if (nick->host == NULL)
        return; /* don't check until host is known */

    nickmask = g_strconcat(nick->nick, "!", nick->host, NULL);

    best_match = 0;
    match = NULL;
    for (tmp = hilights; tmp != NULL; tmp = tmp->next) {
        HILIGHT_REC *rec = tmp->data;

        if (rec->nickmask &&
                hilight_match_channel(rec, channel->name) &&
                match_wildcards(rec->text, nickmask)) {
            len = strlen(rec->text);
            if (best_match < len) {
                best_match = len;
                match = rec;
            }
        }
    }
    g_free_not_null(nickmask);

    if (match != NULL)
        g_hash_table_insert(list, nick, match);
}
Esempio n. 4
0
/* Find nick record from list */
NICK_REC *nicklist_find(CHANNEL_REC *channel, const char *mask)
{
	NICK_REC *nickrec;
	char *nick, *host;

	g_return_val_if_fail(channel != NULL, NULL);
	g_return_val_if_fail(mask != NULL, NULL);

	nick = g_strdup(mask);
	host = strchr(nick, '!');
	if (host != NULL) *host++ = '\0';

	if (strchr(nick, '*') || strchr(nick, '?')) {
		g_free(nick);
		return nicklist_find_wildcards(channel, mask);
	}

	nickrec = g_hash_table_lookup(channel->nicks, nick);

	if (nickrec != NULL && host != NULL &&
	    (nickrec->host == NULL || !match_wildcards(host, nickrec->host))) {
                /* hosts didn't match */
		nickrec = NULL;
	}
	g_free(nick);
	return nickrec;
}
Esempio n. 5
0
void ban_remove(IRC_CHANNEL_REC *channel, const char *bans)
{
	GString *str;
	GSList *tmp;
	char **ban, **banlist;

	g_return_if_fail(bans != NULL);

	str = g_string_new(NULL);
	banlist = g_strsplit(bans, " ", -1);
	for (ban = banlist; *ban != NULL; ban++) {
		for (tmp = channel->banlist; tmp != NULL; tmp = tmp->next) {
			BAN_REC *rec = tmp->data;

			if (match_wildcards(*ban, rec->ban))
				g_string_sprintfa(str, "%s ", rec->ban);
		}
	}
	g_strfreev(banlist);

	if (str->len > 0)
		channel_set_singlemode(channel->server, channel->name,
				       str->str, "-b");
	g_string_free(str, TRUE);
}
Esempio n. 6
0
char *hilight_match(const char *channel, const char *nickmask, int level, const char *str)
{
	GSList *tmp;
	const char *color;
	char number[MAX_INT_STRLEN];
	int len, best_match, colornum;

	g_return_val_if_fail(str != NULL, NULL);

	color = NULL; best_match = 0;
	for (tmp = hilights; tmp != NULL; tmp = tmp->next) {
		HILIGHT_REC *rec = tmp->data;

		if ((level & (rec->level > 0 ? rec->level : DEFAULT_HILIGHT_LEVEL)) == 0)
                        continue;
		if (!rec->nick && nickmask != NULL)
                        continue;
		if (rec->channels != NULL && (channel == NULL || strarray_find(rec->channels, channel) == -1))
			continue;
		if (rec->nickmask) {
			if (nickmask == NULL || !match_wildcards(rec->text, nickmask))
				continue;
		} else if (rec->regexp) {
			if (!regexp_match(str, rec->text))
				continue;
		} else if (rec->fullword) {
			if (stristr_full(str, rec->text) == NULL)
				continue;
		} else {
			if (stristr(str, rec->text) == NULL)
				continue;
		}

		len = strlen(rec->text);
		if (best_match < len) {
			best_match = len;
			color = rec->color;
		}
	}

	if (best_match == 0)
		return NULL;

	if (color == NULL) color = settings_get_str("hilight_color");
	if (isalpha((int) *color)) {
		/* color was specified with it's name - try to convert it */
		colornum = mirc_color_name(color);
		if (colornum <= 0) colornum = 16;

		ltoa(number, colornum);
		color = number;
	}
	return g_strconcat(isdigit(*color) ? "\003" : "", color, NULL);
}
Esempio n. 7
0
File: masks.c Progetto: irssi/irssi
static int check_mask(SERVER_REC *server, const char *mask,
		      const char *str, int wildcards)
{
	if (server != NULL && server->mask_match_func != NULL) {
		/* use server specified mask match function */
		return server->mask_match_func(mask, str);
	}

	return wildcards ? match_wildcards(mask, str) :
		g_ascii_strcasecmp(mask, str) == 0;
}
Esempio n. 8
0
BOT_DOWNLINK_REC *bot_downlink_find(BOTNET_REC *botnet, IPADDR *ip, const char *host)
{
	GSList *tmp, *tmp2;
	char ipname[MAX_IP_LEN];

	g_return_val_if_fail(botnet != NULL, NULL);
	g_return_val_if_fail(ip != NULL, NULL);

	net_ip2host(ip, ipname);

	for (tmp = botnet->downlinks; tmp != NULL; tmp = tmp->next) {
		BOT_DOWNLINK_REC *rec = tmp->data;

		for (tmp2 = rec->valid_addrs; tmp2 != NULL; tmp2 = tmp2->next) {
			if (match_wildcards(tmp2->data, ipname))
				return rec;
			if (match_wildcards(tmp2->data, host) &&
			    !is_ip_mask(tmp2->data))
				return rec;
		}
	}

	return NULL;
}
Esempio n. 9
0
File: bans.c Progetto: irssi/irssi
void ban_remove(IRC_CHANNEL_REC *channel, const char *bans)
{
	GString *str;
	GSList *tmp;
	BAN_REC *rec;
	char **ban, **banlist;
        int found;

	g_return_if_fail(bans != NULL);

	str = g_string_new(NULL);
	banlist = g_strsplit(bans, " ", -1);
	for (ban = banlist; *ban != NULL; ban++) {
                found = FALSE;
		for (tmp = channel->banlist; tmp != NULL; tmp = tmp->next) {
			rec = tmp->data;

			if (match_wildcards(*ban, rec->ban)) {
				g_string_append_printf(str, "%s ", rec->ban);
                                found = TRUE;
			}
		}

		if (!found) {
			rec = NULL;
			if (!g_ascii_strcasecmp(*ban, BAN_LAST)) {
				/* unnbanning last set ban */
				rec = g_slist_nth_data(channel->banlist,
							g_slist_length(channel->banlist) - 1);
			}
			else if (is_numeric(*ban, '\0')) {
				/* unbanning with ban# */
				rec = g_slist_nth_data(channel->banlist,
							atoi(*ban)-1);
			}
			if (rec != NULL)
				g_string_append_printf(str, "%s ", rec->ban);
			else if (!channel->synced)
				g_warning("channel %s is not synced", channel->name);
		}
	}
	g_strfreev(banlist);

	if (str->len > 0)
		channel_set_singlemode(channel, str->str, "-b");
	g_string_free(str, TRUE);
}
Esempio n. 10
0
static char *special_history_func(const char *text, void *item, int *free_ret)
{
	WINDOW_REC *window;
	GList *tmp;
        char *findtext, *ret;

	window = item == NULL ? active_win : window_item_window(item);

	findtext = g_strdup_printf("*%s*", text);
	ret = NULL;

	tmp = window_history ? window->cmdhist : cmdhist;
	for (; tmp != NULL; tmp = tmp->next) {
		const char *line = tmp->data;

		if (match_wildcards(findtext, line)) {
			*free_ret = TRUE;
                        ret = g_strdup(line);
		}
	}
	g_free(findtext);

	return ret;
}
Esempio n. 11
0
int ignore_check(IRC_SERVER_REC *server, const char *nick, const char *host,
		 const char *channel, const char *text, int level)
{
	GSList *tmp;
	int ok, mask_len, patt_len;
	int best_mask, best_patt, best_ignore;

	g_return_val_if_fail(server != NULL, 0);

	best_mask = 0; best_patt = 0; best_ignore = FALSE;
	for (tmp = ignores; tmp != NULL; tmp = tmp->next) {
		IGNORE_REC *rec = tmp->data;

		if ((level & (rec->level|rec->except_level)) == 0)
			continue;

		/* server */
		if (rec->servertag != NULL && g_strcasecmp(server->tag, rec->servertag) != 0)
			continue;

		/* channel list */
		if (rec->channels != NULL) {
			if (channel == NULL || !ischannel(*channel))
				continue;
			if (strarray_find(rec->channels, channel) == -1)
				continue;
		}

		/* nick mask */
		mask_len = 0;
		if (rec->mask != NULL) {
			if (nick == NULL)
				continue;

			mask_len = strlen(rec->mask);
			if (mask_len <= best_mask) continue;

			ok = ((host == NULL || *host == '\0')) ?
				match_wildcards(rec->mask, nick) :
				irc_mask_match_address(rec->mask, nick, host);
			if (!ok) {
                                /* nick didn't match, but maybe this is a reply to nick? */
				if (!rec->replies || channel == NULL || text == NULL ||
				    !ignore_check_replies(rec, server, channel, text))
					continue;
			}
		}

		/* pattern */
		patt_len = 0;
		if (rec->pattern != NULL) {
			if (!mask_len && !best_mask) {
				patt_len = strlen(rec->pattern);
				if (patt_len <= best_patt) continue;
			}

			ok = rec->regexp ? regexp_match(text, rec->pattern) :
				rec->fullword ? stristr_full(text, rec->pattern) != NULL :
				stristr(text, rec->pattern) != NULL;
			if (!ok) continue;
		}

		if (mask_len || best_mask)
			best_mask = mask_len;
		else if (patt_len)
			best_patt = patt_len;

		best_ignore = (rec->level & level) != 0;
	}

	return best_ignore;
}