Software / code / prosody
Comparison
core/sessionmanager.lua @ 6561:bae84401a02c
sessionmanager: Add pre-resource-bind event that would let plugins have a say in resource binding
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 30 Jan 2015 15:38:54 +0100 |
| parent | 6551:784fa05cf594 |
| child | 6602:61b6a4fc65f1 |
comparison
equal
deleted
inserted
replaced
| 6559:0ef7ca5276a1 | 6561:bae84401a02c |
|---|---|
| 114 -- returns nil, err_type, err, err_message on failure | 114 -- returns nil, err_type, err, err_message on failure |
| 115 function bind_resource(session, resource) | 115 function bind_resource(session, resource) |
| 116 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end | 116 if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end |
| 117 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end | 117 if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end |
| 118 -- We don't support binding multiple resources | 118 -- We don't support binding multiple resources |
| 119 | |
| 120 local event_payload = { session = session, resource = resource }; | |
| 121 if hosts[session.host].events.fire_event("pre-resource-bind", event_payload) == false then | |
| 122 local err = event_payload.error; | |
| 123 if err then return nil, err.type, err.condition, err.text; end | |
| 124 return nil, "cancel", "not-allowed"; | |
| 125 else | |
| 126 -- In case a plugin wants to poke at it | |
| 127 resource = event_payload.resource; | |
| 128 end | |
| 119 | 129 |
| 120 resource = resourceprep(resource); | 130 resource = resourceprep(resource); |
| 121 resource = resource ~= "" and resource or uuid_generate(); | 131 resource = resource ~= "" and resource or uuid_generate(); |
| 122 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing | 132 --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing |
| 123 | 133 |