Software / code / prosody
Comparison
core/modulemanager.lua @ 47:33ed4c6ac249
Fix stanza handlers to use xmlns also for matching
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 04 Oct 2008 02:40:47 +0100 |
| parent | 42:2e3715e30912 |
| child | 60:44800be871f5 |
comparison
equal
deleted
inserted
replaced
| 46:d6b3f9dbb624 | 47:33ed4c6ac249 |
|---|---|
| 33 | 33 |
| 34 function modulehelpers.add_handler(origin_type, tag, xmlns, handler) | 34 function modulehelpers.add_handler(origin_type, tag, xmlns, handler) |
| 35 if not (origin_type and tag and xmlns and handler) then return false; end | 35 if not (origin_type and tag and xmlns and handler) then return false; end |
| 36 handlers[origin_type] = handlers[origin_type] or {}; | 36 handlers[origin_type] = handlers[origin_type] or {}; |
| 37 if not handlers[origin_type][tag] then | 37 if not handlers[origin_type][tag] then |
| 38 handlers[origin_type][tag]= handler; | 38 handlers[origin_type][tag] = handlers[origin_type][tag] or {}; |
| 39 handlers[origin_type][tag][xmlns]= handler; | |
| 39 handler_info[handler] = getfenv(2).module; | 40 handler_info[handler] = getfenv(2).module; |
| 40 log("debug", "mod_%s now handles tag '%s'", getfenv(2).module.name, tag); | 41 log("debug", "mod_%s now handles tag '%s'", getfenv(2).module.name, tag); |
| 41 elseif handler_info[handlers[origin_type][tag]] then | 42 elseif handler_info[handlers[origin_type][tag]] then |
| 42 log("warning", "mod_%s wants to handle tag '%s' but mod_%s already handles that", getfenv(2).module.name, tag, handler_info[handlers[origin_type][tag]].module.name); | 43 log("warning", "mod_%s wants to handle tag '%s' but mod_%s already handles that", getfenv(2).module.name, tag, handler_info[handlers[origin_type][tag]].module.name); |
| 43 end | 44 end |
| 44 end | 45 end |
| 45 | 46 |
| 46 function loadall() | 47 function loadall() |
| 47 load("saslauth"); | 48 load("saslauth"); |
| 48 load("legacyauth"); | 49 load("legacyauth"); |
| 49 load("roster"); | 50 load("roster"); |
| 50 end | 51 end |
| 83 | 84 |
| 84 end | 85 end |
| 85 elseif handlers[origin_type] then | 86 elseif handlers[origin_type] then |
| 86 local handler = handlers[origin_type][name]; | 87 local handler = handlers[origin_type][name]; |
| 87 if handler then | 88 if handler then |
| 88 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); | 89 handler = handler[xmlns]; |
| 89 return handler(origin, stanza) or true; | 90 if handler then |
| 91 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); | |
| 92 return handler(origin, stanza) or true; | |
| 93 end | |
| 90 end | 94 end |
| 91 end | 95 end |
| 92 log("debug", "Stanza unhandled by any modules"); | 96 log("debug", "Stanza unhandled by any modules, xmlns: %s", stanza.attr.xmlns); |
| 93 return false; -- we didn't handle it | 97 return false; -- we didn't handle it |
| 94 end | 98 end |
| 95 | 99 |
| 96 do | 100 do |
| 97 local event_handlers = {}; | 101 local event_handlers = {}; |