1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2020 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("EOB", CAPAB_EOB); |
48 |
capab_add("CLUSTER", CAPAB_CLUSTER); |
49 |
capab_add("RHOST", CAPAB_RHOST); |
50 |
} |
51 |
|
52 |
/* capab_add() |
53 |
* |
54 |
* inputs - string name of CAPAB |
55 |
* - int flag of capability |
56 |
* output - NONE |
57 |
* side effects - Adds given capability name and bit mask to |
58 |
* current supported capabilities. This allows |
59 |
* modules to dynamically add or subtract their capability. |
60 |
*/ |
61 |
void |
62 |
capab_add(const char *name, unsigned int flag) |
63 |
{ |
64 |
struct Capability *cap = xcalloc(sizeof(*cap)); |
65 |
|
66 |
cap->name = xstrdup(name); |
67 |
cap->cap = flag; |
68 |
dlinkAdd(cap, &cap->node, &capab_list); |
69 |
} |
70 |
|
71 |
/* capab_del() |
72 |
* |
73 |
* inputs - string name of CAPAB |
74 |
* output - NONE |
75 |
* side effects - delete given capability from ones known. |
76 |
*/ |
77 |
void |
78 |
capab_del(const char *name) |
79 |
{ |
80 |
dlink_node *node, *node_next; |
81 |
|
82 |
DLINK_FOREACH_SAFE(node, node_next, capab_list.head) |
83 |
{ |
84 |
struct Capability *cap = node->data; |
85 |
|
86 |
if (irccmp(cap->name, name) == 0) |
87 |
{ |
88 |
dlinkDelete(node, &capab_list); |
89 |
xfree(cap->name); |
90 |
xfree(cap); |
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
/* |
96 |
* capab_find() |
97 |
* |
98 |
* inputs - string name of capab to find |
99 |
* output - 0 if not found CAPAB otherwise |
100 |
* side effects - none |
101 |
*/ |
102 |
unsigned int |
103 |
capab_find(const char *name) |
104 |
{ |
105 |
dlink_node *node; |
106 |
|
107 |
DLINK_FOREACH(node, capab_list.head) |
108 |
{ |
109 |
const struct Capability *cap = node->data; |
110 |
|
111 |
if (irccmp(cap->name, name) == 0) |
112 |
return cap->cap; |
113 |
} |
114 |
|
115 |
return 0; |
116 |
} |
117 |
|
118 |
/* |
119 |
* capab_get() - show current server capabilities |
120 |
* |
121 |
* inputs - pointer to a struct Client |
122 |
* output - pointer to static string |
123 |
* side effects - build up string representing capabilities of server listed |
124 |
*/ |
125 |
const char * |
126 |
capab_get(const void *ptr) |
127 |
{ |
128 |
static char buf[IRCD_BUFSIZE] = ""; |
129 |
dlink_node *node; |
130 |
|
131 |
buf[0] = '\0'; /* buf is static */ |
132 |
|
133 |
DLINK_FOREACH(node, capab_list.head) |
134 |
{ |
135 |
const struct Capability *cap = node->data; |
136 |
|
137 |
if (ptr && !IsCapable(((const struct Client *)ptr), cap->cap)) |
138 |
continue; |
139 |
|
140 |
strlcat(buf, cap->name, sizeof(buf)); |
141 |
|
142 |
if (node->next) |
143 |
strlcat(buf, " ", sizeof(buf)); |
144 |
} |
145 |
|
146 |
return buf; |
147 |
} |