ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/server_capab.c
Revision: 8512
Committed: Fri Apr 6 19:28:05 2018 UTC (7 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 3480 byte(s)
Log Message:
- Style corrections

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2018 ircd-hybrid development team
5 *
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 server_capab.c
23 * \brief Server CAPAB related functions.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "ircd_defs.h"
32 #include "server_capab.h"
33 #include "memory.h"
34
35
36 static dlink_list capab_list; /* List of capabilities supported by this server */
37
38
39 /* capab_init()
40 *
41 * inputs - none
42 * output - none
43 */
44 void
45 capab_init(void)
46 {
47 capab_add("QS", CAPAB_QS);
48 capab_add("EOB", CAPAB_EOB);
49 capab_add("CLUSTER", CAPAB_CLUSTER);
50 capab_add("SVS", CAPAB_SVS);
51 capab_add("RHOST", CAPAB_RHOST);
52 }
53
54 /* capab_add()
55 *
56 * inputs - string name of CAPAB
57 * - int flag of capability
58 * output - NONE
59 * side effects - Adds given capability name and bit mask to
60 * current supported capabilities. This allows
61 * modules to dynamically add or subtract their capability.
62 */
63 void
64 capab_add(const char *name, unsigned int flag)
65 {
66 struct Capability *cap = xcalloc(sizeof(*cap));
67
68 cap->name = xstrdup(name);
69 cap->cap = flag;
70 dlinkAdd(cap, &cap->node, &capab_list);
71 }
72
73 /* capab_del()
74 *
75 * inputs - string name of CAPAB
76 * output - NONE
77 * side effects - delete given capability from ones known.
78 */
79 void
80 capab_del(const char *name)
81 {
82 dlink_node *node, *node_next;
83
84 DLINK_FOREACH_SAFE(node, node_next, capab_list.head)
85 {
86 struct Capability *cap = node->data;
87
88 if (irccmp(cap->name, name) == 0)
89 {
90 dlinkDelete(node, &capab_list);
91 xfree(cap->name);
92 xfree(cap);
93 }
94 }
95 }
96
97 /*
98 * capab_find()
99 *
100 * inputs - string name of capab to find
101 * output - 0 if not found CAPAB otherwise
102 * side effects - none
103 */
104 unsigned int
105 capab_find(const char *name)
106 {
107 dlink_node *node;
108
109 DLINK_FOREACH(node, capab_list.head)
110 {
111 const struct Capability *cap = node->data;
112
113 if (irccmp(cap->name, name) == 0)
114 return cap->cap;
115 }
116
117 return 0;
118 }
119
120 /*
121 * capab_get() - show current server capabilities
122 *
123 * inputs - pointer to a struct Client
124 * output - pointer to static string
125 * side effects - build up string representing capabilities of server listed
126 */
127 const char *
128 capab_get(const void *ptr)
129 {
130 static char buf[IRCD_BUFSIZE] = "";
131 dlink_node *node;
132
133 buf[0] = '\0'; /* buf is static */
134
135 DLINK_FOREACH(node, capab_list.head)
136 {
137 const struct Capability *cap = node->data;
138
139 if (ptr && !IsCapable(((const struct Client *)ptr), cap->cap))
140 continue;
141
142 strlcat(buf, cap->name, sizeof(buf));
143
144 if (node->next)
145 strlcat(buf, " ", sizeof(buf));
146 }
147
148 return buf;
149 }

Properties

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