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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2381 - (hide annotations)
Sat Jul 6 16:22:05 2013 UTC (7 years ago) by michael
File MIME type: text/x-chdr
File size: 7433 byte(s)
- Add NEWIO branch

1 michael 1447 /*
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 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     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 michael 1834 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
68 michael 1447 me.name, source_p->name);
69     return;
70     }
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     return;
77     }
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     return;
86     }
87    
88 michael 1447 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 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     return;
106     }
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     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 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     return;
129     }
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     return;
135     }
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     return;
144     }
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     modnum = dlink_list_length(&modules_list);
155    
156     DLINK_FOREACH_SAFE(ptr, ptr_next, modules_list.head)
157     {
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     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 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     return;
189     }
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     return;
198     }
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     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 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     return;
231     }
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 1447 }
237    
238    
239     static struct Message module_msgtab = {
240 michael 1448 "MODULE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
241 michael 1447 {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 michael 1448 .flags = MODULE_FLAG_NOUNLOAD
264 michael 1447 };

Properties

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

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