Software /
code /
prosody
Annotate
core/stanza_router.lua @ 152:6b8e2bd82ac5
Moved some code and removed unnecessary checks.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 24 Oct 2008 01:06:54 +0500 |
parent | 151:096c7b9374fc |
child | 153:8310bfddaba8 |
rev | line source |
---|---|
30 | 1 |
2 -- The code in this file should be self-explanatory, though the logic is horrible | |
3 -- for more info on that, see doc/stanza_routing.txt, which attempts to condense | |
4 -- the rules from the RFCs (mainly 3921) | |
5 | |
6 require "core.servermanager" | |
7 | |
8 local log = require "util.logger".init("stanzarouter") | |
9 | |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
10 local st = require "util.stanza"; |
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
11 local send = require "core.sessionmanager".send_to_session; |
122 | 12 -- 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
|
13 local user_exists = require "core.usermanager".user_exists; |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
14 |
105
b099f0f80775
Removed an unnecessary line
Waqas Hussain <waqas20@gmail.com>
parents:
83
diff
changeset
|
15 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
|
16 local print = print; |
30 | 17 |
18 function core_process_stanza(origin, stanza) | |
66 | 19 log("debug", "Received: "..tostring(stanza)) |
73 | 20 -- 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
|
21 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
|
22 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
|
23 error("Invalid IQ"); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
24 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
|
25 error("Invalid IQ"); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
26 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
|
27 end |
78
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
28 |
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 end |
972e31cc91e8
Fized: Added check to ensure that resource binding is done after auth.
Waqas Hussain <waqas20@gmail.com>
parents:
73
diff
changeset
|
34 |
30 | 35 local to = stanza.attr.to; |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
36 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
|
37 -- TODO also, stazas should be returned to their original state before the function ends |
30 | 38 |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
39 -- TODO presence subscriptions |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
40 if not to then |
119
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
41 core_handle_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
42 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
|
43 core_handle_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
44 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
|
45 core_handle_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
46 elseif origin.type == "c2s" then |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
47 core_route_stanza(origin, stanza); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
48 end |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
49 end |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
50 |
121
74e5919e4737
Added a comment, removed all the old code
Matthew Wild <mwild1@gmail.com>
parents:
119
diff
changeset
|
51 -- 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
|
52 -- 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
|
53 function core_handle_stanza(origin, stanza) |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
54 -- Handlers |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
55 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
|
56 local session = origin; |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
57 |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
58 if stanza.name == "presence" and origin.roster then |
152
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
59 if stanza.attr.type == nil or stanza.attr.type == "unavailable" then |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
60 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
|
61 local subscription = origin.roster[jid].subscription; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
62 if subscription == "both" or subscription == "from" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
63 stanza.attr.to = jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
64 core_route_stanza(origin, stanza); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
65 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
66 end |
151 | 67 local node, host = jid_split(stanza.attr.from); |
152
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
68 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
69 if res ~= origin and res.full_jid then -- to resource. FIXME is res.full_jid the correct check? Maybe it should be res.presence |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
70 stanza.attr.to = res.full_jid; |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
71 core_route_stanza(origin, stanza); |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
72 end |
151 | 73 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
74 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
|
75 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
152
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
76 for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
77 local subscription = origin.roster[jid].subscription; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
78 if subscription == "both" or subscription == "to" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
79 probe.attr.to = jid; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
80 core_route_stanza(origin, probe); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
81 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
82 end |
152
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
83 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all resources |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
84 if res ~= origin and stanza.attr.type ~= "unavailable" and res.presence then -- FIXME does unavailable qualify as initial presence? |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
85 res.presence.attr.to = origin.full_jid; |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
86 core_route_stanza(res, res.presence); |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
87 res.presence.attr.to = nil; |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
88 end |
6b8e2bd82ac5
Moved some code and removed unnecessary checks.
Waqas Hussain <waqas20@gmail.com>
parents:
151
diff
changeset
|
89 end |
151 | 90 -- TODO resend subscription requests |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
91 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
92 origin.presence = stanza; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
93 stanza.attr.to = nil; -- reset it |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
94 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
95 -- TODO error, bad type |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
96 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
97 else |
119
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
98 log("debug", "Routing stanza to local"); |
b48a573608e8
Relocate presence broadcast to core_handle_stanza()
Matthew Wild <mwild1@gmail.com>
parents:
113
diff
changeset
|
99 handle_stanza(session, stanza); |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
100 end |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
101 end |
30 | 102 end |
103 | |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
104 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
|
105 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
|
106 local item = roster[origin.username.."@"..origin.host]; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
107 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
|
108 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
109 |
30 | 110 function core_route_stanza(origin, stanza) |
111 -- Hooks | |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
112 --- ...later |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
113 |
30 | 114 -- Deliver |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
115 local to = stanza.attr.to; |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
116 local node, host, resource = jid_split(to); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
117 |
151 | 118 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
119 |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
120 local host_session = hosts[host] |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
121 if host_session and host_session.type == "local" then |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
122 -- Local host |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
123 local user = host_session.sessions[node]; |
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
124 if user then |
72 | 125 local res = user.sessions[resource]; |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
126 if not res then |
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
127 -- 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
|
128 if stanza.name == "presence" then |
151 | 129 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then |
130 if stanza.attr.type == "probe" then | |
131 if is_authorized_to_see_presence(origin, node, host) then | |
132 for k in pairs(user.sessions) do -- return presence for all resources | |
133 if user.sessions[k].presence then | |
134 local pres = user.sessions[k].presence; | |
135 pres.attr.to = origin.full_jid; | |
136 pres.attr.from = user.sessions[k].full_jid; | |
137 send(origin, pres); | |
138 pres.attr.to = nil; | |
139 pres.attr.from = nil; | |
140 end | |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
141 end |
151 | 142 else |
143 send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"})); | |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
144 end |
151 | 145 elseif stanza.attr.type == "subscribe" then |
146 -- TODO | |
147 elseif stanza.attr.type == "unsubscribe" then | |
148 -- TODO | |
149 elseif stanza.attr.type == "subscribed" then | |
150 -- TODO | |
151 elseif stanza.attr.type == "unsubscribed" then | |
152 -- TODO | |
153 end -- discard any other type | |
154 else -- sender is available or unavailable | |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
155 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
|
156 if user.sessions[k].full_jid then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
157 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
|
158 send(user.sessions[k], stanza); |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
159 end |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
160 end |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
161 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
162 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
|
163 for k in pairs(user.sessions) do |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
164 if user.sessions[k].full_jid then |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
165 res = user.sessions[k]; |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
166 break; |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
167 end |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
168 end |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
169 -- TODO find resource with greatest priority |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
170 send(res, stanza); |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
171 else |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
172 -- TODO send IQ error |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
173 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
174 else |
121
74e5919e4737
Added a comment, removed all the old code
Matthew Wild <mwild1@gmail.com>
parents:
119
diff
changeset
|
175 -- User + resource is online... |
106
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
176 stanza.attr.to = res.full_jid; |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
177 send(res, stanza); -- Yay \o/ |
f2a3d204a76a
Added: presence broadcast
Waqas Hussain <waqas20@gmail.com>
parents:
105
diff
changeset
|
178 end |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
179 else |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
180 -- user not online |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
181 if user_exists(node, host) then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
182 if stanza.name == "presence" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
183 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
|
184 -- TODO send last recieved unavailable presence |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
185 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
186 -- TODO send unavailable presence |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
187 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
188 elseif stanza.name == "message" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
189 -- 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
|
190 elseif stanza.name == "iq" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
191 -- TODO send IQ error |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
192 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
193 else -- user does not exist |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
194 -- 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
|
195 if stanza.name == "presence" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
196 if stanza.attr.type == "probe" then |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
197 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
|
198 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
199 -- else ignore |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
200 else |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
201 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
|
202 end |
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
203 end |
71
fbb4ef1da82e
Added: Local stanza routing
Waqas Hussain <waqas20@gmail.com>
parents:
68
diff
changeset
|
204 end |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
205 else |
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
206 -- Remote host |
143
e0f20546cd68
Backed out changeset 98e9fea75e5b
Matthew Wild <mwild1@gmail.com>
parents:
142
diff
changeset
|
207 if host_session then |
e0f20546cd68
Backed out changeset 98e9fea75e5b
Matthew Wild <mwild1@gmail.com>
parents:
142
diff
changeset
|
208 -- Send to session |
e0f20546cd68
Backed out changeset 98e9fea75e5b
Matthew Wild <mwild1@gmail.com>
parents:
142
diff
changeset
|
209 else |
e0f20546cd68
Backed out changeset 98e9fea75e5b
Matthew Wild <mwild1@gmail.com>
parents:
142
diff
changeset
|
210 -- Need to establish the connection |
e0f20546cd68
Backed out changeset 98e9fea75e5b
Matthew Wild <mwild1@gmail.com>
parents:
142
diff
changeset
|
211 end |
68
ceb7a55676a4
Beginnings of real stanza routing
Matthew Wild <mwild1@gmail.com>
parents:
66
diff
changeset
|
212 end |
113
9026fdad1531
Working presence, presence probes and other fixes
Waqas Hussain <waqas20@gmail.com>
parents:
106
diff
changeset
|
213 stanza.attr.to = to; -- reset |
30 | 214 end |
215 | |
216 function handle_stanza_toremote(stanza) | |
217 log("error", "Stanza bound for remote host, but s2s is not implemented"); | |
218 end |