ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_module.c
Revision: 3300
Committed: Sat Apr 12 18:26:22 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 6655 byte(s)
Log Message:
- doxygen

File Contents

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

Properties

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