Annotate

plugins/mod_muc.lua @ 756:2ca5fa47f317

mod_muc: Convert to unix line endings
author Matthew Wild <mwild1@gmail.com>
date Thu, 29 Jan 2009 20:46:34 +0000
parent 752:a9642c1d5827
child 757:f77843f31c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
10
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
11 if module:get_host_type() ~= "component" then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
12 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
13 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
14
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
15 local muc_domain = module:get_host();
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
16
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
17 local muc_name = "MUCMUCMUC!!!";
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
18
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
19 -- room_name -> room
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
20 -- occupant_room_nick -> data
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
21 -- affiliation = ...
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
22 -- role
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
23 -- jid = occupant's real jid
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
24 local rooms = multitable_new();
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
25
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
26 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
27
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
28 -- room_name -> info
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
29 -- name - the room's friendly name
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
30 -- subject - the room's subject
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
31 -- non-anonymous = true|nil
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
32 -- persistent = true|nil
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
33 local rooms_info = multitable_new();
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
34
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
35 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
36 for room in pairs(persist_list) do
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
37 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
38 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
39
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
40 local component;
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 function getUsingPath(stanza, path, getText)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
43 local tag = stanza;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
44 for _, name in ipairs(path) do
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
45 if type(tag) ~= 'table' then return; end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
46 tag = tag:child_with_name(name);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
47 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
48 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
49 return tag;
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 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
52 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
53
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
54 function get_disco_info(stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
55 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
56 :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
57 :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
58 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
59 function get_disco_items(stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
60 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
61 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
62 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
63 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
64 return reply; -- TODO cache disco reply
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 function get_room_disco_info(stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
67 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
68 :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
69 :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
70 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
71 function get_room_disco_items(stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
72 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
73 end -- TODO allow non-private rooms
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
74
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
75 function save_room(room)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
76 local persistent = rooms_info:get(room, 'persistent');
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
77 if persistent then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
78 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
79 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
80 if persistent ~= persist_list[room] then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
81 if not persistent then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
82 datamanager.store(room, muc_domain, 'rooms', nil);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
83 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
84 persist_list[room] = persistent;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
85 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
86 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
87 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
88
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
89 function set_subject(current_nick, room, subject)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
90 -- TODO check nick's authority
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
91 if subject == "" then subject = nil; end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
92 rooms_info:set(room, 'subject', subject);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
93 save_room();
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
94 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
95 return true;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
96 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
97
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
98 function broadcast_presence(type, from, room, code)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
99 local data = rooms:get(room, from);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
100 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
101 :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
102 :tag("item", {affiliation=data.affiliation, role=data.role}):up();
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
103 if code then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
104 stanza:tag("status", {code=code}):up();
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
105 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
106 local me;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
107 local r = rooms:get(room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
108 if r then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
109 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
110 if occupant ~= from then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
111 stanza.attr.to = o_data.jid;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
112 core_route_stanza(component, stanza);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
113 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
114 me = o_data.jid;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
115 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
116 end
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 if me then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
119 stanza:tag("status", {code='110'});
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
120 stanza.attr.to = me;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
121 core_route_stanza(component, stanza);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
122 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
123 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
124 function broadcast_message(from, room, subject, body)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
125 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
126 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
127 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
128 local r = rooms:get(room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
129 if r then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
130 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
131 stanza.attr.to = o_data.jid;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
132 core_route_stanza(component, stanza);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
133 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
134 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
135 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
136
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
137 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
138 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
139 local room = jid_bare(to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
140 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
141 local type = stanza.attr.type;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
142 if stanza.name == "presence" then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
143 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
144 local data = rooms:get(room, to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
145 data.role = 'none';
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
146 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
147 rooms:remove(room, to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
148 jid_nick:remove(from, room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
149 elseif type == "unavailable" then -- unavailable
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
150 if current_nick == to then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
151 local data = rooms:get(room, to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
152 data.role = 'none';
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
153 broadcast_presence('unavailable', to, room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
154 rooms:remove(room, to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
155 jid_nick:remove(from, room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
156 end -- TODO else do nothing?
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
157 elseif not type then -- available
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
158 if current_nick then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
159 if current_nick == to then -- simple presence
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
160 -- TODO broadcast
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
161 else -- change nick
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
162 if rooms:get(room, to) then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
163 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
164 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
165 local data = rooms:get(room, current_nick);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
166 broadcast_presence('unavailable', current_nick, room, '303');
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
167 rooms:remove(room, current_nick);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
168 rooms:set(room, to, data);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
169 jid_nick:set(from, room, to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
170 broadcast_presence(nil, to, room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
171 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
172 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
173 else -- enter room
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
174 if rooms:get(room, to) then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
175 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
176 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
177 local data;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
178 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
179 data = {affiliation='owner', role='moderator', jid=from};
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
180 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
181 if not data then -- new occupant
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
182 data = {affiliation='none', role='participant', jid=from};
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
183 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
184 rooms:set(room, to, data);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
185 jid_nick:set(from, room, to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
186 local r = rooms:get(room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
187 if r then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
188 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
189 if occupant ~= from then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
190 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
191 :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
192 :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
193 core_route_stanza(component, pres);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
194 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
195 end
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 broadcast_presence(nil, to, room);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
198 -- TODO send discussion history
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
199 if rooms_info:get(room, 'subject') then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
200 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
201 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
202 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
203 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
204 elseif type ~= 'result' then -- bad type
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
205 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
206 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
207 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
208 -- groupchat messages not allowed in PM
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
209 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
210 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
211 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
212 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
213 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
214
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
215 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
216 local type = stanza.attr.type;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
217 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
218 local xmlns = stanza.tags[1].attr.xmlns;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
219 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
220 origin.send(get_room_disco_info(stanza));
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
221 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
222 origin.send(get_room_disco_items(stanza));
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
223 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
224 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
225 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
226 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
227 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
228 local room = jid_bare(to);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
229 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
230 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
231 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
232 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
233 local subject = getText(stanza, {"subject"});
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
234 if subject then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
235 set_subject(current_nick, room, subject);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
236 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
237 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
238 -- TODO add to discussion history
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
239 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
240 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
241 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
242 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
243 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
244 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
245 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
246
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
247 function handle_to_domain(origin, stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
248 local type = stanza.attr.type;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
249 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
250 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
251 local xmlns = stanza.tags[1].attr.xmlns;
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
252 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
253 origin.send(get_disco_info(stanza));
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
254 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
255 origin.send(get_disco_items(stanza));
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
256 else
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
257 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
258 end
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 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
261 end
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
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
264 function handle_stanza(origin, stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
265 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
266 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
267 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
268 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
269 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
270 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
271 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
272 elseif to_resource then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
273 handle_to_occupant(origin, stanza);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
274 elseif to_node then
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
275 handle_to_room(origin, stanza)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
276 else -- to the main muc domain
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
277 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
278 handle_to_domain(origin, stanza);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
279 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
280 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
281
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
282 module.load_component = function()
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
283 return handle_stanza; -- Return the function that we want to handle incoming stanzas
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
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
286 module.unload = function()
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
287 deregister_component(muc_domain);
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
288 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
289 module.save = function()
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
290 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
291 end
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
292 module.restore = function(data)
2ca5fa47f317 mod_muc: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents: 752
diff changeset
293 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
294 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
295 end