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

Contents of /botnetop.mod/who.c

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


Revision 1.4 - (show annotations) (download) (as text)
Sun Jul 14 09:28:45 2002 UTC (15 years, 5 months ago) by sup
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +86 -24 lines
File MIME type: text/x-chdr
Updated to 1.1.0-gamma

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23