/[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.5 - (show annotations) (download) (as text)
Sun Jul 14 09:28:45 2002 UTC (16 years, 5 months ago) by sup
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +88 -30 lines
File MIME type: text/x-chdr
Updated to 1.1.0-gamma

1 /*
2 * delay.c -- part of botnetop.mod
3 *
4 * $Id$
5 */
6 /*
7 * Copyright (C) 2000, 2001, 2002 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, char *handle)
25 {
26 struct delay_t *d = NULL;
27
28 for (d = delay_start; d != NULL; d = d->next) {
29 if (!rfc_casecmp(d->chan, chan) && !egg_strcasecmp(d->handle, handle))
30 return d;
31 }
32
33 return NULL;
34 }
35
36 static struct delay_t *add_delay(char *chan, char *handle)
37 {
38 struct delay_t *d = NULL;
39
40 d = (struct delay_t *) nmalloc(sizeof(struct delay_t));
41 if (d == NULL)
42 return NULL;
43
44 d->chan = (char *) nmalloc(strlen(chan) + 1);
45 if (d->chan == NULL) {
46 nfree(d);
47 return NULL;
48 }
49
50 d->handle = (char *) nmalloc(strlen(handle) + 1);
51 if (d->handle == NULL) {
52 nfree(d->chan);
53 nfree(d);
54 return NULL;
55 }
56
57 strncpyz(d->chan, chan, strlen(chan) + 1);
58 strncpyz(d->handle, handle, strlen(handle) + 1);
59 d->reqs = 0;
60 d->reqtime = 0;
61 d->resptime = now;
62
63 d->next = delay_start;
64 delay_start = d;
65
66 putlog(LOG_DEBUG, "*", "botnetop.mod: new delay record created for %s on %s (address: %u)", d->handle, d->chan, d);
67
68 return d;
69 }
70
71 static void del_delay(struct delay_t *delay)
72 {
73 struct delay_t *d = NULL, *old = NULL;
74
75 for (d = delay_start; d != NULL; old = d, d = d->next) {
76 if (d == delay) {
77 if (old != NULL)
78 old->next = d->next;
79 else
80 delay_start = d->next;
81 putlog(LOG_DEBUG, "*", "botnetop.mod: delay record removed from %s on %s (address: %u)", d->handle, d->chan, d);
82 if (d->chan != NULL)
83 nfree(d->chan);
84 if (d->handle != NULL)
85 nfree(d->handle);
86 nfree(d);
87 break;
88 }
89 }
90 }
91
92 static int check_delay_status(char *chan, char *handle)
93 {
94 struct delay_t *d = NULL;
95
96 if (bop_maxreq) {
97
98 if (!(d = find_delay(chan, handle))) {
99 if (!(d = add_delay(chan, handle)))
100 return 0;
101 }
102
103 if (d->resptime < now - 30) {
104 d->resptime = now;
105 d->reqs = 0;
106 return 0;
107 }
108
109 d->reqs++;
110
111 if (d->reqs >= bop_maxreq) {
112 d->resptime = 0;
113 d->reqs = 0;
114 return 1;
115 }
116 }
117
118 return 0;
119 }
120
121 static void check_delay()
122 {
123 struct delay_t *d = NULL;
124
125 for (d = delay_start; d != NULL; d = d->next) {
126 if ((d->reqtime > 0) && (d->reqtime < now)) {
127 d->reqtime = 0;
128 bnop_askbot(d->handle, d->chan);
129 }
130 }
131 }
132
133 static void delay_free_mem()
134 {
135 struct delay_t *d = NULL, *dnext = NULL;
136
137 for (d = delay_start; d != NULL; d = dnext) {
138 dnext = d->next;
139 if (d->chan != NULL)
140 nfree(d->chan);
141 if (d->handle != NULL)
142 nfree(d->handle);
143 nfree(d);
144 }
145 delay_start = NULL;
146 }
147
148 static int delay_expmem()
149 {
150 int size = 0;
151 struct delay_t *d = NULL;
152
153 for (d = delay_start; d != NULL; d = d->next) {
154 if (d->chan != NULL)
155 size += strlen(d->chan) + 1;
156 if (d->handle != NULL)
157 size += strlen(d->handle) + 1;
158 size += sizeof(struct delay_t);
159 }
160
161 return size;
162 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23