Software /
code /
prosody
Annotate
plugins/mod_muc.lua @ 1500:56d05ba00169
prosodyctl: Don't 'blugh' when ^C is pressed during reading passwords
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 08 Jul 2009 16:48:49 +0100 |
parent | 1398:141fec125af0 |
child | 1522:569d58d21612 |
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 if module:get_host_type() ~= "component" then |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
3 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
|
4 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
5 |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
6 local muc_host = module:get_host(); |
1060
fb3b2de0eb2f
mod_muc: The default component name is now 'Chatrooms'
Waqas Hussain <waqas20@gmail.com>
parents:
1059
diff
changeset
|
7 local muc_name = "Chatrooms"; |
782 | 8 local history_length = 20; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
9 |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
10 local muc_new_room = require "util.muc".new_room; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
11 local register_component = require "core.componentmanager".register_component; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
12 local deregister_component = require "core.componentmanager".deregister_component; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
13 local jid_split = require "util.jid".split; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
14 local st = require "util.stanza"; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
15 |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
16 local rooms = {}; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
17 local component; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
18 local host_room = muc_new_room(muc_host); |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
19 host_room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
20 |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
21 local function get_disco_info(stanza) |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
22 return st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#info") |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
23 :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
|
24 :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
|
25 end |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
26 local function get_disco_items(stanza) |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
27 local reply = st.iq({type='result', id=stanza.attr.id, from=muc_host, to=stanza.attr.from}):query("http://jabber.org/protocol/disco#items"); |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
28 for jid, room in pairs(rooms) do |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
29 reply:tag("item", {jid=jid, name=jid}):up(); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
30 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
31 return reply; -- TODO cache disco reply |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
32 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
33 |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
34 local function handle_to_domain(origin, stanza) |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
35 local type = stanza.attr.type; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
36 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
|
37 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
|
38 local xmlns = stanza.tags[1].attr.xmlns; |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
39 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
|
40 origin.send(get_disco_info(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
41 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
|
42 origin.send(get_disco_items(stanza)); |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
43 else |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
44 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
|
45 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
46 else |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
47 host_room:handle_stanza(origin, stanza); |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
48 --origin.send(st.error_reply(stanza, "cancel", "service-unavailable", "The muc server doesn't deal with messages and presence directed at it")); |
756
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 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
51 |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
52 component = register_component(muc_host, function(origin, stanza) |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
53 local to_node, to_host, to_resource = jid_split(stanza.attr.to); |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
54 if to_node then |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
55 local bare = to_node.."@"..to_host; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
56 if to_host == muc_host or bare == muc_host then |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
57 local room = rooms[bare]; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
58 if not room then |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
59 room = muc_new_room(bare); |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
60 room.route_stanza = function(room, stanza) core_post_stanza(component, stanza); end; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
61 rooms[bare] = room; |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
62 end |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
63 room:handle_stanza(origin, stanza); |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
64 else --[[not for us?]] end |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
65 return; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
66 end |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
67 -- to the main muc domain |
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
68 handle_to_domain(origin, stanza); |
779
ec0eadf4e9ff
Changed mod_muc to work with changed component manager
Waqas Hussain <waqas20@gmail.com>
parents:
757
diff
changeset
|
69 end); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
70 |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
71 module.unload = function() |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
72 deregister_component(muc_host); |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
73 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
74 module.save = function() |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
75 return {rooms = rooms}; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
76 end |
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
77 module.restore = function(data) |
1398
141fec125af0
mod_muc: Now based on util.muc
Waqas Hussain <waqas20@gmail.com>
parents:
1352
diff
changeset
|
78 rooms = data.rooms or {}; |
756
2ca5fa47f317
mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
752
diff
changeset
|
79 end |