ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_module.c
Revision: 2959
Committed: Tue Jan 28 17:30:49 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 7505 byte(s)
Log Message:
- Added modules_get_list() and made modules_list visible to only modules.c
- Fixed naming convetion of other linked lists in modules.c

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 1447 /*! \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 michael 2820 static int
58 michael 1447 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 michael 2801 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
68     source_p->name, "module");
69 michael 2820 return 0;
70 michael 1447 }
71    
72     if (EmptyString(parv[1]))
73     {
74 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
75 michael 1447 me.name, source_p->name, "MODULE");
76 michael 2820 return 0;
77 michael 1447 }
78    
79     if (!irccmp(parv[1], "LOAD"))
80     {
81 michael 1448 if (EmptyString(parv[2]))
82     {
83 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
84 michael 1448 me.name, source_p->name, "MODULE");
85 michael 2820 return 0;
86 michael 1448 }
87    
88 michael 2820 if (findmodule_byname((m_bn = libio_basename(parv[2]))))
89 michael 1447 {
90     sendto_one(source_p, ":%s NOTICE %s :Module %s is already loaded",
91     me.name, source_p->name, m_bn);
92 michael 2820 return 0;
93 michael 1447 }
94    
95     load_one_module(parv[2]);
96 michael 2820 return 0;
97 michael 1447 }
98    
99     if (!irccmp(parv[1], "UNLOAD"))
100     {
101 michael 1448 if (EmptyString(parv[2]))
102     {
103 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
104 michael 1448 me.name, source_p->name, "MODULE");
105 michael 2820 return 0;
106 michael 1448 }
107    
108 michael 1447 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 michael 2820 return 0;
113 michael 1447 }
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 michael 2820 return 0;
121 michael 1447 }
122    
123 michael 1448 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 michael 2820 return 0;
129 michael 1448 }
130    
131 michael 1447 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 michael 2820 return 0;
135 michael 1447 }
136    
137     if (!irccmp(parv[1], "RELOAD"))
138     {
139 michael 1448 if (EmptyString(parv[2]))
140     {
141 michael 1834 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
142 michael 1448 me.name, source_p->name, "MODULE");
143 michael 2820 return 0;
144 michael 1448 }
145    
146 michael 1447 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 michael 2959 modnum = dlink_list_length(modules_get_list());
155 michael 1447
156 michael 2959 DLINK_FOREACH_SAFE(ptr, ptr_next, modules_get_list()->head)
157 michael 1447 {
158     modp = ptr->data;
159 michael 1448
160     if (!(modp->flags & MODULE_FLAG_NOUNLOAD))
161     unload_one_module(modp->name, 0);
162 michael 1447 }
163    
164     load_all_modules(0);
165     load_conf_modules();
166     load_core_modules(0);
167    
168 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
169 michael 1447 "Module Restart: %u modules unloaded, %u modules loaded",
170 michael 2959 modnum, dlink_list_length(modules_get_list()));
171 michael 1447 ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded",
172 michael 2959 modnum, dlink_list_length(modules_get_list()));
173 michael 2820 return 0;
174 michael 1447 }
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 michael 2820 return 0;
181 michael 1447 }
182    
183 michael 1448 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 michael 2820 return 0;
189 michael 1448 }
190    
191 michael 1447 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 michael 2820 return 0;
198 michael 1447 }
199    
200     if ((load_one_module(parv[2]) == -1) && check_core)
201     {
202 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
203     "Error reloading core "
204 michael 1447 "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 michael 2820 return 0;
210 michael 1447 }
211    
212     if (!irccmp(parv[1], "LIST"))
213     {
214     const dlink_node *ptr = NULL;
215    
216 michael 2959 DLINK_FOREACH(ptr, modules_get_list()->head)
217 michael 1447 {
218 michael 1448 modp = ptr->data;
219    
220 michael 1653 if (!EmptyString(parv[2]) && match(parv[2], modp->name))
221 michael 1447 continue;
222    
223 michael 1834 sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
224 michael 1447 modp->name, modp->handle,
225     modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
226     }
227    
228 michael 1834 sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
229 michael 1447 me.name, source_p->name);
230 michael 2820 return 0;
231 michael 1447 }
232 michael 1566
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 michael 2820 return 0;
237 michael 1447 }
238    
239    
240 michael 2820 static struct Message module_msgtab =
241     {
242     "MODULE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
243     { m_unregistered, m_not_oper, m_ignore, m_ignore, mo_module, m_ignore }
244 michael 1447 };
245    
246     static void
247     module_init(void)
248     {
249     mod_add_cmd(&module_msgtab);
250     }
251    
252     static void
253     module_exit(void)
254     {
255     mod_del_cmd(&module_msgtab);
256     }
257    
258 michael 2820 struct module module_entry =
259     {
260 michael 1447 .node = { NULL, NULL, NULL },
261     .name = NULL,
262     .version = "$Revision$",
263     .handle = NULL,
264     .modinit = module_init,
265     .modexit = module_exit,
266 michael 1448 .flags = MODULE_FLAG_NOUNLOAD
267 michael 1447 };

Properties

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