Software /
code /
prosody
Comparison
core/modulemanager.lua @ 589:d564f94d5727
Removed pre-multitable code from module manager
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 07 Dec 2008 02:56:17 +0500 |
parent | 579:81e68e5afce2 |
child | 590:54afe37cccbf |
comparison
equal
deleted
inserted
replaced
579:81e68e5afce2 | 589:d564f94d5727 |
---|---|
116 end | 116 end |
117 end | 117 end |
118 | 118 |
119 end | 119 end |
120 | 120 |
121 function _handle_stanza(host, origin, stanza) | |
122 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; | |
123 | |
124 local handlers = stanza_handlers[host]; | |
125 if not handlers then | |
126 log("warn", "No handlers for %s", host); | |
127 return false; | |
128 end | |
129 | |
130 if name == "iq" and xmlns == "jabber:client" and handlers[origin_type] then | |
131 local child = stanza.tags[1]; | |
132 if child then | |
133 local xmlns = child.attr.xmlns or xmlns; | |
134 log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns); | |
135 local handler = handlers[origin_type][name] and handlers[origin_type][name][xmlns]; | |
136 if handler then | |
137 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); | |
138 return handler(origin, stanza) or true; | |
139 end | |
140 end | |
141 elseif handlers[origin_type] then | |
142 local handler = handlers[origin_type][name]; | |
143 if handler then | |
144 handler = handler[xmlns]; | |
145 if handler then | |
146 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); | |
147 return handler(origin, stanza) or true; | |
148 end | |
149 end | |
150 end | |
151 log("debug", "Stanza unhandled by any modules, xmlns: %s", stanza.attr.xmlns); | |
152 return false; -- we didn't handle it | |
153 end | |
154 function handle_stanza(host, origin, stanza) | 121 function handle_stanza(host, origin, stanza) |
155 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; | 122 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; |
156 if name == "iq" and xmlns == "jabber:client" then | 123 if name == "iq" and xmlns == "jabber:client" then |
157 xmlns = stanza.tags[1].attr.xmlns; | 124 xmlns = stanza.tags[1].attr.xmlns; |
158 log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns); | 125 log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns); |
179 function api:get_host() | 146 function api:get_host() |
180 return self.host; | 147 return self.host; |
181 end | 148 end |
182 | 149 |
183 | 150 |
184 local function __add_iq_handler(module, origin_type, xmlns, handler) | |
185 local handlers = stanza_handlers[module.host]; | |
186 handlers[origin_type] = handlers[origin_type] or {}; | |
187 handlers[origin_type].iq = handlers[origin_type].iq or {}; | |
188 if not handlers[origin_type].iq[xmlns] then | |
189 handlers[origin_type].iq[xmlns]= handler; | |
190 handler_info[handler] = module; | |
191 module:log("debug", "I now handle tag 'iq' [%s] with payload namespace '%s'", origin_type, xmlns); | |
192 else | |
193 module:log("warn", "I wanted to handle tag 'iq' [%s] with payload namespace '%s' but mod_%s already handles that", origin_type, xmlns, handler_info[handlers[origin_type].iq[xmlns]].name); | |
194 end | |
195 end | |
196 local function _add_iq_handler(module, origin_type, xmlns, handler) | 151 local function _add_iq_handler(module, origin_type, xmlns, handler) |
197 local handlers = m_stanza_handlers:get(module.host, origin_type, "iq", xmlns); | 152 local handlers = m_stanza_handlers:get(module.host, origin_type, "iq", xmlns); |
198 if not handlers then | 153 if not handlers then |
199 m_stanza_handlers:add(module.host, origin_type, "iq", xmlns, handler); | 154 m_stanza_handlers:add(module.host, origin_type, "iq", xmlns, handler); |
200 handler_info[handler] = module; | 155 handler_info[handler] = module; |
224 end); | 179 end); |
225 end | 180 end |
226 | 181 |
227 function api:add_event_hook (...) return eventmanager.add_event_hook(...); end | 182 function api:add_event_hook (...) return eventmanager.add_event_hook(...); end |
228 | 183 |
229 local function __add_handler(module, origin_type, tag, xmlns, handler) | |
230 local handlers = stanza_handlers[module.host]; | |
231 handlers[origin_type] = handlers[origin_type] or {}; | |
232 if not handlers[origin_type][tag] then | |
233 handlers[origin_type][tag] = handlers[origin_type][tag] or {}; | |
234 handlers[origin_type][tag][xmlns]= handler; | |
235 handler_info[handler] = module; | |
236 module:log("debug", "I now handle tag '%s' [%s] with xmlns '%s'", tag, origin_type, xmlns); | |
237 elseif handler_info[handlers[origin_type][tag]] then | |
238 log("warning", "I wanted to handle tag '%s' [%s] but mod_%s already handles that", tag, origin_type, handler_info[handlers[origin_type][tag]].module.name); | |
239 end | |
240 end | |
241 local function _add_handler(module, origin_type, tag, xmlns, handler) | 184 local function _add_handler(module, origin_type, tag, xmlns, handler) |
242 local handlers = m_stanza_handlers:get(module.host, origin_type, tag, xmlns); | 185 local handlers = m_stanza_handlers:get(module.host, origin_type, tag, xmlns); |
243 if not handlers then | 186 if not handlers then |
244 m_stanza_handlers:add(module.host, origin_type, tag, xmlns, handler); | 187 m_stanza_handlers:add(module.host, origin_type, tag, xmlns, handler); |
245 handler_info[handler] = module; | 188 handler_info[handler] = module; |