core/stanza_dispatch.lua

changeset 7
dcc5ac721c20
parent 6
7ad47ce20394
equal deleted inserted replaced
6:7ad47ce20394 7:dcc5ac721c20
30 :tag("password"):up() 30 :tag("password"):up()
31 :tag("resource"):up()); 31 :tag("resource"):up());
32 return true; 32 return true;
33 else 33 else
34 username, password, resource = t_concat(username), t_concat(password), t_concat(resource); 34 username, password, resource = t_concat(username), t_concat(password), t_concat(resource);
35 print(username, password, resource)
36 local reply = st.reply(stanza); 35 local reply = st.reply(stanza);
37 require "core.usermanager" 36 require "core.usermanager"
38 if usermanager.validate_credentials(session.host, username, password) then 37 if usermanager.validate_credentials(session.host, username, password) then
39 -- Authentication successful! 38 -- Authentication successful!
40 session.username = username; 39 session.username = username;
94 end 93 end
95 log("warn", "Unhandled namespace: "..xmlns); 94 log("warn", "Unhandled namespace: "..xmlns);
96 send(format("<iq type='error' id='%s'><error type='cancel'><service-unavailable/></error></iq>", stanza.attr.id)); 95 send(format("<iq type='error' id='%s'><error type='cancel'><service-unavailable/></error></iq>", stanza.attr.id));
97 return; 96 return;
98 end 97 end
99 elseif stanza.name == "presence" then 98 end
99 if not session.username then log("warn", "Attempt to use an unauthed stream!"); return; end
100 if stanza.name == "presence" then
100 if session.roster then 101 if session.roster then
101 local initial_presence = not session.last_presence; 102 local initial_presence = not session.last_presence;
102 session.last_presence = stanza; 103 session.last_presence = stanza;
103 104
104 -- Broadcast presence and probes 105 -- Broadcast presence and probes
110 end 111 end
111 for contact_jid in pairs(session.roster) do 112 for contact_jid in pairs(session.roster) do
112 broadcast.attr.to = contact_jid; 113 broadcast.attr.to = contact_jid;
113 send_to(contact_jid, broadcast); 114 send_to(contact_jid, broadcast);
114 if initial_presence then 115 if initial_presence then
115 print("Initital presence");
116 local node, host = jid.split(contact_jid); 116 local node, host = jid.split(contact_jid);
117 if hosts[host] and hosts[host].type == "local" then 117 if hosts[host] and hosts[host].type == "local" then
118 local contact = hosts[host].sessions[node] 118 local contact = hosts[host].sessions[node]
119 if contact then 119 if contact then
120 local pres = st.presence { to = session.full_jid }; 120 local pres = st.presence { to = session.full_jid };
135 end 135 end
136 136
137 -- Probe for our contacts' presence 137 -- Probe for our contacts' presence
138 end 138 end
139 end 139 end
140 else 140 elseif session.username then
141 --end 141 --end
142 --if stanza.attr.to and ((not hosts[stanza.attr.to]) or hosts[stanza.attr.to].type ~= "local") then 142 --if stanza.attr.to and ((not hosts[stanza.attr.to]) or hosts[stanza.attr.to].type ~= "local") then
143 -- Need to route stanza 143 -- Need to route stanza
144 stanza.attr.from = session.username.."@"..session.host; 144 stanza.attr.from = session.username.."@"..session.host;
145 session:send_to(stanza.attr.to, stanza); 145 session:send_to(stanza.attr.to, stanza);
146 end 146 end
147 end 147 end
148 148
149 end 149 end
150

mercurial