Software / code / prosody
Comparison
util/pubsub.lua @ 3934:4bd994df7296
util.pubsub: Add service:jids_equal() and new config option normalize_jid
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 22 Dec 2010 03:04:14 +0000 |
| parent | 3931:6daed692264f |
| child | 3936:61f12f8a8539 |
comparison
equal
deleted
inserted
replaced
| 3933:24f0a7544a7a | 3934:4bd994df7296 |
|---|---|
| 14 return setmetatable({ | 14 return setmetatable({ |
| 15 config = setmetatable(config, { __index = default_config }); | 15 config = setmetatable(config, { __index = default_config }); |
| 16 affiliations = {}; | 16 affiliations = {}; |
| 17 nodes = {}; | 17 nodes = {}; |
| 18 }, service_mt); | 18 }, service_mt); |
| 19 end | |
| 20 | |
| 21 function service:jids_equal(jid1, jid2) | |
| 22 local normalize = self.config.normalize_jid; | |
| 23 return normalize(jid1) == normalize(jid2); | |
| 19 end | 24 end |
| 20 | 25 |
| 21 function service:may(node, actor, action) | 26 function service:may(node, actor, action) |
| 22 if actor == true then return true; end | 27 if actor == true then return true; end |
| 23 | 28 |
| 80 end | 85 end |
| 81 | 86 |
| 82 function service:add_subscription(node, actor, jid, options) | 87 function service:add_subscription(node, actor, jid, options) |
| 83 -- Access checking | 88 -- Access checking |
| 84 local cap; | 89 local cap; |
| 85 if jid == actor or self.config.jids_equal(actor, jid) then | 90 if jid == actor or self:jids_equal(actor, jid) then |
| 86 cap = "subscribe"; | 91 cap = "subscribe"; |
| 87 else | 92 else |
| 88 cap = "subscribe_other"; | 93 cap = "subscribe_other"; |
| 89 end | 94 end |
| 90 if not self:may(node, actor, cap) then | 95 if not self:may(node, actor, cap) then |
| 110 end | 115 end |
| 111 | 116 |
| 112 function service:remove_subscription(node, actor, jid) | 117 function service:remove_subscription(node, actor, jid) |
| 113 -- Access checking | 118 -- Access checking |
| 114 local cap; | 119 local cap; |
| 115 if jid == actor or self.config.jids_equal(actor, jid) then | 120 if jid == actor or self:jids_equal(actor, jid) then |
| 116 cap = "unsubscribe"; | 121 cap = "unsubscribe"; |
| 117 else | 122 else |
| 118 cap = "unsubscribe_other"; | 123 cap = "unsubscribe_other"; |
| 119 end | 124 end |
| 120 if not self:may(node, actor, cap) then | 125 if not self:may(node, actor, cap) then |
| 136 end | 141 end |
| 137 | 142 |
| 138 function service:get_subscription(node, actor, jid) | 143 function service:get_subscription(node, actor, jid) |
| 139 -- Access checking | 144 -- Access checking |
| 140 local cap; | 145 local cap; |
| 141 if jid == actor or self.config.jids_equal(actor, jid) then | 146 if jid == actor or self:jids_equal(actor, jid) then |
| 142 cap = "get_subscription"; | 147 cap = "get_subscription"; |
| 143 else | 148 else |
| 144 cap = "get_subscription_other"; | 149 cap = "get_subscription_other"; |
| 145 end | 150 end |
| 146 if not self:may(node, actor, cap) then | 151 if not self:may(node, actor, cap) then |