/************************************************************************
 *   IRC - Internet Relay Chat, modules/rexcom/r_quarantine.c
 *
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Co Center
 *
 *   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, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "struct.h"
#include "common.h"
#include "chanmode.h"
#include "sys.h"
#include "msg.h"
#include "h.h"
#include "hook.h"

static int do_rexcom_quarantine(struct hook_data *thisdata);

#ifndef STATIC_MODULES

void _modinit(void)
{
    hook_add_hook("load rexcom core module", (hookfn *) do_rexcom_quarantine);
}

void _moddeinit(void)
{
    hook_del_hook("load rexcom core module", (hookfn *) do_rexcom_quarantine);
}

char *_version = "$Revision: 1.3 $";

#else

void r_quarantine_init(void)
{
    hook_add_hook("load rexcom core module", (hookfn *) do_rexcom_quarantine);
}

#endif

static int do_rexcom_quarantine(struct hook_data *thisdata)
{
    int what;
    char k = thisdata->statchar;
    struct MaskItem *ami;

    if ((k != 'Q') && (k != 'q'))
	return 0;

    what = thisdata->check;

    if (what == 1) {
	if ((ami = find_maskitem(thisdata->mask, NULL, MASKITEM_QUARANTINE_REGEX, 1)) == NULL) {
	    ami =
		create_maskitem(thisdata->source_p->name, thisdata->mask, NULL,
				MASKITEM_QUARANTINE_REGEX, 0);
	    DupString(ami->reason, thisdata->data);
	    ireg_merge_pattern(ami, thisdata->len, thisdata->mask);
	    sendto_ops("%s added permanent regular expression quarantine to: %s", thisdata->source_p->name, thisdata->mask);
	}
    } else if (what == 2) {
	terminate_maskitem(thisdata->mask, NULL, MASKITEM_QUARANTINE_REGEX);
	sendto_ops("%s removed regular expression quarantine from: %s", thisdata->source_p->name, thisdata->mask);
    }
    return 1;
}


syntax highlighted by Code2HTML, v. 0.9.1