54 --- Stream events handlers |
54 --- Stream events handlers |
55 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
55 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; |
56 |
56 |
57 function stream_callbacks.streamopened(session, attr) |
57 function stream_callbacks.streamopened(session, attr) |
58 local send = session.send; |
58 local send = session.send; |
59 session.host = nameprep(attr.to); |
59 local host = nameprep(attr.to); |
60 if not session.host then |
60 if not host then |
61 session:close{ condition = "improper-addressing", |
61 session:close{ condition = "improper-addressing", |
62 text = "A valid 'to' attribute is required on stream headers" }; |
62 text = "A valid 'to' attribute is required on stream headers" }; |
|
63 return; |
|
64 end |
|
65 if not session.host then |
|
66 session.host = host; |
|
67 elseif session.host ~= host then |
|
68 session:close{ condition = "not-authorized", |
|
69 text = "The 'to' attribute must remain the same across stream restarts" }; |
63 return; |
70 return; |
64 end |
71 end |
65 session.version = tonumber(attr.version) or 0; |
72 session.version = tonumber(attr.version) or 0; |
66 session.streamid = uuid_generate(); |
73 session.streamid = uuid_generate(); |
67 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host); |
74 (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host); |