/[cvs]/botnetop.mod/delay.c
ViewVC logotype

Contents of /botnetop.mod/delay.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Tue Feb 13 18:23:24 2001 UTC (18 years, 5 months ago) by sup
Branch: MAIN
Changes since 1.3: +2 -2 lines
File MIME type: text/x-chdr
Updated to 1.0.1

1 /*
2 * delay.c -- part of botnetop.mod
3 *
4 * $Id: delay.c,v 1.3 2000/10/20 19:35:56 sup Exp $
5 */
6 /*
7 * Copyright (C) 2000, 2001 Teemu Hjelt <temex@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 static struct delay_t *find_delay(char *chan)
25 {
26 struct delay_t *d = NULL;
27
28 for (d = start_delay; d; d = d->next)
29 if (!rfc_casecmp(d->chan, chan))
30 return d;
31 return NULL;
32 }
33
34 static struct delay_t *add_delay(char *chan, char *bot)
35 {
36 struct delay_t *d = NULL;
37
38 d = (struct delay_t *) nmalloc(sizeof(struct delay_t));
39 if (!d)
40 return NULL;
41 d->next = start_delay;
42 start_delay = d;
43 strncpyz(d->chan, chan, sizeof d->chan);
44 strncpyz(d->bot, bot, sizeof d->bot);
45 d->reqtime = 0;
46 d->resptime = 0;
47 d->reqs = 0;
48 putlog(LOG_DEBUG, "*", "botnetop.mod: new delay record created for %s (address: %u)", chan, d);
49 return d;
50 }
51
52 static void del_delay(struct delay_t *delay)
53 {
54 struct delay_t *d = NULL, *old = NULL;
55
56 for (d = start_delay; d; old = d, d = d->next) {
57 if (d == delay) {
58 if (old)
59 old->next = d->next;
60 else
61 start_delay = d->next;
62 putlog(LOG_DEBUG, "*", "botnetop.mod: delay record removed from %s (address: %u)", d->chan, d);
63 nfree(d);
64 break;
65 }
66 }
67 }
68
69 static void check_delay()
70 {
71 struct delay_t *d = NULL;
72
73 for (d = start_delay; d; d = d->next) {
74 if ((d->reqtime) && (d->reqtime <= now)) {
75 d->reqtime = 0;
76 bnop_askbot(d->bot, d->chan);
77 }
78 if ((d->resptime) && (d->resptime <= now)) {
79 d->resptime = 0;
80 d->reqs = 0;
81 }
82 }
83 }
84
85 static void delay_free_mem()
86 {
87 struct delay_t *d = NULL, *dnext = NULL;
88
89 for (d = start_delay; d; d = dnext) {
90 dnext = d->next;
91 nfree(d);
92 }
93 start_delay = NULL;
94 }
95
96 static int delay_expmem()
97 {
98 int size = 0;
99 struct delay_t *d = NULL;
100
101 for (d = start_delay; d; d = d->next)
102 size += sizeof(struct delay_t);
103 return size;
104 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23