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

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 "send.h"
36     #include "parse.h"
37     #include "modules.h"
38    
39    
40 michael 3300 /*! \brief MODULE command handler
41 michael 1447 *
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 michael 3096 * - parv[0] = command
49 michael 1447 * - parv[1] = action [LOAD, UNLOAD, RELOAD, LIST]
50     * - parv[2] = module name
51     */
52 michael 2820 static int
53 michael 3156 mo_module(struct Client *source_p, int parc, char *parv[])
54 michael 1447 {
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 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "module");
62 michael 2820 return 0;
63 michael 1447 }
64    
65     if (EmptyString(parv[1]))
66     {
67 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODULE");
68 michael 2820 return 0;
69 michael 1447 }
70    
71     if (!irccmp(parv[1], "LOAD"))
72     {
73 michael 1448 if (EmptyString(parv[2]))
74     {
75 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODULE");
76 michael 2820 return 0;
77 michael 1448 }
78    
79 michael 2820 if (findmodule_byname((m_bn = libio_basename(parv[2]))))
80 michael 1447 {
81 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is already loaded", m_bn);
82 michael 2820 return 0;
83 michael 1447 }
84    
85     load_one_module(parv[2]);
86 michael 2820 return 0;
87 michael 1447 }
88    
89     if (!irccmp(parv[1], "UNLOAD"))
90     {
91 michael 1448 if (EmptyString(parv[2]))
92     {
93 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODULE");
94 michael 2820 return 0;
95 michael 1448 }
96    
97 michael 1447 if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL)
98     {
99 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is not loaded", m_bn);
100 michael 2820 return 0;
101 michael 1447 }
102    
103     if (modp->flags & MODULE_FLAG_CORE)
104     {
105 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is a core module and may not be unloaded",
106     m_bn);
107 michael 2820 return 0;
108 michael 1447 }
109    
110 michael 1448 if (modp->flags & MODULE_FLAG_NOUNLOAD)
111     {
112 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is a resident module and may not be unloaded",
113     m_bn);
114 michael 2820 return 0;
115 michael 1448 }
116    
117 michael 1447 if (unload_one_module(m_bn, 1) == -1)
118 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is not loaded", m_bn);
119 michael 2820 return 0;
120 michael 1447 }
121    
122     if (!irccmp(parv[1], "RELOAD"))
123     {
124 michael 1448 if (EmptyString(parv[2]))
125     {
126 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "MODULE");
127 michael 2820 return 0;
128 michael 1448 }
129    
130 michael 1447 if (!strcmp(parv[2], "*"))
131     {
132     unsigned int modnum = 0;
133     dlink_node *ptr = NULL, *ptr_next = NULL;
134    
135 michael 3110 sendto_one_notice(source_p, &me, ":Reloading all modules");
136 michael 1447
137 michael 2959 modnum = dlink_list_length(modules_get_list());
138 michael 1447
139 michael 2959 DLINK_FOREACH_SAFE(ptr, ptr_next, modules_get_list()->head)
140 michael 1447 {
141     modp = ptr->data;
142 michael 1448
143     if (!(modp->flags & MODULE_FLAG_NOUNLOAD))
144     unload_one_module(modp->name, 0);
145 michael 1447 }
146    
147     load_all_modules(0);
148     load_conf_modules();
149     load_core_modules(0);
150    
151 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
152 michael 1447 "Module Restart: %u modules unloaded, %u modules loaded",
153 michael 2959 modnum, dlink_list_length(modules_get_list()));
154 michael 1447 ilog(LOG_TYPE_IRCD, "Module Restart: %u modules unloaded, %u modules loaded",
155 michael 2959 modnum, dlink_list_length(modules_get_list()));
156 michael 2820 return 0;
157 michael 1447 }
158    
159     if ((modp = findmodule_byname((m_bn = libio_basename(parv[2])))) == NULL)
160     {
161 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is not loaded", m_bn);
162 michael 2820 return 0;
163 michael 1447 }
164    
165 michael 1448 if (modp->flags & MODULE_FLAG_NOUNLOAD)
166     {
167 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is a resident module and may not be unloaded",
168     m_bn);
169 michael 2820 return 0;
170 michael 1448 }
171    
172 michael 1447 check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
173    
174     if (unload_one_module(m_bn, 1) == -1)
175     {
176 michael 3110 sendto_one_notice(source_p, &me, ":Module %s is not loaded", m_bn);
177 michael 2820 return 0;
178 michael 1447 }
179    
180     if ((load_one_module(parv[2]) == -1) && check_core)
181     {
182 michael 1618 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
183     "Error reloading core "
184 michael 1447 "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 michael 2820 return 0;
190 michael 1447 }
191    
192     if (!irccmp(parv[1], "LIST"))
193     {
194     const dlink_node *ptr = NULL;
195    
196 michael 2959 DLINK_FOREACH(ptr, modules_get_list()->head)
197 michael 1447 {
198 michael 1448 modp = ptr->data;
199    
200 michael 1653 if (!EmptyString(parv[2]) && match(parv[2], modp->name))
201 michael 1447 continue;
202    
203 michael 3109 sendto_one_numeric(source_p, &me, RPL_MODLIST,
204 michael 3301 modp->name, modp->handle,
205     modp->version, (modp->flags & MODULE_FLAG_CORE) ? "(core)" : "");
206 michael 1447 }
207    
208 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFMODLIST);
209 michael 2820 return 0;
210 michael 1447 }
211 michael 1566
212 michael 3110 sendto_one_notice(source_p, &me, ":%s is not a valid option. "
213     "Choose from LOAD, UNLOAD, RELOAD, LIST",
214     parv[1]);
215 michael 2820 return 0;
216 michael 1447 }
217    
218 michael 2820 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 michael 1447 };
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 michael 2820 struct module module_entry =
237     {
238 michael 1447 .node = { NULL, NULL, NULL },
239     .name = NULL,
240     .version = "$Revision$",
241     .handle = NULL,
242     .modinit = module_init,
243     .modexit = module_exit,
244 michael 1448 .flags = MODULE_FLAG_NOUNLOAD
245 michael 1447 };

Properties

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