/[svn]/branches/newio/modules/m_module.c
ViewVC logotype

Contents of /branches/newio/modules/m_module.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1832 - (show annotations)
Fri Apr 19 19:16:09 2013 UTC (7 years, 2 months ago) by michael
Original Path: ircd-hybrid/trunk/modules/m_module.c
File MIME type: text/x-chdr
File size: 7363 byte(s)
- Made all numeric defines use the actual string instead of the numeric value
  which allows to use gcc's printf format attribute
- Remove current message locale implementation

1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 *
4 * Copyright (C) 2002 by the past and present ircd coders, and others.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file m_module.c
23 * \brief Includes required functions for processing the MODULE command.
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.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "log.h"
35 #include "s_user.h"
36 #include "send.h"
37 #include "parse.h"
38 #include "modules.h"
39 #include "packet.h"
40
41
42
43 /*! \brief MODULE command handler (called by operators)
44 *
45 * \param client_p Pointer to allocated Client struct with physical connection
46 * to this server, i.e. with an open socket connected.
47 * \param source_p Pointer to allocated Client struct from which the message
48 * originally comes from. This can be a local or remote client.
49 * \param parc Integer holding the number of supplied arguments.
50 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
51 * pointers.
52 * \note Valid arguments for this command are:
53 * - parv[0] = sender prefix
54 * - parv[1] = action [LOAD, UNLOAD, RELOAD, LIST]
55 * - parv[2] = module name
56 */
57 static void
58 mo_module(struct Client *client_p, struct Client *source_p,
59 int parc, char *parv[])
60 {
61 const char *m_bn = NULL;
62 struct module *modp = NULL;
63 int check_core;
64
65 if (!HasOFlag(source_p, OPER_FLAG_MODULE))
66 {
67 sendto_one(source_p, ERR_NOPRIVILEGES,
68 me.name, source_p->name);
69 return;
70 }
71
72 if (EmptyString(parv[1]))
73 {
74 sendto_one(source_p, ERR_NEEDMOREPARAMS,
75 me.name, source_p->name, "MODULE");
76 return;
77 }
78
79 if (!irccmp(parv[1], "LOAD"))
80 {
81 if (EmptyString(parv[2]))
82 {
83 sendto_one(source_p, ERR_NEEDMOREPARAMS,
84 me.name, source_p->name, "MODULE");
85 return;
86 }
87
88 if (findmodule_byname((m_bn = libio_basename(parv[2]))) != NULL)
89 {
90 sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded",
91 me.name, source_p->name, m_bn);
92 return;
93 }
94
95 load_one_module(parv[2]);
96 return;
97 }
98
99 if (!irccmp(parv[1], "UNLOAD"))
100 {
101 if (EmptyString(parv[2]))
102 {
103 sendto_one(source_p, ERR_NEEDMOREPARAMS,
104 me.name, source_p->name, "MODULE");
105 return;
106 }
107
108 if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL)
109 {
110 sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
111 me.name, source_p->name, m_bn);
112 return;
113 }
114
115 if (modp->flags & MODULE_FLAG_CORE)
116 {
117 sendto_one(source_p,
118 ":%s NOTICE %s :Module %s is a core module and may not be unloaded",
119 me.name, source_p->name, m_bn);
120 return;
121 }
122
123 if (modp->flags & MODULE_FLAG_NOUNLOAD)
124 {
125 sendto_one(source_p,
126 ":%s NOTICE %s :Module %s is a resident module and may not be unloaded",
127 me.name, source_p->name, m_bn);
128 return;
129 }
130
131 if (unload_one_module(m_bn, 1) == -1)
132 sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
133 me.name, source_p->name, m_bn);
134 return;
135 }
136
137 if (!irccmp(parv[1], "RELOAD"))
138 {
139 if (EmptyString(parv[2]))
140 {
141 sendto_one(source_p, ERR_NEEDMOREPARAMS,
142 me.name, source_p->name, "MODULE");
143 return;
144 }
145
146 if (!strcmp(parv[2], "*"))
147 {
148 unsigned int modnum = 0;
149 dlink_node *ptr = NULL, *ptr_next = NULL;
150
151 sendto_one(source_p, ":%s NOTICE %s :Reloading all modules",
152 me.name, source_p->name);
153
154 modnum = dlink_list_length(&modules_list);
155
156 DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
157 {
158 modp = ptr->data;
159
160 if (!(modp->flags & MODULE_FLAG_NOUNLOAD))
161 unload_one_module(modp->name, 0);
162 }
163
164 load_all_modules(0);
165 load_conf_modules();
166 load_core_modules(0);
167
168 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
169 "Module Restart: %u modules unloaded, %u modules loaded",
170 modnum, dlink_list_length(&modules_list));
171 ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded",
172 modnum, dlink_list_length(&modules_list));
173 return;
174 }
175
176 if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL)
177 {
178 sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
179 me.name, source_p->name, m_bn);
180 return;
181 }
182
183 if (modp->flags & MODULE_FLAG_NOUNLOAD)
184 {
185 sendto_one(source_p,
186 ":%s NOTICE %s :Module %s is a resident module and may not be unloaded",
187 me.name, source_p->name, m_bn);
188 return;
189 }
190
191 check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
192
193 if (unload_one_module(m_bn, 1) == -1)
194 {
195 sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
196 me.name, source_p->name, m_bn);
197 return;
198 }
199
200 if ((load_one_module(parv[2]) == -1) && check_core)
201 {
202 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
203 "Error reloading core "
204 "module: %s: terminating ircd", parv[2]);
205 ilog(LOG_TYPE_IRCD, "Error loading core module %s: terminating ircd", parv[2]);
206 exit(0);
207 }
208
209 return;
210 }
211
212 if (!irccmp(parv[1], "LIST"))
213 {
214 const dlink_node *ptr = NULL;
215
216 DLINK_FOREACH(ptr, modules_list.head)
217 {
218 modp = ptr->data;
219
220 if (!EmptyString(parv[2]) && match(parv[2], modp->name))
221 continue;
222
223 sendto_one(source_p, RPL_MODLIST, me.name, source_p->name,
224 modp->name, modp->handle,
225 modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
226 }
227
228 sendto_one(source_p, RPL_ENDOFMODLIST,
229 me.name, source_p->name);
230 return;
231 }
232
233 sendto_one(source_p, ":%s NOTICE %s :%s is not a valid option. "
234 "Choose from LOAD, UNLOAD, RELOAD, LIST",
235 me.name, source_p->name, parv[1]);
236 }
237
238
239 static struct Message module_msgtab = {
240 "MODULE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
241 {m_unregistered, m_not_oper, m_ignore, m_ignore, mo_module, m_ignore}
242 };
243
244 static void
245 module_init(void)
246 {
247 mod_add_cmd(&module_msgtab);
248 }
249
250 static void
251 module_exit(void)
252 {
253 mod_del_cmd(&module_msgtab);
254 }
255
256 struct module module_entry = {
257 .node = { NULL, NULL, NULL },
258 .name = NULL,
259 .version = "$Revision$",
260 .handle = NULL,
261 .modinit = module_init,
262 .modexit = module_exit,
263 .flags = MODULE_FLAG_NOUNLOAD
264 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28