ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_module.c
Revision: 3320
Committed: Tue Apr 15 15:58:33 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 6633 byte(s)
Log Message:
- Removed useless header includes

File Contents

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

Properties

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