ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/isupport.c
Revision: 9250
Committed: Sat Feb 1 13:36:10 2020 UTC (5 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 5237 byte(s)
Log Message:
- Rename most occurrences of 'client_p' to 'client'

File Contents

# User Rev Content
1 michael 6185 /*
2     * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3     *
4 michael 9101 * Copyright (c) 1997-2020 ircd-hybrid development team
5 michael 6185 *
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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19     * USA
20     */
21    
22     /*! \file isupport.c
23     * \brief Contains functions pertaining to RPL_ISUPPORT.
24     * \version $Id$
25     */
26    
27     #include "stdinc.h"
28     #include "list.h"
29     #include "ircd.h"
30     #include "conf.h"
31     #include "send.h"
32     #include "numeric.h"
33     #include "client.h"
34     #include "irc_string.h"
35     #include "memory.h"
36     #include "isupport.h"
37 michael 9234 #include "channel.h"
38 michael 6185 #include "channel_mode.h"
39     #include "parse.h"
40    
41    
42     /* Used for building up the isupport string,
43     * used with init_isupport, add_isupport, delete_isupport
44     */
45     struct Isupport
46     {
47     dlink_node node;
48     char *name;
49     char *options;
50     int number;
51     };
52    
53     static dlink_list isupport_list;
54     static dlink_list isupport_list_lines;
55    
56     /*
57     * isupport_init()
58     *
59     * input - NONE
60     * output - NONE
61     * side effects - Must be called before isupport is enabled
62     */
63     void
64     isupport_init(void)
65     {
66     isupport_add("CALLERID", NULL, -1);
67 michael 6824 isupport_add("CASEMAPPING", "ascii", -1);
68 michael 6185 isupport_add("DEAF", "D", -1);
69     isupport_add("KICKLEN", NULL, KICKLEN);
70     isupport_add("MODES", NULL, MAXMODEPARAMS);
71 michael 6904 isupport_add("PREFIX", "(ohv)" CMEMBER_STATUS_FLAGS, -1);
72     isupport_add("STATUSMSG", CMEMBER_STATUS_FLAGS, -1);
73 michael 6185 isupport_add("EXCEPTS", NULL, -1);
74     isupport_add("INVEX", NULL, -1);
75     }
76    
77     /*
78     * isupport_add()
79     *
80     * input - name of supported function
81     * - options if any
82     * - number if any
83     * output - NONE
84     * side effects - Each supported item must call this when activated
85     */
86     void
87     isupport_add(const char *name, const char *options, int n)
88     {
89     dlink_node *node = NULL;
90     struct Isupport *support = NULL;
91    
92     DLINK_FOREACH(node, isupport_list.head)
93     {
94     support = node->data;
95     if (irccmp(support->name, name) == 0)
96     {
97 michael 7032 xfree(support->name);
98     xfree(support->options);
99 michael 6185 break;
100     }
101     }
102    
103     if (node == NULL)
104     {
105 michael 7032 support = xcalloc(sizeof(*support));
106 michael 6185 dlinkAddTail(support, &support->node, &isupport_list);
107     }
108    
109     support->name = xstrdup(name);
110     if (options)
111     support->options = xstrdup(options);
112     support->number = n;
113    
114     isupport_rebuild();
115     }
116    
117     /*
118     * isupport_delete()
119     *
120     * input - name of supported function
121     * output - NONE
122     * side effects - Each supported item must call this when deactivated
123     */
124     void
125     isupport_delete(const char *name)
126     {
127     dlink_node *node = NULL;
128    
129     DLINK_FOREACH(node, isupport_list.head)
130     {
131     struct Isupport *support = node->data;
132    
133     if (irccmp(support->name, name) == 0)
134     {
135     dlinkDelete(node, &isupport_list);
136 michael 7032 xfree(support->name);
137     xfree(support->options);
138     xfree(support);
139 michael 6185 break;
140     }
141     }
142    
143     isupport_rebuild();
144     }
145    
146     /*
147     * issuport_rebuild()
148     *
149     * input - NONE
150     * output - NONE
151     * side effects - Destroy the isupport MessageFile lines, and rebuild.
152     */
153     void
154     isupport_rebuild(void)
155     {
156     char isupportbuffer[IRCD_BUFSIZE];
157     char *p = isupportbuffer;
158     dlink_node *node = NULL, *node_next = NULL;
159     int n = 0;
160     int tokens = 0;
161     size_t len = 0;
162     size_t reserve = strlen(me.name) + HOSTLEN + strlen(numeric_form(RPL_ISUPPORT));
163    
164     DLINK_FOREACH_SAFE(node, node_next, isupport_list_lines.head)
165     {
166     dlinkDelete(node, &isupport_list_lines);
167 michael 7032 xfree(node->data);
168 michael 6185 free_dlink_node(node);
169     }
170    
171     DLINK_FOREACH(node, isupport_list.head)
172     {
173     struct Isupport *support = node->data;
174    
175     p += (n = sprintf(p, "%s", support->name));
176     len += n;
177    
178     if (support->options)
179     {
180     p += (n = sprintf(p, "=%s", support->options));
181     len += n;
182     }
183    
184     if (support->number > 0)
185     {
186     p += (n = sprintf(p, "=%d", support->number));
187     len += n;
188     }
189    
190     *p++ = ' ';
191     len++;
192     *p = '\0';
193    
194     if (++tokens == (MAXPARA-2) || len >= (sizeof(isupportbuffer)-reserve))
195     { /* arbritrary for now */
196     if (*--p == ' ')
197     *p = '\0';
198    
199     dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &isupport_list_lines);
200     p = isupportbuffer;
201     len = 0;
202 michael 6193 n = 0;
203     tokens = 0;
204 michael 6185 }
205     }
206    
207     if (len)
208     {
209     if (*--p == ' ')
210     *p = '\0';
211     dlinkAddTail(xstrdup(isupportbuffer), make_dlink_node(), &isupport_list_lines);
212     }
213     }
214    
215     /* isupport_show()
216     *
217     * inputs - pointer to client
218     * output - NONE
219     * side effects - display to client what we support (for them)
220     */
221     void
222 michael 9250 isupport_show(struct Client *client)
223 michael 6185 {
224 michael 9250 dlink_node *node;
225 michael 6185
226     DLINK_FOREACH(node, isupport_list_lines.head)
227 michael 9250 sendto_one_numeric(client, &me, RPL_ISUPPORT, node->data);
228 michael 6185 }

Properties

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