| 23 |
|
*/ |
| 24 |
|
|
| 25 |
|
#include "stdinc.h" |
| 26 |
< |
#include "tools.h" |
| 27 |
< |
#include "s_conf.h" |
| 26 |
> |
#include "list.h" |
| 27 |
> |
#include "balloc.h" |
| 28 |
> |
#include "conf.h" |
| 29 |
|
#include "channel.h" |
| 30 |
|
#include "channel_mode.h" |
| 31 |
|
#include "client.h" |
| 31 |
– |
#include "common.h" |
| 32 |
– |
#include "handlers.h" |
| 33 |
– |
#include "list.h" |
| 32 |
|
#include "modules.h" |
| 33 |
|
#include "hash.h" |
| 34 |
|
#include "resv.h" |
| 35 |
+ |
#include "rng_mt.h" |
| 36 |
|
#include "userhost.h" |
| 37 |
|
#include "irc_string.h" |
| 38 |
|
#include "ircd.h" |
| 47 |
|
static BlockHeap *namehost_heap = NULL; |
| 48 |
|
static struct UserHost *find_or_add_userhost(const char *); |
| 49 |
|
|
| 50 |
< |
static unsigned int ircd_random_key = 0; |
| 50 |
> |
static unsigned int hashf_xor_key = 0; |
| 51 |
|
|
| 52 |
|
/* The actual hash tables, They MUST be of the same HASHSIZE, variable |
| 53 |
|
* size tables could be supported but the rehash routine should also |
| 80 |
|
userhost_heap = BlockHeapCreate("userhost", sizeof(struct UserHost), CLIENT_HEAP_SIZE); |
| 81 |
|
namehost_heap = BlockHeapCreate("namehost", sizeof(struct NameHost), CLIENT_HEAP_SIZE); |
| 82 |
|
|
| 83 |
< |
ircd_random_key = rand() % 256; /* better than nothing --adx */ |
| 85 |
< |
|
| 86 |
< |
/* Clear the hash tables first */ |
| 87 |
< |
for (i = 0; i < HASHSIZE; ++i) |
| 88 |
< |
{ |
| 89 |
< |
idTable[i] = NULL; |
| 90 |
< |
clientTable[i] = NULL; |
| 91 |
< |
channelTable[i] = NULL; |
| 92 |
< |
userhostTable[i] = NULL; |
| 93 |
< |
resvchannelTable[i] = NULL; |
| 94 |
< |
} |
| 83 |
> |
hashf_xor_key = genrand_int32() % 256; /* better than nothing --adx */ |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
/* |
| 102 |
|
{ |
| 103 |
|
hval += (hval << 1) + (hval << 4) + (hval << 7) + |
| 104 |
|
(hval << 8) + (hval << 24); |
| 105 |
< |
hval ^= (ToLower(*p) ^ ircd_random_key); |
| 105 |
> |
hval ^= (ToLower(*p) ^ hashf_xor_key); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
< |
return (hval >> FNV1_32_BITS) ^ (hval & ((1 << FNV1_32_BITS) -1)); |
| 108 |
> |
return (hval >> FNV1_32_BITS) ^ (hval & ((1 << FNV1_32_BITS) - 1)); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
/************************** Externally visible functions ********************/ |
| 204 |
|
else |
| 205 |
|
{ |
| 206 |
|
while (tmp->idhnext != client_p) |
| 218 |
– |
{ |
| 207 |
|
if ((tmp = tmp->idhnext) == NULL) |
| 208 |
|
return; |
| 221 |
– |
} |
| 209 |
|
|
| 210 |
|
tmp->idhnext = tmp->idhnext->idhnext; |
| 211 |
|
client_p->idhnext = client_p; |
| 235 |
|
else |
| 236 |
|
{ |
| 237 |
|
while (tmp->hnext != client_p) |
| 251 |
– |
{ |
| 238 |
|
if ((tmp = tmp->hnext) == NULL) |
| 239 |
|
return; |
| 254 |
– |
} |
| 240 |
|
|
| 241 |
|
tmp->hnext = tmp->hnext->hnext; |
| 242 |
|
client_p->hnext = client_p; |
| 266 |
|
else |
| 267 |
|
{ |
| 268 |
|
while (tmp->next != userhost) |
| 284 |
– |
{ |
| 269 |
|
if ((tmp = tmp->next) == NULL) |
| 270 |
|
return; |
| 287 |
– |
} |
| 271 |
|
|
| 272 |
|
tmp->next = tmp->next->next; |
| 273 |
|
userhost->next = userhost; |
| 298 |
|
else |
| 299 |
|
{ |
| 300 |
|
while (tmp->hnextch != chptr) |
| 318 |
– |
{ |
| 301 |
|
if ((tmp = tmp->hnextch) == NULL) |
| 302 |
|
return; |
| 321 |
– |
} |
| 303 |
|
|
| 304 |
|
tmp->hnextch = tmp->hnextch->hnextch; |
| 305 |
|
chptr->hnextch = chptr; |
| 323 |
|
else |
| 324 |
|
{ |
| 325 |
|
while (tmp->hnext != chptr) |
| 345 |
– |
{ |
| 326 |
|
if ((tmp = tmp->hnext) == NULL) |
| 327 |
|
return; |
| 348 |
– |
} |
| 328 |
|
|
| 329 |
|
tmp->hnext = tmp->hnext->hnext; |
| 330 |
|
chptr->hnext = chptr; |
| 332 |
|
} |
| 333 |
|
} |
| 334 |
|
|
| 335 |
< |
/* find_client() |
| 335 |
> |
/* hash_find_client() |
| 336 |
|
* |
| 337 |
|
* inputs - pointer to name |
| 338 |
|
* output - NONE |
| 341 |
|
* it to the top of the list and returns it. |
| 342 |
|
*/ |
| 343 |
|
struct Client * |
| 344 |
< |
find_client(const char *name) |
| 344 |
> |
hash_find_client(const char *name) |
| 345 |
|
{ |
| 346 |
|
unsigned int hashv = strhash(name); |
| 347 |
|
struct Client *client_p; |
| 376 |
|
|
| 377 |
|
if ((client_p = idTable[hashv]) != NULL) |
| 378 |
|
{ |
| 379 |
< |
if (irccmp(name, client_p->id)) |
| 379 |
> |
if (strcmp(name, client_p->id)) |
| 380 |
|
{ |
| 381 |
|
struct Client *prev; |
| 382 |
|
|
| 383 |
|
while (prev = client_p, (client_p = client_p->idhnext) != NULL) |
| 384 |
|
{ |
| 385 |
< |
if (!irccmp(name, client_p->id)) |
| 385 |
> |
if (!strcmp(name, client_p->id)) |
| 386 |
|
{ |
| 387 |
|
prev->idhnext = client_p->idhnext; |
| 388 |
|
client_p->idhnext = idTable[hashv]; |
| 396 |
|
return client_p; |
| 397 |
|
} |
| 398 |
|
|
| 420 |
– |
/* |
| 421 |
– |
* Whats happening in this next loop ? Well, it takes a name like |
| 422 |
– |
* foo.bar.edu and proceeds to earch for *.edu and then *.bar.edu. |
| 423 |
– |
* This is for checking full server names against masks although |
| 424 |
– |
* it isnt often done this way in lieu of using matches(). |
| 425 |
– |
* |
| 426 |
– |
* Rewrote to do *.bar.edu first, which is the most likely case, |
| 427 |
– |
* also made const correct |
| 428 |
– |
* --Bleep |
| 429 |
– |
*/ |
| 430 |
– |
static struct Client * |
| 431 |
– |
hash_find_masked_server(const char *name) |
| 432 |
– |
{ |
| 433 |
– |
char buf[HOSTLEN + 1]; |
| 434 |
– |
char *p = buf; |
| 435 |
– |
char *s = NULL; |
| 436 |
– |
struct Client *server = NULL; |
| 437 |
– |
|
| 438 |
– |
if (*name == '*' || *name == '.') |
| 439 |
– |
return NULL; |
| 440 |
– |
|
| 441 |
– |
/* |
| 442 |
– |
* copy the damn thing and be done with it |
| 443 |
– |
*/ |
| 444 |
– |
strlcpy(buf, name, sizeof(buf)); |
| 445 |
– |
|
| 446 |
– |
while ((s = strchr(p, '.')) != NULL) |
| 447 |
– |
{ |
| 448 |
– |
*--s = '*'; |
| 449 |
– |
|
| 450 |
– |
/* Dont need to check IsServer() here since nicknames cant |
| 451 |
– |
* have *'s in them anyway. |
| 452 |
– |
*/ |
| 453 |
– |
if ((server = find_client(s)) != NULL) |
| 454 |
– |
return server; |
| 455 |
– |
p = s + 2; |
| 456 |
– |
} |
| 457 |
– |
|
| 458 |
– |
return NULL; |
| 459 |
– |
} |
| 460 |
– |
|
| 399 |
|
struct Client * |
| 400 |
< |
find_server(const char *name) |
| 400 |
> |
hash_find_server(const char *name) |
| 401 |
|
{ |
| 402 |
|
unsigned int hashv = strhash(name); |
| 403 |
|
struct Client *client_p = NULL; |
| 426 |
|
} |
| 427 |
|
} |
| 428 |
|
|
| 429 |
< |
return (client_p != NULL) ? client_p : hash_find_masked_server(name); |
| 429 |
> |
return client_p; |
| 430 |
|
} |
| 431 |
|
|
| 432 |
|
/* hash_find_channel() |
| 835 |
|
*/ |
| 836 |
|
static void |
| 837 |
|
list_one_channel(struct Client *source_p, struct Channel *chptr, |
| 838 |
< |
struct ListTask *list_task, int remote_request) |
| 838 |
> |
struct ListTask *list_task) |
| 839 |
|
{ |
| 840 |
< |
if ((remote_request && chptr->chname[0] == '&') || |
| 903 |
< |
(SecretChannel(chptr) && !IsMember(source_p, chptr))) |
| 840 |
> |
if (SecretChannel(chptr) && !IsMember(source_p, chptr)) |
| 841 |
|
return; |
| 842 |
< |
if ((unsigned int)dlink_list_length(&chptr->members) < list_task->users_min || |
| 843 |
< |
(unsigned int)dlink_list_length(&chptr->members) > list_task->users_max || |
| 842 |
> |
if (dlink_list_length(&chptr->members) < list_task->users_min || |
| 843 |
> |
dlink_list_length(&chptr->members) > list_task->users_max || |
| 844 |
|
(chptr->channelts != 0 && |
| 845 |
|
((unsigned int)chptr->channelts < list_task->created_min || |
| 846 |
|
(unsigned int)chptr->channelts > list_task->created_max)) || |
| 853 |
|
return; |
| 854 |
|
sendto_one(source_p, form_str(RPL_LIST), me.name, source_p->name, |
| 855 |
|
chptr->chname, dlink_list_length(&chptr->members), |
| 856 |
< |
chptr->topic == NULL ? "" : chptr->topic); |
| 856 |
> |
chptr->topic); |
| 857 |
|
} |
| 858 |
|
|
| 859 |
|
/* safe_list_channels() |
| 872 |
|
*/ |
| 873 |
|
void |
| 874 |
|
safe_list_channels(struct Client *source_p, struct ListTask *list_task, |
| 875 |
< |
int only_unmasked_channels, int remote_request) |
| 875 |
> |
int only_unmasked_channels) |
| 876 |
|
{ |
| 877 |
|
struct Channel *chptr = NULL; |
| 878 |
|
|
| 879 |
|
if (!only_unmasked_channels) |
| 880 |
|
{ |
| 881 |
< |
int i; |
| 881 |
> |
unsigned int i; |
| 882 |
|
|
| 883 |
< |
for (i = list_task->hash_index; i < HASHSIZE; i++) |
| 883 |
> |
for (i = list_task->hash_index; i < HASHSIZE; ++i) |
| 884 |
|
{ |
| 885 |
|
if (exceeding_sendq(source_p->from)) |
| 886 |
|
{ |
| 887 |
|
list_task->hash_index = i; |
| 888 |
< |
return; /* still more to do */ |
| 888 |
> |
return; /* still more to do */ |
| 889 |
|
} |
| 890 |
|
|
| 891 |
|
for (chptr = channelTable[i]; chptr; chptr = chptr->hnextch) |
| 892 |
< |
list_one_channel(source_p, chptr, list_task, remote_request); |
| 892 |
> |
list_one_channel(source_p, chptr, list_task); |
| 893 |
|
} |
| 894 |
|
} |
| 895 |
|
else |
| 898 |
|
|
| 899 |
|
DLINK_FOREACH(dl, list_task->show_mask.head) |
| 900 |
|
if ((chptr = hash_find_channel(dl->data)) != NULL) |
| 901 |
< |
list_one_channel(source_p, chptr, list_task, remote_request); |
| 901 |
> |
list_one_channel(source_p, chptr, list_task); |
| 902 |
|
} |
| 903 |
|
|
| 904 |
|
free_list_task(list_task, source_p); |