]> jfr.im git - irc/rqf/shadowircd.git/blame - src/s_newconf.c
Fixing time_t warnings
[irc/rqf/shadowircd.git] / src / s_newconf.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: an advanced Internet Relay Chat Daemon(ircd).
3 * s_newconf.c - code for dealing with conf stuff
4 *
5 * Copyright (C) 2004 Lee Hardy <lee@leeh.co.uk>
6 * Copyright (C) 2004-2005 ircd-ratbox development team
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * 1.Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * 2.Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3.The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *
7d08aa89 32 * $Id: s_newconf.c 3508 2007-06-04 16:04:49Z jilles $
212380e3 33 */
34
35#include "stdinc.h"
36#include "ircd_defs.h"
37#include "common.h"
38#include "s_conf.h"
39#include "s_newconf.h"
212380e3 40#include "client.h"
212380e3 41#include "s_serv.h"
42#include "send.h"
43#include "hostmask.h"
44#include "newconf.h"
45#include "hash.h"
212380e3 46#include "sprintf_irc.h"
b37021a4 47#include "irc_dictionary.h"
212380e3 48
af81d5a0
WP
49rb_dlink_list shared_conf_list;
50rb_dlink_list cluster_conf_list;
51rb_dlink_list oper_conf_list;
52rb_dlink_list hubleaf_conf_list;
53rb_dlink_list server_conf_list;
54rb_dlink_list xline_conf_list;
55rb_dlink_list resv_conf_list; /* nicks only! */
56rb_dlink_list nd_list; /* nick delay */
57rb_dlink_list tgchange_list;
212380e3 58
7f4fa195 59rb_patricia_tree_t *tgchange_tree;
212380e3 60
6e9b4415 61static rb_bh *nd_heap = NULL;
212380e3 62
63static void expire_temp_rxlines(void *unused);
64static void expire_nd_entries(void *unused);
65
7c944f64
WP
66struct ev_entry *expire_nd_entries_ev = NULL;
67struct ev_entry *expire_temp_rxlines_ev = NULL;
68
212380e3 69void
70init_s_newconf(void)
71{
7c944f64
WP
72 tgchange_tree = rb_new_patricia(PATRICIA_BITS);
73 nd_heap = rb_bh_create(sizeof(struct nd_entry), ND_HEAP_SIZE, "nd_heap");
74 expire_nd_entries_ev = rb_event_addish("expire_nd_entries", expire_nd_entries, NULL, 30);
75 expire_temp_rxlines_ev = rb_event_addish("expire_temp_rxlines", expire_temp_rxlines, NULL, 60);
212380e3 76}
77
78void
79clear_s_newconf(void)
80{
81 struct server_conf *server_p;
af81d5a0 82 rb_dlink_node *ptr;
90a3c35b 83 rb_dlink_node *next_ptr;
212380e3 84
90a3c35b 85 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head)
212380e3 86 {
87 /* ptr here is ptr->data->node */
af81d5a0 88 rb_dlinkDelete(ptr, &shared_conf_list);
212380e3 89 free_remote_conf(ptr->data);
90 }
91
90a3c35b 92 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head)
212380e3 93 {
af81d5a0 94 rb_dlinkDelete(ptr, &cluster_conf_list);
212380e3 95 free_remote_conf(ptr->data);
96 }
97
90a3c35b 98 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head)
212380e3 99 {
af81d5a0 100 rb_dlinkDelete(ptr, &hubleaf_conf_list);
212380e3 101 free_remote_conf(ptr->data);
102 }
103
90a3c35b 104 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head)
212380e3 105 {
106 free_oper_conf(ptr->data);
af81d5a0 107 rb_dlinkDestroy(ptr, &oper_conf_list);
212380e3 108 }
109
90a3c35b 110 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, server_conf_list.head)
212380e3 111 {
112 server_p = ptr->data;
113
114 if(!server_p->servers)
115 {
af81d5a0 116 rb_dlinkDelete(ptr, &server_conf_list);
212380e3 117 free_server_conf(ptr->data);
118 }
119 else
120 server_p->flags |= SERVER_ILLEGAL;
121 }
122}
123
124void
125clear_s_newconf_bans(void)
126{
127 struct ConfItem *aconf;
90a3c35b 128 rb_dlink_node *ptr, *next_ptr;
212380e3 129
90a3c35b 130 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
212380e3 131 {
132 aconf = ptr->data;
133
134 if(aconf->hold)
135 continue;
136
137 free_conf(aconf);
af81d5a0 138 rb_dlinkDestroy(ptr, &xline_conf_list);
212380e3 139 }
140
90a3c35b 141 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
212380e3 142 {
143 aconf = ptr->data;
144
145 /* temporary resv */
146 if(aconf->hold)
147 continue;
148
149 free_conf(aconf);
af81d5a0 150 rb_dlinkDestroy(ptr, &resv_conf_list);
212380e3 151 }
152
153 clear_resv_hash();
154}
155
156struct remote_conf *
157make_remote_conf(void)
158{
8e43b0b4 159 struct remote_conf *remote_p = rb_malloc(sizeof(struct remote_conf));
212380e3 160 return remote_p;
161}
162
163void
164free_remote_conf(struct remote_conf *remote_p)
165{
166 s_assert(remote_p != NULL);
167 if(remote_p == NULL)
168 return;
169
90a3c35b
VY
170 rb_free(remote_p->username);
171 rb_free(remote_p->host);
172 rb_free(remote_p->server);
173 rb_free(remote_p);
212380e3 174}
175
176int
177find_shared_conf(const char *username, const char *host,
178 const char *server, int flags)
179{
180 struct remote_conf *shared_p;
af81d5a0 181 rb_dlink_node *ptr;
212380e3 182
8e69bb4e 183 RB_DLINK_FOREACH(ptr, shared_conf_list.head)
212380e3 184 {
185 shared_p = ptr->data;
186
187 if(match(shared_p->username, username) &&
188 match(shared_p->host, host) &&
189 match(shared_p->server, server))
190 {
191 if(shared_p->flags & flags)
192 return YES;
193 else
194 return NO;
195 }
196 }
197
198 return NO;
199}
200
201void
202propagate_generic(struct Client *source_p, const char *command,
203 const char *target, int cap, const char *format, ...)
204{
205 char buffer[BUFSIZE];
206 va_list args;
207
208 va_start(args, format);
7c944f64 209 rb_vsnprintf(buffer, sizeof(buffer), format, args);
212380e3 210 va_end(args);
211
212 sendto_match_servs(source_p, target, cap, NOCAPS,
213 "%s %s %s",
214 command, target, buffer);
215 sendto_match_servs(source_p, target, CAP_ENCAP, cap,
216 "ENCAP %s %s %s",
217 target, command, buffer);
218}
219
220void
221cluster_generic(struct Client *source_p, const char *command,
222 int cltype, int cap, const char *format, ...)
223{
224 char buffer[BUFSIZE];
225 struct remote_conf *shared_p;
226 va_list args;
af81d5a0 227 rb_dlink_node *ptr;
212380e3 228
229 va_start(args, format);
7c944f64 230 rb_vsnprintf(buffer, sizeof(buffer), format, args);
212380e3 231 va_end(args);
232
8e69bb4e 233 RB_DLINK_FOREACH(ptr, cluster_conf_list.head)
212380e3 234 {
235 shared_p = ptr->data;
236
237 if(!(shared_p->flags & cltype))
238 continue;
239
240 sendto_match_servs(source_p, shared_p->server, cap, NOCAPS,
241 "%s %s %s",
242 command, shared_p->server, buffer);
243 sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, cap,
244 "ENCAP %s %s %s",
245 shared_p->server, command, buffer);
246 }
247}
248
249struct oper_conf *
250make_oper_conf(void)
251{
8e43b0b4 252 struct oper_conf *oper_p = rb_malloc(sizeof(struct oper_conf));
212380e3 253 return oper_p;
254}
255
256void
257free_oper_conf(struct oper_conf *oper_p)
258{
259 s_assert(oper_p != NULL);
260 if(oper_p == NULL)
261 return;
262
90a3c35b
VY
263 rb_free(oper_p->username);
264 rb_free(oper_p->host);
265 rb_free(oper_p->name);
212380e3 266
267 if(oper_p->passwd)
268 {
269 memset(oper_p->passwd, 0, strlen(oper_p->passwd));
90a3c35b 270 rb_free(oper_p->passwd);
212380e3 271 }
272
273#ifdef HAVE_LIBCRYPTO
90a3c35b 274 rb_free(oper_p->rsa_pubkey_file);
212380e3 275
276 if(oper_p->rsa_pubkey)
277 RSA_free(oper_p->rsa_pubkey);
278#endif
279
90a3c35b 280 rb_free(oper_p);
212380e3 281}
282
283struct oper_conf *
284find_oper_conf(const char *username, const char *host, const char *locip, const char *name)
285{
286 struct oper_conf *oper_p;
3ea5fee7 287 struct rb_sockaddr_storage ip, cip;
212380e3 288 char addr[HOSTLEN+1];
289 int bits, cbits;
af81d5a0 290 rb_dlink_node *ptr;
212380e3 291
292 parse_netmask(locip, (struct sockaddr *)&cip, &cbits);
293
8e69bb4e 294 RB_DLINK_FOREACH(ptr, oper_conf_list.head)
212380e3 295 {
296 oper_p = ptr->data;
297
298 /* name/username doesnt match.. */
299 if(irccmp(oper_p->name, name) || !match(oper_p->username, username))
300 continue;
301
302 strlcpy(addr, oper_p->host, sizeof(addr));
303
304 if(parse_netmask(addr, (struct sockaddr *)&ip, &bits) != HM_HOST)
305 {
306 if(ip.ss_family == cip.ss_family &&
307 comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits))
308 return oper_p;
309 }
310
311 /* we have to compare against the host as well, because its
312 * valid to set a spoof to an IP, which if we only compare
313 * in ip form to sockhost will not necessarily match --anfl
314 */
315 if(match(oper_p->host, host))
316 return oper_p;
317 }
318
319 return NULL;
320}
321
322struct oper_flags
323{
324 int flag;
325 char has;
326 char hasnt;
327};
328static struct oper_flags oper_flagtable[] =
329{
330 { OPER_GLINE, 'G', 'g' },
331 { OPER_KLINE, 'K', 'k' },
332 { OPER_XLINE, 'X', 'x' },
1ebe6ffc 333 { OPER_RESV, 'Q', 'q' },
212380e3 334 { OPER_GLOBKILL, 'O', 'o' },
335 { OPER_LOCKILL, 'C', 'c' },
336 { OPER_REMOTE, 'R', 'r' },
337 { OPER_UNKLINE, 'U', 'u' },
338 { OPER_REHASH, 'H', 'h' },
339 { OPER_DIE, 'D', 'd' },
340 { OPER_ADMIN, 'A', 'a' },
341 { OPER_NICKS, 'N', 'n' },
342 { OPER_OPERWALL, 'L', 'l' },
343 { OPER_SPY, 'S', 's' },
344 { OPER_INVIS, 'P', 'p' },
345 { OPER_REMOTEBAN, 'B', 'b' },
c13a2d9a 346 { OPER_MASSNOTICE, 'M', 'm' },
212380e3 347 { 0, '\0', '\0' }
348};
349
350const char *
351get_oper_privs(int flags)
352{
353 static char buf[20];
354 char *p;
355 int i;
356
357 p = buf;
358
359 for(i = 0; oper_flagtable[i].flag; i++)
360 {
361 if(flags & oper_flagtable[i].flag)
362 *p++ = oper_flagtable[i].has;
363 else
364 *p++ = oper_flagtable[i].hasnt;
365 }
366
367 *p = '\0';
368
369 return buf;
370}
371
372struct server_conf *
373make_server_conf(void)
374{
8e43b0b4 375 struct server_conf *server_p = rb_malloc(sizeof(struct server_conf));
212380e3 376 server_p->aftype = AF_INET;
377 return server_p;
378}
379
380void
381free_server_conf(struct server_conf *server_p)
382{
383 s_assert(server_p != NULL);
384 if(server_p == NULL)
385 return;
386
387 if(!EmptyString(server_p->passwd))
388 {
389 memset(server_p->passwd, 0, strlen(server_p->passwd));
90a3c35b 390 rb_free(server_p->passwd);
212380e3 391 }
392
393 if(!EmptyString(server_p->spasswd))
394 {
395 memset(server_p->spasswd, 0, strlen(server_p->spasswd));
90a3c35b 396 rb_free(server_p->spasswd);
212380e3 397 }
398
90a3c35b
VY
399 rb_free(server_p->name);
400 rb_free(server_p->host);
401 rb_free(server_p->class_name);
402 rb_free(server_p);
212380e3 403}
404
405void
406add_server_conf(struct server_conf *server_p)
407{
408 if(EmptyString(server_p->class_name))
409 {
62d28946 410 server_p->class_name = rb_strdup("default");
212380e3 411 server_p->class = default_class;
412 return;
413 }
414
415 server_p->class = find_class(server_p->class_name);
416
417 if(server_p->class == default_class)
418 {
419 conf_report_error("Warning connect::class invalid for %s",
420 server_p->name);
421
90a3c35b 422 rb_free(server_p->class_name);
62d28946 423 server_p->class_name = rb_strdup("default");
212380e3 424 }
425
426 if(strchr(server_p->host, '*') || strchr(server_p->host, '?'))
427 return;
428}
429
430struct server_conf *
431find_server_conf(const char *name)
432{
433 struct server_conf *server_p;
af81d5a0 434 rb_dlink_node *ptr;
212380e3 435
8e69bb4e 436 RB_DLINK_FOREACH(ptr, server_conf_list.head)
212380e3 437 {
438 server_p = ptr->data;
439
440 if(ServerConfIllegal(server_p))
441 continue;
442
443 if(match(name, server_p->name))
444 return server_p;
445 }
446
447 return NULL;
448}
449
450void
451attach_server_conf(struct Client *client_p, struct server_conf *server_p)
452{
453 /* already have an attached conf */
454 if(client_p->localClient->att_sconf)
455 {
456 /* short circuit this special case :) */
457 if(client_p->localClient->att_sconf == server_p)
458 return;
459
460 detach_server_conf(client_p);
461 }
462
463 CurrUsers(server_p->class)++;
464
465 client_p->localClient->att_sconf = server_p;
466 server_p->servers++;
467}
468
469void
470detach_server_conf(struct Client *client_p)
471{
472 struct server_conf *server_p = client_p->localClient->att_sconf;
473
474 if(server_p == NULL)
475 return;
476
477 client_p->localClient->att_sconf = NULL;
478 server_p->servers--;
479 CurrUsers(server_p->class)--;
480
481 if(ServerConfIllegal(server_p) && !server_p->servers)
482 {
483 /* the class this one is using may need destroying too */
484 if(MaxUsers(server_p->class) < 0 && CurrUsers(server_p->class) <= 0)
485 free_class(server_p->class);
486
af81d5a0 487 rb_dlinkDelete(&server_p->node, &server_conf_list);
212380e3 488 free_server_conf(server_p);
489 }
490}
491
492void
493set_server_conf_autoconn(struct Client *source_p, char *name, int newval)
494{
495 struct server_conf *server_p;
496
497 if((server_p = find_server_conf(name)) != NULL)
498 {
499 if(newval)
500 server_p->flags |= SERVER_AUTOCONN;
501 else
502 server_p->flags &= ~SERVER_AUTOCONN;
503
504 sendto_realops_snomask(SNO_GENERAL, L_ALL,
505 "%s has changed AUTOCONN for %s to %i",
506 get_oper_name(source_p), name, newval);
507 }
508 else
5366977b 509 sendto_one_notice(source_p, ":Can't find %s", name);
212380e3 510}
511
512struct ConfItem *
513find_xline(const char *gecos, int counter)
514{
515 struct ConfItem *aconf;
af81d5a0 516 rb_dlink_node *ptr;
212380e3 517
8e69bb4e 518 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
212380e3 519 {
520 aconf = ptr->data;
521
522 if(match_esc(aconf->name, gecos))
523 {
524 if(counter)
525 aconf->port++;
526 return aconf;
527 }
528 }
529
530 return NULL;
531}
532
0fdb2570
JT
533struct ConfItem *
534find_xline_mask(const char *gecos)
535{
536 struct ConfItem *aconf;
af81d5a0 537 rb_dlink_node *ptr;
0fdb2570 538
8e69bb4e 539 RB_DLINK_FOREACH(ptr, xline_conf_list.head)
0fdb2570
JT
540 {
541 aconf = ptr->data;
542
543 if(!irccmp(aconf->name, gecos))
544 return aconf;
545 }
546
547 return NULL;
548}
549
212380e3 550struct ConfItem *
551find_nick_resv(const char *name)
552{
553 struct ConfItem *aconf;
af81d5a0 554 rb_dlink_node *ptr;
212380e3 555
8e69bb4e 556 RB_DLINK_FOREACH(ptr, resv_conf_list.head)
212380e3 557 {
558 aconf = ptr->data;
559
560 if(match_esc(aconf->name, name))
561 {
562 aconf->port++;
563 return aconf;
564 }
565 }
566
567 return NULL;
568}
569
0fdb2570
JT
570struct ConfItem *
571find_nick_resv_mask(const char *name)
572{
573 struct ConfItem *aconf;
af81d5a0 574 rb_dlink_node *ptr;
0fdb2570 575
8e69bb4e 576 RB_DLINK_FOREACH(ptr, resv_conf_list.head)
0fdb2570
JT
577 {
578 aconf = ptr->data;
579
580 if(!irccmp(aconf->name, name))
581 return aconf;
582 }
583
584 return NULL;
585}
586
212380e3 587/* clean_resv_nick()
588 *
589 * inputs - nick
590 * outputs - 1 if nick is vaild resv, 0 otherwise
591 * side effects -
592 */
593int
594clean_resv_nick(const char *nick)
595{
596 char tmpch;
597 int as = 0;
598 int q = 0;
599 int ch = 0;
600
601 if(*nick == '-' || IsDigit(*nick))
602 return 0;
603
604 while ((tmpch = *nick++))
605 {
606 if(tmpch == '?' || tmpch == '@' || tmpch == '#')
607 q++;
608 else if(tmpch == '*')
609 as++;
610 else if(IsNickChar(tmpch))
611 ch++;
612 else
613 return 0;
614 }
615
616 if(!ch && as)
617 return 0;
618
619 return 1;
620}
621
622/* valid_wild_card_simple()
623 *
624 * inputs - "thing" to test
625 * outputs - 1 if enough wildcards, else 0
626 * side effects -
627 */
628int
629valid_wild_card_simple(const char *data)
630{
631 const char *p;
632 char tmpch;
633 int nonwild = 0;
7d08aa89 634 int wild = 0;
212380e3 635
636 /* check the string for minimum number of nonwildcard chars */
637 p = data;
638
639 while((tmpch = *p++))
640 {
641 /* found an escape, p points to the char after it, so skip
642 * that and move on.
643 */
7d08aa89 644 if(tmpch == '\\' && *p)
212380e3 645 {
646 p++;
7d08aa89 647 if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
648 return 1;
212380e3 649 }
650 else if(!IsMWildChar(tmpch))
651 {
652 /* if we have enough nonwildchars, return */
653 if(++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
654 return 1;
655 }
7d08aa89 656 else
657 wild++;
212380e3 658 }
659
7d08aa89 660 /* strings without wilds are also ok */
661 return wild == 0;
212380e3 662}
663
664time_t
665valid_temp_time(const char *p)
666{
667 time_t result = 0;
668
669 while(*p)
670 {
671 if(IsDigit(*p))
672 {
673 result *= 10;
674 result += ((*p) & 0xF);
675 p++;
676 }
677 else
678 return -1;
679 }
680
681 if(result > (60 * 24 * 7 * 52))
682 result = (60 * 24 * 7 * 52);
683
684 return(result * 60);
685}
686
687static void
688expire_temp_rxlines(void *unused)
689{
690 struct ConfItem *aconf;
af81d5a0 691 rb_dlink_node *ptr;
90a3c35b 692 rb_dlink_node *next_ptr;
212380e3 693 int i;
694
90a3c35b 695 HASH_WALK_SAFE(i, R_MAX, ptr, next_ptr, resvTable)
212380e3 696 {
697 aconf = ptr->data;
698
9f6bbe3c 699 if(aconf->hold && aconf->hold <= rb_current_time())
212380e3 700 {
701 if(ConfigFileEntry.tkline_expire_notices)
702 sendto_realops_snomask(SNO_GENERAL, L_ALL,
703 "Temporary RESV for [%s] expired",
704 aconf->name);
705
706 free_conf(aconf);
af81d5a0 707 rb_dlinkDestroy(ptr, &resvTable[i]);
212380e3 708 }
709 }
710 HASH_WALK_END
711
90a3c35b 712 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, resv_conf_list.head)
212380e3 713 {
714 aconf = ptr->data;
715
9f6bbe3c 716 if(aconf->hold && aconf->hold <= rb_current_time())
212380e3 717 {
718 if(ConfigFileEntry.tkline_expire_notices)
719 sendto_realops_snomask(SNO_GENERAL, L_ALL,
720 "Temporary RESV for [%s] expired",
721 aconf->name);
722 free_conf(aconf);
af81d5a0 723 rb_dlinkDestroy(ptr, &resv_conf_list);
212380e3 724 }
725 }
726
90a3c35b 727 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, xline_conf_list.head)
212380e3 728 {
729 aconf = ptr->data;
730
9f6bbe3c 731 if(aconf->hold && aconf->hold <= rb_current_time())
212380e3 732 {
733 if(ConfigFileEntry.tkline_expire_notices)
734 sendto_realops_snomask(SNO_GENERAL, L_ALL,
735 "Temporary X-line for [%s] expired",
736 aconf->name);
737 free_conf(aconf);
af81d5a0 738 rb_dlinkDestroy(ptr, &xline_conf_list);
212380e3 739 }
740 }
741}
742
743unsigned long
744get_nd_count(void)
745{
af81d5a0 746 return(rb_dlink_list_length(&nd_list));
212380e3 747}
748
212380e3 749void
750add_nd_entry(const char *name)
751{
752 struct nd_entry *nd;
753
b37021a4 754 if(irc_dictionary_find(nd_dict, name) != NULL)
212380e3 755 return;
756
6e9b4415 757 nd = rb_bh_alloc(nd_heap);
212380e3 758
759 strlcpy(nd->name, name, sizeof(nd->name));
9f6bbe3c 760 nd->expire = rb_current_time() + ConfigFileEntry.nick_delay;
212380e3 761
762 /* this list is ordered */
af81d5a0 763 rb_dlinkAddTail(nd, &nd->lnode, &nd_list);
b37021a4
WP
764
765 irc_dictionary_add(nd_dict, nd->name, nd);
212380e3 766}
767
768void
769free_nd_entry(struct nd_entry *nd)
770{
b37021a4
WP
771 irc_dictionary_delete(nd_dict, nd->name);
772
af81d5a0 773 rb_dlinkDelete(&nd->lnode, &nd_list);
6e9b4415 774 rb_bh_free(nd_heap, nd);
212380e3 775}
776
777void
778expire_nd_entries(void *unused)
779{
780 struct nd_entry *nd;
af81d5a0 781 rb_dlink_node *ptr;
90a3c35b 782 rb_dlink_node *next_ptr;
212380e3 783
90a3c35b 784 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, nd_list.head)
212380e3 785 {
786 nd = ptr->data;
787
788 /* this list is ordered - we can stop when we hit the first
789 * entry that doesnt expire..
790 */
9f6bbe3c 791 if(nd->expire > rb_current_time())
212380e3 792 return;
793
794 free_nd_entry(nd);
795 }
796}
797
798void
799add_tgchange(const char *host)
800{
801 tgchange *target;
7c944f64 802 rb_patricia_node_t *pnode;
212380e3 803
804 if(find_tgchange(host))
805 return;
806
8e43b0b4 807 target = rb_malloc(sizeof(tgchange));
212380e3 808 pnode = make_and_lookup(tgchange_tree, host);
809
810 pnode->data = target;
811 target->pnode = pnode;
812
62d28946 813 target->ip = rb_strdup(host);
9f6bbe3c 814 target->expiry = rb_current_time() + (60*60*12);
212380e3 815
af81d5a0 816 rb_dlinkAdd(target, &target->node, &tgchange_list);
212380e3 817}
818
819tgchange *
820find_tgchange(const char *host)
821{
7c944f64 822 rb_patricia_node_t *pnode;
212380e3 823
7c944f64 824 if((pnode = rb_match_exact_string(tgchange_tree, host)))
212380e3 825 return pnode->data;
826
827 return NULL;
828}
829