Software /
code /
prosody
Annotate
plugins/muc/muc.lib.lua @ 2527:3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 29 Jan 2010 14:26:54 +0000 |
parent | 2504:8b12ee9a5027 |
child | 2528:3365ed0ed5bd |
rev | line source |
---|---|
1734 | 1 -- Prosody IM |
2 -- Copyright (C) 2008-2009 Matthew Wild | |
3 -- Copyright (C) 2008-2009 Waqas Hussain | |
4 -- | |
5 -- This project is MIT/X11 licensed. Please see the | |
6 -- COPYING file in the source package for more information. | |
7 -- | |
8 | |
9 local datamanager = require "util.datamanager"; | |
10 local datetime = require "util.datetime"; | |
11 | |
12 local jid_split = require "util.jid".split; | |
13 local jid_bare = require "util.jid".bare; | |
1862
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
14 local jid_prep = require "util.jid".prep; |
1734 | 15 local st = require "util.stanza"; |
16 local log = require "util.logger".init("mod_muc"); | |
17 local multitable_new = require "util.multitable".new; | |
18 local t_insert, t_remove = table.insert, table.remove; | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
19 local setmetatable = setmetatable; |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
20 local base64 = require "util.encodings".base64; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
21 local md5 = require "util.hashes".md5; |
1734 | 22 |
23 local muc_domain = nil; --module:get_host(); | |
24 local history_length = 20; | |
25 | |
26 ------------ | |
27 local function filter_xmlns_from_array(array, filters) | |
28 local count = 0; | |
29 for i=#array,1,-1 do | |
30 local attr = array[i].attr; | |
31 if filters[attr and attr.xmlns] then | |
32 t_remove(array, i); | |
33 count = count + 1; | |
34 end | |
35 end | |
36 return count; | |
37 end | |
38 local function filter_xmlns_from_stanza(stanza, filters) | |
39 if filters then | |
40 if filter_xmlns_from_array(stanza.tags, filters) ~= 0 then | |
41 return stanza, filter_xmlns_from_array(stanza, filters); | |
42 end | |
43 end | |
44 return stanza, 0; | |
45 end | |
46 local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; | |
47 local function get_filtered_presence(stanza) | |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
48 return filter_xmlns_from_stanza(st.clone(stanza):reset(), presence_filters); |
1734 | 49 end |
50 local kickable_error_conditions = { | |
51 ["gone"] = true; | |
52 ["internal-server-error"] = true; | |
53 ["item-not-found"] = true; | |
54 ["jid-malformed"] = true; | |
55 ["recipient-unavailable"] = true; | |
56 ["redirect"] = true; | |
57 ["remote-server-not-found"] = true; | |
58 ["remote-server-timeout"] = true; | |
59 ["service-unavailable"] = true; | |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
60 ["malformed error"] = true; |
1734 | 61 }; |
2527
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
62 |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
63 local function get_error_condition(stanza) |
2527
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
64 local _, condition = stanza:get_error(); |
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
65 return condition or "malformed error"; |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
66 end |
2527
3fe3dbb27b6f
MUC: Have get_error_condition() use the new stanza:get_error() (muc.lib.lua 11 lines shorter \o/)
Matthew Wild <mwild1@gmail.com>
parents:
2504
diff
changeset
|
67 |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
68 local function is_kickable_error(stanza) |
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
69 local cond = get_error_condition(stanza); |
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
70 return kickable_error_conditions[cond] and cond; |
1734 | 71 end |
72 local function getUsingPath(stanza, path, getText) | |
73 local tag = stanza; | |
74 for _, name in ipairs(path) do | |
75 if type(tag) ~= 'table' then return; end | |
76 tag = tag:child_with_name(name); | |
77 end | |
78 if tag and getText then tag = table.concat(tag); end | |
79 return tag; | |
80 end | |
81 local function getTag(stanza, path) return getUsingPath(stanza, path); end | |
82 local function getText(stanza, path) return getUsingPath(stanza, path, true); end | |
83 ----------- | |
84 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
85 local room_mt = {}; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
86 room_mt.__index = room_mt; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
87 |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
88 function room_mt:get_default_role(affiliation) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
89 if affiliation == "owner" or affiliation == "admin" then |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
90 return "moderator"; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
91 elseif affiliation == "member" or not affiliation then |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
92 return "participant"; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
93 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
94 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
95 |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
96 function room_mt:broadcast_presence(stanza, sid, code, nick) |
1734 | 97 stanza = get_filtered_presence(stanza); |
1825
f67e4bfc62f1
MUC: Renamed a variable name.
Waqas Hussain <waqas20@gmail.com>
parents:
1824
diff
changeset
|
98 local occupant = self._occupants[stanza.attr.from]; |
1734 | 99 stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
100 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none", nick=nick}):up(); |
1734 | 101 if code then |
102 stanza:tag("status", {code=code}):up(); | |
103 end | |
1824
8e66c9d09f81
MUC: Refactored to remove some duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents:
1819
diff
changeset
|
104 self:broadcast_except_nick(stanza, stanza.attr.from); |
8e66c9d09f81
MUC: Refactored to remove some duplicate code.
Waqas Hussain <waqas20@gmail.com>
parents:
1819
diff
changeset
|
105 local me = self._occupants[stanza.attr.from]; |
1734 | 106 if me then |
107 stanza:tag("status", {code='110'}); | |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
108 stanza.attr.to = sid; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
109 self:_route_stanza(stanza); |
1734 | 110 end |
111 end | |
1736
98f833669d7f
MUC: Fixed function declarations.
Waqas Hussain <waqas20@gmail.com>
parents:
1735
diff
changeset
|
112 function room_mt:broadcast_message(stanza, historic) |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
113 local to = stanza.attr.to; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
114 for occupant, o_data in pairs(self._occupants) do |
1734 | 115 for jid in pairs(o_data.sessions) do |
116 stanza.attr.to = jid; | |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
117 self:_route_stanza(stanza); |
1734 | 118 end |
119 end | |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
120 stanza.attr.to = to; |
1734 | 121 if historic then -- add to history |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
122 local history = self._data['history']; |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
123 if not history then history = {}; self._data['history'] = history; end |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
124 stanza = st.clone(stanza); |
1734 | 125 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 |
126 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
127 t_insert(history, st.preserialize(stanza)); |
1734 | 128 while #history > history_length do t_remove(history, 1) end |
129 end | |
130 end | |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
131 function room_mt:broadcast_except_nick(stanza, nick) |
1751
55ee6e792e3e
MUC: Fixed a variable scoping bug causing problems with presence routing on affiliation/role change.
Waqas Hussain <waqas20@gmail.com>
parents:
1750
diff
changeset
|
132 for rnick, occupant in pairs(self._occupants) do |
55ee6e792e3e
MUC: Fixed a variable scoping bug causing problems with presence routing on affiliation/role change.
Waqas Hussain <waqas20@gmail.com>
parents:
1750
diff
changeset
|
133 if rnick ~= nick then |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
134 for jid in pairs(occupant.sessions) do |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
135 stanza.attr.to = jid; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
136 self:_route_stanza(stanza); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
137 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
138 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
139 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
140 end |
1734 | 141 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
142 function room_mt:send_occupant_list(to) |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
143 local current_nick = self._jid_nick[to]; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
144 for occupant, o_data in pairs(self._occupants) do |
1734 | 145 if occupant ~= current_nick then |
146 local pres = get_filtered_presence(o_data.sessions[o_data.jid]); | |
147 pres.attr.to, pres.attr.from = to, occupant; | |
148 pres:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
149 :tag("item", {affiliation=o_data.affiliation or "none", role=o_data.role or "none"}):up(); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
150 self:_route_stanza(pres); |
1734 | 151 end |
152 end | |
153 end | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
154 function room_mt:send_history(to) |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
155 local history = self._data['history']; -- send discussion history |
1734 | 156 if history then |
157 for _, msg in ipairs(history) do | |
158 msg = st.deserialize(msg); | |
159 msg.attr.to=to; | |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
160 self:_route_stanza(msg); |
1734 | 161 end |
162 end | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
163 if self._data['subject'] then |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
164 self:_route_stanza(st.message({type='groupchat', from=self.jid, to=to}):tag("subject"):text(self._data['subject'])); |
1734 | 165 end |
166 end | |
167 | |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
168 function room_mt:get_disco_info(stanza) |
1808
e164fdb2d18f
MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1778
diff
changeset
|
169 return st.reply(stanza):query("http://jabber.org/protocol/disco#info") |
e164fdb2d18f
MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1778
diff
changeset
|
170 :tag("identity", {category="conference", type="text"}):up() |
e164fdb2d18f
MUC: Added MUC feature to the disco#info replies of rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1778
diff
changeset
|
171 :tag("feature", {var="http://jabber.org/protocol/muc"}); |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
172 end |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
173 function room_mt:get_disco_items(stanza) |
2035
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
174 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
175 for room_jid in pairs(self._occupants) do |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
176 reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up(); |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
177 end |
b8c3dbf76a2e
MUC: List occupants in a room's disco#items response.
Waqas Hussain <waqas20@gmail.com>
parents:
2008
diff
changeset
|
178 return reply; |
1756
b2291156a9c2
MUC: Added service discovery replies for rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1755
diff
changeset
|
179 end |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
180 function room_mt:set_subject(current_nick, subject) |
1734 | 181 -- TODO check nick's authority |
182 if subject == "" then subject = nil; end | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
183 self._data['subject'] = subject; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
184 if self.save then self:save(); end |
1734 | 185 local msg = st.message({type='groupchat', from=current_nick}) |
186 :tag('subject'):text(subject):up(); | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
187 self:broadcast_message(msg, false); |
1734 | 188 return true; |
189 end | |
190 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
191 function room_mt:handle_to_occupant(origin, stanza) -- PM, vCards, etc |
1734 | 192 local from, to = stanza.attr.from, stanza.attr.to; |
193 local room = jid_bare(to); | |
194 local current_nick = self._jid_nick[from]; | |
195 local type = stanza.attr.type; | |
196 log("debug", "room: %s, current_nick: %s, stanza: %s", room or "nil", current_nick or "nil", stanza:top_tag()); | |
197 if (select(2, jid_split(from)) == muc_domain) then error("Presence from the MUC itself!!!"); end | |
198 if stanza.name == "presence" then | |
199 local pr = get_filtered_presence(stanza); | |
200 pr.attr.from = current_nick; | |
201 if type == "error" then -- error, kick em out! | |
202 if current_nick then | |
203 log("debug", "kicking %s from %s", current_nick, room); | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
204 self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}) |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
205 :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable |
1734 | 206 end |
207 elseif type == "unavailable" then -- unavailable | |
208 if current_nick then | |
209 log("debug", "%s leaving %s", current_nick, room); | |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
210 local occupant = self._occupants[current_nick]; |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
211 local new_jid = next(occupant.sessions); |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
212 if new_jid == from then new_jid = next(occupant.sessions, new_jid); end |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
213 if new_jid then |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
214 local jid = occupant.jid; |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
215 occupant.jid = new_jid; |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
216 occupant.sessions[from] = nil; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
217 pr.attr.to = from; |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
218 pr:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
219 :tag("item", {affiliation=occupant.affiliation or "none", role='none'}):up() |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
220 :tag("status", {code='110'}); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
221 self:_route_stanza(pr); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
222 if jid ~= new_jid then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
223 pr = st.clone(occupant.sessions[new_jid]) |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
224 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
225 :tag("item", {affiliation=occupant.affiliation or "none", role=occupant.role or "none"}); |
2051
2567f4bf0085
MUC: Fixed an issue with multi-session nicks where the 'from' attribute in a presence broadcast was not being properly set.
Waqas Hussain <waqas20@gmail.com>
parents:
2035
diff
changeset
|
226 pr.attr.from = current_nick; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
227 self:broadcast_except_nick(pr, current_nick); |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
228 end |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
229 else |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
230 occupant.role = 'none'; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
231 self:broadcast_presence(pr, from); |
1826
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
232 self._occupants[current_nick] = nil; |
de165b5de254
MUC: Added multi-session support to the room-exiting occupant use case.
Waqas Hussain <waqas20@gmail.com>
parents:
1825
diff
changeset
|
233 end |
1734 | 234 self._jid_nick[from] = nil; |
235 end | |
236 elseif not type then -- available | |
237 if current_nick then | |
238 --if #pr == #stanza or current_nick ~= to then -- commented because google keeps resending directed presence | |
239 if current_nick == to then -- simple presence | |
240 log("debug", "%s broadcasted presence", current_nick); | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
241 self._occupants[current_nick].sessions[from] = pr; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
242 self:broadcast_presence(pr, from); |
1734 | 243 else -- change nick |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
244 local occupant = self._occupants[current_nick]; |
2008
6b6b924ee558
MUC: Re-enable nick changes for non-multisession nicks.
Waqas Hussain <waqas20@gmail.com>
parents:
2006
diff
changeset
|
245 local is_multisession = next(occupant.sessions, next(occupant.sessions)); |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
246 if self._occupants[to] or is_multisession then |
1734 | 247 log("debug", "%s couldn't change nick", current_nick); |
1818
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
248 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
249 reply.tags[1].attr.code = "409"; |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
250 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1734 | 251 else |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
252 local data = self._occupants[current_nick]; |
1734 | 253 local to_nick = select(3, jid_split(to)); |
254 if to_nick then | |
255 log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to); | |
256 local p = st.presence({type='unavailable', from=current_nick}); | |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
257 self:broadcast_presence(p, from, '303', to_nick); |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
258 self._occupants[current_nick] = nil; |
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
259 self._occupants[to] = data; |
1734 | 260 self._jid_nick[from] = to; |
261 pr.attr.from = to; | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
262 self._occupants[to].sessions[from] = pr; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
263 self:broadcast_presence(pr, from); |
1734 | 264 else |
265 --TODO malformed-jid | |
266 end | |
267 end | |
268 end | |
269 --else -- possible rejoin | |
270 -- log("debug", "%s had connection replaced", current_nick); | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
271 -- self:handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}) |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
272 -- :tag('status'):text('Replaced by new connection'):up()); -- send unavailable |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
273 -- self:handle_to_occupant(origin, stanza); -- resend available |
1734 | 274 --end |
275 else -- enter room | |
276 local new_nick = to; | |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
277 local is_merge; |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
278 if self._occupants[to] then |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
279 if jid_bare(from) ~= jid_bare(self._occupants[to].jid) then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
280 new_nick = nil; |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
281 end |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
282 is_merge = true; |
1734 | 283 end |
284 if not new_nick then | |
285 log("debug", "%s couldn't join due to nick conflict: %s", from, to); | |
1818
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
286 local reply = st.error_reply(stanza, "cancel", "conflict"):up(); |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
287 reply.tags[1].attr.code = "409"; |
a394e0bd4847
MUC: Added legacy error codes to nickname conflict presence errors.
Waqas Hussain <waqas20@gmail.com>
parents:
1808
diff
changeset
|
288 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1734 | 289 else |
290 log("debug", "%s joining as %s", from, to); | |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
291 if not next(self._affiliations) then -- new room, no owners |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
292 self._affiliations[jid_bare(from)] = "owner"; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
293 end |
1740
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
294 local affiliation = self:get_affiliation(from); |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
295 local role = self:get_default_role(affiliation) |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
296 if role then -- new occupant |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
297 if not is_merge then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
298 self._occupants[to] = {affiliation=affiliation, role=role, jid=from, sessions={[from]=get_filtered_presence(stanza)}}; |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
299 else |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
300 self._occupants[to].sessions[from] = get_filtered_presence(stanza); |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
301 end |
1740
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
302 self._jid_nick[from] = to; |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
303 self:send_occupant_list(from); |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
304 pr.attr.from = to; |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
305 if not is_merge then |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
306 self:broadcast_presence(pr, from); |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
307 else |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
308 pr.attr.to = from; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
309 self:_route_stanza(pr:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2053
f5a198127dd3
MUC: Fixed: affiliation='none' was omitted from some presence broadcasts.
Waqas Hussain <waqas20@gmail.com>
parents:
2051
diff
changeset
|
310 :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up() |
1989
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
311 :tag("status", {code='110'})); |
97c3236cc4ac
MUC: Multiple sessions per nick.
Waqas Hussain <waqas20@gmail.com>
parents:
1862
diff
changeset
|
312 end |
1740
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
313 self:send_history(from); |
b37ccf9bec89
MUC: Send appropriate error to banned users on join.
Waqas Hussain <waqas20@gmail.com>
parents:
1739
diff
changeset
|
314 else -- banned |
1819
ed1911be26c7
MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents:
1818
diff
changeset
|
315 local reply = st.error_reply(stanza, "auth", "forbidden"):up(); |
ed1911be26c7
MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents:
1818
diff
changeset
|
316 reply.tags[1].attr.code = "403"; |
ed1911be26c7
MUC: Added legacy error code to the presence error returned when a banned user attempts to join.
Waqas Hussain <waqas20@gmail.com>
parents:
1818
diff
changeset
|
317 origin.send(reply:tag("x", {xmlns = "http://jabber.org/protocol/muc"})); |
1734 | 318 end |
319 end | |
320 end | |
321 elseif type ~= 'result' then -- bad type | |
1998
40792c18a8e4
MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents:
1997
diff
changeset
|
322 if type ~= 'visible' and type ~= 'invisible' then -- COMPAT ejabberd can broadcast or forward XEP-0018 presences |
40792c18a8e4
MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents:
1997
diff
changeset
|
323 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? |
40792c18a8e4
MUC: Ignore invisible presence (incorrectly broadcasted or forwarded by ejabberd).
Waqas Hussain <waqas20@gmail.com>
parents:
1997
diff
changeset
|
324 end |
1734 | 325 end |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
326 elseif not current_nick then -- not in room |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
327 if type == "error" or type == "result" then |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
328 local id = stanza.name == "iq" and stanza.attr.id and base64.decode(stanza.attr.id); |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
329 local _nick, _id, _hash = (id or ""):match("^(.+)%z(.*)%z(.+)$"); |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
330 local occupant = self._occupants[stanza.attr.to]; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
331 if occupant and _nick and self._jid_nick[_nick] and _id and _hash then |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
332 local id, _to = stanza.attr.id; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
333 for jid in pairs(occupant.sessions) do |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
334 if md5(jid) == _hash then |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
335 _to = jid; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
336 break; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
337 end |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
338 end |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
339 if _to then |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
340 stanza.attr.to, stanza.attr.from, stanza.attr.id = _to, self._jid_nick[_nick], _id; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
341 self:_route_stanza(stanza); |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
342 stanza.attr.to, stanza.attr.from, stanza.attr.id = to, from, id; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
343 end |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
344 end |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
345 else |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
346 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
347 end |
1734 | 348 elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM |
349 origin.send(st.error_reply(stanza, "modify", "bad-request")); | |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
350 elseif current_nick and stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
1996
3e6b36c6d7b7
MUC: Kick occupants on sending error messages to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1989
diff
changeset
|
351 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
3e6b36c6d7b7
MUC: Kick occupants on sending error messages to other occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1989
diff
changeset
|
352 self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
353 :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable |
1734 | 354 else -- private stanza |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
355 local o_data = self._occupants[to]; |
1734 | 356 if o_data then |
357 log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); | |
358 local jid = o_data.jid; | |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
359 local bare = jid_bare(jid); |
1769
39865fbbb2f7
MUC: Preserve stanza attributes for private messages.
Waqas Hussain <waqas20@gmail.com>
parents:
1768
diff
changeset
|
360 stanza.attr.to, stanza.attr.from = jid, current_nick; |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
361 local id = stanza.attr.id; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
362 if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' and bare ~= jid then |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
363 stanza.attr.to = bare; |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
364 stanza.attr.id = base64.encode(jid.."\0"..id.."\0"..md5(from)); |
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
365 end |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
366 self:_route_stanza(stanza); |
1778
f4213d84ba8a
MUC: Correct routing of vCard requests to bare JID.
Waqas Hussain <waqas20@gmail.com>
parents:
1769
diff
changeset
|
367 stanza.attr.to, stanza.attr.from, stanza.attr.id = to, from, id; |
1734 | 368 elseif type ~= "error" and type ~= "result" then -- recipient not in room |
369 origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); | |
370 end | |
371 end | |
372 end | |
373 | |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
374 function room_mt:send_form(origin, stanza) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
375 local title = "Configuration for "..self.jid; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
376 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner") |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
377 :tag("x", {xmlns='jabber:x:data', type='form'}) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
378 :tag("title"):text(title):up() |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
379 :tag("instructions"):text(title):up() |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
380 :tag("field", {type='hidden', var='FORM_TYPE'}):tag("value"):text("http://jabber.org/protocol/muc#roomconfig"):up():up() |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
381 :tag("field", {type='boolean', label='Make Room Persistent?', var='muc#roomconfig_persistentroom'}) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
382 :tag("value"):text(self._data.persistent and "1" or "0"):up() |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
383 :up() |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
384 :tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'}) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
385 :tag("value"):text(self._data.hidden and "0" or "1"):up() |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
386 :up() |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
387 :tag("field", {type='list-single', label='Who May Discover Real JIDs?', var='muc#roomconfig_whois'}) |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
388 :tag("value"):text(self._data.whois or 'moderators'):up() |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
389 :tag("option", {label = 'Moderators Only'}) |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
390 :tag("value"):text('moderators'):up() |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
391 :up() |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
392 :tag("option", {label = 'Anyone'}) |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
393 :tag("value"):text('anyone'):up() |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
394 :up() |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
395 :up() |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
396 ); |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
397 end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
398 |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
399 local valid_whois = { |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
400 moderators = true, |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
401 anyone = true, |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
402 } |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
403 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
404 function room_mt:process_form(origin, stanza) |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
405 local query = stanza.tags[1]; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
406 local form; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
407 for _, tag in ipairs(query.tags) do if tag.name == "x" and tag.attr.xmlns == "jabber:x:data" then form = tag; break; end end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
408 if not form then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); return; end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
409 if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
410 if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
411 local fields = {}; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
412 for _, field in pairs(form.tags) do |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
413 if field.name == "field" and field.attr.var and field.tags[1].name == "value" and #field.tags[1].tags == 0 then |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
414 fields[field.attr.var] = field.tags[1][1] or ""; |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
415 end |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
416 end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
417 if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
418 |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
419 local dirty = false |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
420 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
421 local persistent = fields['muc#roomconfig_persistentroom']; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
422 if persistent == "0" or persistent == "false" then persistent = nil; elseif persistent == "1" or persistent == "true" then persistent = true; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
423 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
424 dirty = dirty or (self._data.persistent ~= persistent) |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
425 self._data.persistent = persistent; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
426 module:log("debug", "persistent=%s", tostring(persistent)); |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
427 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
428 local public = fields['muc#roomconfig_publicroom']; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
429 if public == "0" or public == "false" then public = nil; elseif public == "1" or public == "true" then public = true; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
430 else origin.send(st.error_reply(stanza, "cancel", "bad-request")); return; end |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
431 dirty = dirty or (self._data.hidden ~= (not public and true or nil)) |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
432 self._data.hidden = not public and true or nil; |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
433 |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
434 local whois = fields['muc#roomconfig_whois']; |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
435 if not valid_whois[whois] then |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
436 origin.send(st.error_reply(stanza, 'cancel', 'bad-request')); |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
437 return; |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
438 end |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
439 local whois_changed = self._data.whois ~= whois |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
440 self._data.whois = whois |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
441 module:log('debug', 'whois=%s', tostring(whois)) |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
442 |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
443 if self.save then self:save(true); end |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
444 origin.send(st.reply(stanza)); |
2412
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
445 |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
446 if dirty or whois_changed then |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
447 local msg = st.message({type='groupchat', from=self.jid}) |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
448 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}):up() |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
449 |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
450 if dirty then |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
451 msg.tags[1]:tag('status', {code = '104'}) |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
452 end |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
453 if whois_changed then |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
454 local code = (whois == 'moderators') and 173 or 172 |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
455 msg.tags[1]:tag('status', {code = code}) |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
456 end |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
457 |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
458 self:broadcast_message(msg, false) |
e243b7c81de6
Added notification of configuration changes for MUCs
Rob Hoelz <rob@hoelzro.net>
parents:
2411
diff
changeset
|
459 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
460 end |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
461 |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
462 function room_mt:destroy(newjid, reason, password) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
463 local pr = st.presence({type = "unavailable"}) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
464 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
465 :tag("item", { affiliation='none', role='none' }):up() |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
466 :tag("destroy", {jid=newjid}) |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
467 if reason then pr:tag("reason"):text(reason):up(); end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
468 if password then pr:tag("password"):text(password):up(); end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
469 for nick, occupant in pairs(self._occupants) do |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
470 pr.attr.from = nick; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
471 for jid in pairs(occupant.sessions) do |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
472 pr.attr.to = jid; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
473 self:_route_stanza(pr); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
474 self._jid_nick[jid] = nil; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
475 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
476 self._occupants[nick] = nil; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
477 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
478 self._data.persistent = nil; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
479 if self.save then self:save(true); end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
480 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
481 |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
482 function room_mt:handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc |
1734 | 483 local type = stanza.attr.type; |
1745
15039fac3693
MUC: Some fixes for minor bugs in IQ handling.
Waqas Hussain <waqas20@gmail.com>
parents:
1744
diff
changeset
|
484 local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns; |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
485 if stanza.name == "iq" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
486 if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
487 origin.send(self:get_disco_info(stanza)); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
488 elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then |
2503
bb6b0bd7f2cf
MUC: Converted some local functions into methods.
Waqas Hussain <waqas20@gmail.com>
parents:
2416
diff
changeset
|
489 origin.send(self:get_disco_items(stanza)); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
490 elseif xmlns == "http://jabber.org/protocol/muc#admin" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
491 local actor = stanza.attr.from; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
492 local affiliation = self:get_affiliation(actor); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
493 local current_nick = self._jid_nick[actor]; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
494 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
495 local item = stanza.tags[1].tags[1]; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
496 if item and item.name == "item" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
497 if type == "set" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
498 local callback = function() origin.send(st.reply(stanza)); end |
1862
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
499 if item.attr.jid then -- Validate provided JID |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
500 item.attr.jid = jid_prep(item.attr.jid); |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
501 if not item.attr.jid then |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
502 origin.send(st.error_reply(stanza, "modify", "jid-malformed")); |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
503 return; |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
504 end |
115f274dd17f
MUC: Prep given JID when changing affiliation.
Waqas Hussain <waqas20@gmail.com>
parents:
1826
diff
changeset
|
505 end |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
506 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
507 local occupant = self._occupants[self.jid.."/"..item.attr.nick]; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
508 if occupant then item.attr.jid = occupant.jid; end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
509 end |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
510 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1]; |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
511 if item.attr.affiliation and item.attr.jid and not item.attr.role then |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
512 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
513 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
514 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
515 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason); |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
516 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
517 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
518 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
519 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
520 elseif type == "get" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
521 local _aff = item.attr.affiliation; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
522 local _rol = item.attr.role; |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
523 if _aff and not _rol then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
524 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
525 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
526 for jid, affiliation in pairs(self._affiliations) do |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
527 if affiliation == _aff then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
528 reply:tag("item", {affiliation = _aff, jid = jid}):up(); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
529 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
530 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
531 origin.send(reply); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
532 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
533 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
534 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
535 elseif _rol and not _aff then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
536 if role == "moderator" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
537 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
538 if _rol == "none" then _rol = nil; end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
539 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
540 for nick, occupant in pairs(self._occupants) do |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
541 if occupant.role == _rol then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
542 reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
543 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
544 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
545 origin.send(reply); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
546 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
547 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
548 end |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
549 else |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
550 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
551 end |
1744
265863a5612b
MUC: Added support for requesting various lists (owner, admin, voice, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
1743
diff
changeset
|
552 end |
1753
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
553 elseif type == "set" or type == "get" then |
a84901db4085
MUC: Refactored IQ handling to be more easily extensible.
Waqas Hussain <waqas20@gmail.com>
parents:
1752
diff
changeset
|
554 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
555 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
556 elseif xmlns == "http://jabber.org/protocol/muc#owner" and (type == "get" or type == "set") and stanza.tags[1].name == "query" then |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
557 if self:get_affiliation(stanza.attr.from) ~= "owner" then |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
558 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
559 elseif stanza.attr.type == "get" then |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
560 self:send_form(origin, stanza); |
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
561 elseif stanza.attr.type == "set" then |
2217
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
562 local child = stanza.tags[1].tags[1]; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
563 if not child then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
564 origin.send(st.error_reply(stanza, "auth", "bad-request")); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
565 elseif child.name == "destroy" then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
566 local newjid = child.attr.jid; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
567 local reason, password; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
568 for _,tag in ipairs(child.tags) do |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
569 if tag.name == "reason" then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
570 reason = #tag.tags == 0 and tag[1]; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
571 elseif tag.name == "password" then |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
572 password = #tag.tags == 0 and tag[1]; |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
573 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
574 end |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
575 self:destroy(newjid, reason, password); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
576 origin.send(st.reply(stanza)); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
577 else |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
578 self:process_form(origin, stanza); |
838f6d546177
MUC: Added support for the room-destroy owner use case.
Waqas Hussain <waqas20@gmail.com>
parents:
2216
diff
changeset
|
579 end |
2216
dbbb5ed41365
MUC: Slightly refactored form processing.
Waqas Hussain <waqas20@gmail.com>
parents:
2174
diff
changeset
|
580 end |
1754
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
581 elseif type == "set" or type == "get" then |
67b66eec9777
MUC: Added support for room configuration forms, persistence and hidden rooms.
Waqas Hussain <waqas20@gmail.com>
parents:
1753
diff
changeset
|
582 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
583 end |
1734 | 584 elseif stanza.name == "message" and type == "groupchat" then |
585 local from, to = stanza.attr.from, stanza.attr.to; | |
586 local room = jid_bare(to); | |
587 local current_nick = self._jid_nick[from]; | |
2173
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
588 local occupant = self._occupants[current_nick]; |
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
589 if not occupant then -- not in room |
1734 | 590 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
2173
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
591 elseif occupant.role == "visitor" then |
f9af31dbfeb8
MUC: Prevent visitors from broadcasting messages.
Waqas Hussain <waqas20@gmail.com>
parents:
2172
diff
changeset
|
592 origin.send(st.error_reply(stanza, "cancel", "forbidden")); |
1734 | 593 else |
594 local from = stanza.attr.from; | |
595 stanza.attr.from = current_nick; | |
596 local subject = getText(stanza, {"subject"}); | |
597 if subject then | |
2174
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
598 if occupant.role == "moderator" then |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
599 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
600 else |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
601 stanza.attr.from = from; |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
602 origin.send(st.error_reply(stanza, "cancel", "forbidden")); |
13375e6c4ecb
MUC: Only allow moderators to change the room subject.
Waqas Hussain <waqas20@gmail.com>
parents:
2173
diff
changeset
|
603 end |
1734 | 604 else |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
605 self:broadcast_message(stanza, true); |
1734 | 606 end |
2172
84dd0fada45b
MUC: Improved handling of incoming groupchat messages (state preserved for possible later use).
Waqas Hussain <waqas20@gmail.com>
parents:
2064
diff
changeset
|
607 stanza.attr.from = from; |
1734 | 608 end |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
609 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
1768
802c40384dd0
MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents:
1764
diff
changeset
|
610 local current_nick = self._jid_nick[stanza.attr.from]; |
802c40384dd0
MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents:
1764
diff
changeset
|
611 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
802c40384dd0
MUC: Don't kick on errors in private messages.
Waqas Hussain <waqas20@gmail.com>
parents:
1764
diff
changeset
|
612 self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) |
1999
05054e360d89
MUC: Improved handling of error stanzas and made error messages concise.
Waqas Hussain <waqas20@gmail.com>
parents:
1998
diff
changeset
|
613 :tag('status'):text('Kicked: '..get_error_condition(stanza))); -- send unavailable |
1734 | 614 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick |
615 local to = stanza.attr.to; | |
616 local current_nick = self._jid_nick[stanza.attr.from]; | |
617 if current_nick then | |
618 stanza.attr.to = current_nick; | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
619 self:handle_to_occupant(origin, stanza); |
1734 | 620 stanza.attr.to = to; |
621 elseif type ~= "error" and type ~= "result" then | |
622 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
623 end | |
624 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from] | |
2005
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
625 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
626 local x = stanza.tags[1]; |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
627 local payload = (#x.tags == 1 and x.tags[1]); |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
628 if payload and payload.name == "invite" and payload.attr.to then |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
629 local _from, _to = stanza.attr.from, stanza.attr.to; |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
630 local _invitee = jid_prep(payload.attr.to); |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
631 if _invitee then |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
632 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1]; |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
633 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
634 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
635 :tag('invite', {from=_from}) |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
636 :tag('reason'):text(_reason or ""):up() |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
637 :up() |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
638 :up() |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
639 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
640 :text(_reason or "") |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
641 :up() |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
642 :tag('body') -- Add a plain message for clients which don't support invites |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
643 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
644 :up(); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
645 self:_route_stanza(invite); |
2005
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
646 else |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
647 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
648 end |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
649 else |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
650 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
Waqas Hussain <waqas20@gmail.com>
parents:
1999
diff
changeset
|
651 end |
1734 | 652 else |
653 if type == "error" or type == "result" then return; end | |
654 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
655 end | |
656 end | |
657 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
658 function room_mt:handle_stanza(origin, stanza) |
1734 | 659 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
660 if to_resource then | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
661 self:handle_to_occupant(origin, stanza); |
1734 | 662 else |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
663 self:handle_to_room(origin, stanza); |
1734 | 664 end |
665 end | |
666 | |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
667 function room_mt:route_stanza(stanza) end -- Replace with a routing function, e.g., function(room, stanza) core_route_stanza(origin, stanza); end |
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
668 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
669 function room_mt:get_affiliation(jid) |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
670 local node, host, resource = jid_split(jid); |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
671 local bare = node and node.."@"..host or host; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
672 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
673 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
674 return result; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
675 end |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
676 function room_mt:set_affiliation(actor, jid, affiliation, callback, reason) |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
677 jid = jid_bare(jid); |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
678 if affiliation == "none" then affiliation = nil; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
679 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
680 return nil, "modify", "not-acceptable"; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
681 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
682 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
683 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
684 self._affiliations[jid] = affiliation; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
685 local role = self:get_default_role(affiliation); |
1750
a1c18470eeee
MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1749
diff
changeset
|
686 local p = st.presence() |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
687 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
688 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
689 :tag("reason"):text(reason or ""):up() |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
690 :up(); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
691 local x = p.tags[1]; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
692 local item = x.tags[1]; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
693 if not role then -- getting kicked |
1750
a1c18470eeee
MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1749
diff
changeset
|
694 p.attr.type = "unavailable"; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
695 if affiliation == "outcast" then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
696 x:tag("status", {code="301"}):up(); -- banned |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
697 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
698 x:tag("status", {code="321"}):up(); -- affiliation change |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
699 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
700 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
701 local modified_nicks = {}; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
702 for nick, occupant in pairs(self._occupants) do |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
703 if jid_bare(occupant.jid) == jid then |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
704 if not role then -- getting kicked |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
705 self._occupants[nick] = nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
706 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
707 t_insert(modified_nicks, nick); |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
708 occupant.affiliation, occupant.role = affiliation, role; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
709 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
710 p.attr.from = nick; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
711 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
712 if not role then self._jid_nick[jid] = nil; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
713 p.attr.to = jid; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
714 self:_route_stanza(p); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
715 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
716 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
717 end |
1755
1614e8e62ad5
MUC: Fixed an undefined global access.
Waqas Hussain <waqas20@gmail.com>
parents:
1754
diff
changeset
|
718 if self.save then self:save(); end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
719 if callback then callback(); end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
720 for _, nick in ipairs(modified_nicks) do |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
721 p.attr.from = nick; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
722 self:broadcast_except_nick(p, nick); |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
723 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
724 return true; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
725 end |
1734 | 726 |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
727 function room_mt:get_role(nick) |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
728 local session = self._occupants[nick]; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
729 return session and session.role or nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
730 end |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
731 function room_mt:set_role(actor, nick, role, callback, reason) |
1752
4db786919805
MUC: Added kicking support.
Waqas Hussain <waqas20@gmail.com>
parents:
1751
diff
changeset
|
732 if role == "none" then role = nil; end |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
733 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
734 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
735 local occupant = self._occupants[nick]; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
736 if not occupant then return nil, "modify", "not-acceptable"; end |
1743
d00b144f4bcf
MUC: An admin or owner MUST NOT be able to revoke moderation privileges from another admin or owner.
Waqas Hussain <waqas20@gmail.com>
parents:
1742
diff
changeset
|
737 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end |
1750
a1c18470eeee
MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1749
diff
changeset
|
738 local p = st.presence({from = nick}) |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
739 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
2006
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
740 :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}) |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
741 :tag("reason"):text(reason or ""):up() |
0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
Waqas Hussain <waqas20@gmail.com>
parents:
2005
diff
changeset
|
742 :up(); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
743 if not role then -- kick |
1750
a1c18470eeee
MUC: Fixed: Unavailable presence was being sent for all role and affiliation changes. Now sent only for kicked occupants.
Waqas Hussain <waqas20@gmail.com>
parents:
1749
diff
changeset
|
744 p.attr.type = "unavailable"; |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
745 self._occupants[nick] = nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
746 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
747 self._jid_nick[jid] = nil; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
748 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
749 p:tag("status", {code = "307"}):up(); |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
750 else |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
751 occupant.role = role; |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
752 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
753 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
754 p.attr.to = jid; |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
755 self:_route_stanza(p); |
1742
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
756 end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
757 if callback then callback(); end |
1483a62d69bb
MUC: Owners can now modify roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1740
diff
changeset
|
758 self:broadcast_except_nick(p, nick); |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
759 return true; |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
760 end |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
761 |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
762 function room_mt:_route_stanza(stanza) |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
763 local muc_child; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
764 local to_occupant = self._occupants[self._jid_nick[stanza.attr.to]]; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
765 local from_occupant = self._occupants[stanza.attr.from]; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
766 if stanza.name == "presence" then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
767 if to_occupant and from_occupant then |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
768 if self._data.whois == 'anyone' then |
2416
89be536aae25
mod_muc/muc.lib: Use stanza:get_child() to locate MUC child element
Matthew Wild <mwild1@gmail.com>
parents:
2412
diff
changeset
|
769 muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
770 else |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
771 if to_occupant.role == "moderator" or jid_bare(to_occupant.jid) == jid_bare(from_occupant.jid) then |
2416
89be536aae25
mod_muc/muc.lib: Use stanza:get_child() to locate MUC child element
Matthew Wild <mwild1@gmail.com>
parents:
2412
diff
changeset
|
772 muc_child = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
773 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
774 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
775 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
776 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
777 if muc_child then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
778 for _, item in pairs(muc_child.tags) do |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
779 if item.name == "item" then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
780 if from_occupant == to_occupant then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
781 item.attr.jid = stanza.attr.to; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
782 else |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
783 item.attr.jid = from_occupant.jid; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
784 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
785 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
786 end |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
787 if self._data.whois == 'anyone' then |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
788 muc_child:tag('status', { code = '100' }); |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
789 end |
2064
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
790 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
791 self:route_stanza(stanza); |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
792 if muc_child then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
793 for _, item in pairs(muc_child.tags) do |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
794 if item.name == "item" then |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
795 item.attr.jid = nil; |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
796 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
797 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
798 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
799 end |
1ee862fd1afe
MUC: Include occupants' real JIDs in their presence (semi-anonymous rooms).
Waqas Hussain <waqas20@gmail.com>
parents:
2053
diff
changeset
|
800 |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
801 local _M = {}; -- module "muc" |
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
802 |
1749
cf2ade983e12
MUC: Changed a MUC library method into a function.
Waqas Hussain <waqas20@gmail.com>
parents:
1746
diff
changeset
|
803 function _M.new_room(jid) |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
804 return setmetatable({ |
1734 | 805 jid = jid; |
806 _jid_nick = {}; | |
1739
393abf245322
MUC: Renamed _participants table to _occupants
Waqas Hussain <waqas20@gmail.com>
parents:
1737
diff
changeset
|
807 _occupants = {}; |
2411
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
808 _data = { |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
809 whois = 'moderators', |
c2b6c55201af
Add support for non-anonymous MUC rooms
Rob Hoelz <rob@hoelzro.net>
parents:
2217
diff
changeset
|
810 }; |
1737
31c3eb5797c7
MUC: Initial support for roles and affiliations
Waqas Hussain <waqas20@gmail.com>
parents:
1736
diff
changeset
|
811 _affiliations = {}; |
1735
81406277279e
MUC: The MUC lib is now metatable based. Cleaned up code, etc.
Waqas Hussain <waqas20@gmail.com>
parents:
1734
diff
changeset
|
812 }, room_mt); |
1734 | 813 end |
814 | |
815 return _M; |