ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/resv.c
Revision: 1632
Committed: Sun Nov 4 15:37:10 2012 UTC (12 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 4933 byte(s)
Log Message:
- Initial rewrite of the configuration subsystem

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 1309 #include "conf.h"
37 michael 1622 #include "conf_db.h"
38 adx 30
39     dlink_list resv_channel_list = { NULL, NULL, 0 };
40    
41    
42     /* 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 michael 1632 struct MaskItem *
51 adx 30 create_channel_resv(char *name, char *reason, int in_conf)
52     {
53 michael 1632 struct MaskItem *conf = NULL;
54 adx 30
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 michael 1632 conf = conf_make(CONF_CRESV);
65 adx 30
66 michael 867 DupString(conf->name, name);
67 michael 1632 DupString(conf->reason, reason);
68 adx 30
69 michael 1632 dlinkAdd(conf, &conf->node, &resv_channel_list);
70     hash_add_resv(conf);
71 adx 30
72     return conf;
73     }
74    
75     /* create_nick_resv()
76     *
77     * inputs - name of nick to create resv for
78     * - reason for resv
79     * - 1 if from ircd.conf, 0 if from elsewhere
80     * output - pointer to struct ResvNick
81     * side effects -
82     */
83 michael 1632 struct MaskItem *
84 adx 30 create_nick_resv(char *name, char *reason, int in_conf)
85     {
86 michael 1632 struct MaskItem *conf = NULL;
87 adx 30
88     if (name == NULL || reason == NULL)
89     return NULL;
90    
91 michael 1632 if (find_matching_name_conf(CONF_NRESV, name, NULL, NULL, 0))
92 adx 30 return NULL;
93    
94     if (strlen(reason) > REASONLEN)
95     reason[REASONLEN] = '\0';
96    
97 michael 1632 conf = conf_make(CONF_NRESV);
98 adx 30
99     DupString(conf->name, name);
100 michael 1632 DupString(conf->reason, reason);
101 adx 30
102     return conf;
103     }
104    
105     /* clear_conf_resv()
106     *
107     * inputs - none
108     * output - none
109     * side effects - All resvs are cleared out
110     */
111     void
112     clear_conf_resv(void)
113     {
114 michael 867 dlink_node *ptr = NULL, *next_ptr = NULL;
115 adx 30
116     DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
117 michael 1628 {
118 michael 1632 struct MaskItem *conf = ptr->data;
119 michael 1628
120 michael 1632 if (!IsConfDatabase(conf))
121     delete_channel_resv(conf);
122 michael 1628 }
123 adx 30 }
124    
125     /* 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 michael 1632 delete_channel_resv(struct MaskItem *conf)
133 adx 30 {
134 michael 1632 hash_del_resv(conf);
135     dlinkDelete(&conf->node, &resv_channel_list);
136     conf_free(conf);
137 adx 30
138     return 1;
139     }
140    
141     /* match_find_resv()
142     *
143     * inputs - pointer to name
144     * output - pointer to a struct ResvChannel
145     * side effects - Finds a reserved channel whose name matches 'name',
146     * if can't find one returns NULL.
147     */
148 michael 1632 struct MaskItem *
149 adx 30 match_find_resv(const char *name)
150     {
151     dlink_node *ptr = NULL;
152    
153     if (EmptyString(name))
154     return NULL;
155    
156     DLINK_FOREACH(ptr, resv_channel_list.head)
157     {
158 michael 1632 struct MaskItem *conf = ptr->data;
159 adx 30
160 michael 1632 if (match_chan(name, conf->name))
161     return conf;
162 adx 30 }
163    
164     return NULL;
165     }
166    
167     /* report_resv()
168     *
169     * inputs - pointer to client pointer to report to.
170     * output - NONE
171     * side effects - report all resvs to client.
172     */
173     void
174     report_resv(struct Client *source_p)
175     {
176 michael 1632 dlink_node *ptr = NULL;
177     struct MaskItem *conf = NULL;
178 adx 30
179     DLINK_FOREACH(ptr, resv_channel_list.head)
180     {
181 michael 1632 conf = ptr->data;
182 adx 30 sendto_one(source_p, form_str(RPL_STATSQLINE),
183     me.name, source_p->name,
184 michael 1632 conf->hold ? 'q' : 'Q',
185     conf->name, conf->reason);
186 adx 30 }
187    
188     DLINK_FOREACH(ptr, nresv_items.head)
189     {
190 michael 1632 conf = ptr->data;;
191 adx 30 sendto_one(source_p, form_str(RPL_STATSQLINE),
192     me.name, source_p->name,
193 michael 1632 conf->hold ? 'q' : 'Q',
194     conf->name, conf->reason);
195 adx 30 }
196     }
197    
198     /* valid_wild_card_simple()
199     *
200     * inputs - data to check for sufficient non-wildcard characters
201     * outputs - 1 if valid, else 0
202     * side effects - none
203     */
204     int
205     valid_wild_card_simple(const char *data)
206     {
207     const unsigned char *p = (const unsigned char *)data;
208     int nonwild = 0;
209    
210     while (*p != '\0')
211     {
212     if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
213     if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
214     return 1;
215     if (*p != '\0')
216     ++p;
217     }
218    
219     return 0;
220     }

Properties

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