ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/resv.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (14 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/resv.c
File size: 5338 byte(s)
Log Message:
- renaming files:

  ircd_parser.y -> conf_parser.y
  ircd_lexer.l  -> conf_lexer.l
  s_conf.c      -> conf.c
  s_conf.h      -> conf.h
  s_log.c       -> log.c
  s_log.h       -> log.h

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

Properties

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