Software /
code /
prosody
Annotate
core/stanza_router.lua @ 142:98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 23 Oct 2008 18:42:25 +0100 |
parent | 141:37b3e9ed8918 |
child | 143:e0f20546cd68 |
rev | line source |
---|---|
142
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
1 <<<<<<< local |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
2 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
3 -- The code in this file should be self-explanatory, though the logic is horrible |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
4 -- for more info on that, see doc/stanza_routing.txt, which attempts to condense |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
5 -- the rules from the RFCs (mainly 3921) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
6 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
7 require "core.servermanager" |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
8 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
9 local log = require "util.logger".init("stanzarouter") |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
10 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
11 local st = require "util.stanza"; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
12 local send = require "core.sessionmanager".send_to_session; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
13 -- local send_s2s = require "core.s2smanager".send_to_host; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
14 local user_exists = require "core.usermanager".user_exists; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
15 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
16 local jid_split = require "util.jid".split; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
17 local print, debug = print, debug; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
18 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
19 function core_process_stanza(origin, stanza) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
20 log("debug", "Received: "..tostring(stanza)) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
21 -- TODO verify validity of stanza (as well as JID validity) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
22 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
23 if stanza.attr.type == "set" or stanza.attr.type == "get" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
24 error("Invalid IQ"); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
25 elseif #stanza.tags > 1 or not(stanza.attr.type == "error" or stanza.attr.type == "result") then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
26 error("Invalid IQ"); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
27 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
28 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
29 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
30 if origin.type == "c2s" and not origin.full_jid |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
31 and not(stanza.name == "iq" and stanza.tags[1].name == "bind" |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
32 and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
33 error("Client MUST bind resource after auth"); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
34 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
35 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
36 local to = stanza.attr.to; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
37 stanza.attr.from = origin.full_jid; -- quick fix to prevent impersonation (FIXME this would be incorrect when the origin is not c2s) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
38 -- TODO also, stazas should be returned to their original state before the function ends |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
39 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
40 -- TODO presence subscriptions |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
41 if not to then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
42 core_handle_stanza(origin, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
43 elseif hosts[to] and hosts[to].type == "local" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
44 core_handle_stanza(origin, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
45 elseif stanza.name == "iq" and not select(3, jid_split(to)) then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
46 core_handle_stanza(origin, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
47 elseif origin.type == "c2s" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
48 core_route_stanza(origin, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
49 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
50 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
51 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
52 -- This function handles stanzas which are not routed any further, |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
53 -- that is, they are handled by this server |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
54 function core_handle_stanza(origin, stanza) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
55 -- Handlers |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
56 if origin.type == "c2s" or origin.type == "c2s_unauthed" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
57 local session = origin; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
58 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
59 if stanza.name == "presence" and origin.roster then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
60 if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
61 for jid in pairs(origin.roster) do -- broadcast to all interested contacts |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
62 local subscription = origin.roster[jid].subscription; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
63 if subscription == "both" or subscription == "from" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
64 stanza.attr.to = jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
65 core_route_stanza(origin, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
66 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
67 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
68 local node, host = jid_split(stanza.attr.from); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
69 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
70 if res ~= origin then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
71 if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
72 stanza.attr.to = res.full_jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
73 core_route_stanza(origin, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
74 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
75 if res.presence then -- from all resources for which we have presence |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
76 res.presence.attr.to = origin.full_jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
77 core_route_stanza(res, res.presence); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
78 res.presence.attr.to = nil; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
79 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
80 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
81 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
82 if not origin.presence then -- presence probes on initial presence |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
83 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
84 for jid in pairs(origin.roster) do |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
85 local subscription = origin.roster[jid].subscription; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
86 if subscription == "both" or subscription == "to" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
87 probe.attr.to = jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
88 core_route_stanza(origin, probe); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
89 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
90 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
91 -- TODO resend subscription requests |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
92 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
93 origin.presence = stanza; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
94 stanza.attr.to = nil; -- reset it |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
95 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
96 -- TODO error, bad type |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
97 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
98 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
99 log("debug", "Routing stanza to local"); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
100 handle_stanza(session, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
101 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
102 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
103 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
104 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
105 function is_authorized_to_see_presence(origin, username, host) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
106 local roster = datamanager.load(username, host, "roster") or {}; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
107 local item = roster[origin.username.."@"..origin.host]; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
108 return item and (item.subscription == "both" or item.subscription == "from"); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
109 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
110 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
111 function core_route_stanza(origin, stanza) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
112 -- Hooks |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
113 --- ...later |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
114 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
115 -- Deliver |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
116 local to = stanza.attr.to; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
117 local node, host, resource = jid_split(to); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
118 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
119 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
120 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
121 local host_session = hosts[host] |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
122 if host_session and host_session.type == "local" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
123 -- Local host |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
124 local user = host_session.sessions[node]; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
125 if user then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
126 local res = user.sessions[resource]; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
127 if not res then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
128 -- if we get here, resource was not specified or was unavailable |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
129 if stanza.name == "presence" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
130 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
131 if stanza.attr.type == "probe" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
132 if is_authorized_to_see_presence(origin, node, host) then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
133 for k in pairs(user.sessions) do -- return presence for all resources |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
134 if user.sessions[k].presence then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
135 local pres = user.sessions[k].presence; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
136 pres.attr.to = origin.full_jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
137 pres.attr.from = user.sessions[k].full_jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
138 send(origin, pres); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
139 pres.attr.to = nil; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
140 pres.attr.from = nil; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
141 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
142 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
143 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
144 send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"})); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
145 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
146 elseif stanza.attr.type == "subscribe" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
147 -- TODO |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
148 elseif stanza.attr.type == "unsubscribe" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
149 -- TODO |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
150 elseif stanza.attr.type == "subscribed" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
151 -- TODO |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
152 elseif stanza.attr.type == "unsubscribed" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
153 -- TODO |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
154 end -- discard any other type |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
155 else -- sender is available or unavailable |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
156 for k in pairs(user.sessions) do -- presence broadcast to all user resources |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
157 if user.sessions[k].full_jid then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
158 stanza.attr.to = user.sessions[k].full_jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
159 send(user.sessions[k], stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
160 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
161 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
162 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
163 elseif stanza.name == "message" then -- select a resource to recieve message |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
164 for k in pairs(user.sessions) do |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
165 if user.sessions[k].full_jid then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
166 res = user.sessions[k]; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
167 break; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
168 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
169 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
170 -- TODO find resource with greatest priority |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
171 send(res, stanza); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
172 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
173 -- TODO send IQ error |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
174 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
175 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
176 -- User + resource is online... |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
177 stanza.attr.to = res.full_jid; |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
178 send(res, stanza); -- Yay \o/ |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
179 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
180 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
181 -- user not online |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
182 if user_exists(node, host) then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
183 if stanza.name == "presence" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
184 if stanza.attr.type == "probe" and is_authorized_to_see_presence(origin, node, host) then -- FIXME what to do for not c2s? |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
185 -- TODO send last recieved unavailable presence |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
186 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
187 -- TODO send unavailable presence |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
188 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
189 elseif stanza.name == "message" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
190 -- TODO send message error, or store offline messages |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
191 elseif stanza.name == "iq" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
192 -- TODO send IQ error |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
193 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
194 else -- user does not exist |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
195 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses? |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
196 if stanza.name == "presence" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
197 if stanza.attr.type == "probe" then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
198 send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
199 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
200 -- else ignore |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
201 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
202 send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
203 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
204 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
205 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
206 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
207 -- Remote host |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
208 if host_session then |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
209 -- Send to session |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
210 else |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
211 -- Need to establish the connection |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
212 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
213 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
214 stanza.attr.to = to; -- reset |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
215 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
216 |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
217 function handle_stanza_toremote(stanza) |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
218 log("error", "Stanza bound for remote host, but s2s is not implemented"); |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
219 end |
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
220 ======= |
30 | 221 |
222 -- The code in this file should be self-explanatory, though the logic is horrible | |
223 -- for more info on that, see doc/stanza_routing.txt, which attempts to condense | |
224 -- the rules from the RFCs (mainly 3921) | |
225 | |
226 require "core.servermanager" | |
227 | |
228 local log = require "util.logger".init("stanzarouter") | |
229 | |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
230 local st = require "util.stanza"; |
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
231 local send = require "core.sessionmanager".send_to_session; |
122 | 232 -- local send_s2s = require "core.s2smanager".send_to_host; |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
233 local user_exists = require "core.usermanager".user_exists; |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
234 |
105
b099f0f80775
Removed an unnecessary line
Waqas Hussain <waqas20@gmail.com>
parents:
83
diff
changeset
|
235 local jid_split = require "util.jid".split; |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
236 local print = print; |
30 | 237 |
238 function core_process_stanza(origin, stanza) | |
66 | 239 log("debug", "Received: "..tostring(stanza)) |
73 | 240 -- TODO verify validity of stanza (as well as JID validity) |
83
79608fc8f98d
Fixed routing for IQs to bare JIDs, and added a simple IQ validity check
Waqas Hussain <waqas20@gmail.com>
parents:
78
diff
changeset
|
241 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
242 if stanza.attr.type == "set" or stanza.attr.type == "get" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
243 error("Invalid IQ"); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
244 elseif #stanza.tags > 1 or not(stanza.attr.type == "error" or stanza.attr.type == "result") then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
245 error("Invalid IQ"); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
246 end |
83
79608fc8f98d
Fixed routing for IQs to bare JIDs, and added a simple IQ validity check
Waqas Hussain <waqas20@gmail.com>
parents:
78
diff
changeset
|
247 end |
78
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
248 |
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
249 if origin.type == "c2s" and not origin.full_jid |
83
79608fc8f98d
Fixed routing for IQs to bare JIDs, and added a simple IQ validity check
Waqas Hussain <waqas20@gmail.com>
parents:
78
diff
changeset
|
250 and not(stanza.name == "iq" and stanza.tags[1].name == "bind" |
78
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
251 and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then |
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
252 error("Client MUST bind resource after auth"); |
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
253 end |
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
254 |
30 | 255 local to = stanza.attr.to; |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
256 stanza.attr.from = origin.full_jid; -- quick fix to prevent impersonation (FIXME this would be incorrect when the origin is not c2s) |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
257 -- TODO also, stazas should be returned to their original state before the function ends |
30 | 258 |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
259 -- TODO presence subscriptions |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
260 if not to then |
119
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
261 core_handle_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
262 elseif hosts[to] and hosts[to].type == "local" then |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
263 core_handle_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
264 elseif stanza.name == "iq" and not select(3, jid_split(to)) then |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
265 core_handle_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
266 elseif origin.type == "c2s" then |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
267 core_route_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
268 end |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
269 end |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
270 |
121
74e5919e4737
Added a comment, removed all the old code
Matthew Wild <mwild1@gmail.com>
parents:
119
diff
changeset
|
271 -- This function handles stanzas which are not routed any further, |
74e5919e4737
Added a comment, removed all the old code
Matthew Wild <mwild1@gmail.com>
parents:
119
diff
changeset
|
272 -- that is, they are handled by this server |
119
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
273 function core_handle_stanza(origin, stanza) |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
274 -- Handlers |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
275 if origin.type == "c2s" or origin.type == "c2s_unauthed" then |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
276 local session = origin; |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
277 |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
278 if stanza.name == "presence" and origin.roster then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
279 if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
280 for jid in pairs(origin.roster) do -- broadcast to all interested contacts |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
281 local subscription = origin.roster[jid].subscription; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
282 if subscription == "both" or subscription == "from" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
283 stanza.attr.to = jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
284 core_route_stanza(origin, stanza); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
285 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
286 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
287 --[[local node, host = jid_split(stanza.attr.from); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
288 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
289 if res.full_jid then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
290 res = user.sessions[k]; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
291 break; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
292 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
293 end]] |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
294 if not origin.presence then -- presence probes on initial presence |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
295 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
296 for jid in pairs(origin.roster) do |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
297 local subscription = origin.roster[jid].subscription; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
298 if subscription == "both" or subscription == "to" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
299 probe.attr.to = jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
300 core_route_stanza(origin, probe); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
301 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
302 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
303 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
304 origin.presence = stanza; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
305 stanza.attr.to = nil; -- reset it |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
306 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
307 -- TODO error, bad type |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
308 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
309 else |
119
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
310 log("debug", "Routing stanza to local"); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
311 handle_stanza(session, stanza); |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
312 end |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
313 end |
30 | 314 end |
315 | |
142
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
316 -- TODO: Does this function belong here? |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
317 function is_authorized_to_see_presence(origin, username, host) |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
318 local roster = datamanager.load(username, host, "roster") or {}; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
319 local item = roster[origin.username.."@"..origin.host]; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
320 return item and (item.subscription == "both" or item.subscription == "from"); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
321 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
322 |
30 | 323 function core_route_stanza(origin, stanza) |
324 -- Hooks | |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
325 --- ...later |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
326 |
30 | 327 -- Deliver |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
328 local to = stanza.attr.to; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
329 local node, host, resource = jid_split(to); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
330 |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
331 if stanza.name == "presence" and stanza.attr.type == "probe" then resource = nil; end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
332 |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
333 local host_session = hosts[host] |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
334 if host_session and host_session.type == "local" then |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
335 -- Local host |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
336 local user = host_session.sessions[node]; |
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
337 if user then |
72 | 338 local res = user.sessions[resource]; |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
339 if not res then |
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
340 -- if we get here, resource was not specified or was unavailable |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
341 if stanza.name == "presence" then |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
342 if stanza.attr.type == "probe" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
343 if is_authorized_to_see_presence(origin, node, host) then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
344 for k in pairs(user.sessions) do -- return presence for all resources |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
345 if user.sessions[k].presence then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
346 local pres = user.sessions[k].presence; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
347 pres.attr.to = origin.full_jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
348 pres.attr.from = user.sessions[k].full_jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
349 send(origin, pres); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
350 pres.attr.to = nil; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
351 pres.attr.from = nil; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
352 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
353 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
354 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
355 send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
356 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
357 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
358 for k in pairs(user.sessions) do -- presence broadcast to all user resources |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
359 if user.sessions[k].full_jid then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
360 stanza.attr.to = user.sessions[k].full_jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
361 send(user.sessions[k], stanza); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
362 end |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
363 end |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
364 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
365 elseif stanza.name == "message" then -- select a resource to recieve message |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
366 for k in pairs(user.sessions) do |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
367 if user.sessions[k].full_jid then |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
368 res = user.sessions[k]; |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
369 break; |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
370 end |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
371 end |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
372 -- TODO find resource with greatest priority |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
373 send(res, stanza); |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
374 else |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
375 -- TODO send IQ error |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
376 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
377 else |
121
74e5919e4737
Added a comment, removed all the old code
Matthew Wild <mwild1@gmail.com>
parents:
119
diff
changeset
|
378 -- User + resource is online... |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
379 stanza.attr.to = res.full_jid; |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
380 send(res, stanza); -- Yay \o/ |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
381 end |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
382 else |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
383 -- user not online |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
384 if user_exists(node, host) then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
385 if stanza.name == "presence" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
386 if stanza.attr.type == "probe" and is_authorized_to_see_presence(origin, node, host) then -- FIXME what to do for not c2s? |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
387 -- TODO send last recieved unavailable presence |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
388 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
389 -- TODO send unavailable presence |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
390 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
391 elseif stanza.name == "message" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
392 -- TODO send message error, or store offline messages |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
393 elseif stanza.name == "iq" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
394 -- TODO send IQ error |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
395 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
396 else -- user does not exist |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
397 -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses? |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
398 if stanza.name == "presence" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
399 if stanza.attr.type == "probe" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
400 send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
401 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
402 -- else ignore |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
403 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
404 send(origin, st.error_reply(stanza, "cancel", "service-unavailable")); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
405 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
406 end |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
407 end |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
408 else |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
409 -- Remote host |
142
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
410 send_s2s(origin.host, host, stanza); |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
411 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
412 stanza.attr.to = to; -- reset |
30 | 413 end |
414 | |
415 function handle_stanza_toremote(stanza) | |
416 log("error", "Stanza bound for remote host, but s2s is not implemented"); | |
417 end | |
142
98e9fea75e5b
Backed out changeset 37b3e9ed8918 (again)
Matthew Wild <mwild1@gmail.com>
parents:
141
diff
changeset
|
418 >>>>>>> other |