core/modulemanager.lua

changeset 710
56f6c115bc69
parent 709
8bb83563cb21
child 713
2afd6d9e21cd
equal deleted inserted replaced
709:8bb83563cb21 710:56f6c115bc69
138 138
139 function unload(host, name, ...) 139 function unload(host, name, ...)
140 local mod = modulemap[host] and modulemap[host][name]; 140 local mod = modulemap[host] and modulemap[host][name];
141 if not mod then return nil, "module-not-loaded"; end 141 if not mod then return nil, "module-not-loaded"; end
142 142
143 if type(rawget(mod, "unload")) == "function" then 143 if type(mod.module.unload) == "function" then
144 local ok, err = pcall(rawget(mod, "unload"), ...) 144 local ok, err = pcall(mod.module.unload, ...)
145 if (not ok) and err then 145 if (not ok) and err then
146 log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err); 146 log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
147 end 147 end
148 end 148 end
149 modulemap[host][name] = nil; 149 modulemap[host][name] = nil;
156 stanza_handlers:remove(param[1], param[2], param[3], param[4]); 156 stanza_handlers:remove(param[1], param[2], param[3], param[4]);
157 end 157 end
158 end 158 end
159 event_hooks:remove(host, name); 159 event_hooks:remove(host, name);
160 return true; 160 return true;
161 end
162
163 function reload(host, name, ...)
164 local mod = modulemap[host] and modulemap[host][name];
165 if not mod then return nil, "module-not-loaded"; end
166
167 local saved;
168 if type(mod.module.save) == "function" then
169 local ok, err = pcall(mod.module.save)
170 if (not ok) and err then
171 log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
172 else
173 saved = err;
174 end
175 end
176
177 unload(host, name, ...);
178 if load(host, name, ...) then
179 mod = modulemap[host] and modulemap[host][name];
180 if type(mod.module.restore) == "function" then
181 local ok, err = pcall(mod.module.restore, saved or {})
182 if (not ok) and err then
183 log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
184 end
185 end
186 return true;
187 end
161 end 188 end
162 189
163 function handle_stanza(host, origin, stanza) 190 function handle_stanza(host, origin, stanza)
164 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; 191 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;
165 if name == "iq" and xmlns == "jabber:client" then 192 if name == "iq" and xmlns == "jabber:client" then

mercurial