ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_class.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/conf_class.c (file contents):
Revision 4415 by michael, Thu Aug 7 14:09:36 2014 UTC vs.
Revision 8437 by michael, Thu Mar 29 09:05:34 2018 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2018 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 47 | Line 47 | class_get_list(void)
47   struct ClassItem *
48   class_make(void)
49   {
50 <  struct ClassItem *class = MyCalloc(sizeof(*class));
50 >  struct ClassItem *class = xcalloc(sizeof(*class));
51  
52    class->active    = 1;
53    class->con_freq  = DEFAULT_CONNECTFREQUENCY;
# Line 62 | Line 62 | class_make(void)
62   }
63  
64   void
65 < class_free(struct ClassItem *class)
65 > class_free(struct ClassItem *const class)
66   {
67    assert(class != class_default);
68    assert(class->active    == 0);
69    assert(class->ref_count == 0);
70  
71    dlinkDelete(&class->node, &class_list);
72 <  MyFree(class->name);
73 <  MyFree(class);
72 >  xfree(class->name);
73 >  xfree(class);
74   }
75  
76   void
77   class_init(void)
78   {
79 <  (class_default = class_make())->name = xstrdup("default");
79 >  class_default = class_make();
80 >  class_default->name = xstrdup("default");
81   }
82  
83 < struct ClassItem *
84 < get_class_ptr(const dlink_list *const list)
83 > const struct ClassItem *
84 > class_get_ptr(const dlink_list *const list)
85   {
86 <  const dlink_node *ptr = NULL;
86 >  const dlink_node *const node = list->head;
87  
88 <  if ((ptr = list->head))
88 >  if (node)
89    {
90 <    const struct MaskItem *conf = ptr->data;
90 >    const struct MaskItem *const conf = node->data;
91  
92      assert(conf->class);
93      assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
# Line 100 | Line 101 | get_class_ptr(const dlink_list *const li
101   const char *
102   get_client_class(const dlink_list *const list)
103   {
104 <  const dlink_node *ptr = NULL;
104 <
105 <  if ((ptr = list->head))
106 <  {
107 <    const struct MaskItem *conf = ptr->data;
108 <
109 <    assert(conf->class);
110 <    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
111 <
112 <    return conf->class->name;
113 <  }
114 <
115 <  return class_default->name;
104 >  return class_get_ptr(list)->name;
105   }
106  
107   unsigned int
108   get_client_ping(const dlink_list *const list)
109   {
110 <  const dlink_node *ptr = NULL;
122 <
123 <  if ((ptr = list->head))
124 <  {
125 <    const struct MaskItem *conf = ptr->data;
126 <
127 <    assert(conf->class);
128 <    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
129 <
130 <    return conf->class->ping_freq;
131 <  }
132 <
133 <  return class_default->ping_freq;
110 >  return class_get_ptr(list)->ping_freq;
111   }
112  
113   unsigned int
114   get_sendq(const dlink_list *const list)
115   {
116 <  const dlink_node *ptr = NULL;
140 <
141 <  if ((ptr = list->head))
142 <  {
143 <    const struct MaskItem *conf = ptr->data;
144 <
145 <    assert(conf->class);
146 <    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
147 <
148 <    return conf->class->max_sendq;
149 <  }
150 <
151 <  return class_default->max_sendq;
116 >  return class_get_ptr(list)->max_sendq;
117   }
118  
119   unsigned int
120   get_recvq(const dlink_list *const list)
121   {
122 <  const dlink_node *ptr = NULL;
158 <
159 <  if ((ptr = list->head))
160 <  {
161 <    const struct MaskItem *conf = ptr->data;
162 <
163 <    assert(conf->class);
164 <    assert(conf->type & (CONF_OPER | CONF_CLIENT | CONF_SERVER));
165 <
166 <    return conf->class->max_recvq;
167 <  }
168 <
169 <  return class_default->max_recvq;
122 >  return class_get_ptr(list)->max_recvq;
123   }
124  
125   /*
# Line 177 | Line 130 | get_recvq(const dlink_list *const list)
130   struct ClassItem *
131   class_find(const char *name, int active)
132   {
133 <  dlink_node *ptr = NULL;
133 >  dlink_node *node;
134  
135 <  DLINK_FOREACH(ptr, class_list.head)
135 >  DLINK_FOREACH(node, class_list.head)
136    {
137 <    struct ClassItem *class = ptr->data;
137 >    struct ClassItem *class = node->data;
138  
139      if (!irccmp(class->name, name))
140        return active && !class->active ? NULL : class;
# Line 197 | Line 150 | class_find(const char *name, int active)
150   void
151   class_mark_for_deletion(void)
152   {
153 <  dlink_node *ptr = NULL;
153 >  dlink_node *node;
154  
155 <  DLINK_FOREACH_PREV(ptr, class_list.tail->prev)
156 <    ((struct ClassItem *)ptr->data)->active = 0;
155 >  DLINK_FOREACH_PREV(node, class_list.tail->prev)
156 >    ((struct ClassItem *)node->data)->active = 0;
157   }
158  
159   void
160   class_delete_marked(void)
161   {
162 <  dlink_node *ptr = NULL, *ptr_next = NULL;
162 >  dlink_node *node, *node_next;
163  
164 <  DLINK_FOREACH_SAFE(ptr, ptr_next, class_list.head)
164 >  DLINK_FOREACH_SAFE(node, node_next, class_list.head)
165    {
166 <    struct ClassItem *class = ptr->data;
166 >    struct ClassItem *class = node->data;
167  
168 <    if (!class->active && !class->ref_count)
168 >    if (class->active == 0 && class->ref_count == 0)
169      {
170        destroy_cidr_class(class);
171        class_free(class);
# Line 233 | Line 186 | class_delete_marked(void)
186   int
187   cidr_limit_reached(int over_rule, struct irc_ssaddr *ip, struct ClassItem *class)
188   {
189 <  dlink_node *ptr = NULL;
237 <  struct CidrItem *cidr = NULL;
189 >  dlink_node *node;
190  
191    if (class->number_per_cidr == 0)
192      return 0;
# Line 244 | Line 196 | cidr_limit_reached(int over_rule, struct
196      if (class->cidr_bitlen_ipv4 == 0)
197        return 0;
198  
199 <    DLINK_FOREACH(ptr, class->list_ipv4.head)
199 >    DLINK_FOREACH(node, class->list_ipv4.head)
200      {
201 <      cidr = ptr->data;
201 >      struct CidrItem *cidr = node->data;
202  
203        if (match_ipv4(ip, &cidr->mask, class->cidr_bitlen_ipv4))
204        {
# Line 258 | Line 210 | cidr_limit_reached(int over_rule, struct
210        }
211      }
212  
213 <    cidr = MyCalloc(sizeof(struct CidrItem));
213 >    struct CidrItem *cidr = xcalloc(sizeof(*cidr));
214      cidr->number_on_this_cidr = 1;
215      cidr->mask = *ip;
216      mask_addr(&cidr->mask, class->cidr_bitlen_ipv4);
# Line 266 | Line 218 | cidr_limit_reached(int over_rule, struct
218    }
219    else if (class->cidr_bitlen_ipv6 > 0)
220    {
221 <    DLINK_FOREACH(ptr, class->list_ipv6.head)
221 >    DLINK_FOREACH(node, class->list_ipv6.head)
222      {
223 <      cidr = ptr->data;
223 >      struct CidrItem *cidr = node->data;
224  
225        if (match_ipv6(ip, &cidr->mask, class->cidr_bitlen_ipv6))
226        {
# Line 280 | Line 232 | cidr_limit_reached(int over_rule, struct
232        }
233      }
234  
235 <    cidr = MyCalloc(sizeof(struct CidrItem));
235 >    struct CidrItem *cidr = xcalloc(sizeof(*cidr));
236      cidr->number_on_this_cidr = 1;
237      cidr->mask = *ip;
238      mask_addr(&cidr->mask, class->cidr_bitlen_ipv6);
# Line 301 | Line 253 | cidr_limit_reached(int over_rule, struct
253   void
254   remove_from_cidr_check(struct irc_ssaddr *ip, struct ClassItem *aclass)
255   {
256 <  dlink_node *ptr = NULL;
305 <  dlink_node *next_ptr = NULL;
306 <  struct CidrItem *cidr;
256 >  dlink_node *node, *node_next;
257  
258    if (aclass->number_per_cidr == 0)
259      return;
# Line 313 | Line 263 | remove_from_cidr_check(struct irc_ssaddr
263      if (aclass->cidr_bitlen_ipv4 == 0)
264        return;
265  
266 <    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv4.head)
266 >    DLINK_FOREACH_SAFE(node, node_next, aclass->list_ipv4.head)
267      {
268 <      cidr = ptr->data;
268 >      struct CidrItem *cidr = node->data;
269  
270        if (match_ipv4(ip, &cidr->mask, aclass->cidr_bitlen_ipv4))
271        {
# Line 323 | Line 273 | remove_from_cidr_check(struct irc_ssaddr
273  
274          if (cidr->number_on_this_cidr == 0)
275          {
276 <          dlinkDelete(ptr, &aclass->list_ipv4);
277 <          MyFree(cidr);
276 >          dlinkDelete(node, &aclass->list_ipv4);
277 >          xfree(cidr);
278            return;
279          }
280        }
# Line 332 | Line 282 | remove_from_cidr_check(struct irc_ssaddr
282    }
283    else if (aclass->cidr_bitlen_ipv6 > 0)
284    {
285 <    DLINK_FOREACH_SAFE(ptr, next_ptr, aclass->list_ipv6.head)
285 >    DLINK_FOREACH_SAFE(node, node_next, aclass->list_ipv6.head)
286      {
287 <      cidr = ptr->data;
287 >      struct CidrItem *cidr = node->data;
288  
289        if (match_ipv6(ip, &cidr->mask, aclass->cidr_bitlen_ipv6))
290        {
# Line 342 | Line 292 | remove_from_cidr_check(struct irc_ssaddr
292  
293          if (cidr->number_on_this_cidr == 0)
294          {
295 <          dlinkDelete(ptr, &aclass->list_ipv6);
296 <          MyFree(cidr);
295 >          dlinkDelete(node, &aclass->list_ipv6);
296 >          xfree(cidr);
297            return;
298          }
299        }
# Line 354 | Line 304 | remove_from_cidr_check(struct irc_ssaddr
304   void
305   rebuild_cidr_list(struct ClassItem *class)
306   {
307 <  dlink_node *ptr = NULL;
307 >  dlink_node *node;
308  
309    destroy_cidr_class(class);
310  
311 <  DLINK_FOREACH(ptr, local_client_list.head)
311 >  DLINK_FOREACH(node, local_client_list.head)
312    {
313 <    struct Client *client_p = ptr->data;
314 <    struct MaskItem *conf = client_p->localClient->confs.tail->data;
313 >    struct Client *client_p = node->data;
314 >    struct MaskItem *conf = client_p->connection->confs.tail->data;
315  
316      if (conf && (conf->type == CONF_CLIENT))
317        if (conf->class == class)
318 <        cidr_limit_reached(1, &client_p->localClient->ip, class);
318 >        cidr_limit_reached(1, &client_p->connection->ip, class);
319    }
320   }
321  
# Line 379 | Line 329 | rebuild_cidr_list(struct ClassItem *clas
329   static void
330   destroy_cidr_list(dlink_list *list)
331   {
332 <  dlink_node *ptr = NULL, *ptr_next = NULL;
383 <
384 <  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
332 >  while (list->head)
333    {
334 <    dlinkDelete(ptr, list);
335 <    MyFree(ptr->data);
334 >    struct CidrItem *cidr = list->head->data;
335 >    dlinkDelete(&cidr->node, list);
336 >    xfree(cidr);
337    }
338   }
339  

Comparing ircd-hybrid/trunk/src/conf_class.c (property svn:keywords):
Revision 4415 by michael, Thu Aug 7 14:09:36 2014 UTC vs.
Revision 8437 by michael, Thu Mar 29 09:05:34 2018 UTC

# Line 1 | Line 1
1 < Id Revision
1 > Id

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)