Software /
code /
prosody
Annotate
plugins/mod_presence.lua @ 10800:62794e065e33
MAM: Remove 1% of contents when reaching limits, fix #1545
With mod\_storage\_internal this counts out to 100 messages out of 10 000,
meaning should not hit the quota limit immediately until that many
messages have been added again.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 05 May 2020 22:21:39 +0200 |
parent | 10694:0cda5d597607 |
child | 10813:4a9ff4f61796 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1508
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2643
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2643
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5416
diff
changeset
|
4 -- |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
6 -- COPYING file in the source package for more information. |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
7 -- |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
8 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
9 local log = module._log; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
10 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
11 local require = require; |
5416
0ba3a49d3863
mod_presence: Remove some unused variables
Matthew Wild <mwild1@gmail.com>
parents:
5370
diff
changeset
|
12 local pairs = pairs; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
13 local s_find = string.find; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
14 local tonumber = tonumber; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
15 |
5013
ab693eea0869
mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table.
Kim Alvefur <zash@zash.se>
parents:
4993
diff
changeset
|
16 local core_post_stanza = prosody.core_post_stanza; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
17 local st = require "util.stanza"; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
18 local jid_split = require "util.jid".split; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
19 local jid_bare = require "util.jid".bare; |
5297
7453245f16e7
mod_presence: Put a timestamp on presence we store for probes
Kim Alvefur <zash@zash.se>
parents:
5171
diff
changeset
|
20 local datetime = require "util.datetime"; |
5370
7838acadb0fa
mod_announce, mod_auth_anonymous, mod_c2s, mod_c2s, mod_component, mod_iq, mod_message, mod_presence, mod_tls: Access prosody.{hosts,bare_sessions,full_sessions} instead of the old globals
Kim Alvefur <zash@zash.se>
parents:
5297
diff
changeset
|
21 local hosts = prosody.hosts; |
7838acadb0fa
mod_announce, mod_auth_anonymous, mod_c2s, mod_c2s, mod_component, mod_iq, mod_message, mod_presence, mod_tls: Access prosody.{hosts,bare_sessions,full_sessions} instead of the old globals
Kim Alvefur <zash@zash.se>
parents:
5297
diff
changeset
|
22 local bare_sessions = prosody.bare_sessions; |
7838acadb0fa
mod_announce, mod_auth_anonymous, mod_c2s, mod_c2s, mod_component, mod_iq, mod_message, mod_presence, mod_tls: Access prosody.{hosts,bare_sessions,full_sessions} instead of the old globals
Kim Alvefur <zash@zash.se>
parents:
5297
diff
changeset
|
23 local full_sessions = prosody.full_sessions; |
2592
3af266f7037f
mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast.
Waqas Hussain <waqas20@gmail.com>
parents:
2532
diff
changeset
|
24 local NULL = {}; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
25 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
26 local rostermanager = require "core.rostermanager"; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
27 local sessionmanager = require "core.sessionmanager"; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
28 |
7281
21da137d83b0
mod_presence: Fix partial rename
Kim Alvefur <zash@zash.se>
parents:
7279
diff
changeset
|
29 local recalc_resource_map = require "util.presence".recalc_resource_map; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
30 |
7265
78be11bf62bf
mod_presence: Use type-specific config API for boolean 'ignore_presence_priority' option
Kim Alvefur <zash@zash.se>
parents:
6613
diff
changeset
|
31 local ignore_presence_priority = module:get_option_boolean("ignore_presence_priority", false); |
3084
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
32 |
10694
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
33 local pre_approval_stream_feature = st.stanza("sub", {xmlns="urn:xmpp:features:pre-approval"}); |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
34 module:hook("stream-features", function(event) |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
35 local origin, features = event.origin, event.features; |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
36 if origin.username then |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
37 features:add_child(pre_approval_stream_feature); |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
38 end |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
39 end); |
0cda5d597607
mod_presence: Advertise support for Subscription Pre-Approval
Kim Alvefur <zash@zash.se>
parents:
10556
diff
changeset
|
40 |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
41 function handle_normal_presence(origin, stanza) |
3084
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
42 if ignore_presence_priority then |
6302
76699a0ae4c4
mod_lastactivity, mod_legacyauth, mod_presence, mod_saslauth, mod_tls: Use the newer stanza:get_child APIs and optimize away some table lookups
Kim Alvefur <zash@zash.se>
parents:
6291
diff
changeset
|
43 local priority = stanza:get_child("priority"); |
3084
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
44 if priority and priority[1] ~= "0" then |
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
45 for i=#priority.tags,1,-1 do priority.tags[i] = nil; end |
8071
c3790ca4144f
mod_presence: No need to overwrite index 1 since it's set on the line below
Kim Alvefur <zash@zash.se>
parents:
7779
diff
changeset
|
46 for i=#priority,2,-1 do priority[i] = nil; end |
3084
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
47 priority[1] = "0"; |
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
48 end |
9b17449fb5f4
mod_presence: Added option 'ignore_presence_priority'.
Waqas Hussain <waqas20@gmail.com>
parents:
3083
diff
changeset
|
49 end |
8072
194409dcba22
mod_presence: Use get_child_text on priority child element (fixes #552)
Kim Alvefur <zash@zash.se>
parents:
8071
diff
changeset
|
50 local priority = stanza:get_child_text("priority"); |
194409dcba22
mod_presence: Use get_child_text on priority child element (fixes #552)
Kim Alvefur <zash@zash.se>
parents:
8071
diff
changeset
|
51 if priority and s_find(priority, "^[+-]?[0-9]+$") then |
194409dcba22
mod_presence: Use get_child_text on priority child element (fixes #552)
Kim Alvefur <zash@zash.se>
parents:
8071
diff
changeset
|
52 priority = tonumber(priority); |
194409dcba22
mod_presence: Use get_child_text on priority child element (fixes #552)
Kim Alvefur <zash@zash.se>
parents:
8071
diff
changeset
|
53 if priority < -128 then priority = -128 end |
194409dcba22
mod_presence: Use get_child_text on priority child element (fixes #552)
Kim Alvefur <zash@zash.se>
parents:
8071
diff
changeset
|
54 if priority > 127 then priority = 127 end |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3518
diff
changeset
|
55 else priority = 0; end |
2643
21eb99b06f4d
mod_presence: Reflect the user's own presence back to them.
Waqas Hussain <waqas20@gmail.com>
parents:
2593
diff
changeset
|
56 if full_sessions[origin.full_jid] then -- if user is still connected |
21eb99b06f4d
mod_presence: Reflect the user's own presence back to them.
Waqas Hussain <waqas20@gmail.com>
parents:
2593
diff
changeset
|
57 origin.send(stanza); -- reflect their presence back to them |
21eb99b06f4d
mod_presence: Reflect the user's own presence back to them.
Waqas Hussain <waqas20@gmail.com>
parents:
2593
diff
changeset
|
58 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
59 local roster = origin.roster; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
60 local node, host = origin.username, origin.host; |
2592
3af266f7037f
mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast.
Waqas Hussain <waqas20@gmail.com>
parents:
2532
diff
changeset
|
61 local user = bare_sessions[node.."@"..host]; |
3af266f7037f
mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast.
Waqas Hussain <waqas20@gmail.com>
parents:
2532
diff
changeset
|
62 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
63 if res ~= origin and res.presence then -- to resource |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
64 stanza.attr.to = res.full_jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
65 core_post_stanza(origin, stanza, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
66 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
67 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
68 for jid, item in pairs(roster) do -- broadcast to all interested contacts |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
69 if item.subscription == "both" or item.subscription == "from" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
70 stanza.attr.to = jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
71 core_post_stanza(origin, stanza, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
72 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
73 end |
9788
f47b2ab877d0
mod_presence: Revert empty 'to' attribute of presence before presence/initial event (fixes #1296)
Kim Alvefur <zash@zash.se>
parents:
8728
diff
changeset
|
74 stanza.attr.to = nil; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
75 if stanza.attr.type == nil and not origin.presence then -- initial presence |
6291
7a604381d6fc
mod_presence: Move presence/initial event to correct place so it actually fires
Kim Alvefur <zash@zash.se>
parents:
6281
diff
changeset
|
76 module:fire_event("presence/initial", { origin = origin, stanza = stanza } ); |
2532
b1b1b4a7db26
mod_presence: Quick fix to make probes from local users to local hosts work.
Waqas Hussain <waqas20@gmail.com>
parents:
2531
diff
changeset
|
77 origin.presence = stanza; -- FIXME repeated later |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
78 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
79 for jid, item in pairs(roster) do -- probe all contacts we are subscribed to |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
80 if item.subscription == "both" or item.subscription == "to" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
81 probe.attr.to = jid; |
3183
28a5c0bda928
mod_presence: Enable firing of pre-events for probes.
Waqas Hussain <waqas20@gmail.com>
parents:
3182
diff
changeset
|
82 core_post_stanza(origin, probe, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
83 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
84 end |
2592
3af266f7037f
mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast.
Waqas Hussain <waqas20@gmail.com>
parents:
2532
diff
changeset
|
85 for _, res in pairs(user and user.sessions or NULL) do -- broadcast from all available resources |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
86 if res ~= origin and res.presence then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
87 res.presence.attr.to = origin.full_jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
88 core_post_stanza(res, res.presence, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
89 res.presence.attr.to = nil; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
90 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
91 end |
9671
e50559a42dfe
rostermanager, mod_presence: Store stanza for incoming subscription requests (fixes #689) (thanks Zash, Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents:
8728
diff
changeset
|
92 for jid, pending_request in pairs(roster[false].pending) do -- resend incoming subscription requests |
9677
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
93 if type(pending_request) == "table" then |
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
94 local subscribe = st.deserialize(pending_request); |
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
95 subscribe.attr.type, subscribe.attr.from = "subscribe", jid; |
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
96 origin.send(subscribe); |
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
97 else |
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
98 origin.send(st.presence({type="subscribe", from=jid})); |
d0cc1c4e1a1c
mod_presence: Handle older boolean subscription request data (thanks Martin)
Kim Alvefur <zash@zash.se>
parents:
9676
diff
changeset
|
99 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
100 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
101 local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host}); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
102 for jid, item in pairs(roster) do -- resend outgoing subscription requests |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
103 if item.ask then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
104 request.attr.to = jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
105 core_post_stanza(origin, request, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
106 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
107 end |
3518
d3399d1b484a
Don't send offline messages to resource with negative priorities
Robert Hoelz <rob@hoelz.ro>
parents:
3235
diff
changeset
|
108 |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3518
diff
changeset
|
109 if priority >= 0 then |
5171 | 110 local event = { origin = origin } |
111 module:fire_event('message/offline/broadcast', event); | |
3540
bc139431830b
Monster whitespace commit (beware the whitespace monster).
Waqas Hussain <waqas20@gmail.com>
parents:
3518
diff
changeset
|
112 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
113 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
114 if stanza.attr.type == "unavailable" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
115 origin.presence = nil; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
116 if origin.priority then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
117 origin.priority = nil; |
2593
06995c8bfe80
mod_presence: Don't depend on user being online when calculating top resources.
Waqas Hussain <waqas20@gmail.com>
parents:
2592
diff
changeset
|
118 recalc_resource_map(user); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
119 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
120 if origin.directed then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
121 for jid in pairs(origin.directed) do |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
122 stanza.attr.to = jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
123 core_post_stanza(origin, stanza, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
124 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
125 origin.directed = nil; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
126 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
127 else |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
128 origin.presence = stanza; |
5297
7453245f16e7
mod_presence: Put a timestamp on presence we store for probes
Kim Alvefur <zash@zash.se>
parents:
5171
diff
changeset
|
129 stanza:tag("delay", { xmlns = "urn:xmpp:delay", from = host, stamp = datetime.datetime() }):up(); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
130 if origin.priority ~= priority then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
131 origin.priority = priority; |
2593
06995c8bfe80
mod_presence: Don't depend on user being online when calculating top resources.
Waqas Hussain <waqas20@gmail.com>
parents:
2592
diff
changeset
|
132 recalc_resource_map(user); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
133 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
134 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
135 stanza.attr.to = nil; -- reset it |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
136 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
137 |
8579
801ae5cb1341
mod_presence: Ignore unused argument but make note of its use elsewhere [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8574
diff
changeset
|
138 -- luacheck: ignore 212/recipient_session |
801ae5cb1341
mod_presence: Ignore unused argument but make note of its use elsewhere [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8574
diff
changeset
|
139 -- TODO This argument is used in 3rd party modules |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
140 function send_presence_of_available_resources(user, host, jid, recipient_session, stanza) |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
141 local h = hosts[host]; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
142 local count = 0; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
143 if h and h.type == "local" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
144 local u = h.sessions[user]; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
145 if u then |
7470
893378a1c03e
mod_presence: remove unused one-letter loop variable [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7433
diff
changeset
|
146 for _, session in pairs(u.sessions) do |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
147 local pres = session.presence; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
148 if pres then |
2038
4ab83f96585a
mod_presence: Send unavailable presence when sending unsubscribed presence stanzas (some legacy clients continue to display unsubscribed contacts as available).
Waqas Hussain <waqas20@gmail.com>
parents:
1731
diff
changeset
|
149 if stanza then pres = stanza; pres.attr.from = session.full_jid; end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
150 pres.attr.to = jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
151 core_post_stanza(session, pres, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
152 pres.attr.to = nil; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
153 count = count + 1; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
154 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
155 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
156 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
157 end |
4993
5243b74a4cbb
Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents:
4967
diff
changeset
|
158 log("debug", "broadcasted presence of %d resources from %s@%s to %s", count, user, host, jid); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
159 return count; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
160 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
161 |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
162 function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
163 local node, host = jid_split(from_bare); |
3235
651139e831b1
mod_presence: Fixed a traceback on outgoing subscriptions from offline users.
Waqas Hussain <waqas20@gmail.com>
parents:
3215
diff
changeset
|
164 if to_bare == from_bare then return; end -- No self contacts |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
165 local st_from, st_to = stanza.attr.from, stanza.attr.to; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
166 stanza.attr.from, stanza.attr.to = from_bare, to_bare; |
4993
5243b74a4cbb
Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents:
4967
diff
changeset
|
167 log("debug", "outbound presence %s from %s for %s", stanza.attr.type, from_bare, to_bare); |
3182
a19dbb6446a0
mod_presence: Don't stop pre-event for outgoing probes.
Waqas Hussain <waqas20@gmail.com>
parents:
3181
diff
changeset
|
168 if stanza.attr.type == "probe" then |
a19dbb6446a0
mod_presence: Don't stop pre-event for outgoing probes.
Waqas Hussain <waqas20@gmail.com>
parents:
3181
diff
changeset
|
169 stanza.attr.from, stanza.attr.to = st_from, st_to; |
a19dbb6446a0
mod_presence: Don't stop pre-event for outgoing probes.
Waqas Hussain <waqas20@gmail.com>
parents:
3181
diff
changeset
|
170 return; |
a19dbb6446a0
mod_presence: Don't stop pre-event for outgoing probes.
Waqas Hussain <waqas20@gmail.com>
parents:
3181
diff
changeset
|
171 elseif stanza.attr.type == "subscribe" then |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
172 -- 1. route stanza |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
173 -- 2. roster push (subscription = none, ask = subscribe) |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
174 if rostermanager.set_contact_pending_out(node, host, to_bare) then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
175 rostermanager.roster_push(node, host, to_bare); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
176 end -- else file error |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
177 core_post_stanza(origin, stanza); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
178 elseif stanza.attr.type == "unsubscribe" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
179 -- 1. route stanza |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
180 -- 2. roster push (subscription = none or from) |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
181 if rostermanager.unsubscribe(node, host, to_bare) then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
182 rostermanager.roster_push(node, host, to_bare); -- FIXME do roster push when roster has in fact not changed? |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
183 end -- else file error |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
184 core_post_stanza(origin, stanza); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
185 elseif stanza.attr.type == "subscribed" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
186 -- 1. route stanza |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
187 -- 2. roster_push () |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
188 -- 3. send_presence_of_available_resources |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
189 if rostermanager.subscribed(node, host, to_bare) then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
190 rostermanager.roster_push(node, host, to_bare); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
191 end |
10514
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
192 if rostermanager.is_contact_subscribed(node, host, to_bare) then |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
193 core_post_stanza(origin, stanza); |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
194 send_presence_of_available_resources(node, host, to_bare, origin); |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
195 end |
7778
62e7d6a73c72
mod_presence: Send probe once subscribed (fixes #794)
Kim Alvefur <zash@zash.se>
parents:
7430
diff
changeset
|
196 if rostermanager.is_user_subscribed(node, host, to_bare) then |
62e7d6a73c72
mod_presence: Send probe once subscribed (fixes #794)
Kim Alvefur <zash@zash.se>
parents:
7430
diff
changeset
|
197 core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare })); |
62e7d6a73c72
mod_presence: Send probe once subscribed (fixes #794)
Kim Alvefur <zash@zash.se>
parents:
7430
diff
changeset
|
198 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
199 elseif stanza.attr.type == "unsubscribed" then |
5060
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
200 -- 1. send unavailable |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
201 -- 2. route stanza |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
202 -- 3. roster push (subscription = from or both) |
10556
79fe4ed1332b
mod_presence: Ignore an unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10514
diff
changeset
|
203 -- luacheck: ignore 211/pending_in |
79fe4ed1332b
mod_presence: Ignore an unused variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10514
diff
changeset
|
204 -- Is pending_in meant to be used? |
5060
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
205 local success, pending_in, subscribed = rostermanager.unsubscribed(node, host, to_bare); |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
206 if success then |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
207 if subscribed then |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
208 rostermanager.roster_push(node, host, to_bare); |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
209 end |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
210 core_post_stanza(origin, stanza); |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
211 if subscribed then |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
212 send_presence_of_available_resources(node, host, to_bare, origin, st.presence({ type = "unavailable" })); |
b0e36777f715
mod_presence, rostermanager: Bring outbound subscription cancellation in line with RFC6121.
Waqas Hussain <waqas20@gmail.com>
parents:
5013
diff
changeset
|
213 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
214 end |
4139
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
215 else |
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
216 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid presence type")); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
217 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
218 stanza.attr.from, stanza.attr.to = st_from, st_to; |
3181
1f73b3a960cf
mod_presence: Small refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
3156
diff
changeset
|
219 return true; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
220 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
221 |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
222 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
223 local node, host = jid_split(to_bare); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
224 local st_from, st_to = stanza.attr.from, stanza.attr.to; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
225 stanza.attr.from, stanza.attr.to = from_bare, to_bare; |
4993
5243b74a4cbb
Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages
Matthew Wild <mwild1@gmail.com>
parents:
4967
diff
changeset
|
226 log("debug", "inbound presence %s from %s for %s", stanza.attr.type, from_bare, to_bare); |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5416
diff
changeset
|
227 |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
228 if stanza.attr.type == "probe" then |
3112
c311fdffccce
mod_presence: Don't send 'unsubscribed' in response to probes when roster loading fails.
Waqas Hussain <waqas20@gmail.com>
parents:
3109
diff
changeset
|
229 local result, err = rostermanager.is_contact_subscribed(node, host, from_bare); |
c311fdffccce
mod_presence: Don't send 'unsubscribed' in response to probes when roster loading fails.
Waqas Hussain <waqas20@gmail.com>
parents:
3109
diff
changeset
|
230 if result then |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
231 if 0 == send_presence_of_available_resources(node, host, st_from, origin) then |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
232 core_post_stanza(hosts[host], st.presence({from=to_bare, to=st_from, type="unavailable"}), true); -- TODO send last activity |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
233 end |
3112
c311fdffccce
mod_presence: Don't send 'unsubscribed' in response to probes when roster loading fails.
Waqas Hussain <waqas20@gmail.com>
parents:
3109
diff
changeset
|
234 elseif not err then |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
235 core_post_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"}), true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
236 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
237 elseif stanza.attr.type == "subscribe" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
238 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
239 core_post_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"}), true); -- already subscribed |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
240 -- Sending presence is not clearly stated in the RFC, but it seems appropriate |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
241 if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
242 core_post_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"}), true); -- TODO send last activity |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
243 end |
10514
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
244 elseif rostermanager.is_contact_preapproved(node, host, from_bare) then |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
245 if not rostermanager.is_contact_pending_in(node, host, from_bare) then |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
246 if rostermanager.set_contact_pending_in(node, host, from_bare, stanza) then |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
247 core_post_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"}), true); |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
248 end -- TODO else return error, unable to save |
f0e9e5bda415
rostermanager, mod_presence: Support for subscription preapproval (fixes #686)
Matthew Wild <mwild1@gmail.com>
parents:
9790
diff
changeset
|
249 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
250 else |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
251 core_post_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"}), true); -- acknowledging receipt |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
252 if not rostermanager.is_contact_pending_in(node, host, from_bare) then |
9671
e50559a42dfe
rostermanager, mod_presence: Store stanza for incoming subscription requests (fixes #689) (thanks Zash, Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents:
8728
diff
changeset
|
253 if rostermanager.set_contact_pending_in(node, host, from_bare, stanza) then |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
254 sessionmanager.send_to_available_resources(node, host, stanza); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
255 end -- TODO else return error, unable to save |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
256 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
257 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
258 elseif stanza.attr.type == "unsubscribe" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
259 if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then |
2143
13ac68e8760b
mod_presence: Route incoming presence subscription stanzas (types unsubscribe, subscribed and unsubscribed) to the user before roster pushes.
Waqas Hussain <waqas20@gmail.com>
parents:
2142
diff
changeset
|
260 sessionmanager.send_to_interested_resources(node, host, stanza); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
261 rostermanager.roster_push(node, host, from_bare); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
262 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
263 elseif stanza.attr.type == "subscribed" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
264 if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then |
2143
13ac68e8760b
mod_presence: Route incoming presence subscription stanzas (types unsubscribe, subscribed and unsubscribed) to the user before roster pushes.
Waqas Hussain <waqas20@gmail.com>
parents:
2142
diff
changeset
|
265 sessionmanager.send_to_interested_resources(node, host, stanza); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
266 rostermanager.roster_push(node, host, from_bare); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
267 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
268 elseif stanza.attr.type == "unsubscribed" then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
269 if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then |
2143
13ac68e8760b
mod_presence: Route incoming presence subscription stanzas (types unsubscribe, subscribed and unsubscribed) to the user before roster pushes.
Waqas Hussain <waqas20@gmail.com>
parents:
2142
diff
changeset
|
270 sessionmanager.send_to_interested_resources(node, host, stanza); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
271 rostermanager.roster_push(node, host, from_bare); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
272 end |
4139
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
273 else |
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
274 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid presence type")); |
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
275 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
276 stanza.attr.from, stanza.attr.to = st_from, st_to; |
3181
1f73b3a960cf
mod_presence: Small refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
3156
diff
changeset
|
277 return true; |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
278 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
279 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
280 local outbound_presence_handler = function(data) |
8728
41c959c5c84b
Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents:
8579
diff
changeset
|
281 -- outbound presence received |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
282 local origin, stanza = data.origin, data.stanza; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
283 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
284 local to = stanza.attr.to; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
285 if to then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
286 local t = stanza.attr.type; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
287 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes |
3181
1f73b3a960cf
mod_presence: Small refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
3156
diff
changeset
|
288 return handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
289 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
290 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
291 local to_bare = jid_bare(to); |
3215
e55782f20679
mod_presence: Fixed a traceback.
Waqas Hussain <waqas20@gmail.com>
parents:
3198
diff
changeset
|
292 local roster = origin.roster; |
e55782f20679
mod_presence: Fixed a traceback.
Waqas Hussain <waqas20@gmail.com>
parents:
3198
diff
changeset
|
293 if roster and not(roster[to_bare] and (roster[to_bare].subscription == "both" or roster[to_bare].subscription == "from")) then -- directed presence |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
294 origin.directed = origin.directed or {}; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
295 if t then -- removing from directed presence list on sending an error or unavailable |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
296 origin.directed[to] = nil; -- FIXME does it make more sense to add to_bare rather than to? |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
297 else |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
298 origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to? |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
299 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
300 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
301 end -- TODO maybe handle normal presence here, instead of letting it pass to incoming handlers? |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
302 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
303 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
304 module:hook("pre-presence/full", outbound_presence_handler); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
305 module:hook("pre-presence/bare", outbound_presence_handler); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
306 module:hook("pre-presence/host", outbound_presence_handler); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
307 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
308 module:hook("presence/bare", function(data) |
8728
41c959c5c84b
Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents:
8579
diff
changeset
|
309 -- inbound presence to bare JID received |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
310 local origin, stanza = data.origin, data.stanza; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
311 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
312 local to = stanza.attr.to; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
313 local t = stanza.attr.type; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
314 if to then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
315 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to bare JID |
3181
1f73b3a960cf
mod_presence: Small refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
3156
diff
changeset
|
316 return handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
317 end |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5416
diff
changeset
|
318 |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
319 local user = bare_sessions[to]; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
320 if user then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
321 for _, session in pairs(user.sessions) do |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
322 if session.presence then -- only send to available resources |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
323 session.send(stanza); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
324 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
325 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
326 end -- no resources not online, discard |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
327 elseif not t or t == "unavailable" then |
3153
fd435cab928f
mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions.
Waqas Hussain <waqas20@gmail.com>
parents:
3112
diff
changeset
|
328 handle_normal_presence(origin, stanza); |
4139
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
329 else |
eef75a0c85e3
mod_presence: Bounce errors for invalid presence types (thanks nolan/Astro)
Matthew Wild <mwild1@gmail.com>
parents:
3969
diff
changeset
|
330 origin.send(st.error_reply(stanza, "modify", "bad-request", "Invalid presence type")); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
331 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
332 return true; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
333 end); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
334 module:hook("presence/full", function(data) |
8728
41c959c5c84b
Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents:
8579
diff
changeset
|
335 -- inbound presence to full JID received |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
336 local origin, stanza = data.origin, data.stanza; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
337 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
338 local t = stanza.attr.type; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
339 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to full JID |
3181
1f73b3a960cf
mod_presence: Small refactoring.
Waqas Hussain <waqas20@gmail.com>
parents:
3156
diff
changeset
|
340 return handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
341 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
342 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
343 local session = full_sessions[stanza.attr.to]; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
344 if session then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
345 -- TODO fire post processing event |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
346 session.send(stanza); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
347 end -- resource not online, discard |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
348 return true; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
349 end); |
2531
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
350 module:hook("presence/host", function(data) |
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
351 -- inbound presence to the host |
5416
0ba3a49d3863
mod_presence: Remove some unused variables
Matthew Wild <mwild1@gmail.com>
parents:
5370
diff
changeset
|
352 local stanza = data.stanza; |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5416
diff
changeset
|
353 |
2531
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
354 local from_bare = jid_bare(stanza.attr.from); |
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
355 local t = stanza.attr.type; |
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
356 if t == "probe" then |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
357 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id })); |
2531
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
358 elseif t == "subscribe" then |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
359 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id, type = "subscribed" })); |
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
360 core_post_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id })); |
2531
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
361 end |
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
362 return true; |
697ff4f98033
mod_presence: Added handler for presence subscriptions and probes to local hosts.
Waqas Hussain <waqas20@gmail.com>
parents:
2525
diff
changeset
|
363 end); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
364 |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
365 module:hook("resource-unbind", function(event) |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
366 local session, err = event.session, event.error; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
367 -- Send unavailable presence |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
368 if session.presence then |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
369 local pres = st.presence{ type = "unavailable" }; |
4967
b7bcf088e723
mod_presence: Handle nil disconnection error
Matthew Wild <mwild1@gmail.com>
parents:
4139
diff
changeset
|
370 if err then |
b7bcf088e723
mod_presence: Handle nil disconnection error
Matthew Wild <mwild1@gmail.com>
parents:
4139
diff
changeset
|
371 pres:tag("status"):text("Disconnected: "..err):up(); |
b7bcf088e723
mod_presence: Handle nil disconnection error
Matthew Wild <mwild1@gmail.com>
parents:
4139
diff
changeset
|
372 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
373 session:dispatch_stanza(pres); |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
374 elseif session.directed then |
1606
bbadcaab0036
mod_presence: Tag outgoing unavailables generated by a disconnect with a from attribute
Matthew Wild <mwild1@gmail.com>
parents:
1568
diff
changeset
|
375 local pres = st.presence{ type = "unavailable", from = session.full_jid }; |
4967
b7bcf088e723
mod_presence: Handle nil disconnection error
Matthew Wild <mwild1@gmail.com>
parents:
4139
diff
changeset
|
376 if err then |
b7bcf088e723
mod_presence: Handle nil disconnection error
Matthew Wild <mwild1@gmail.com>
parents:
4139
diff
changeset
|
377 pres:tag("status"):text("Disconnected: "..err):up(); |
b7bcf088e723
mod_presence: Handle nil disconnection error
Matthew Wild <mwild1@gmail.com>
parents:
4139
diff
changeset
|
378 end |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
379 for jid in pairs(session.directed) do |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
380 pres.attr.to = jid; |
3198
5a4e766a3577
mod_presence: Enable firing of pre-events for all outbound stanzas, and switching completely to core_post_stanza.
Waqas Hussain <waqas20@gmail.com>
parents:
3196
diff
changeset
|
381 core_post_stanza(session, pres, true); |
1508
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
382 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
383 session.directed = nil; |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
384 end |
762d758e116a
mod_presence: Convert from Windows line endings
Matthew Wild <mwild1@gmail.com>
parents:
1488
diff
changeset
|
385 end); |
7331
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
386 |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
387 module:hook("roster-item-removed", function (event) |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
388 local username = event.username; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
389 local session = event.origin; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
390 local roster = event.roster or session and session.roster; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
391 local jid = event.jid; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
392 local item = event.item; |
7345
0c69305ab525
mod_presence: Fix variable name
Kim Alvefur <zash@zash.se>
parents:
7344
diff
changeset
|
393 local from_jid = session.full_jid or (username .. "@" .. module.host); |
7331
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
394 |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
395 local subscription = item and item.subscription or "none"; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
396 local ask = item and item.ask; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
397 local pending = roster and roster[false].pending[jid]; |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
398 |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
399 if subscription == "both" or subscription == "from" or pending then |
7344
81efa212db1e
mod_presence: Construct a 'from' JID when roster items are removed outside of a session
Kim Alvefur <zash@zash.se>
parents:
7332
diff
changeset
|
400 core_post_stanza(session, st.presence({type="unsubscribed", from=from_jid, to=jid})); |
7331
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
401 end |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
402 |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
403 if subscription == "both" or subscription == "to" or ask then |
7332
ba32289e8d0b
mod_presence: Send unavailable presence when roster items are removed (fixes #331)
Kim Alvefur <zash@zash.se>
parents:
7331
diff
changeset
|
404 send_presence_of_available_resources(username, module.host, jid, session, st.presence({type="unavailable"})); |
7344
81efa212db1e
mod_presence: Construct a 'from' JID when roster items are removed outside of a session
Kim Alvefur <zash@zash.se>
parents:
7332
diff
changeset
|
405 core_post_stanza(session, st.presence({type="unsubscribe", from=from_jid, to=jid})); |
7331
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
406 end |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
407 |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
408 end, -1); |
c8ad387aab1c
mod_presence, mod_roster: Move responsibility for sending presence on roster removal to mod_presence
Kim Alvefur <zash@zash.se>
parents:
7281
diff
changeset
|
409 |