Software /
code /
prosody
Annotate
plugins/mod_roster.lua @ 132:9a4aa57af367
Roster updates
- Added support for item.ask attribute in rostermanager and mod_roster
- Updated roster docs
- Removed old code from rostermanager
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 20:02:30 +0500 |
parent | 114:bed2a8508cf5 |
child | 177:606c433955e7 |
rev | line source |
---|---|
30 | 1 |
2 local st = require "util.stanza" | |
3 local send = require "core.sessionmanager".send_to_session | |
4 | |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
5 local jid_split = require "util.jid".split; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
6 local t_concat = table.concat; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
7 |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
8 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; |
110 | 9 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
|
10 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
|
11 |
30 | 12 add_iq_handler("c2s", "jabber:iq:roster", |
13 function (session, stanza) | |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
14 if stanza.tags[1].name == "query" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
15 if stanza.attr.type == "get" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
16 local roster = st.reply(stanza) |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
17 :query("jabber:iq:roster"); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
18 for jid in pairs(session.roster) do |
110 | 19 roster:tag("item", { |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
20 jid = jid, |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
21 subscription = session.roster[jid].subscription, |
132 | 22 ask = session.roster[jid].ask, |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
23 name = session.roster[jid].name, |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
24 }); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
25 for group in pairs(session.roster[jid].groups) do |
110 | 26 roster:tag("group"):text(group):up(); |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
27 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
|
28 end |
108
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
29 send(session, roster); |
114
bed2a8508cf5
Added session property for interested resources
Waqas Hussain <waqas20@gmail.com>
parents:
110
diff
changeset
|
30 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
|
31 return true; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
32 elseif stanza.attr.type == "set" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
33 local query = stanza.tags[1]; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
34 if #query.tags == 1 and query.tags[1].name == "item" |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
35 and query.tags[1].attr.xmlns == "jabber:iq:roster" and query.tags[1].attr.jid then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
36 local item = query.tags[1]; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
37 local from_node, from_host = jid_split(stanza.attr.from); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
38 local node, host, resource = jid_split(item.attr.jid); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
39 if not resource then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
40 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
|
41 if item.attr.subscription == "remove" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
42 if session.roster[item.attr.jid] then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
43 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
|
44 if success then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
45 send(session, st.reply(stanza)); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
46 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
|
47 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
48 send(session, st.error_reply(stanza, err_type, err_cond, err_msg)); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
49 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
50 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
51 send(session, st.error_reply(stanza, "modify", "item-not-found")); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
52 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
53 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
54 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
|
55 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
|
56 if session.roster[item.attr.jid] then |
110 | 57 r_item.subscription = session.roster[item.attr.jid].subscription; |
132 | 58 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
|
59 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
60 r_item.subscription = "none"; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
61 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
62 for _, child in ipairs(item) do |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
63 if child.name == "group" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
64 local text = t_concat(child); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
65 if text and text ~= "" then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
66 r_item.groups[text] = true; |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
67 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
68 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
69 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
70 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
|
71 if success then |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
72 send(session, st.reply(stanza)); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
73 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
|
74 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
75 send(session, st.error_reply(stanza, err_type, err_cond, err_msg)); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
76 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
77 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
78 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
79 send(session, st.error_reply(stanza, "cancel", "not-allowed")); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
80 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
81 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
82 send(session, st.error_reply(stanza, "modify", "bad-request")); -- FIXME what's the correct error? |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
83 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
84 else |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
85 send(session, st.error_reply(stanza, "modify", "bad-request")); |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
86 end |
1d79da482c5d
Added: More complete implementation for mod_roster
Waqas Hussain <waqas20@gmail.com>
parents:
102
diff
changeset
|
87 return true; |
30 | 88 end |
89 end | |
90 end); |