ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/resv.c
Revision: 1646
Committed: Wed Nov 7 21:02:43 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 4893 byte(s)
Log Message:
- First pass of conf parser stabilization/cleanup

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * resv.c: Functions to reserve(jupe) a nick/channel.
4     *
5     * Copyright (C) 2001-2002 Hybrid Development Team
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26 michael 1011 #include "list.h"
27 adx 30 #include "ircd.h"
28     #include "send.h"
29     #include "client.h"
30     #include "memory.h"
31     #include "numeric.h"
32     #include "resv.h"
33     #include "hash.h"
34     #include "irc_string.h"
35     #include "ircd_defs.h"
36 michael 1646 #include "s_misc.h"
37 michael 1309 #include "conf.h"
38 michael 1622 #include "conf_db.h"
39 adx 30
40     dlink_list resv_channel_list = { NULL, NULL, 0 };
41    
42    
43     /* create_channel_resv()
44     *
45     * inputs - name of channel to create resv for
46     * - reason for resv
47     * - flag, 1 for from ircd.conf 0 from elsehwere
48     * output - pointer to struct ResvChannel
49     * side effects -
50     */
51 michael 1632 struct MaskItem *
52 adx 30 create_channel_resv(char *name, char *reason, int in_conf)
53     {
54 michael 1632 struct MaskItem *conf = NULL;
55 adx 30
56     if (name == NULL || reason == NULL)
57     return NULL;
58    
59     if (hash_find_resv(name))
60     return NULL;
61    
62 michael 1632 conf = conf_make(CONF_CRESV);
63 michael 1646 conf->name = xstrdup(name);
64     conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
65 adx 30
66 michael 1632 dlinkAdd(conf, &conf->node, &resv_channel_list);
67     hash_add_resv(conf);
68 adx 30
69     return conf;
70     }
71    
72     /* create_nick_resv()
73     *
74     * inputs - name of nick to create resv for
75     * - reason for resv
76     * - 1 if from ircd.conf, 0 if from elsewhere
77     * output - pointer to struct ResvNick
78     * side effects -
79     */
80 michael 1632 struct MaskItem *
81 adx 30 create_nick_resv(char *name, char *reason, int in_conf)
82     {
83 michael 1632 struct MaskItem *conf = NULL;
84 adx 30
85     if (name == NULL || reason == NULL)
86     return NULL;
87    
88 michael 1632 if (find_matching_name_conf(CONF_NRESV, name, NULL, NULL, 0))
89 adx 30 return NULL;
90    
91 michael 1632 conf = conf_make(CONF_NRESV);
92 michael 1646 conf->name = xstrdup(name);
93     conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
94 adx 30
95     return conf;
96     }
97    
98     /* clear_conf_resv()
99     *
100     * inputs - none
101     * output - none
102     * side effects - All resvs are cleared out
103     */
104     void
105     clear_conf_resv(void)
106     {
107 michael 867 dlink_node *ptr = NULL, *next_ptr = NULL;
108 adx 30
109     DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
110 michael 1628 {
111 michael 1632 struct MaskItem *conf = ptr->data;
112 michael 1628
113 michael 1632 if (!IsConfDatabase(conf))
114     delete_channel_resv(conf);
115 michael 1628 }
116 adx 30 }
117    
118     /* delete_channel_resv()
119     *
120     * inputs - pointer to channel resv to delete
121     * output - none
122     * side effects - given struct ResvChannel * is removed
123     */
124     int
125 michael 1632 delete_channel_resv(struct MaskItem *conf)
126 adx 30 {
127 michael 1632 hash_del_resv(conf);
128     dlinkDelete(&conf->node, &resv_channel_list);
129     conf_free(conf);
130 adx 30
131     return 1;
132     }
133    
134     /* match_find_resv()
135     *
136     * inputs - pointer to name
137     * output - pointer to a struct ResvChannel
138     * side effects - Finds a reserved channel whose name matches 'name',
139     * if can't find one returns NULL.
140     */
141 michael 1632 struct MaskItem *
142 adx 30 match_find_resv(const char *name)
143     {
144     dlink_node *ptr = NULL;
145    
146     if (EmptyString(name))
147     return NULL;
148    
149     DLINK_FOREACH(ptr, resv_channel_list.head)
150     {
151 michael 1632 struct MaskItem *conf = ptr->data;
152 adx 30
153 michael 1632 if (match_chan(name, conf->name))
154     return conf;
155 adx 30 }
156    
157     return NULL;
158     }
159    
160     /* report_resv()
161     *
162     * inputs - pointer to client pointer to report to.
163     * output - NONE
164     * side effects - report all resvs to client.
165     */
166     void
167     report_resv(struct Client *source_p)
168     {
169 michael 1632 dlink_node *ptr = NULL;
170     struct MaskItem *conf = NULL;
171 adx 30
172     DLINK_FOREACH(ptr, resv_channel_list.head)
173     {
174 michael 1632 conf = ptr->data;
175 adx 30 sendto_one(source_p, form_str(RPL_STATSQLINE),
176     me.name, source_p->name,
177 michael 1632 conf->hold ? 'q' : 'Q',
178     conf->name, conf->reason);
179 adx 30 }
180    
181     DLINK_FOREACH(ptr, nresv_items.head)
182     {
183 michael 1632 conf = ptr->data;;
184 adx 30 sendto_one(source_p, form_str(RPL_STATSQLINE),
185     me.name, source_p->name,
186 michael 1632 conf->hold ? 'q' : 'Q',
187     conf->name, conf->reason);
188 adx 30 }
189     }
190    
191     /* valid_wild_card_simple()
192     *
193     * inputs - data to check for sufficient non-wildcard characters
194     * outputs - 1 if valid, else 0
195     * side effects - none
196     */
197     int
198     valid_wild_card_simple(const char *data)
199     {
200     const unsigned char *p = (const unsigned char *)data;
201     int nonwild = 0;
202    
203     while (*p != '\0')
204     {
205     if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
206     if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
207     return 1;
208     if (*p != '\0')
209     ++p;
210     }
211    
212     return 0;
213     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision