Software /
code /
prosody
Comparison
core/modulemanager.lua @ 590:54afe37cccbf
Combined and merged similar code
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 07 Dec 2008 03:10:47 +0500 |
parent | 589:d564f94d5727 |
child | 591:980ded4c60ef |
comparison
equal
deleted
inserted
replaced
589:d564f94d5727 | 590:54afe37cccbf |
---|---|
145 -- Returns the host that the current module is serving | 145 -- Returns the host that the current module is serving |
146 function api:get_host() | 146 function api:get_host() |
147 return self.host; | 147 return self.host; |
148 end | 148 end |
149 | 149 |
150 | 150 local function _add_handler(module, origin_type, tag, xmlns, handler) |
151 local function _add_iq_handler(module, origin_type, xmlns, handler) | 151 local handlers = m_stanza_handlers:get(module.host, origin_type, tag, xmlns); |
152 local handlers = m_stanza_handlers:get(module.host, origin_type, "iq", xmlns); | 152 local msg = (tag == "iq") and "namespace" or "payload namespace"; |
153 if not handlers then | 153 if not handlers then |
154 m_stanza_handlers:add(module.host, origin_type, "iq", xmlns, handler); | 154 m_stanza_handlers:add(module.host, origin_type, tag, xmlns, handler); |
155 handler_info[handler] = module; | 155 handler_info[handler] = module; |
156 module:log("debug", "I now handle tag 'iq' [%s] with payload namespace '%s'", origin_type, xmlns); | 156 module:log("debug", "I now handle tag '%s' [%s] with %s '%s'", tag, origin_type, msg, xmlns); |
157 else | 157 else |
158 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[1]].name); | 158 module:log("warn", "I wanted to handle tag '%s' [%s] with %s '%s' but mod_%s already handles that", tag, origin_type, msg, xmlns, handler_info[handlers[1]].module.name); |
159 end | 159 end |
160 end | 160 end |
161 | 161 |
162 function api:add_iq_handler(origin_type, xmlns, handler) | 162 function api:add_handler(origin_type, tag, xmlns, handler) |
163 if not (origin_type and handler and xmlns) then return false; end | 163 if not (origin_type and tag and xmlns and handler) then return false; end |
164 if type(origin_type) == "table" then | 164 if type(origin_type) == "table" then |
165 for _, origin_type in ipairs(origin_type) do | 165 for _, origin_type in ipairs(origin_type) do |
166 _add_iq_handler(self, origin_type, xmlns, handler); | 166 _add_handler(self, origin_type, tag, xmlns, handler); |
167 end | 167 end |
168 return; | 168 else |
169 _add_handler(self, origin_type, tag, xmlns, handler); | |
169 end | 170 end |
170 _add_iq_handler(self, origin_type, xmlns, handler); | 171 end |
172 function api:add_iq_handler(origin_type, xmlns, handler) | |
173 self:add_handler(origin_type, "iq", xmlns, handler); | |
171 end | 174 end |
172 | 175 |
173 function api:add_feature(xmlns) | 176 function api:add_feature(xmlns) |
174 addDiscoInfoHandler(self.host, function(reply, to, from, node) | 177 addDiscoInfoHandler(self.host, function(reply, to, from, node) |
175 if #node == 0 then | 178 if #node == 0 then |
179 end); | 182 end); |
180 end | 183 end |
181 | 184 |
182 function api:add_event_hook (...) return eventmanager.add_event_hook(...); end | 185 function api:add_event_hook (...) return eventmanager.add_event_hook(...); end |
183 | 186 |
184 local function _add_handler(module, origin_type, tag, xmlns, handler) | |
185 local handlers = m_stanza_handlers:get(module.host, origin_type, tag, xmlns); | |
186 if not handlers then | |
187 m_stanza_handlers:add(module.host, origin_type, tag, xmlns, handler); | |
188 handler_info[handler] = module; | |
189 module:log("debug", "I now handle tag '%s' [%s] with xmlns '%s'", tag, origin_type, xmlns); | |
190 else | |
191 module:log("warning", "I wanted to handle tag '%s' [%s] but mod_%s already handles that", tag, origin_type, handler_info[handlers[1]].module.name); | |
192 end | |
193 end | |
194 | |
195 function api:add_handler(origin_type, tag, xmlns, handler) | |
196 if not (origin_type and tag and xmlns and handler) then return false; end | |
197 if type(origin_type) == "table" then | |
198 for _, origin_type in ipairs(origin_type) do | |
199 _add_handler(self, origin_type, tag, xmlns, handler); | |
200 end | |
201 return; | |
202 end | |
203 _add_handler(self, origin_type, tag, xmlns, handler); | |
204 end | |
205 | |
206 -------------------------------------------------------------------- | 187 -------------------------------------------------------------------- |
207 | 188 |
208 return _M; | 189 return _M; |