ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/node.C
(Generate patch)

Comparing ermyth/src/node.C (file contents):
Revision 1.4 by pippijn, Tue Aug 28 17:08:12 2007 UTC vs.
Revision 1.5 by pippijn, Sun Sep 9 20:05:52 2007 UTC

3 * Rights to this code are documented in doc/pod/license.pod. 3 * Rights to this code are documented in doc/pod/license.pod.
4 * 4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) 5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */ 6 */
7 7
8static char const rcsid[] = "$Id: node.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; 8static char const rcsid[] = "$Id: node.C,v 1.5 2007/09/09 20:05:52 pippijn Exp $";
9 9
10#include "atheme.h" 10#include "atheme.h"
11#include "servers.h"
11#include <account/kline.h> 12#include <account/kline.h>
12#include "uplink.h" 13#include "uplink.h"
13#include "privs.h" 14#include "privs.h"
14 15
15kline_vector klnlist; 16kline_t::list_type kline_t::list;
16 17
17/************* 18/*************
18 * L I S T S * 19 * L I S T S *
19 *************/ 20 *************/
20 21
95/************* 96/*************
96 * K L I N E * 97 * K L I N E *
97 *************/ 98 *************/
98 99
99kline_t * 100kline_t *
100kline_add (char const * const user, char const * const host, char const * const reason, long duration) 101kline_t::create (char const * const user, char const * const host, char const * const reason, long duration)
101{ 102{
102 kline_t *k; 103 kline_t *k;
103 static unsigned int kcnt = 0; 104 static unsigned int kcnt = 0;
104 105
105 slog (LG_DEBUG, "kline_add(): %s@%s -> %s (%ld)", user, host, reason, duration); 106 slog (LG_DEBUG, "kline_t::create(): %s@%s -> %s (%ld)", user, host, reason, duration);
106 107
107 k = new kline_t; 108 k = new kline_t;
108 109
109 k->user = sstrdup (user); 110 k->user = sstrdup (user);
110 k->host = sstrdup (host); 111 k->host = sstrdup (host);
112 k->duration = duration; 113 k->duration = duration;
113 k->settime = NOW; 114 k->settime = NOW;
114 k->expires = NOW + duration; 115 k->expires = NOW + duration;
115 k->number = ++kcnt; 116 k->number = ++kcnt;
116 117
117 klnlist.push_back (k); 118 list.push_back (k);
118 119
119 cnt.kline++; 120 cnt.kline++;
120 121
121 phandler->kline_sts ("*", user, host, duration, reason); 122 phandler->kline_sts ("*", user, host, duration, reason);
122 123
123 return k; 124 return k;
124} 125}
125 126
126void 127void
127kline_delete (kline_t *k)
128{
129 klnlist.erase (k);
130
131 sfree (k->user);
132 sfree (k->host);
133 sfree (k->reason);
134 sfree (k->setby);
135
136 delete k;
137
138 cnt.kline--;
139}
140
141void
142kline_delete (char const * const user, char const * const host) 128kline_t::destroy (char const * const user, char const * const host)
143{ 129{
144 kline_t *k = kline_find (user, host); 130 kline_t *k = find (user, host);
145 131
146 if (!k) 132 if (!k)
147 { 133 {
148 slog (LG_DEBUG, "kline_delete(): called for nonexistant kline: %s@%s", user, host); 134 slog (LG_DEBUG, "kline_t::destroy(): called for nonexistant kline: %s@%s", user, host);
149 135
150 return; 136 return;
151 } 137 }
152 138
153 slog (LG_DEBUG, "kline_delete(): %s@%s -> %s", k->user, k->host, k->reason); 139 slog (LG_DEBUG, "kline_t::destroy(): %s@%s -> %s", k->user, k->host, k->reason);
154 /* only unkline if ircd has not already removed this -- jilles */ 140 /* only unkline if ircd has not already removed this -- jilles */
155 if (k->duration == 0 || k->expires > NOW) 141 if (k->duration == 0 || k->expires > NOW)
156 phandler->unkline_sts ("*", k->user, k->host); 142 phandler->unkline_sts ("*", k->user, k->host);
157 143
158 kline_delete (k); 144 k->destroy ();
159} 145}
160 146
161kline_t * 147kline_t *
162kline_find (char const * const user, char const * const host) 148kline_t::find (char const * const user, char const * const host)
163{ 149{
164 kline_t *k; 150 kline_t *k;
165 kline_vector::iterator klit = klnlist.begin (); 151 list_type::iterator klit = list.begin ();
166 kline_vector::iterator klet = klnlist.end (); 152 list_type::iterator klet = list.end ();
167 153
168 while (klit != klet) 154 while (klit != klet)
169 { 155 {
170 k = *klit; 156 k = *klit;
171 157
177 163
178 return NULL; 164 return NULL;
179} 165}
180 166
181kline_t * 167kline_t *
182kline_find_num (unsigned int number) 168kline_t::find (unsigned int number)
183{ 169{
184 kline_t *k; 170 kline_t *k;
185 kline_vector::iterator klit = klnlist.begin (); 171 list_type::iterator klit = list.begin ();
186 kline_vector::iterator klet = klnlist.end (); 172 list_type::iterator klet = list.end ();
187 173
188 while (klit != klet) 174 while (klit != klet)
189 { 175 {
190 k = *klit; 176 k = *klit;
191 177
197 183
198 return NULL; 184 return NULL;
199} 185}
200 186
201kline_t * 187kline_t *
202kline_find_user (user_t *u) 188kline_t::find (user_t *u)
203{ 189{
204 kline_t *k; 190 kline_t *k;
205 kline_vector::iterator klit = klnlist.begin (); 191 list_type::iterator klit = list.begin ();
206 kline_vector::iterator klet = klnlist.end (); 192 list_type::iterator klet = list.end ();
207 193
208 while (klit != klet) 194 while (klit != klet)
209 { 195 {
210 k = *klit; 196 k = *klit;
211 197
218 204
219 return NULL; 205 return NULL;
220} 206}
221 207
222void 208void
223kline_expire (void *arg) 209kline_t::expire (void *arg)
224{ 210{
225 kline_t *k; 211 kline_t *k;
226 std::vector<kline_t *> mortals; 212 std::vector<kline_t *> mortals;
227 kline_vector::iterator klit = klnlist.begin (); 213 list_type::iterator klit = list.begin ();
228 kline_vector::iterator klet = klnlist.end (); 214 list_type::iterator klet = list.end ();
229 215
230 while (klit != klet) 216 while (klit != klet)
231 { 217 {
232 k = *klit; 218 k = *klit;
233 219
247 } 233 }
248 234
249 // We have to do this because we cannot destroy klines while iterating 235 // We have to do this because we cannot destroy klines while iterating
250 while (!mortals.empty ()) 236 while (!mortals.empty ())
251 { 237 {
252 k = mortals.back (); 238 mortals.back ()->destroy ();
253 kline_delete (k);
254 mortals.pop_back (); 239 mortals.pop_back ();
255 } 240 }
256} 241}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines