author | Waqas Hussain <waqas20@gmail.com> |
Fri, 20 Feb 2009 02:23:21 +0500 | |
changeset 830 | c0554caf90e6 |
parent 828 | 97ea39b7bf90 |
child 831 | e2d2095705dc |
permissions | -rw-r--r-- |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
1 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
2 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
3 |
local register_component = require "core.componentmanager".register_component; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
4 |
local deregister_component = require "core.componentmanager".deregister_component; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
5 |
local jid_split = require "util.jid".split; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
6 |
local jid_bare = require "util.jid".bare; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
7 |
local st = require "util.stanza"; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
8 |
local log = require "util.logger".init("mod_muc"); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
9 |
local multitable_new = require "util.multitable".new; |
782 | 10 |
local t_insert, t_remove = table.insert, table.remove; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
11 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
12 |
if module:get_host_type() ~= "component" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
13 |
error("MUC should be loaded as a component, please see http://prosody.im/doc/components", 0); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
14 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
15 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
16 |
local muc_domain = module:get_host(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
17 |
local muc_name = "MUCMUCMUC!!!"; |
782 | 18 |
local history_length = 20; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
19 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
20 |
-- room_name -> room |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
21 |
-- occupant_room_nick -> data |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
22 |
-- affiliation = ... |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
23 |
-- role |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
24 |
-- jid = occupant's real jid |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
25 |
local rooms = multitable_new(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
26 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
27 |
local jid_nick = multitable_new(); -- real jid -> room's jid -> room nick |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
28 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
29 |
-- room_name -> info |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
30 |
-- name - the room's friendly name |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
31 |
-- subject - the room's subject |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
32 |
-- non-anonymous = true|nil |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
33 |
-- persistent = true|nil |
782 | 34 |
-- history = {preserialized stanzas} |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
35 |
local rooms_info = multitable_new(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
36 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
37 |
local persist_list = datamanager.load(nil, muc_domain, 'room_list') or {}; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
38 |
for room in pairs(persist_list) do |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
39 |
rooms_info:set(room, datamanager.store(room, muc_domain, 'rooms') or nil); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
40 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
41 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
42 |
local component; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
43 |
|
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
44 |
function filter_xmlns_from_array(array, filters) |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
45 |
local count = 0; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
46 |
for i=#array,1,-1 do |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
47 |
local attr = array[i].attr; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
48 |
if filters[attr and attr.xmlns] then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
49 |
t_remove(array, i); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
50 |
count = count + 1; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
51 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
52 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
53 |
return count; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
54 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
55 |
function filter_xmlns_from_stanza(stanza, filters) |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
56 |
if filters then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
57 |
if filter_xmlns_from_array(stanza.tags, filters) ~= 0 then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
58 |
return stanza, filter_xmlns_from_array(stanza, filters); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
59 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
60 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
61 |
return stanza, 0; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
62 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
63 |
local presence_filters = {["http://jabber.org/protocol/muc"]=true;["http://jabber.org/protocol/muc#user"]=true}; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
64 |
function get_filtered_presence(stanza) |
830
c0554caf90e6
MUC: Use util.stanza.clone instead of pre/deserialize for cloning stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
828
diff
changeset
|
65 |
return filter_xmlns_from_stanza(st.clone(stanza), presence_filters); |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
66 |
end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
67 |
function getUsingPath(stanza, path, getText) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
68 |
local tag = stanza; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
69 |
for _, name in ipairs(path) do |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
70 |
if type(tag) ~= 'table' then return; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
71 |
tag = tag:child_with_name(name); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
72 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
73 |
if tag and getText then tag = table.concat(tag); end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
74 |
return tag; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
75 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
76 |
function getTag(stanza, path) return getUsingPath(stanza, path); end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
77 |
function getText(stanza, path) return getUsingPath(stanza, path, true); end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
78 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
79 |
function get_disco_info(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
80 |
return st.iq({type='result', id=stanza.attr.id, from=muc_domain, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
81 |
:tag("identity", {category='conference', type='text', name=muc_name}):up() |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
82 |
:tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
83 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
84 |
function get_disco_items(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
85 |
local reply = st.iq({type='result', id=stanza.attr.id, from=muc_domain, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
86 |
for room in pairs(rooms_info:get()) do |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
87 |
reply:tag("item", {jid=room, name=rooms_info:get(room, "name")}):up(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
88 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
89 |
return reply; -- TODO cache disco reply |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
90 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
91 |
function get_room_disco_info(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
92 |
return st.iq({type='result', id=stanza.attr.id, from=stanza.attr.to, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
93 |
:tag("identity", {category='conference', type='text', name=rooms_info:get(stanza.attr.to, "name")}):up() |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
94 |
:tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
95 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
96 |
function get_room_disco_items(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
97 |
return st.iq({type='result', id=stanza.attr.id, from=stanza.attr.to, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
98 |
end -- TODO allow non-private rooms |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
99 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
100 |
function save_room(room) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
101 |
local persistent = rooms_info:get(room, 'persistent'); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
102 |
if persistent then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
103 |
datamanager.store(room, muc_domain, 'rooms', rooms_info:get(room)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
104 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
105 |
if persistent ~= persist_list[room] then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
106 |
if not persistent then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
107 |
datamanager.store(room, muc_domain, 'rooms', nil); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
108 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
109 |
persist_list[room] = persistent; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
110 |
datamanager.store(nil, muc_domain, 'room_list', persist_list); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
111 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
112 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
113 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
114 |
function set_subject(current_nick, room, subject) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
115 |
-- TODO check nick's authority |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
116 |
if subject == "" then subject = nil; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
117 |
rooms_info:set(room, 'subject', subject); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
118 |
save_room(); |
818 | 119 |
local msg = st.message({type='groupchat', from=current_nick}) |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
120 |
:tag('subject'):text(subject):up(); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
121 |
broadcast_message_stanza(room, msg, false); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
122 |
--broadcast_message(current_nick, room, subject or "", nil); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
123 |
return true; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
124 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
125 |
|
757
f77843f31c7d
mod_muc: Add 'nick' to unavailable presence of nick changes. Thanks to Asterix for spotting :)
Matthew Wild <mwild1@gmail.com>
parents:
756
diff
changeset
|
126 |
function broadcast_presence(type, from, room, code, newnick) |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
127 |
local data = rooms:get(room, from); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
128 |
local stanza = st.presence({type=type, from=from}) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
129 |
:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
757
f77843f31c7d
mod_muc: Add 'nick' to unavailable presence of nick changes. Thanks to Asterix for spotting :)
Matthew Wild <mwild1@gmail.com>
parents:
756
diff
changeset
|
130 |
:tag("item", {affiliation=data.affiliation, role=data.role, nick = newnick}):up(); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
131 |
if code then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
132 |
stanza:tag("status", {code=code}):up(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
133 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
134 |
local me; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
135 |
local r = rooms:get(room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
136 |
if r then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
137 |
for occupant, o_data in pairs(r) do |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
138 |
if occupant ~= from then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
139 |
stanza.attr.to = o_data.jid; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
140 |
core_route_stanza(component, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
141 |
else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
142 |
me = o_data.jid; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
143 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
144 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
145 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
146 |
if me then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
147 |
stanza:tag("status", {code='110'}); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
148 |
stanza.attr.to = me; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
149 |
core_route_stanza(component, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
150 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
151 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
152 |
function broadcast_message(from, room, subject, body) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
153 |
local stanza = st.message({type='groupchat', from=from}); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
154 |
if subject then stanza:tag('subject'):text(subject):up(); end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
155 |
if body then stanza:tag('body'):text(body):up(); end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
156 |
local r = rooms:get(room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
157 |
if r then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
158 |
for occupant, o_data in pairs(r) do |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
159 |
stanza.attr.to = o_data.jid; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
160 |
core_route_stanza(component, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
161 |
end |
782 | 162 |
if not subject and body then -- add to history |
163 |
local history = rooms_info:get(room, 'history'); |
|
164 |
if not history then history = {}; rooms_info:set(room, 'history', history); end |
|
830
c0554caf90e6
MUC: Use util.stanza.clone instead of pre/deserialize for cloning stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
828
diff
changeset
|
165 |
-- stanza = st.clone(stanza); |
782 | 166 |
stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 |
167 |
stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
|
830
c0554caf90e6
MUC: Use util.stanza.clone instead of pre/deserialize for cloning stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
828
diff
changeset
|
168 |
t_insert(history, st.clone(st.preserialize(stanza))); |
782 | 169 |
while #history > history_length do t_remove(history, 1) end |
170 |
end |
|
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
171 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
172 |
end |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
173 |
function broadcast_message_stanza(room, stanza, historic) |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
174 |
local r = rooms:get(room); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
175 |
if r then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
176 |
for occupant, o_data in pairs(r) do |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
177 |
for jid in pairs(o_data.sessions) do |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
178 |
stanza.attr.to = jid; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
179 |
core_route_stanza(component, stanza); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
180 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
181 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
182 |
if historic then -- add to history |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
183 |
local history = rooms_info:get(room, 'history'); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
184 |
if not history then history = {}; rooms_info:set(room, 'history', history); end |
830
c0554caf90e6
MUC: Use util.stanza.clone instead of pre/deserialize for cloning stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
828
diff
changeset
|
185 |
-- stanza = st.clone(stanza); |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
186 |
stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
187 |
stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
830
c0554caf90e6
MUC: Use util.stanza.clone instead of pre/deserialize for cloning stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
828
diff
changeset
|
188 |
t_insert(history, st.clone(st.preserialize(stanza))); |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
189 |
while #history > history_length do t_remove(history, 1) end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
190 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
191 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
192 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
193 |
function broadcast_presence_stanza(room, stanza, code, nick) |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
194 |
stanza = get_filtered_presence(stanza); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
195 |
local data = rooms:get(room, stanza.attr.from); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
196 |
stanza:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
197 |
:tag("item", {affiliation=data.affiliation, role=data.role, nick=nick}):up(); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
198 |
if code then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
199 |
stanza:tag("status", {code=code}):up(); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
200 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
201 |
local me; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
202 |
local r = rooms:get(room); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
203 |
if r then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
204 |
for occupant, o_data in pairs(r) do |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
205 |
if occupant ~= stanza.attr.from then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
206 |
for jid in pairs(o_data.sessions) do |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
207 |
stanza.attr.to = jid; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
208 |
core_route_stanza(component, stanza); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
209 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
210 |
else |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
211 |
me = o_data; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
212 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
213 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
214 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
215 |
if me then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
216 |
stanza:tag("status", {code='110'}); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
217 |
for jid in pairs(me.sessions) do |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
218 |
stanza.attr.to = jid; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
219 |
core_route_stanza(component, stanza); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
220 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
221 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
222 |
end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
223 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
224 |
function handle_to_occupant(origin, stanza) -- PM, vCards, etc |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
225 |
local from, to = stanza.attr.from, stanza.attr.to; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
226 |
local room = jid_bare(to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
227 |
local current_nick = jid_nick:get(from, room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
228 |
local type = stanza.attr.type; |
822
a82eadc415ff
MUC: Logging - logger doesn't like nils
Waqas Hussain <waqas20@gmail.com>
parents:
820
diff
changeset
|
229 |
log("debug", "room: %s, current_nick: %s, stanza: %s", room or "nil", current_nick or "nil", stanza:top_tag()); |
828
97ea39b7bf90
MUC: Syntax error in last commit - this is lua :)
Waqas Hussain <waqas20@gmail.com>
parents:
827
diff
changeset
|
230 |
if (select(2, jid_split(from)) == muc_domain) then error("Presence from the MUC itself!!!"); end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
231 |
if stanza.name == "presence" then |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
232 |
local pr = get_filtered_presence(stanza); |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
233 |
pr.attr.from = current_nick; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
234 |
if type == "error" then -- error, kick em out! |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
235 |
if current_nick then |
820 | 236 |
log("debug", "kicking %s from %s", current_nick, room); |
818 | 237 |
local data = rooms:get(room, current_nick); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
238 |
data.role = 'none'; |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
239 |
local pr = st.presence({type='unavailable', from=current_nick}):tag('status'):text('This participant is kicked from the room because he sent an error presence'):up() |
818 | 240 |
--:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
241 |
--:tag("item", {affiliation=data.affiliation, role=data.role}):up(); |
|
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
242 |
broadcast_presence_stanza(room, pr); |
818 | 243 |
--broadcast_presence('unavailable', current_nick, room); -- TODO also add <status>This participant is kicked from the room because he sent an error presence: badformed error stanza</status> |
244 |
rooms:remove(room, current_nick); |
|
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
245 |
jid_nick:remove(from, room); |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
246 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
247 |
elseif type == "unavailable" then -- unavailable |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
248 |
if current_nick then |
820 | 249 |
log("debug", "%s leaving %s", current_nick, room); |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
250 |
-- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data)); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
251 |
-- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data)); |
818 | 252 |
local data = rooms:get(room, current_nick); |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
253 |
data.role = 'none'; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
254 |
broadcast_presence_stanza(room, pr); |
818 | 255 |
--broadcast_presence('unavailable', current_nick, room); |
256 |
rooms:remove(room, current_nick); |
|
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
257 |
jid_nick:remove(from, room); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
258 |
end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
259 |
elseif not type then -- available |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
260 |
if current_nick then |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
261 |
if #pr == #stanza then |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
262 |
if current_nick == to then -- simple presence |
820 | 263 |
log("debug", "%s broadcasted presence", current_nick); |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
264 |
rooms:get(room, current_nick).sessions[from] = pr; |
818 | 265 |
broadcast_presence_stanza(room, pr); |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
266 |
else -- change nick |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
267 |
if rooms:get(room, to) then |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
268 |
log("debug", "%s couldn't change nick", current_nick); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
269 |
origin.send(st.error_reply(stanza, "cancel", "conflict")); |
757
f77843f31c7d
mod_muc: Add 'nick' to unavailable presence of nick changes. Thanks to Asterix for spotting :)
Matthew Wild <mwild1@gmail.com>
parents:
756
diff
changeset
|
270 |
else |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
271 |
local data = rooms:get(room, current_nick); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
272 |
local to_nick = select(3, jid_split(to)); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
273 |
if to_nick then |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
274 |
log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
275 |
-- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data)); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
276 |
-- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data)); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
277 |
local p = st.presence({type='unavailable', from=current_nick}); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
278 |
--[[:tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
279 |
:tag('item', {affiliation=data.affiliation, role=data.role, nick=to_nick}):up() |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
280 |
:tag('status', {code='303'});]] |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
281 |
broadcast_presence_stanza(room, p, '303', to_nick); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
282 |
--broadcast_presence('unavailable', current_nick, room, '303', to_nick); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
283 |
rooms:remove(room, current_nick); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
284 |
rooms:set(room, to, data); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
285 |
jid_nick:set(from, room, to); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
286 |
pr.attr.from = to; |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
287 |
rooms:get(room, to).sessions[from] = pr; |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
288 |
broadcast_presence_stanza(room, pr); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
289 |
-- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data)); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
290 |
-- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data)); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
291 |
--broadcast_presence(nil, to, room, nil); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
292 |
else |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
293 |
--TODO malformed-jid |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
294 |
end |
757
f77843f31c7d
mod_muc: Add 'nick' to unavailable presence of nick changes. Thanks to Asterix for spotting :)
Matthew Wild <mwild1@gmail.com>
parents:
756
diff
changeset
|
295 |
end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
296 |
end |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
297 |
else -- possible rejoin |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
298 |
log("debug", "%s had connection replaced", current_nick); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
299 |
local pr_ = st.presence({type='unavailable', from=from, to=current_nick}):tag('status'):text('Replaced by new connection'); |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
300 |
handle_to_occupant(origin, pr_); -- send unavailable |
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
301 |
handle_to_occupant(origin, stanza); -- resend available |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
302 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
303 |
else -- enter room |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
304 |
local new_nick = to; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
305 |
if rooms:get(room, to) then |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
306 |
new_nick = nil; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
307 |
end |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
308 |
if not new_nick then |
820 | 309 |
log("debug", "%s couldn't join due to nick conflict: %s", from, to); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
310 |
origin.send(st.error_reply(stanza, "cancel", "conflict")); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
311 |
else |
820 | 312 |
log("debug", "%s joining as %s", from, to); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
313 |
local data; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
314 |
if not rooms:get(room) and not rooms_info:get(room) then -- new room |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
315 |
data = {affiliation='owner', role='moderator', jid=from, sessions={[from]=get_filtered_presence(stanza)}}; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
316 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
317 |
if not data then -- new occupant |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
318 |
data = {affiliation='none', role='participant', jid=from, sessions={[from]=get_filtered_presence(stanza)}}; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
319 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
320 |
rooms:set(room, to, data); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
321 |
jid_nick:set(from, room, to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
322 |
local r = rooms:get(room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
323 |
if r then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
324 |
for occupant, o_data in pairs(r) do |
817
e3e3919b6c7e
MUC: Fixed: Presence for user joining the roomi was sent twice to the user
Waqas Hussain <waqas20@gmail.com>
parents:
813
diff
changeset
|
325 |
if occupant ~= to then |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
326 |
local pres = get_filtered_presence(o_data.sessions[o_data.jid]); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
327 |
pres.attr.to, pres.attr.from = from, occupant; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
328 |
pres |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
329 |
--local pres = st.presence({to=from, from=occupant}) |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
330 |
:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
331 |
:tag("item", {affiliation=o_data.affiliation, role=o_data.role}):up(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
332 |
core_route_stanza(component, pres); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
333 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
334 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
335 |
end |
824
b6ee70721783
MUC: Bug fixes and workarounds
Waqas Hussain <waqas20@gmail.com>
parents:
822
diff
changeset
|
336 |
pr.attr.from = to; |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
337 |
broadcast_presence_stanza(room, pr); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
338 |
--broadcast_presence(nil, to, room); |
782 | 339 |
local history = rooms_info:get(room, 'history'); -- send discussion history |
340 |
if history then |
|
341 |
for _, msg in ipairs(history) do |
|
342 |
msg = st.deserialize(msg); |
|
343 |
msg.attr.to=from; |
|
344 |
core_route_stanza(component, msg); |
|
345 |
end |
|
346 |
end |
|
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
347 |
if rooms_info:get(room, 'subject') then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
348 |
core_route_stanza(component, st.message({type='groupchat', from=room, to=from}):tag("subject"):text(rooms_info:get(room, 'subject'))); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
349 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
350 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
351 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
352 |
elseif type ~= 'result' then -- bad type |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
353 |
origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
354 |
end |
811
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
355 |
elseif not current_nick then -- not in room |
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
356 |
origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
812
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
357 |
elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
358 |
origin.send(st.error_reply(stanza, "modify", "bad-request")); |
812
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
359 |
elseif stanza.name == "message" and type == "error" then |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
360 |
if current_nick then |
820 | 361 |
log("debug", "%s kicked from %s for sending an error message", current_nick, room); |
812
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
362 |
local data = rooms:get(room, to); |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
363 |
data.role = 'none'; |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
364 |
local pr = st.presence({type='unavailable', from=current_nick}):tag('status'):text('This participant is kicked from the room because he sent an error message to another occupant'):up() |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
365 |
:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
366 |
:tag("item", {affiliation=data.affiliation, role=data.role}):up(); |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
367 |
broadcast_presence_stanza(room, pr); |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
368 |
rooms:remove(room, to); |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
369 |
jid_nick:remove(from, room); |
1dbcf57154bd
MUC: Kick participants sending error messages to other participants
Waqas Hussain <waqas20@gmail.com>
parents:
811
diff
changeset
|
370 |
end |
811
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
371 |
else -- private stanza |
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
372 |
local o_data = rooms:get(room, to); |
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
373 |
if o_data then |
820 | 374 |
log("debug", "%s sent private stanza to %s (%s)", from, to, o_data.jid); |
813
ebfb904640d8
MUC: Made vCards work by redirecting vCard requests to bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents:
812
diff
changeset
|
375 |
local jid = o_data.jid; |
ebfb904640d8
MUC: Made vCards work by redirecting vCard requests to bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents:
812
diff
changeset
|
376 |
if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' then jid = jid_bare(jid); end |
ebfb904640d8
MUC: Made vCards work by redirecting vCard requests to bare JIDs
Waqas Hussain <waqas20@gmail.com>
parents:
812
diff
changeset
|
377 |
stanza.attr.to, stanza.attr.from = jid, current_nick; |
811
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
378 |
core_route_stanza(component, stanza); |
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
379 |
else -- recipient not in room |
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
380 |
origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room")); |
863046d84b56
MUC: Private stanzas (private messages, IQs, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
810
diff
changeset
|
381 |
end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
382 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
383 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
384 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
385 |
function handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
386 |
local type = stanza.attr.type; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
387 |
if stanza.name == "iq" and type == "get" then -- disco requests |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
388 |
local xmlns = stanza.tags[1].attr.xmlns; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
389 |
if xmlns == "http://jabber.org/protocol/disco#info" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
390 |
origin.send(get_room_disco_info(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
391 |
elseif xmlns == "http://jabber.org/protocol/disco#items" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
392 |
origin.send(get_room_disco_items(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
393 |
else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
394 |
origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
395 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
396 |
elseif stanza.name == "message" and type == "groupchat" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
397 |
local from, to = stanza.attr.from, stanza.attr.to; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
398 |
local room = jid_bare(to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
399 |
local current_nick = jid_nick:get(from, room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
400 |
if not current_nick then -- not in room |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
401 |
origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
402 |
else |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
403 |
local from = stanza.attr.from; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
404 |
stanza.attr.from = current_nick; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
405 |
local subject = getText(stanza, {"subject"}); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
406 |
if subject then |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
407 |
set_subject(current_nick, room, subject); -- TODO use broadcast_message_stanza |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
408 |
else |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
409 |
--broadcast_message(current_nick, room, nil, getText(stanza, {"body"})); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
410 |
broadcast_message_stanza(room, stanza, true); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
411 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
412 |
end |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
413 |
elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
414 |
local to = stanza.attr.to; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
415 |
local current_nick = jid_nick:get(stanza.attr.from, to); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
416 |
if current_nick then |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
417 |
stanza.attr.to = current_nick; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
418 |
handle_to_occupant(origin, stanza); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
419 |
stanza.attr.to = to; |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
420 |
else |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
421 |
origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
422 |
end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
423 |
else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
424 |
if type == "error" or type == "result" then return; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
425 |
origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
426 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
427 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
428 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
429 |
function handle_to_domain(origin, stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
430 |
local type = stanza.attr.type; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
431 |
if type == "error" or type == "result" then return; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
432 |
if stanza.name == "iq" and type == "get" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
433 |
local xmlns = stanza.tags[1].attr.xmlns; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
434 |
if xmlns == "http://jabber.org/protocol/disco#info" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
435 |
origin.send(get_disco_info(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
436 |
elseif xmlns == "http://jabber.org/protocol/disco#items" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
437 |
origin.send(get_disco_items(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
438 |
else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
439 |
origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- TODO disco/etc |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
440 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
441 |
else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
442 |
origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
443 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
444 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
445 |
|
779
ec0eadf4e9ff
Changed mod_muc to work with changed component manager
Waqas Hussain <waqas20@gmail.com>
parents:
757
diff
changeset
|
446 |
register_component(muc_domain, function(origin, stanza) |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
447 |
local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
810
09d6b5fadc84
MUC: Presence and message stanzas now fully work (status messages, xhtml-im, etc)
Waqas Hussain <waqas20@gmail.com>
parents:
782
diff
changeset
|
448 |
if to_resource and not to_node then |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
449 |
if type == "error" or type == "result" then return; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
450 |
origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- host/resource |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
451 |
elseif to_resource then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
452 |
handle_to_occupant(origin, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
453 |
elseif to_node then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
454 |
handle_to_room(origin, stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
455 |
else -- to the main muc domain |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
456 |
if type == "error" or type == "result" then return; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
457 |
handle_to_domain(origin, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
458 |
end |
779
ec0eadf4e9ff
Changed mod_muc to work with changed component manager
Waqas Hussain <waqas20@gmail.com>
parents:
757
diff
changeset
|
459 |
end); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
460 |
|
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
461 |
module.unload = function() |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
462 |
deregister_component(muc_domain); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
463 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
464 |
module.save = function() |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
465 |
return {rooms = rooms.data; jid_nick = jid_nick.data; rooms_info = rooms_info.data; persist_list = persist_list}; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
466 |
end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
467 |
module.restore = function(data) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
468 |
rooms.data, jid_nick.data, rooms_info.data, persist_list = |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
469 |
data.rooms or {}, data.jid_nick or {}, data.rooms_info or {}, data.persist_list or {}; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
470 |
end |