Comparison

core/stanza_router.lua @ 151:096c7b9374fc

Presence fixes (again) - Presence to other resources sent correctly - Resource of the recipient ignored for all presence except available and unavailable - Set things up for presence subscriptions
author Waqas Hussain <waqas20@gmail.com>
date Fri, 24 Oct 2008 00:26:01 +0500
parent 143:e0f20546cd68
child 152:6b8e2bd82ac5
comparison
equal deleted inserted replaced
143:e0f20546cd68 151:096c7b9374fc
62 if subscription == "both" or subscription == "from" then 62 if subscription == "both" or subscription == "from" then
63 stanza.attr.to = jid; 63 stanza.attr.to = jid;
64 core_route_stanza(origin, stanza); 64 core_route_stanza(origin, stanza);
65 end 65 end
66 end 66 end
67 --[[local node, host = jid_split(stanza.attr.from); 67 local node, host = jid_split(stanza.attr.from);
68 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources 68 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources
69 if res.full_jid then 69 if res ~= origin then
70 res = user.sessions[k]; 70 if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence
71 break; 71 stanza.attr.to = res.full_jid;
72 end 72 core_route_stanza(origin, stanza);
73 end]] 73 end
74 if res.presence then -- from all resources for which we have presence
75 res.presence.attr.to = origin.full_jid;
76 core_route_stanza(res, res.presence);
77 res.presence.attr.to = nil;
78 end
79 end
80 end
74 if not origin.presence then -- presence probes on initial presence 81 if not origin.presence then -- presence probes on initial presence
75 local probe = st.presence({from = origin.full_jid, type = "probe"}); 82 local probe = st.presence({from = origin.full_jid, type = "probe"});
76 for jid in pairs(origin.roster) do 83 for jid in pairs(origin.roster) do
77 local subscription = origin.roster[jid].subscription; 84 local subscription = origin.roster[jid].subscription;
78 if subscription == "both" or subscription == "to" then 85 if subscription == "both" or subscription == "to" then
79 probe.attr.to = jid; 86 probe.attr.to = jid;
80 core_route_stanza(origin, probe); 87 core_route_stanza(origin, probe);
81 end 88 end
82 end 89 end
90 -- TODO resend subscription requests
83 end 91 end
84 origin.presence = stanza; 92 origin.presence = stanza;
85 stanza.attr.to = nil; -- reset it 93 stanza.attr.to = nil; -- reset it
86 else 94 else
87 -- TODO error, bad type 95 -- TODO error, bad type
105 113
106 -- Deliver 114 -- Deliver
107 local to = stanza.attr.to; 115 local to = stanza.attr.to;
108 local node, host, resource = jid_split(to); 116 local node, host, resource = jid_split(to);
109 117
110 if stanza.name == "presence" and stanza.attr.type == "probe" then resource = nil; end 118 if stanza.name == "presence" and (stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable") then resource = nil; end
111 119
112 local host_session = hosts[host] 120 local host_session = hosts[host]
113 if host_session and host_session.type == "local" then 121 if host_session and host_session.type == "local" then
114 -- Local host 122 -- Local host
115 local user = host_session.sessions[node]; 123 local user = host_session.sessions[node];
116 if user then 124 if user then
117 local res = user.sessions[resource]; 125 local res = user.sessions[resource];
118 if not res then 126 if not res then
119 -- if we get here, resource was not specified or was unavailable 127 -- if we get here, resource was not specified or was unavailable
120 if stanza.name == "presence" then 128 if stanza.name == "presence" then
121 if stanza.attr.type == "probe" then 129 if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then
122 if is_authorized_to_see_presence(origin, node, host) then 130 if stanza.attr.type == "probe" then
123 for k in pairs(user.sessions) do -- return presence for all resources 131 if is_authorized_to_see_presence(origin, node, host) then
124 if user.sessions[k].presence then 132 for k in pairs(user.sessions) do -- return presence for all resources
125 local pres = user.sessions[k].presence; 133 if user.sessions[k].presence then
126 pres.attr.to = origin.full_jid; 134 local pres = user.sessions[k].presence;
127 pres.attr.from = user.sessions[k].full_jid; 135 pres.attr.to = origin.full_jid;
128 send(origin, pres); 136 pres.attr.from = user.sessions[k].full_jid;
129 pres.attr.to = nil; 137 send(origin, pres);
130 pres.attr.from = nil; 138 pres.attr.to = nil;
139 pres.attr.from = nil;
140 end
131 end 141 end
142 else
143 send(origin, st.presence({from=user.."@"..host, to=origin.username.."@"..origin.host, type="unsubscribed"}));
132 end 144 end
133 else 145 elseif stanza.attr.type == "subscribe" then
134 send(origin, st.presence({from = user.."@"..host, to = origin.username.."@"..origin.host, type = "unsubscribed"})); 146 -- TODO
135 end 147 elseif stanza.attr.type == "unsubscribe" then
136 else 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
137 for k in pairs(user.sessions) do -- presence broadcast to all user resources 155 for k in pairs(user.sessions) do -- presence broadcast to all user resources
138 if user.sessions[k].full_jid then 156 if user.sessions[k].full_jid then
139 stanza.attr.to = user.sessions[k].full_jid; 157 stanza.attr.to = user.sessions[k].full_jid;
140 send(user.sessions[k], stanza); 158 send(user.sessions[k], stanza);
141 end 159 end