]>
jfr.im git - solanum.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 $
36 #include "s_newconf.h"
38 #include "irc_string.h"
40 #define BAD_CONF_CLASS -1
42 #define BAD_CLIENT_CLASS -3
44 rb_dlink_list class_list
;
45 struct Class
*default_class
;
52 tmp
= (struct Class
*) rb_malloc(sizeof(struct Class
));
54 ConFreq(tmp
) = DEFAULT_CONNECTFREQUENCY
;
55 PingFreq(tmp
) = DEFAULT_PINGFREQUENCY
;
57 MaxSendq(tmp
) = DEFAULT_SENDQ
;
59 tmp
->ip_limits
= rb_new_patricia(PATRICIA_BITS
);
64 free_class(struct Class
*tmp
)
67 rb_destroy_patricia(tmp
->ip_limits
, NULL
);
69 rb_free(tmp
->class_name
);
77 * inputs - pointer to struct ConfItem
78 * output - ping frequency
82 get_conf_ping(struct ConfItem
*aconf
)
84 if((aconf
) && ClassPtr(aconf
))
85 return (ConfPingFreq(aconf
));
93 * inputs - pointer to client struct
94 * output - pointer to name of class
98 get_client_class(struct Client
*target_p
)
100 const char *retc
= "unknown";
102 if(target_p
== NULL
|| IsMe(target_p
))
105 if(IsServer(target_p
))
107 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
108 return server_p
->class_name
;
112 struct ConfItem
*aconf
;
113 aconf
= target_p
->localClient
->att_conf
;
115 if((aconf
== NULL
) || (aconf
->className
== NULL
))
118 retc
= aconf
->className
;
127 * inputs - pointer to client struct
128 * output - ping frequency
129 * side effects - NONE
132 get_client_ping(struct Client
*target_p
)
136 if(IsServer(target_p
))
138 struct server_conf
*server_p
= target_p
->localClient
->att_sconf
;
139 ping
= PingFreq(server_p
->class);
143 struct ConfItem
*aconf
;
145 aconf
= target_p
->localClient
->att_conf
;
148 ping
= get_conf_ping(aconf
);
150 ping
= DEFAULT_PINGFREQUENCY
;
154 ping
= DEFAULT_PINGFREQUENCY
;
162 * inputs - pointer to class struct
163 * output - connection frequency
164 * side effects - NONE
167 get_con_freq(struct Class
*clptr
)
170 return (ConFreq(clptr
));
171 return (DEFAULT_CONNECTFREQUENCY
);
176 * input - class to add
178 * side effects - class is added to class_list if new, else old class
179 * is updated with new values.
182 add_class(struct Class
*classptr
)
184 struct Class
*tmpptr
;
186 tmpptr
= find_class(classptr
->class_name
);
188 if(tmpptr
== default_class
)
190 rb_dlinkAddAlloc(classptr
, &class_list
);
191 CurrUsers(classptr
) = 0;
195 MaxUsers(tmpptr
) = MaxUsers(classptr
);
196 MaxLocal(tmpptr
) = MaxLocal(classptr
);
197 MaxGlobal(tmpptr
) = MaxGlobal(classptr
);
198 MaxIdent(tmpptr
) = MaxIdent(classptr
);
199 PingFreq(tmpptr
) = PingFreq(classptr
);
200 MaxSendq(tmpptr
) = MaxSendq(classptr
);
201 ConFreq(tmpptr
) = ConFreq(classptr
);
202 CidrBitlen(tmpptr
) = CidrBitlen(classptr
);
203 CidrAmount(tmpptr
) = CidrAmount(classptr
);
205 free_class(classptr
);
213 * inputs - string name of class
214 * output - corresponding class pointer
215 * side effects - NONE
218 find_class(const char *classname
)
223 if(classname
== NULL
)
224 return default_class
;
226 RB_DLINK_FOREACH(ptr
, class_list
.head
)
230 if(!strcmp(ClassName(cltmp
), classname
))
234 return default_class
;
249 rb_dlink_node
*next_ptr
;
251 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, class_list
.head
)
255 if(MaxUsers(cltmp
) < 0)
257 rb_dlinkDestroy(ptr
, &class_list
);
258 if(CurrUsers(cltmp
) <= 0)
274 default_class
= make_class();
275 ClassName(default_class
) = rb_strdup("default");
281 * inputs - pointer to client to report to
283 * side effects - class report is done to this client
286 report_classes(struct Client
*source_p
)
291 RB_DLINK_FOREACH(ptr
, class_list
.head
)
295 sendto_one_numeric(source_p
, RPL_STATSYLINE
,
296 form_str(RPL_STATSYLINE
),
297 ClassName(cltmp
), PingFreq(cltmp
),
298 ConFreq(cltmp
), MaxUsers(cltmp
),
300 MaxLocal(cltmp
), MaxIdent(cltmp
),
301 MaxGlobal(cltmp
), MaxIdent(cltmp
),
305 /* also output the default class */
306 sendto_one_numeric(source_p
, RPL_STATSYLINE
, form_str(RPL_STATSYLINE
),
307 ClassName(default_class
), PingFreq(default_class
),
308 ConFreq(default_class
), MaxUsers(default_class
),
309 MaxSendq(default_class
),
310 MaxLocal(default_class
), MaxIdent(default_class
),
311 MaxGlobal(default_class
), MaxIdent(default_class
),
312 CurrUsers(default_class
));
318 * inputs - pointer to client
319 * output - sendq for this client as found from its class
320 * side effects - NONE
323 get_sendq(struct Client
*client_p
)
325 if(client_p
== NULL
|| IsMe(client_p
))
326 return DEFAULT_SENDQ
;
328 if(IsServer(client_p
))
330 struct server_conf
*server_p
;
331 server_p
= client_p
->localClient
->att_sconf
;
332 return MaxSendq(server_p
->class);
336 struct ConfItem
*aconf
= client_p
->localClient
->att_conf
;
338 if(aconf
!= NULL
&& aconf
->status
& CONF_CLIENT
)
339 return ConfMaxSendq(aconf
);
342 return DEFAULT_SENDQ
;