Software / code / prosody
Comparison
core/stanza_router.lua @ 130:907cff6b5359
Presence fixes
- Presence to other resources sent correctly
- Resource of the recipient ignored for all presence except available and unavailable
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Thu, 23 Oct 2008 19:47:56 +0500 |
| parent | 128:77a1778b16e8 |
| child | 135:bf10d42dd41b |
comparison
equal
deleted
inserted
replaced
| 129:0f119bece309 | 130:907cff6b5359 |
|---|---|
| 10 local st = require "util.stanza"; | 10 local st = require "util.stanza"; |
| 11 local send = require "core.sessionmanager".send_to_session; | 11 local send = require "core.sessionmanager".send_to_session; |
| 12 local user_exists = require "core.usermanager".user_exists; | 12 local user_exists = require "core.usermanager".user_exists; |
| 13 | 13 |
| 14 local jid_split = require "util.jid".split; | 14 local jid_split = require "util.jid".split; |
| 15 local print = print; | 15 local print, debug = print, debug; |
| 16 | 16 |
| 17 function core_process_stanza(origin, stanza) | 17 function core_process_stanza(origin, stanza) |
| 18 log("debug", "Received: "..tostring(stanza)) | 18 log("debug", "Received: "..tostring(stanza)) |
| 19 -- TODO verify validity of stanza (as well as JID validity) | 19 -- TODO verify validity of stanza (as well as JID validity) |
| 20 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then | 20 if stanza.name == "iq" and not(#stanza.tags == 1 and stanza.tags[1].attr.xmlns) then |
| 61 if subscription == "both" or subscription == "from" then | 61 if subscription == "both" or subscription == "from" then |
| 62 stanza.attr.to = jid; | 62 stanza.attr.to = jid; |
| 63 core_route_stanza(origin, stanza); | 63 core_route_stanza(origin, stanza); |
| 64 end | 64 end |
| 65 end | 65 end |
| 66 --[[local node, host = jid_split(stanza.attr.from); | 66 local node, host = jid_split(stanza.attr.from); |
| 67 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources | 67 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources |
| 68 if res.full_jid then | 68 if res ~= origin then |
| 69 res = user.sessions[k]; | 69 if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence |
| 70 break; | 70 stanza.attr.to = res.full_jid; |
| 71 end | 71 core_route_stanza(origin, stanza); |
| 72 end]] | 72 end |
| 73 if res.presence then -- from all resources for which we have presence | |
| 74 res.presence.attr.to = origin.full_jid; | |
| 75 core_route_stanza(res, res.presence); | |
| 76 res.presence.attr.to = nil; | |
| 77 end | |
| 78 end | |
| 79 end | |
| 73 if not origin.presence then -- presence probes on initial presence | 80 if not origin.presence then -- presence probes on initial presence |
| 74 local probe = st.presence({from = origin.full_jid, type = "probe"}); | 81 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
| 75 for jid in pairs(origin.roster) do | 82 for jid in pairs(origin.roster) do |
| 76 local subscription = origin.roster[jid].subscription; | 83 local subscription = origin.roster[jid].subscription; |
| 77 if subscription == "both" or subscription == "to" then | 84 if subscription == "both" or subscription == "to" then |
| 104 | 111 |
| 105 -- Deliver | 112 -- Deliver |
| 106 local to = stanza.attr.to; | 113 local to = stanza.attr.to; |
| 107 local node, host, resource = jid_split(to); | 114 local node, host, resource = jid_split(to); |
| 108 | 115 |
| 109 if stanza.name == "presence" and stanza.attr.type == "probe" then resource = nil; end | 116 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end |
| 110 | 117 |
| 111 local host_session = hosts[host] | 118 local host_session = hosts[host] |
| 112 if host_session and host_session.type == "local" then | 119 if host_session and host_session.type == "local" then |
| 113 -- Local host | 120 -- Local host |
| 114 local user = host_session.sessions[node]; | 121 local user = host_session.sessions[node]; |