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

Comparing ircd-hybrid/trunk/src/resv.c (file contents):
Revision 1632 by michael, Sun Nov 4 15:37:10 2012 UTC vs.
Revision 1859 by michael, Thu Apr 25 15:09:36 2013 UTC

# Line 33 | Line 33
33   #include "hash.h"
34   #include "irc_string.h"
35   #include "ircd_defs.h"
36 + #include "s_misc.h"
37   #include "conf.h"
38   #include "conf_db.h"
39 + #include "channel.h"
40 + #include "hostmask.h"
41  
42   dlink_list resv_channel_list = { NULL, NULL, 0 };
43  
44  
45 < /* create_channel_resv()
43 < *
44 < * inputs       - name of channel to create resv for
45 < *              - reason for resv
46 < *              - flag, 1 for from ircd.conf 0 from elsehwere
47 < * output       - pointer to struct ResvChannel
48 < * side effects -
49 < */
50 < struct MaskItem *
51 < create_channel_resv(char *name, char *reason, int in_conf)
52 < {
53 <  struct MaskItem *conf = NULL;
54 <
55 <  if (name == NULL || reason == NULL)
56 <    return NULL;
57 <
58 <  if (hash_find_resv(name))
59 <    return NULL;
60 <
61 <  if (strlen(reason) > REASONLEN)
62 <    reason[REASONLEN] = '\0';
63 <
64 <  conf = conf_make(CONF_CRESV);
65 <
66 <  DupString(conf->name, name);
67 <  DupString(conf->reason, reason);
68 <
69 <  dlinkAdd(conf, &conf->node, &resv_channel_list);
70 <  hash_add_resv(conf);
71 <
72 <  return conf;
73 < }
74 <
75 < /* create_nick_resv()
45 > /* create_resv()
46   *
47   * inputs       - name of nick to create resv for
48   *              - reason for resv
# Line 81 | Line 51 | create_channel_resv(char *name, char *re
51   * side effects -
52   */
53   struct MaskItem *
54 < create_nick_resv(char *name, char *reason, int in_conf)
54 > create_resv(const char *name, const char *reason, const dlink_list *list)
55   {
56    struct MaskItem *conf = NULL;
57 +  enum maskitem_type type;
58  
59    if (name == NULL || reason == NULL)
60      return NULL;
61  
62 <  if (find_matching_name_conf(CONF_NRESV, name, NULL, NULL, 0))
63 <    return NULL;
62 >  if (IsChanPrefix(*name))
63 >    type = CONF_CRESV;
64 >  else
65 >    type = CONF_NRESV;
66  
67 <  if (strlen(reason) > REASONLEN)
68 <    reason[REASONLEN] = '\0';
67 >  if (find_exact_name_conf(type, NULL, name, NULL, NULL))
68 >    return NULL;
69  
70 <  conf = conf_make(CONF_NRESV);
70 >  conf = conf_make(type);
71 >  conf->name = xstrdup(name);
72 >  conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
73  
74 <  DupString(conf->name, name);
75 <  DupString(conf->reason, reason);
74 >  if (list)
75 >  {
76 >    if (strlen(name) == 2 && IsAlpha(*(name + 1) && IsAlpha(*(name + 2))))
77 >    {
78 >      struct exempt *exptr = MyMalloc(sizeof(*exptr));
79 >
80 >      exptr->name = xstrdup(name);
81 >      exptr->coid = GeoIP_id_by_code(name);
82 >      dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
83 >    }
84 >    else
85 >    {
86 >      dlink_node *ptr = NULL;
87 >
88 >      DLINK_FOREACH(ptr, list->head)
89 >      {
90 >        char nick[NICKLEN + 1];
91 >        char user[USERLEN + 1];
92 >        char host[HOSTLEN + 1];
93 >        struct split_nuh_item nuh;
94 >        struct exempt *exptr = NULL;
95 >
96 >        nuh.nuhmask  = name;
97 >        nuh.nickptr  = nick;
98 >        nuh.userptr  = user;
99 >        nuh.hostptr  = host;
100 >
101 >        nuh.nicksize = sizeof(nick);
102 >        nuh.usersize = sizeof(user);
103 >        nuh.hostsize = sizeof(host);
104 >
105 >        split_nuh(&nuh);
106 >
107 >        exptr = MyMalloc(sizeof(*exptr));
108 >        exptr->name = xstrdup(name);
109 >        exptr->user = xstrdup(user);
110 >        exptr->host = xstrdup(host);
111 >        exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits);
112 >        dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
113 >      }
114 >    }
115 >  }
116  
117    return conf;
118   }
119  
120 < /* clear_conf_resv()
121 < *
107 < * inputs       - none
108 < * output       - none
109 < * side effects - All resvs are cleared out
110 < */
111 < void
112 < clear_conf_resv(void)
120 > int
121 > resv_find_exempt(const struct Client *who, const struct MaskItem *conf)
122   {
123 <  dlink_node *ptr = NULL, *next_ptr = NULL;
123 >  const dlink_node *ptr = NULL;
124  
125 <  DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
125 >  DLINK_FOREACH(ptr, conf->exempt_list.head)
126    {
127 <    struct MaskItem *conf = ptr->data;
127 >    const struct exempt *exptr = ptr->data;
128  
129 <    if (!IsConfDatabase(conf))
130 <      delete_channel_resv(conf);
129 >    if (exptr->coid)
130 >    {
131 >      if (exptr->coid == who->localClient->country_id)
132 >        return 1;
133 >    }
134 >    else if (!match(exptr->name, who->name) && !match(exptr->user, who->username))
135 >    {
136 >      switch (exptr->type)
137 >      {
138 >        case HM_HOST:
139 >          if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost))
140 >            return 1;
141 >          break;
142 >        case HM_IPV4:
143 >          if (who->localClient->aftype == AF_INET)
144 >            if (match_ipv4(&who->localClient->ip, &exptr->addr, exptr->bits))
145 >              return 1;
146 >          break;
147 > #ifdef IPV6
148 >        case HM_IPV6:
149 >          if (who->localClient->aftype == AF_INET6)
150 >            if (match_ipv6(&who->localClient->ip, &exptr->addr, exptr->bits))
151 >              return 1;
152 >          break;
153 > #endif
154 >        default:
155 >          assert(0);
156 >      }
157 >    }
158    }
123 – }
159  
160 < /* delete_channel_resv()
126 < *
127 < * inputs       - pointer to channel resv to delete
128 < * output       - none
129 < * side effects - given struct ResvChannel * is removed
130 < */
131 < int
132 < delete_channel_resv(struct MaskItem *conf)
133 < {
134 <  hash_del_resv(conf);
135 <  dlinkDelete(&conf->node, &resv_channel_list);
136 <  conf_free(conf);
137 <
138 <  return 1;
160 >  return 0;
161   }
162  
163   /* match_find_resv()
# Line 157 | Line 179 | match_find_resv(const char *name)
179    {
180      struct MaskItem *conf = ptr->data;
181  
182 <    if (match_chan(name, conf->name))
182 >    if (!match(conf->name, name))
183        return conf;
184    }
185  
# Line 181 | Line 203 | report_resv(struct Client *source_p)
203      conf = ptr->data;
204      sendto_one(source_p, form_str(RPL_STATSQLINE),
205                 me.name, source_p->name,
206 <               conf->hold ? 'q' : 'Q',
206 >               conf->until ? 'q' : 'Q', conf->count,
207                 conf->name, conf->reason);
208    }
209  
210    DLINK_FOREACH(ptr, nresv_items.head)
211    {
212 <    conf = ptr->data;;
212 >    conf = ptr->data;
213      sendto_one(source_p, form_str(RPL_STATSQLINE),
214                 me.name, source_p->name,
215 <               conf->hold ? 'q' : 'Q',
215 >               conf->until ? 'q' : 'Q', conf->count,
216                 conf->name, conf->reason);
217    }
218   }

Diff Legend

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