Software /
code /
prosody
Annotate
plugins/mod_roster.lua @ 560:6c07f15a34f4
Fix the last couple of places where we send strings from mod_dialback
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 05 Dec 2008 05:28:16 +0000 |
parent | 541:3521e0851c9e |
child | 609:64849cfa9869 |
rev | line source |
---|---|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
1 -- Prosody IM v0.1 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
2 -- Copyright (C) 2008 Matthew Wild |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
3 -- Copyright (C) 2008 Waqas Hussain |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
4 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
5 -- This program is free software; you can redistribute it and/or |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
6 -- modify it under the terms of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- as published by the Free Software Foundation; either version 2 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 -- of the License, or (at your option) any later version. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
10 -- This program is distributed in the hope that it will be useful, |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
13 -- GNU General Public License for more details. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
14 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
15 -- You should have received a copy of the GNU General Public License |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
16 -- along with this program; if not, write to the Free Software |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
18 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
19 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
20 |
30 | 21 |
22 local st = require "util.stanza" | |
23 | |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
24 local jid_split = require "util.jid".split; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
25 local t_concat = table.concat; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
26 |
326
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
27 local handle_outbound_presence_subscriptions_and_probes = require "core.presencemanager".handle_outbound_presence_subscriptions_and_probes; |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
28 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; |
110 | 29 local rm_add_to_roster = require "core.rostermanager".add_to_roster; |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
30 local rm_roster_push = require "core.rostermanager".roster_push; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
31 |
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
32 module:add_feature("jabber:iq:roster"); |
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
326
diff
changeset
|
33 |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
34 module:add_iq_handler("c2s", "jabber:iq:roster", |
30 | 35 function (session, stanza) |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
36 if stanza.tags[1].name == "query" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
37 if stanza.attr.type == "get" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
38 local roster = st.reply(stanza) |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
39 :query("jabber:iq:roster"); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
40 for jid in pairs(session.roster) do |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
41 if jid ~= "pending" then |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
42 roster:tag("item", { |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
43 jid = jid, |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
44 subscription = session.roster[jid].subscription, |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
45 ask = session.roster[jid].ask, |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
46 name = session.roster[jid].name, |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
47 }); |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
48 for group in pairs(session.roster[jid].groups) do |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
49 roster:tag("group"):text(group):up(); |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
50 end |
193 | 51 roster:up(); -- move out from item |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
52 end |
102
a5b914370db5
Fixed: mod_roster now outputs all roster data (instead of just the JIDs)
Waqas Hussain <waqas20@gmail.com>
parents:
79
diff
changeset
|
53 end |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
54 session.send(roster); |
114
bed2a8508cf5
Added session property for interested resources
Waqas Hussain <waqas20@gmail.com>
parents:
110
diff
changeset
|
55 session.interested = true; -- resource is interested in roster updates |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
56 return true; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
57 elseif stanza.attr.type == "set" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
58 local query = stanza.tags[1]; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
59 if #query.tags == 1 and query.tags[1].name == "item" |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
60 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid |
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
61 and query.tags[1].attr.jid ~= "pending" then |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
62 local item = query.tags[1]; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
63 local from_node, from_host = jid_split(stanza.attr.from); |
326
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
64 local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
65 local node, host, resource = jid_split(item.attr.jid); |
326
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
66 local to_bare = node and (node.."@"..host) or host; -- bare JID |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
67 if not resource and host then |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
68 if item.attr.jid ~= from_node.."@"..from_host then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
69 if item.attr.subscription == "remove" then |
326
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
70 local r_item = session.roster[item.attr.jid]; |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
71 if r_item then |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
72 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, item.attr.jid); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
73 if success then |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
74 session.send(st.reply(stanza)); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
75 rm_roster_push(from_node, from_host, item.attr.jid); |
326
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
76 if r_item.subscription == "both" or r_item.subscription == "from" then |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
77 handle_outbound_presence_subscriptions_and_probes(session, |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
78 st.presence({type="unsubscribed"}), from_bare, to_bare); |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
79 elseif r_item.subscription == "both" or r_item.subscription == "to" then |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
80 handle_outbound_presence_subscriptions_and_probes(session, |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
81 st.presence({type="unsubscribe"}), from_bare, to_bare); |
99a8317d1235
Send unsubscribe and unsubscribed on roster item delete, and broadcast available resources' presence in reply to pre-approved subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
299
diff
changeset
|
82 end |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
83 else |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
84 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
85 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
86 else |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
87 session.send(st.error_reply(stanza, "modify", "item-not-found")); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
88 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
89 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
90 local r_item = {name = item.attr.name, groups = {}}; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
91 if r_item.name == "" then r_item.name = nil; end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
92 if session.roster[item.attr.jid] then |
110 | 93 r_item.subscription = session.roster[item.attr.jid].subscription; |
132 | 94 r_item.ask = session.roster[item.attr.jid].ask; |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
95 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
96 r_item.subscription = "none"; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
97 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
98 for _, child in ipairs(item) do |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
99 if child.name == "group" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
100 local text = t_concat(child); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
101 if text and text ~= "" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
102 r_item.groups[text] = true; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
103 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
104 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
105 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
106 local success, err_type, err_cond, err_msg = rm_add_to_roster(session, item.attr.jid, r_item); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
107 if success then |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
108 session.send(st.reply(stanza)); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
109 rm_roster_push(from_node, from_host, item.attr.jid); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
110 else |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
111 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
112 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
113 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
114 else |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
115 session.send(st.error_reply(stanza, "cancel", "not-allowed")); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
116 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
117 else |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
118 session.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME what's the correct error? |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
119 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
120 else |
299
300b5a201ad3
Fix mod_roster to use session.send for sending stanzas
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
121 session.send(st.error_reply(stanza, "modify", "bad-request")); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
122 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
123 return true; |
30 | 124 end |
125 end | |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
126 end); |