/* X-Chat * Copyright (C) 1998 Peter Zelezny. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include #include #include #include #include #ifdef WIN32 #include #else #include #endif #include "hexchat.h" #include "ignore.h" #include "cfgfiles.h" #include "fe.h" #include "text.h" #include "util.h" #include "hexchatc.h" #include "typedef.h" int ignored_ctcp = 0; /* keep a count of all we ignore */ int ignored_priv = 0; int ignored_chan = 0; int ignored_noti = 0; int ignored_invi = 0; static int ignored_total = 0; /* ignore_exists (): * returns: struct ig, if this mask is in the ignore list already * NULL, otherwise */ struct ignore * ignore_exists (char *mask) { struct ignore *ig = NULL; GSList *list; list = ignore_list; while (list) { ig = (struct ignore *) list->data; if (!rfc_casecmp (ig->mask, mask)) return ig; list = list->next; } return NULL; } /* ignore_add(...) * returns: * 0 fail * 1 success * 2 success (old ignore has been changed) */ int ignore_add (char *mask, int type, gboolean overwrite) { struct ignore *ig = NULL; int change_only = FALSE; /* first check if it's already ignored */ ig = ignore_exists (mask); if (ig) change_only = TRUE; if (!change_only) ig = g_new (struct ignore, 1); ig->mask = g_strdup (mask); if (!overwrite && change_only) ig->type |= type; else ig->type = type; if (!change_only) ignore_list = g_slist_prepend (ignore_list, ig); fe_ignore_update (1); if (change_only) return 2; return 1; } void ignore_showlist (session *sess) { struct ignore *ig; GSList *list = ignore_list; char tbuf[256]; int i = 0; EMIT_SIGNAL (XP_TE_IGNOREHEADER, sess, 0, 0, 0, 0, 0); while (list) { ig = list->data; i++; g_snprintf (tbuf, sizeof (tbuf), " %-25s ", ig->mask); if (ig->type & IG_PRIV) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); if (ig->type & IG_NOTI) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); if (ig->type & IG_CHAN) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); if (ig->type & IG_CTCP) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); if (ig->type & IG_DCC) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); if (ig->type & IG_INVI) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); if (ig->type & IG_UNIG) strcat (tbuf, _("YES ")); else strcat (tbuf, _("NO ")); strcat (tbuf, "\n"); PrintText (sess, tbuf); /*EMIT_SIGNAL (XP_TE_IGNORELIST, sess, ig->mask, 0, 0, 0, 0); */ /* use this later, when TE's support 7 args */ list = list->next; } if (!i) EMIT_SIGNAL (XP_TE_IGNOREEMPTY, sess, 0, 0, 0, 0, 0); EMIT_SIGNAL (XP_TE_IGNOREFOOTER, sess, 0, 0, 0, 0, 0); } /* ignore_del() * one of the args must be NULL, use mask OR *ig, not both * */ int ignore_del (char *mask, struct ignore *ig) { if (!ig) { GSList *list = ignore_list; while (list) { ig = (struct ignore *) list->data; if (!rfc_casecmp (ig->mask, mask)) break; list = list->next; ig = 0; } } if (ig) { ignore_list = g_slist_remove (ignore_list, ig); g_free (ig->mask); g_free (ig); fe_ignore_update (1); return TRUE; } return FALSE; } /* check if a msg should be ignored by browsing our ignore list */ int ignore_check (char *host, int type) { struct ignore *ig; GSList *list = ignore_list; /* check if there's an UNIGNORE first, they take precendance. */ while (list) { ig = (struct ignore *) list->data; if (ig->type & IG_UNIG) { if (ig->type & type) { if (match (ig->mask, host))