101 end |
101 end |
102 |
102 |
103 |
103 |
104 local function bosh_reset_stream(session) session.notopen = true; end |
104 local function bosh_reset_stream(session) session.notopen = true; end |
105 |
105 |
106 local session_close_reply = { headers = default_headers, body = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" }) }; |
106 local session_close_reply = { headers = default_headers, body = st.stanza("body", { xmlns = xmlns_bosh, type = "terminate" }), attr = {} }; |
107 local function bosh_close_stream(session, reason) |
107 local function bosh_close_stream(session, reason) |
108 (session.log or log)("info", "BOSH client disconnected"); |
108 (session.log or log)("info", "BOSH client disconnected"); |
109 session_close_reply.attr.condition = reason; |
109 session_close_reply.attr.condition = reason; |
110 local session_close_reply = tostring(session_close_reply); |
110 local session_close_reply = tostring(session_close_reply); |
111 for _, held_request in ipairs(session.requests) do |
111 for _, held_request in ipairs(session.requests) do |
124 request.notopen = nil; -- Signals that we accept this opening tag |
124 request.notopen = nil; -- Signals that we accept this opening tag |
125 |
125 |
126 -- TODO: Sanity checks here (rid, to, known host, etc.) |
126 -- TODO: Sanity checks here (rid, to, known host, etc.) |
127 if not hosts[attr.to] then |
127 if not hosts[attr.to] then |
128 -- Unknown host |
128 -- Unknown host |
|
129 log("debug", "BOSH client tried to connect to unknown host: %s", tostring(attr.to)); |
129 session_close_reply.attr.condition = "host-unknown"; |
130 session_close_reply.attr.condition = "host-unknown"; |
130 request:send{ headers = default_headers, body = tostring(session_close_reply) }; |
131 request:send{ headers = default_headers, body = tostring(session_close_reply) }; |
131 request.notopen = nil |
132 request.notopen = nil |
132 return; |
133 return; |
133 end |
134 end |
178 local features = st.stanza("stream:features"); |
179 local features = st.stanza("stream:features"); |
179 fire_event("stream-features", session, features); |
180 fire_event("stream-features", session, features); |
180 --xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh' |
181 --xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh' |
181 local response = st.stanza("body", { xmlns = xmlns_bosh, |
182 local response = st.stanza("body", { xmlns = xmlns_bosh, |
182 inactivity = tostring(BOSH_DEFAULT_INACTIVITY), polling = tostring(BOSH_DEFAULT_POLLING), requests = tostring(BOSH_DEFAULT_REQUESTS), hold = tostring(session.bosh_hold), maxpause = "120", |
183 inactivity = tostring(BOSH_DEFAULT_INACTIVITY), polling = tostring(BOSH_DEFAULT_POLLING), requests = tostring(BOSH_DEFAULT_REQUESTS), hold = tostring(session.bosh_hold), maxpause = "120", |
183 sid = sid, ver = '1.6', from = session.host, secure = 'true', ["xmpp:version"] = "1.0", |
184 sid = sid, authid = sid, ver = '1.6', from = session.host, secure = 'true', ["xmpp:version"] = "1.0", |
184 ["xmlns:xmpp"] = "urn:xmpp:xbosh", ["xmlns:stream"] = "http://etherx.jabber.org/streams" }):add_child(features); |
185 ["xmlns:xmpp"] = "urn:xmpp:xbosh", ["xmlns:stream"] = "http://etherx.jabber.org/streams" }):add_child(features); |
185 request:send{ headers = default_headers, body = tostring(response) }; |
186 request:send{ headers = default_headers, body = tostring(response) }; |
186 |
187 |
187 request.sid = sid; |
188 request.sid = sid; |
188 return; |
189 return; |