Software /
code /
prosody
Annotate
plugins/mod_muc.lua @ 682:dedd19e9d4b3
Add more tests for util/stanza.lua serialization routines
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 09 Jan 2009 17:44:59 +0000 |
parent | 671:c7519f0c9a2c |
child | 707:bb9583314ec7 |
rev | line source |
---|---|
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 local register_component = require "core.componentmanager".register_component; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local jid_split = require "util.jid".split; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local jid_bare = require "util.jid".bare; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 local st = require "util.stanza"; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local log = require "util.logger".init("mod_muc"); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local multitable_new = require "util.multitable".new; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local muc_domain = "conference."..module:get_host(); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local muc_name = "MUCMUCMUC!!!"; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
13 -- room_name -> room |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
14 -- occupant_room_nick -> data |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
15 -- affiliation = ... |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
16 -- role |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
17 -- jid = occupant's real jid |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local rooms = multitable_new(); |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
19 |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
20 local jid_nick = multitable_new(); -- real jid -> room's jid -> room nick |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
21 |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
22 -- room_name -> info |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
23 -- name - the room's friendly name |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
24 -- subject - the room's subject |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
25 -- non-anonymous = true|nil |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
26 -- persistent = true|nil |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local rooms_info = multitable_new(); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
29 local persist_list = datamanager.load(nil, muc_domain, 'room_list') or {}; |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
30 for room in pairs(persist_list) do |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
31 rooms_info:set(room, datamanager.store(room, muc_domain, 'rooms') or nil); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
32 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
33 |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 local component; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 function getUsingPath(stanza, path, getText) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 local tag = stanza; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 for _, name in ipairs(path) do |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 if type(tag) ~= 'table' then return; end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 tag = tag:child_with_name(name); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 if tag and getText then tag = table.concat(tag); end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 return tag; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 function getTag(stanza, path) return getUsingPath(stanza, path); end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 function getText(stanza, path) return getUsingPath(stanza, path, true); end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 function get_disco_info(stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 return st.iq({type='result', id=stanza.attr.id, from=muc_domain, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 :tag("identity", {category='conference', type='text', name=muc_name}):up() |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 :tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 function get_disco_items(stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 local reply = st.iq({type='result', id=stanza.attr.id, from=muc_domain, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 for room in pairs(rooms_info:get()) do |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 reply:tag("item", {jid=room, name=rooms_info:get(room, "name")}):up(); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 return reply; -- TODO cache disco reply |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 function get_room_disco_info(stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 return st.iq({type='result', id=stanza.attr.id, from=stanza.attr.to, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 :tag("identity", {category='conference', type='text', name=rooms_info:get(stanza.attr.to, "name")}):up() |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 :tag("feature", {var="http://jabber.org/protocol/muc"}); -- TODO cache disco reply |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 function get_room_disco_items(stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 return st.iq({type='result', id=stanza.attr.id, from=stanza.attr.to, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 end -- TODO allow non-private rooms |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
69 function save_room(room) |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
70 local persistent = rooms_info:get(room, 'persistent'); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
71 if persistent then |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
72 datamanager.store(room, muc_domain, 'rooms', rooms_info:get(room)); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
73 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
74 if persistent ~= persist_list[room] then |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
75 if not persistent then |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
76 datamanager.store(room, muc_domain, 'rooms', nil); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
77 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
78 persist_list[room] = persistent; |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
79 datamanager.store(nil, muc_domain, 'room_list', persist_list); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
80 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
81 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
82 |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
83 function set_subject(current_nick, room, subject) |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
84 -- TODO check nick's authority |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
85 if subject == "" then subject = nil; end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
86 rooms_info:set(room, 'subject', subject); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
87 save_room(); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
88 broadcast_message(current_nick, room, subject or "", nil); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
89 return true; |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
90 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
91 |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 function broadcast_presence(type, from, room, code) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 local data = rooms:get(room, from); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 local stanza = st.presence({type=type, from=from}) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 :tag("item", {affiliation=data.affiliation, role=data.role}):up(); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 if code then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 stanza:tag("status", {code=code}):up(); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 local me; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 local r = rooms:get(room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 if r then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 for occupant, o_data in pairs(r) do |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 if occupant ~= from then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 stanza.attr.to = o_data.jid; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 core_route_stanza(component, stanza); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 me = o_data.jid; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 if me then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 stanza:tag("status", {code='110'}); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 stanza.attr.to = me; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 core_route_stanza(component, stanza); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 function broadcast_message(from, room, subject, body) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 local stanza = st.message({type='groupchat', from=from}); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 if subject then stanza:tag('subject'):text(subject):up(); end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 if body then stanza:tag('body'):text(body):up(); end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 local r = rooms:get(room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 if r then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 for occupant, o_data in pairs(r) do |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 stanza.attr.to = o_data.jid; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 core_route_stanza(component, stanza); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
128 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 function handle_to_occupant(origin, stanza) -- PM, vCards, etc |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 local from, to = stanza.attr.from, stanza.attr.to; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 local room = jid_bare(to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 local current_nick = jid_nick:get(from, room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 local type = stanza.attr.type; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 if stanza.name == "presence" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 if type == "error" then -- error, kick em out! |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 local data = rooms:get(room, to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 data.role = 'none'; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 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> |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 rooms:remove(room, to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 jid_nick:remove(from, room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 elseif type == "unavailable" then -- unavailable |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 if current_nick == to then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 local data = rooms:get(room, to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 data.role = 'none'; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 broadcast_presence('unavailable', to, room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 rooms:remove(room, to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
149 jid_nick:remove(from, room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
150 end -- TODO else do nothing? |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 elseif not type then -- available |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 if current_nick then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 if current_nick == to then -- simple presence |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 -- TODO broadcast |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 else -- change nick |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 if rooms:get(room, to) then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 origin.send(st.error_reply(stanza, "cancel", "conflict")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
159 local data = rooms:get(room, current_nick); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 broadcast_presence('unavailable', current_nick, room, '303'); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 rooms:remove(room, current_nick); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 rooms:set(room, to, data); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 jid_nick:set(from, room, to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 broadcast_presence(nil, to, room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 else -- enter room |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 if rooms:get(room, to) then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 origin.send(st.error_reply(stanza, "cancel", "conflict")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 else |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
171 local data; |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
172 if not rooms:get(room) and not rooms_info:get(room) then -- new room |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
173 data = {affiliation='owner', role='moderator', jid=from}; |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
174 end |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
175 if not data then -- new occupant |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
176 data = {affiliation='none', role='participant', jid=from}; |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
177 end |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 rooms:set(room, to, data); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 jid_nick:set(from, room, to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 local r = rooms:get(room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
181 if r then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 for occupant, o_data in pairs(r) do |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
183 if occupant ~= from then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
184 local pres = st.presence({to=from, from=occupant}) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 :tag("item", {affiliation=o_data.affiliation, role=o_data.role}):up(); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 core_route_stanza(component, pres); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
188 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
189 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 broadcast_presence(nil, to, room); |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
192 -- TODO send discussion history |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
193 if rooms_info:get(room, 'subject') then |
671
c7519f0c9a2c
mod_muc: Room subject should be sent only the newly joined occupant
Waqas Hussain <waqas20@gmail.com>
parents:
668
diff
changeset
|
194 core_route_stanza(component, st.message({type='groupchat', from=room, to=from}):tag("subject"):text(rooms_info:get(room, 'subject'))); |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
195 end |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
196 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
197 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
198 elseif type ~= 'result' then -- bad type |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
199 origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error? |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
200 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
201 elseif stanza.name == "message" and type == "groupchat" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
202 -- groupchat messages not allowed in PM |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
203 origin.send(st.error_reply(stanza, "modify", "bad-request")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
204 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
205 origin.send(st.error_reply(stanza, "cancel", "not-implemented", "Private stanzas not implemented")); -- TODO route private stanza |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
206 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
207 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
208 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
209 function handle_to_room(origin, stanza) -- presence changes and groupchat messages, along with disco/etc |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
210 local type = stanza.attr.type; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
211 if stanza.name == "iq" and type == "get" then -- disco requests |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
212 local xmlns = stanza.tags[1].attr.xmlns; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
213 if xmlns == "http://jabber.org/protocol/disco#info" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
214 origin.send(get_room_disco_info(stanza)); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
215 elseif xmlns == "http://jabber.org/protocol/disco#items" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
216 origin.send(get_room_disco_items(stanza)); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
217 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
218 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
219 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
220 elseif stanza.name == "message" and type == "groupchat" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
221 local from, to = stanza.attr.from, stanza.attr.to; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
222 local room = jid_bare(to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
223 local current_nick = jid_nick:get(from, room); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
224 if not current_nick then -- not in room |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
225 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
226 else |
668
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
227 local subject = getText(stanza, {"subject"}); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
228 if subject then |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
229 set_subject(current_nick, room, subject); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
230 else |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
231 broadcast_message(current_nick, room, nil, getText(stanza, {"body"})); |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
232 -- TODO add to discussion history |
50072761e02d
mod_muc: Room subjects stored, and room persistence code in place. First user now the owner.
Waqas Hussain <waqas20@gmail.com>
parents:
666
diff
changeset
|
233 end |
666
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
234 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
235 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
236 if type == "error" or type == "result" then return; end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
237 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
238 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
239 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
240 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
241 function handle_to_domain(origin, stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
242 local type = stanza.attr.type; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
243 if type == "error" or type == "result" then return; end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
244 if stanza.name == "iq" and type == "get" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
245 local xmlns = stanza.tags[1].attr.xmlns; |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
246 if xmlns == "http://jabber.org/protocol/disco#info" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
247 origin.send(get_disco_info(stanza)); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
248 elseif xmlns == "http://jabber.org/protocol/disco#items" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
249 origin.send(get_disco_items(stanza)); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
250 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
251 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- TODO disco/etc |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
252 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
253 else |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
254 origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
255 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
256 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
257 |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
258 component = register_component(muc_domain, function(origin, stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
259 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
260 if stanza.name == "presence" and stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
261 if type == "error" or type == "result" then return; end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
262 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME what's appropriate? |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
263 elseif to_resource and not to_node then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
264 if type == "error" or type == "result" then return; end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
265 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- host/resource |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
266 elseif to_resource then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
267 handle_to_occupant(origin, stanza); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
268 elseif to_node then |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
269 handle_to_room(origin, stanza) |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
270 else -- to the main muc domain |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
271 if type == "error" or type == "result" then return; end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
272 handle_to_domain(origin, stanza); |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
273 end |
27f76695f43b
Initial mod_muc: XEP-0045: Multi-User Chat
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
274 end); |