Software /
code /
prosody
Annotate
plugins/mod_muc.lua @ 800:5e12bca2a4f8
Merging with tip.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sat, 14 Feb 2009 19:13:14 +0100 |
parent | 782:6f9b2a9d6d45 |
child | 810:09d6b5fadc84 |
rev | line source |
---|---|
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 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
44 function getUsingPath(stanza, path, getText) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
45 local tag = stanza; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
46 for _, name in ipairs(path) do |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
47 if type(tag) ~= 'table' then return; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
48 tag = tag:child_with_name(name); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
49 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
50 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
|
51 return tag; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
52 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
53 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
|
54 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
|
55 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
56 function get_disco_info(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
57 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
|
58 :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
|
59 :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
|
60 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
61 function get_disco_items(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
66 return reply; -- TODO cache disco reply |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
67 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
68 function get_room_disco_info(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
69 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
|
70 :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
|
71 :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
|
72 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
73 function get_room_disco_items(stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
74 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
|
75 end -- TODO allow non-private rooms |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
76 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
77 function save_room(room) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
78 local persistent = rooms_info:get(room, 'persistent'); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
79 if persistent then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
80 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
|
81 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
82 if persistent ~= persist_list[room] then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
83 if not persistent then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
84 datamanager.store(room, muc_domain, 'rooms', nil); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
85 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
86 persist_list[room] = persistent; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
87 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
|
88 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
89 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
90 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
91 function set_subject(current_nick, room, subject) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
92 -- TODO check nick's authority |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
93 if subject == "" then subject = nil; end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
94 rooms_info:set(room, 'subject', subject); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
95 save_room(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
96 broadcast_message(current_nick, room, subject or "", nil); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
97 return true; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
98 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
99 |
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
|
100 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
|
101 local data = rooms:get(room, from); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
102 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
|
103 :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
|
104 :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
|
105 if code then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
106 stanza:tag("status", {code=code}):up(); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
107 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
108 local me; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
109 local r = rooms:get(room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
110 if r then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
111 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
|
112 if occupant ~= from then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
113 stanza.attr.to = o_data.jid; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
114 core_route_stanza(component, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
115 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
116 me = o_data.jid; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
117 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
118 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
119 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
120 if me then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
121 stanza:tag("status", {code='110'}); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
122 stanza.attr.to = me; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
123 core_route_stanza(component, stanza); |
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 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
126 function broadcast_message(from, room, subject, body) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 local r = rooms:get(room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
131 if r then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
132 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
|
133 stanza.attr.to = o_data.jid; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
134 core_route_stanza(component, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
135 end |
782 | 136 if not subject and body then -- add to history |
137 local history = rooms_info:get(room, 'history'); | |
138 if not history then history = {}; rooms_info:set(room, 'history', history); end | |
139 -- stanza = st.deserialize(st.preserialize(stanza)); | |
140 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 | |
141 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | |
142 t_insert(history, st.preserialize(stanza)); | |
143 while #history > history_length do t_remove(history, 1) end | |
144 end | |
756
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 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
147 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
148 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
|
149 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
|
150 local room = jid_bare(to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
151 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
|
152 local type = stanza.attr.type; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
153 if stanza.name == "presence" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
154 if type == "error" then -- error, kick em out! |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
155 local data = rooms:get(room, to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
156 data.role = 'none'; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
157 broadcast_presence('unavailable', to, room); -- TODO also add <status>This participant is kicked from the room because he sent an error presence: badformed error stanza</status> |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
158 rooms:remove(room, to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
159 jid_nick:remove(from, room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
160 elseif type == "unavailable" then -- unavailable |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
161 if current_nick == to then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
162 local data = rooms:get(room, to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
163 data.role = 'none'; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
164 broadcast_presence('unavailable', to, room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
165 rooms:remove(room, to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
166 jid_nick:remove(from, room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
167 end -- TODO else do nothing? |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
168 elseif not type then -- available |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
169 if current_nick then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
170 if current_nick == to then -- simple presence |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
171 -- TODO broadcast |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
172 else -- change nick |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
173 if rooms:get(room, to) then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
174 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
|
175 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
176 local data = rooms:get(room, current_nick); |
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
|
177 local to_nick = select(3, jid_split(to)); |
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
|
178 if to_nick then |
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
|
179 broadcast_presence('unavailable', current_nick, room, '303', to_nick); |
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
|
180 rooms:remove(room, current_nick); |
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
|
181 rooms:set(room, to, data); |
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
|
182 jid_nick:set(from, room, to); |
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
|
183 broadcast_presence(nil, to, room, nil); |
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
|
184 else |
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
|
185 --TODO: malformed-jid |
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
|
186 end |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
187 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
188 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
189 else -- enter room |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
190 if rooms:get(room, to) then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
191 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
|
192 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
193 local data; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
194 if not rooms:get(room) and not rooms_info:get(room) then -- new room |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
195 data = {affiliation='owner', role='moderator', jid=from}; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
196 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
197 if not data then -- new occupant |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
198 data = {affiliation='none', role='participant', jid=from}; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
199 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
200 rooms:set(room, to, data); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
201 jid_nick:set(from, room, to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
202 local r = rooms:get(room); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
203 if r then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
204 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
|
205 if occupant ~= from then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
206 local pres = st.presence({to=from, from=occupant}) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
207 :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
|
208 :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
|
209 core_route_stanza(component, pres); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
210 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
211 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
212 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
213 broadcast_presence(nil, to, room); |
782 | 214 local history = rooms_info:get(room, 'history'); -- send discussion history |
215 if history then | |
216 for _, msg in ipairs(history) do | |
217 msg = st.deserialize(msg); | |
218 msg.attr.to=from; | |
219 core_route_stanza(component, msg); | |
220 end | |
221 end | |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
222 if rooms_info:get(room, 'subject') then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
223 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
|
224 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
225 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
226 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
227 elseif type ~= 'result' then -- bad type |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
228 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
|
229 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
230 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
|
231 -- groupchat messages not allowed in PM |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
232 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
233 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
234 origin.send(st.error_reply(stanza, "cancel", "not-implemented", "Private stanzas not implemented")); -- TODO route private stanza |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
235 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
236 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
237 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
238 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
|
239 local type = stanza.attr.type; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
240 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
|
241 local xmlns = stanza.tags[1].attr.xmlns; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
242 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
|
243 origin.send(get_room_disco_info(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
244 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
|
245 origin.send(get_room_disco_items(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
246 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
247 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
|
248 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
249 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
|
250 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
|
251 local room = jid_bare(to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
256 local subject = getText(stanza, {"subject"}); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
257 if subject then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
258 set_subject(current_nick, room, subject); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
259 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
260 broadcast_message(current_nick, room, nil, getText(stanza, {"body"})); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
261 -- TODO add to discussion history |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
262 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
263 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
264 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
265 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
|
266 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
|
267 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
268 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
269 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
270 function handle_to_domain(origin, stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
271 local type = stanza.attr.type; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
272 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
|
273 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
|
274 local xmlns = stanza.tags[1].attr.xmlns; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
275 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
|
276 origin.send(get_disco_info(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
277 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
|
278 origin.send(get_disco_items(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
279 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
280 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
|
281 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
282 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
283 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
|
284 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
285 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
286 |
779
ec0eadf4e9ff
Changed mod_muc to work with changed component manager
Waqas Hussain <waqas20@gmail.com>
parents:
757
diff
changeset
|
287 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
|
288 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
289 if stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
290 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
|
291 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME what's appropriate? |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
292 elseif to_resource and not to_node then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
293 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
|
294 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
|
295 elseif to_resource then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
296 handle_to_occupant(origin, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
297 elseif to_node then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
298 handle_to_room(origin, stanza) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
299 else -- to the main muc domain |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
300 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
|
301 handle_to_domain(origin, stanza); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
302 end |
779
ec0eadf4e9ff
Changed mod_muc to work with changed component manager
Waqas Hussain <waqas20@gmail.com>
parents:
757
diff
changeset
|
303 end); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
304 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
305 module.unload = function() |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
306 deregister_component(muc_domain); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
307 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
308 module.save = function() |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
309 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
|
310 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
311 module.restore = function(data) |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
312 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
|
313 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
|
314 end |