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

Annotation of /botnetop.mod/delay.c

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


Revision 1.5 - (hide annotations) (download) (as text)
Sun Jul 14 09:28:45 2002 UTC (17 years, 3 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 sup 1.5 /*
2 sup 1.1 * delay.c -- part of botnetop.mod
3 sup 1.5 *
4     * $Id$
5 sup 1.1 */
6 sup 1.5 /*
7     * Copyright (C) 2000, 2001, 2002 Teemu Hjelt <temex@iki.fi>
8 sup 1.1 *
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 sup 1.5 static struct delay_t *find_delay(char *chan, char *handle)
25 sup 1.1 {
26 sup 1.2 struct delay_t *d = NULL;
27 sup 1.1
28 sup 1.5 for (d = delay_start; d != NULL; d = d->next) {
29     if (!rfc_casecmp(d->chan, chan) && !egg_strcasecmp(d->handle, handle))
30 sup 1.2 return d;
31 sup 1.5 }
32    
33 sup 1.1 return NULL;
34     }
35    
36 sup 1.5 static struct delay_t *add_delay(char *chan, char *handle)
37 sup 1.1 {
38 sup 1.2 struct delay_t *d = NULL;
39 sup 1.1
40 sup 1.2 d = (struct delay_t *) nmalloc(sizeof(struct delay_t));
41 sup 1.5 if (d == NULL)
42 sup 1.2 return NULL;
43 sup 1.5
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 sup 1.2 d->reqtime = 0;
61 sup 1.5 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 sup 1.2 return d;
69 sup 1.1 }
70    
71 sup 1.2 static void del_delay(struct delay_t *delay)
72 sup 1.1 {
73 sup 1.2 struct delay_t *d = NULL, *old = NULL;
74 sup 1.1
75 sup 1.5 for (d = delay_start; d != NULL; old = d, d = d->next) {
76 sup 1.2 if (d == delay) {
77 sup 1.5 if (old != NULL)
78 sup 1.2 old->next = d->next;
79     else
80 sup 1.5 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 sup 1.2 nfree(d);
87     break;
88     }
89 sup 1.1 }
90     }
91    
92 sup 1.5 static int check_delay_status(char *chan, char *handle)
93 sup 1.1 {
94 sup 1.2 struct delay_t *d = NULL;
95 sup 1.1
96 sup 1.5 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 sup 1.1 }
108 sup 1.5
109     d->reqs++;
110    
111     if (d->reqs >= bop_maxreq) {
112 sup 1.1 d->resptime = 0;
113     d->reqs = 0;
114 sup 1.5 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 sup 1.1 }
130     }
131     }
132    
133 sup 1.2 static void delay_free_mem()
134     {
135     struct delay_t *d = NULL, *dnext = NULL;
136    
137 sup 1.5 for (d = delay_start; d != NULL; d = dnext) {
138 sup 1.2 dnext = d->next;
139 sup 1.5 if (d->chan != NULL)
140     nfree(d->chan);
141     if (d->handle != NULL)
142     nfree(d->handle);
143 sup 1.2 nfree(d);
144     }
145 sup 1.5 delay_start = NULL;
146 sup 1.2 }
147    
148     static int delay_expmem()
149     {
150     int size = 0;
151     struct delay_t *d = NULL;
152    
153 sup 1.5 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 sup 1.2 size += sizeof(struct delay_t);
159 sup 1.5 }
160    
161 sup 1.2 return size;
162     }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23