]>
jfr.im git - irc/rqf/shadowircd.git/blob - src/class.c
2 * ircd-ratbox: A slightly useful ircd.
3 * class.c: Controls connection classes.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
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.
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
24 * $Id: class.c 254 2005-09-21 23:35:12Z nenolod $
37 #include "s_newconf.h"
39 #include "irc_string.h"
42 #define BAD_CONF_CLASS -1
44 #define BAD_CLIENT_CLASS -3
46 rb_dlink_list class_list
;
47 struct Class
*default_class
;
54 tmp
= (struct Class
*) MyMalloc(sizeof(struct Class
));
56 ConFreq(tmp
) = DEFAULT_CONNECTFREQUENCY
;
57 PingFreq(tmp
) = DEFAULT_PINGFREQUENCY
;
59 MaxSendq(tmp
) = DEFAULT_SENDQ
;
61 tmp
->ip_limits
= rb_new_patricia(PATRICIA_BITS
);
66 free_class(struct Class
*tmp
)
69 rb_destroy_patricia(tmp
->ip_limits
, NULL
);
71 MyFree(tmp
->class_name
);
79 * inputs - pointer to struct ConfItem
80 * output - ping frequency
84 get_conf_ping(struct ConfItem
*aconf
)
86 if((aconf
) && ClassPtr(aconf
))
87 return (ConfPingFreq(aconf
));
95 * inputs - pointer to client struct
96 * output - pointer to name of class
100 get_client_class(struct Client
*target_p
)
102 const char *retc
= "unknown";
104 if(target_p
== NULL
|| IsMe(target_p
))
107 if(IsServer(target_p
))
109 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
110 return server_p
->class_name
;
114 struct ConfItem
*aconf
;
115 aconf
= target_p
->localClient
->att_conf
;
117 if((aconf
== NULL
) || (aconf
->className
== NULL
))
120 retc
= aconf
->className
;
129 * inputs - pointer to client struct
130 * output - ping frequency
131 * side effects - NONE
134 get_client_ping(struct Client
*target_p
)
138 if(IsServer(target_p
))
140 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
141 ping
= PingFreq(server_p
->class);
145 struct ConfItem
*aconf
;
147 aconf
= target_p
->localClient
->att_conf
;
150 ping
= get_conf_ping(aconf
);
152 ping
= DEFAULT_PINGFREQUENCY
;
156 ping
= DEFAULT_PINGFREQUENCY
;
164 * inputs - pointer to class struct
165 * output - connection frequency
166 * side effects - NONE
169 get_con_freq(struct Class
*clptr
)
172 return (ConFreq(clptr
));
173 return (DEFAULT_CONNECTFREQUENCY
);
178 * input - class to add
180 * side effects - class is added to class_list if new, else old class
181 * is updated with new values.
184 add_class(struct Class
*classptr
)
186 struct Class
*tmpptr
;
188 tmpptr
= find_class(classptr
->class_name
);
190 if(tmpptr
== default_class
)
192 rb_dlinkAddAlloc(classptr
, &class_list
);
193 CurrUsers(classptr
) = 0;
197 MaxUsers(tmpptr
) = MaxUsers(classptr
);
198 MaxLocal(tmpptr
) = MaxLocal(classptr
);
199 MaxGlobal(tmpptr
) = MaxGlobal(classptr
);
200 MaxIdent(tmpptr
) = MaxIdent(classptr
);
201 PingFreq(tmpptr
) = PingFreq(classptr
);
202 MaxSendq(tmpptr
) = MaxSendq(classptr
);
203 ConFreq(tmpptr
) = ConFreq(classptr
);
204 CidrBitlen(tmpptr
) = CidrBitlen(classptr
);
205 CidrAmount(tmpptr
) = CidrAmount(classptr
);
207 free_class(classptr
);
215 * inputs - string name of class
216 * output - corresponding class pointer
217 * side effects - NONE
220 find_class(const char *classname
)
225 if(classname
== NULL
)
226 return default_class
;
228 RB_DLINK_FOREACH(ptr
, class_list
.head
)
232 if(!strcmp(ClassName(cltmp
), classname
))
236 return default_class
;
251 rb_dlink_node
*next_ptr
;
253 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, class_list
.head
)
257 if(MaxUsers(cltmp
) < 0)
259 rb_dlinkDestroy(ptr
, &class_list
);
260 if(CurrUsers(cltmp
) <= 0)
276 default_class
= make_class();
277 DupString(ClassName(default_class
), "default");
283 * inputs - pointer to client to report to
285 * side effects - class report is done to this client
288 report_classes(struct Client
*source_p
)
293 RB_DLINK_FOREACH(ptr
, class_list
.head
)
297 sendto_one_numeric(source_p
, RPL_STATSYLINE
,
298 form_str(RPL_STATSYLINE
),
299 ClassName(cltmp
), PingFreq(cltmp
),
300 ConFreq(cltmp
), MaxUsers(cltmp
),
302 MaxLocal(cltmp
), MaxIdent(cltmp
),
303 MaxGlobal(cltmp
), MaxIdent(cltmp
),
307 /* also output the default class */
308 sendto_one_numeric(source_p
, RPL_STATSYLINE
, form_str(RPL_STATSYLINE
),
309 ClassName(default_class
), PingFreq(default_class
),
310 ConFreq(default_class
), MaxUsers(default_class
),
311 MaxSendq(default_class
),
312 MaxLocal(default_class
), MaxIdent(default_class
),
313 MaxGlobal(default_class
), MaxIdent(default_class
),
314 CurrUsers(default_class
));
320 * inputs - pointer to client
321 * output - sendq for this client as found from its class
322 * side effects - NONE
325 get_sendq(struct Client
*client_p
)
327 if(client_p
== NULL
|| IsMe(client_p
))
328 return DEFAULT_SENDQ
;
330 if(IsServer(client_p
))
332 struct server_conf
*server_p
;
333 server_p
= client_p
->localClient
->att_sconf
;
334 return MaxSendq(server_p
->class);
338 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
340 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
341 return ConfMaxSendq(aconf
);
344 return DEFAULT_SENDQ
;