/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_hash.c
 *
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Co Center
 *
 *   See file AUTHORS in IRC package for additional names of
 *   the programmers.
 *
 *   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.
 */

/*
 * $Id: m_hash.c,v 1.4 2003/06/14 13:55:51 tr-ircd Exp $ 
 */

#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include "h.h"
#include "s_conf.h"

static struct Message _msgtab[] = {
    {MSG_HASH, 0, MAXPARA, M_SLOW, 0L,
     m_unregistered, m_permission, m_hash, m_hash, m_ignore}
};

static char *token = TOK1_HASH;

#ifndef STATIC_MODULES

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

void _modinit(void)
{
    mod_add_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = _msgtab;
}

void _moddeinit(void)
{
    mod_del_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = NULL;
}
#else
void m_hash_init(void)
{
    mod_add_cmd(_msgtab);
    tok1_msgtab[(u_char) *token].msg = _msgtab;
}
#endif

typedef struct {
    char *name;
    char **array;
} HashItem;

static HashItem hlist[] = {
    {"SERVER", serversums },
    {"SYSTEM", srcsums },
    {"MODULES", modulessums },
    {"PROTOCOL", protocolsums },
    {"CMODES", chanmodessums },
    {"INCLUDES", includesums },
    {"LOGSYSTEM", logsystemsums },
    {"I-UPDATE", iupdtsums },
    {"PROXYMON", proxymonsums },
    {"HTTPD", httpdsums },
    {"ULIMIT", ulimit_result },
    {"UNAME", uname_result },
    {NULL},
};

/*
 * * m_hash 
 *      parv[0] = sender prefix 
 *      parv[1] = servername
 *      parv[2] = type
 */
int m_hash(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    char **text;

    if (parc < 2) {
	send_me_numeric(sptr, ERR_NEEDMOREPARAMS, MSG_HASH);
	return 0;
    }

    if (hunt_server(cptr, sptr, ":%s %s %s %s", TOK1_HASH, 2, parc, parv) == HUNTED_ISME) {

    int i, j;

	if (irc_strcmp(parv[1], "HELP") == 0) {
            send_me_notice(sptr, ":Hash elements");
            for (j = 0; hlist[j].name; j++)
                send_me_notice(sptr, ":%s", hlist[j].name);
        }

        for (i = 0; hlist[i].name; i++) {
            if (irc_strcmp(parv[1], hlist[i].name) == 0) {
		text = hlist[i].array;
                while (*text)
                    send_me_numeric(sptr, RPL_INFO, *text++);
                send_me_numeric(sptr, RPL_ENDOFHASH);
		logevent_call(LogSys.operevent, MSG_HASH, sptr, &parv, parc);
            }
	}
    }

    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1