Software /
code /
prosody
Annotate
core/rostermanager.lua @ 1897:6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 04 Oct 2009 21:25:59 +0500 |
parent | 1523:841d61be198f |
child | 1898:1ce02e2f5a3f |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1380
diff
changeset
|
1 -- Prosody IM |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
268
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
268
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
268
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
268
diff
changeset
|
9 |
0 | 10 |
263
75275b6b4e03
Update rostermanager to use new logger
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
11 |
75275b6b4e03
Update rostermanager to use new logger
Matthew Wild <mwild1@gmail.com>
parents:
193
diff
changeset
|
12 local log = require "util.logger".init("rostermanager"); |
0 | 13 |
14 local setmetatable = setmetatable; | |
15 local format = string.format; | |
16 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; | |
110 | 17 local pairs, ipairs = pairs, ipairs; |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
18 local tostring = tostring; |
0 | 19 |
103
ebdb7875443e
Fixed: Typos caused by lack of sleep.
Waqas Hussain <waqas20@gmail.com>
parents:
101
diff
changeset
|
20 local hosts = hosts; |
ebdb7875443e
Fixed: Typos caused by lack of sleep.
Waqas Hussain <waqas20@gmail.com>
parents:
101
diff
changeset
|
21 |
183 | 22 local datamanager = require "util.datamanager" |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
23 local st = require "util.stanza"; |
0 | 24 |
25 module "rostermanager" | |
26 | |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
27 function add_to_roster(session, jid, item) |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
28 if session.roster then |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
29 local old_item = session.roster[jid]; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
30 session.roster[jid] = item; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
31 if save_roster(session.username, session.host) then |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
32 return true; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
33 else |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
34 session.roster[jid] = old_item; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
35 return nil, "wait", "internal-server-error", "Unable to save roster"; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
36 end |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
37 else |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
38 return nil, "auth", "not-authorized", "Session's roster not loaded"; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
39 end |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
40 end |
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
41 |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
42 function remove_from_roster(session, jid) |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
43 if session.roster then |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
44 local old_item = session.roster[jid]; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
45 session.roster[jid] = nil; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
46 if save_roster(session.username, session.host) then |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
47 return true; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
48 else |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
49 session.roster[jid] = old_item; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
50 return nil, "wait", "internal-server-error", "Unable to save roster"; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
51 end |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
52 else |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
53 return nil, "auth", "not-authorized", "Session's roster not loaded"; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
54 end |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
55 end |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
56 |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
57 function roster_push(username, host, jid) |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
58 local roster = jid and jid ~= "pending" and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster; |
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
59 if roster then |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
60 local item = hosts[host].sessions[username].roster[jid]; |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
61 local stanza = st.iq({type="set"}); |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
62 stanza:tag("query", {xmlns = "jabber:iq:roster", ver = tostring(roster[false].version or "1") }); |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
63 if item then |
132 | 64 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask}); |
110 | 65 for group in pairs(item.groups) do |
66 stanza:tag("group"):text(group):up(); | |
67 end | |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
68 else |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
69 stanza:tag("item", {jid = jid, subscription = "remove"}); |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
70 end |
193 | 71 stanza:up(); -- move out from item |
72 stanza:up(); -- move out from stanza | |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
73 -- stanza ready |
110 | 74 for _, session in pairs(hosts[host].sessions[username].sessions) do |
114
bed2a8508cf5
Added session property for interested resources
Waqas Hussain <waqas20@gmail.com>
parents:
110
diff
changeset
|
75 if session.interested then |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
76 -- FIXME do we need to set stanza.attr.to? |
110 | 77 session.send(stanza); |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
78 end |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
79 end |
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
80 end |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
81 end |
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
82 |
103
ebdb7875443e
Fixed: Typos caused by lack of sleep.
Waqas Hussain <waqas20@gmail.com>
parents:
101
diff
changeset
|
83 function load_roster(username, host) |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
84 log("debug", "load_roster: asked for: "..username.."@"..host); |
1380
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
85 local roster; |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
86 if hosts[host] and hosts[host].sessions[username] then |
1380
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
87 roster = hosts[host].sessions[username].roster; |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
88 if not roster then |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
89 log("debug", "load_roster: loading for new user: "..username.."@"..host); |
103
ebdb7875443e
Fixed: Typos caused by lack of sleep.
Waqas Hussain <waqas20@gmail.com>
parents:
101
diff
changeset
|
90 roster = datamanager.load(username, host, "roster") or {}; |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
91 if not roster[false] then roster[false] = { }; end |
103
ebdb7875443e
Fixed: Typos caused by lack of sleep.
Waqas Hussain <waqas20@gmail.com>
parents:
101
diff
changeset
|
92 hosts[host].sessions[username].roster = roster; |
1380
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
93 hosts[host].events.fire_event("roster-load", username, host, roster); |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
94 end |
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
95 return roster; |
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
96 end |
1380
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
97 |
107
8d8debda3df2
Added: Roster manipulation functions to core.rostermanager
Waqas Hussain <waqas20@gmail.com>
parents:
103
diff
changeset
|
98 -- Attempt to load roster for non-loaded user |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
99 log("debug", "load_roster: loading for offline user: "..username.."@"..host); |
1380
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
100 roster = datamanager.load(username, host, "roster") or {}; |
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
101 hosts[host].events.fire_event("roster-load", username, host, roster); |
9b3b43b8963a
rostermanager: Fire event on roster load
Matthew Wild <mwild1@gmail.com>
parents:
925
diff
changeset
|
102 return roster; |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
103 end |
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
104 |
1897
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
105 function save_roster(username, host, roster) |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
106 log("debug", "save_roster: saving roster for "..username.."@"..host); |
1897
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
107 if not roster then |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
108 roster = hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster; |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
109 --if not roster then |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
110 -- --roster = load_roster(username, host); |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
111 -- return true; -- roster unchanged, no reason to save |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
112 --end |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
113 end |
6d81e74310a7
rostermanager: Added support for saving rosters of offline users to the save_roster function.
Waqas Hussain <waqas20@gmail.com>
parents:
1523
diff
changeset
|
114 if roster then |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
115 local roster = hosts[host].sessions[username].roster; |
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
116 roster[false].version = (roster[false].version or 1) + 1; |
110 | 117 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
118 end |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
119 log("warn", "save_roster: user had no roster to save"); |
101
c690fa382743
Added some roster management functions
Waqas Hussain <waqas20@gmail.com>
parents:
80
diff
changeset
|
120 return nil; |
0 | 121 end |
80
523ac742cc19
Fixed: rostermanager.lua now returns the module
Waqas Hussain <waqas20@gmail.com>
parents:
6
diff
changeset
|
122 |
171
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
123 function process_inbound_subscription_approval(username, host, jid) |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
124 local roster = load_roster(username, host); |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
125 local item = roster[jid]; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
126 if item and item.ask then |
171
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
127 if item.subscription == "none" then |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
128 item.subscription = "to"; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
129 else -- subscription == from |
171
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
130 item.subscription = "both"; |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
131 end |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
132 item.ask = nil; |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
133 return datamanager.store(username, host, "roster", roster); |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
134 end |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
135 end |
28f420d057a0
Inbound subscription approval
Waqas Hussain <waqas20@gmail.com>
parents:
132
diff
changeset
|
136 |
172
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
137 function process_inbound_subscription_cancellation(username, host, jid) |
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
138 local roster = load_roster(username, host); |
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
139 local item = roster[jid]; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
140 local changed = nil; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
141 if is_contact_pending_out(username, host, jid) then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
142 item.ask = nil; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
143 changed = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
144 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
145 if item then |
172
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
146 if item.subscription == "to" then |
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
147 item.subscription = "none"; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
148 changed = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
149 elseif item.subscription == "both" then |
172
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
150 item.subscription = "from"; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
151 changed = true; |
172
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
152 end |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
153 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
154 if changed then |
172
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
155 return datamanager.store(username, host, "roster", roster); |
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
156 end |
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
157 end |
71247788c7c7
Inbound subscription cancellation
Waqas Hussain <waqas20@gmail.com>
parents:
171
diff
changeset
|
158 |
173 | 159 function process_inbound_unsubscribe(username, host, jid) |
160 local roster = load_roster(username, host); | |
161 local item = roster[jid]; | |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
162 local changed = nil; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
163 if is_contact_pending_in(username, host, jid) then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
164 roster.pending[jid] = nil; -- TODO maybe delete roster.pending if empty? |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
165 changed = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
166 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
167 if item then |
173 | 168 if item.subscription == "from" then |
169 item.subscription = "none"; | |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
170 changed = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
171 elseif item.subscription == "both" then |
173 | 172 item.subscription = "to"; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
173 changed = true; |
173 | 174 end |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
175 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
176 if changed then |
173 | 177 return datamanager.store(username, host, "roster", roster); |
178 end | |
179 end | |
180 | |
174
f9aff1fc7e99
Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
173
diff
changeset
|
181 function is_contact_subscribed(username, host, jid) |
f9aff1fc7e99
Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
173
diff
changeset
|
182 local roster = load_roster(username, host); |
f9aff1fc7e99
Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
173
diff
changeset
|
183 local item = roster[jid]; |
f9aff1fc7e99
Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
173
diff
changeset
|
184 return item and (item.subscription == "from" or item.subscription == "both"); |
f9aff1fc7e99
Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
173
diff
changeset
|
185 end |
f9aff1fc7e99
Inbound subscription request
Waqas Hussain <waqas20@gmail.com>
parents:
173
diff
changeset
|
186 |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
187 function is_contact_pending_in(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
188 local roster = load_roster(username, host); |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
189 return roster.pending and roster.pending[jid]; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
190 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
191 function set_contact_pending_in(username, host, jid, pending) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
192 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
193 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
194 if item and (item.subscription == "from" or item.subscription == "both") then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
195 return; -- false |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
196 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
197 if not roster.pending then roster.pending = {}; end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
198 roster.pending[jid] = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
199 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
200 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
201 function is_contact_pending_out(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
202 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
203 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
204 return item and item.ask; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
205 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
206 function set_contact_pending_out(username, host, jid) -- subscribe |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
207 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
208 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
209 if item and (item.ask or item.subscription == "to" or item.subscription == "both") then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
210 return true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
211 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
212 if not item then |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
213 item = {subscription = "none", groups = {}}; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
214 roster[jid] = item; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
215 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
216 item.ask = "subscribe"; |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
217 log("debug", "set_contact_pending_out: saving roster; set "..username.."@"..host..".roster["..jid.."].ask=subscribe"); |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
218 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
219 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
220 function unsubscribe(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
221 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
222 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
223 if not item then return false; end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
224 if (item.subscription == "from" or item.subscription == "none") and not item.ask then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
225 return true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
226 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
227 item.ask = nil; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
228 if item.subscription == "both" then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
229 item.subscription = "from"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
230 elseif item.subscription == "to" then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
231 item.subscription = "none"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
232 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
233 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
234 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
235 function subscribed(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
236 if is_contact_pending_in(username, host, jid) then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
237 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
238 local item = roster[jid]; |
925
4861bcf0afa4
Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents:
916
diff
changeset
|
239 if not item then -- FIXME should roster item be auto-created? |
4861bcf0afa4
Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents:
916
diff
changeset
|
240 item = {subscription = "none", groups = {}}; |
4861bcf0afa4
Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents:
916
diff
changeset
|
241 roster[jid] = item; |
4861bcf0afa4
Fixed: rostermanager: Create new roster item if one doesn't exist on subscription approval (fixes issue #77)
Waqas Hussain <waqas20@gmail.com>
parents:
916
diff
changeset
|
242 end |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
243 if item.subscription == "none" then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
244 item.subscription = "from"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
245 else -- subscription == to |
177
606c433955e7
Bug fixes and checks for presence subscriptions, etc
Waqas Hussain <waqas20@gmail.com>
parents:
176
diff
changeset
|
246 item.subscription = "both"; |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
247 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
248 roster.pending[jid] = nil; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
249 -- TODO maybe remove roster.pending if empty |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
250 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
251 end -- TODO else implement optional feature pre-approval (ask = subscribed) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
252 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
253 function unsubscribed(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
254 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
255 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
256 local pending = is_contact_pending_in(username, host, jid); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
257 local changed = nil; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
258 if is_contact_pending_in(username, host, jid) then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
259 roster.pending[jid] = nil; -- TODO maybe delete roster.pending if empty? |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
260 changed = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
261 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
262 if item then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
263 if item.subscription == "from" then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
264 item.subscription = "none"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
265 changed = true; |
267 | 266 elseif item.subscription == "both" then |
176
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
267 item.subscription = "to"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
268 changed = true; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
269 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
270 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
271 if changed then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
272 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
273 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
274 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
275 |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
276 function process_outbound_subscription_request(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
277 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
278 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
279 if item and (item.subscription == "none" or item.subscription == "from") then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
280 item.ask = "subscribe"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
281 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
282 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
283 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
284 |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
285 --[[function process_outbound_subscription_approval(username, host, jid) |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
286 local roster = load_roster(username, host); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
287 local item = roster[jid]; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
288 if item and (item.subscription == "none" or item.subscription == "from" then |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
289 item.ask = "subscribe"; |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
290 return datamanager.store(username, host, "roster", roster); |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
291 end |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
292 end]] |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
293 |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
294 |
e5cd2a03891d
Outbound presence subscription
Waqas Hussain <waqas20@gmail.com>
parents:
174
diff
changeset
|
295 |
916
f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
296 return _M; |