nickdelay -> dictionary.
This commit is contained in:
parent
3e91d7006f
commit
b37021a45e
|
@ -29,13 +29,16 @@
|
||||||
|
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
|
struct Dictionary;
|
||||||
|
|
||||||
extern dlink_list *clientTable;
|
extern dlink_list *clientTable;
|
||||||
extern dlink_list *channelTable;
|
extern dlink_list *channelTable;
|
||||||
extern dlink_list *idTable;
|
extern dlink_list *idTable;
|
||||||
extern dlink_list *resvTable;
|
extern dlink_list *resvTable;
|
||||||
extern dlink_list *hostTable;
|
extern dlink_list *hostTable;
|
||||||
extern dlink_list *helpTable;
|
extern dlink_list *helpTable;
|
||||||
extern dlink_list *ndTable;
|
|
||||||
|
extern struct Dictionary *nd_dict;
|
||||||
|
|
||||||
/* Magic value for FNV hash functions */
|
/* Magic value for FNV hash functions */
|
||||||
#define FNV1_32_INIT 0x811c9dc5UL
|
#define FNV1_32_INIT 0x811c9dc5UL
|
||||||
|
@ -101,9 +104,6 @@ extern void add_to_help_hash(const char *name, struct cachefile *hptr);
|
||||||
extern void clear_help_hash(void);
|
extern void clear_help_hash(void);
|
||||||
extern struct cachefile *hash_find_help(const char *name, int flags);
|
extern struct cachefile *hash_find_help(const char *name, int flags);
|
||||||
|
|
||||||
extern void add_to_nd_hash(const char *name, struct nd_entry *nd);
|
|
||||||
extern struct nd_entry *hash_find_nd(const char *name);
|
|
||||||
|
|
||||||
extern void hash_stats(struct Client *);
|
extern void hash_stats(struct Client *);
|
||||||
|
|
||||||
#endif /* INCLUDED_hash_h */
|
#endif /* INCLUDED_hash_h */
|
||||||
|
|
|
@ -249,9 +249,6 @@ struct nd_entry
|
||||||
{
|
{
|
||||||
char name[NICKLEN+1];
|
char name[NICKLEN+1];
|
||||||
time_t expire;
|
time_t expire;
|
||||||
unsigned int hashv;
|
|
||||||
|
|
||||||
dlink_node hnode; /* node in hash */
|
|
||||||
dlink_node lnode; /* node in ll */
|
dlink_node lnode; /* node in ll */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ mr_nick(struct Client *client_p, struct Client *source_p, int parc, const char *
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hash_find_nd(nick))
|
if(irc_dictionary_find(nd_dict, nick))
|
||||||
{
|
{
|
||||||
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
|
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
|
||||||
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
|
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
|
||||||
|
@ -217,7 +217,7 @@ m_nick(struct Client *client_p, struct Client *source_p, int parc, const char *p
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hash_find_nd(nick))
|
if(irc_dictionary_find(nd_dict, nick))
|
||||||
{
|
{
|
||||||
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
|
sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
|
||||||
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
|
me.name, EmptyString(source_p->name) ? "*" : source_p->name, nick);
|
||||||
|
@ -890,7 +890,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p,
|
||||||
del_from_client_hash(source_p->name, source_p);
|
del_from_client_hash(source_p->name, source_p);
|
||||||
|
|
||||||
/* invalidate nick delay when a remote client uses the nick.. */
|
/* invalidate nick delay when a remote client uses the nick.. */
|
||||||
if((nd = hash_find_nd(nick)))
|
if((nd = irc_dictionary_retrieve(nd_dict, nick)))
|
||||||
free_nd_entry(nd);
|
free_nd_entry(nd);
|
||||||
|
|
||||||
strcpy(source_p->name, nick);
|
strcpy(source_p->name, nick);
|
||||||
|
@ -1225,7 +1225,7 @@ register_client(struct Client *client_p, struct Client *server,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove any nd entries for this nick */
|
/* remove any nd entries for this nick */
|
||||||
if((nd = hash_find_nd(nick)))
|
if((nd = irc_dictionary_retrieve(nd_dict, nick)))
|
||||||
free_nd_entry(nd);
|
free_nd_entry(nd);
|
||||||
|
|
||||||
add_to_client_hash(nick, source_p);
|
add_to_client_hash(nick, source_p);
|
||||||
|
|
|
@ -259,7 +259,7 @@ me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const c
|
||||||
duration = atoi(parv[1]);
|
duration = atoi(parv[1]);
|
||||||
if (duration <= 0)
|
if (duration <= 0)
|
||||||
{
|
{
|
||||||
nd = hash_find_nd(parv[2]);
|
nd = irc_dictionary_retrieve(nd_dict, parv[2]);
|
||||||
if (nd != NULL)
|
if (nd != NULL)
|
||||||
free_nd_entry(nd);
|
free_nd_entry(nd);
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const c
|
||||||
if (duration > 86400)
|
if (duration > 86400)
|
||||||
duration = 86400;
|
duration = 86400;
|
||||||
add_nd_entry(parv[2]);
|
add_nd_entry(parv[2]);
|
||||||
nd = hash_find_nd(parv[2]);
|
nd = irc_dictionary_retrieve(nd_dict, parv[2]);
|
||||||
if (nd != NULL)
|
if (nd != NULL)
|
||||||
nd->expire = CurrentTime + duration;
|
nd->expire = CurrentTime + duration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,16 +259,13 @@ static void
|
||||||
stats_delay(struct Client *source_p)
|
stats_delay(struct Client *source_p)
|
||||||
{
|
{
|
||||||
struct nd_entry *nd;
|
struct nd_entry *nd;
|
||||||
dlink_node *ptr;
|
struct DictionaryIter iter;
|
||||||
int i;
|
|
||||||
|
|
||||||
HASH_WALK(i, U_MAX, ptr, ndTable)
|
DICTIONARY_FOREACH(nd, &iter, nd_dict)
|
||||||
{
|
{
|
||||||
nd = ptr->data;
|
|
||||||
sendto_one_notice(source_p, "Delaying: %s for %ld",
|
sendto_one_notice(source_p, "Delaying: %s for %ld",
|
||||||
nd->name, (long) nd->expire);
|
nd->name, (long) nd->expire);
|
||||||
}
|
}
|
||||||
HASH_WALK_END
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
/*
|
/*
|
||||||
* ircd-ratbox: A slightly useful ircd.
|
* charybdis: an advanced ircd.
|
||||||
* client.c: Controls clients.
|
* client.c: Controls clients.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
||||||
* Copyright (C) 1996-2002 Hybrid Development Team
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
||||||
* Copyright (C) 2002-2005 ircd-ratbox development team
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
||||||
|
* Copyright (C) 2007 William Pitcock
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -60,6 +61,7 @@
|
||||||
#include "blacklist.h"
|
#include "blacklist.h"
|
||||||
#include "reject.h"
|
#include "reject.h"
|
||||||
#include "scache.h"
|
#include "scache.h"
|
||||||
|
#include "irc_dictionary.h"
|
||||||
|
|
||||||
#define DEBUG_EXITED_CLIENTS
|
#define DEBUG_EXITED_CLIENTS
|
||||||
|
|
||||||
|
|
32
src/hash.c
32
src/hash.c
|
@ -47,7 +47,6 @@ dlink_list *idTable;
|
||||||
dlink_list *resvTable;
|
dlink_list *resvTable;
|
||||||
dlink_list *hostTable;
|
dlink_list *hostTable;
|
||||||
dlink_list *helpTable;
|
dlink_list *helpTable;
|
||||||
dlink_list *ndTable;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* look in whowas.c for the missing ...[WW_MAX]; entry
|
* look in whowas.c for the missing ...[WW_MAX]; entry
|
||||||
|
@ -95,7 +94,6 @@ init_hash(void)
|
||||||
{
|
{
|
||||||
clientTable = MyMalloc(sizeof(dlink_list) * U_MAX);
|
clientTable = MyMalloc(sizeof(dlink_list) * U_MAX);
|
||||||
idTable = MyMalloc(sizeof(dlink_list) * U_MAX);
|
idTable = MyMalloc(sizeof(dlink_list) * U_MAX);
|
||||||
ndTable = MyMalloc(sizeof(dlink_list) * U_MAX);
|
|
||||||
channelTable = MyMalloc(sizeof(dlink_list) * CH_MAX);
|
channelTable = MyMalloc(sizeof(dlink_list) * CH_MAX);
|
||||||
hostTable = MyMalloc(sizeof(dlink_list) * HOST_MAX);
|
hostTable = MyMalloc(sizeof(dlink_list) * HOST_MAX);
|
||||||
resvTable = MyMalloc(sizeof(dlink_list) * R_MAX);
|
resvTable = MyMalloc(sizeof(dlink_list) * R_MAX);
|
||||||
|
@ -306,13 +304,6 @@ add_to_help_hash(const char *name, struct cachefile *hptr)
|
||||||
dlinkAddAlloc(hptr, &helpTable[hashv]);
|
dlinkAddAlloc(hptr, &helpTable[hashv]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
add_to_nd_hash(const char *name, struct nd_entry *nd)
|
|
||||||
{
|
|
||||||
nd->hashv = hash_nick(name);
|
|
||||||
dlinkAdd(nd, &nd->hnode, &ndTable[nd->hashv]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* del_from_id_hash()
|
/* del_from_id_hash()
|
||||||
*
|
*
|
||||||
* removes an id from the id hash table
|
* removes an id from the id hash table
|
||||||
|
@ -733,29 +724,6 @@ clear_resv_hash(void)
|
||||||
HASH_WALK_END
|
HASH_WALK_END
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nd_entry *
|
|
||||||
hash_find_nd(const char *name)
|
|
||||||
{
|
|
||||||
struct nd_entry *nd;
|
|
||||||
dlink_node *ptr;
|
|
||||||
unsigned int hashv;
|
|
||||||
|
|
||||||
if(EmptyString(name))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
hashv = hash_nick(name);
|
|
||||||
|
|
||||||
DLINK_FOREACH(ptr, ndTable[hashv].head)
|
|
||||||
{
|
|
||||||
nd = ptr->data;
|
|
||||||
|
|
||||||
if(!irccmp(name, nd->name))
|
|
||||||
return nd;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest)
|
output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "balloc.h"
|
#include "balloc.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "sprintf_irc.h"
|
#include "sprintf_irc.h"
|
||||||
|
#include "irc_dictionary.h"
|
||||||
|
|
||||||
dlink_list shared_conf_list;
|
dlink_list shared_conf_list;
|
||||||
dlink_list cluster_conf_list;
|
dlink_list cluster_conf_list;
|
||||||
|
@ -744,13 +745,17 @@ get_nd_count(void)
|
||||||
return(dlink_list_length(&nd_list));
|
return(dlink_list_length(&nd_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Dictionary *nd_dict = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
add_nd_entry(const char *name)
|
add_nd_entry(const char *name)
|
||||||
{
|
{
|
||||||
struct nd_entry *nd;
|
struct nd_entry *nd;
|
||||||
|
|
||||||
if(hash_find_nd(name) != NULL)
|
if(nd_dict == NULL)
|
||||||
|
nd_dict = irc_dictionary_create(irccmp);
|
||||||
|
|
||||||
|
if(irc_dictionary_find(nd_dict, name) != NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nd = BlockHeapAlloc(nd_heap);
|
nd = BlockHeapAlloc(nd_heap);
|
||||||
|
@ -760,14 +765,16 @@ add_nd_entry(const char *name)
|
||||||
|
|
||||||
/* this list is ordered */
|
/* this list is ordered */
|
||||||
dlinkAddTail(nd, &nd->lnode, &nd_list);
|
dlinkAddTail(nd, &nd->lnode, &nd_list);
|
||||||
add_to_nd_hash(name, nd);
|
|
||||||
|
irc_dictionary_add(nd_dict, nd->name, nd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
free_nd_entry(struct nd_entry *nd)
|
free_nd_entry(struct nd_entry *nd)
|
||||||
{
|
{
|
||||||
|
irc_dictionary_delete(nd_dict, nd->name);
|
||||||
|
|
||||||
dlinkDelete(&nd->lnode, &nd_list);
|
dlinkDelete(&nd->lnode, &nd_list);
|
||||||
dlinkDelete(&nd->hnode, &ndTable[nd->hashv]);
|
|
||||||
BlockHeapFree(nd_heap, nd);
|
BlockHeapFree(nd_heap, nd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue