Merge 0.9->0.10
[prosody.git] / util / xmppstream.lua
index 586ad5f94a4cdaede7ae18b3fcbea3f99a700e69..dede0da94d7b5b60e0d5185ad906c46a105286bf 100644 (file)
@@ -109,7 +109,7 @@ function new_sax_handlers(session, stream_callbacks, cb_handleprogress)
                                        end
                                else
                                        -- Garbage before stream?
-                                       cb_error(session, "no-stream");
+                                       cb_error(session, "no-stream", tagname);
                                end
                                return;
                        end
@@ -241,6 +241,25 @@ function new(session, stream_callbacks, stanza_size_limit)
        local parser = new_parser(handlers, ns_separator, false);
        local parse = parser.parse;
 
+       function session.open_stream(session, from, to)
+               local send = session.sends2s or session.send;
+
+               local attr = {
+                       ["xmlns:stream"] = "http://etherx.jabber.org/streams",
+                       ["xml:lang"] = "en",
+                       xmlns = stream_callbacks.default_ns,
+                       version = session.version and (session.version > 0 and "1.0" or nil),
+                       id = session.streamid,
+                       from = from or session.host, to = to,
+               };
+               if session.stream_attrs then
+                       session:stream_attrs(from, to, attr)
+               end
+               send("<?xml version='1.0'?>");
+               send(st.stanza("stream:stream", attr):top_tag());
+               return true;
+       end
+
        return {
                reset = function ()
                        parser = new_parser(handlers, ns_separator, false);