Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME.
authorMatthew Wild <mwild1@gmail.com>
Thu, 20 Nov 2008 01:33:25 +0000 (01:33 +0000)
committerMatthew Wild <mwild1@gmail.com>
Thu, 20 Nov 2008 01:33:25 +0000 (01:33 +0000)
core/sessionmanager.lua
plugins/mod_saslauth.lua
plugins/mod_tls.lua
plugins/mod_vcard.lua

index 8be7bdec6a1f885d943903c096f5d30a5b71c7a2..e83b7c2334217e8ef28df6562aae9059f3f4abbc 100644 (file)
@@ -121,18 +121,12 @@ function streamopened(session, attr)
                                                end
                                                
                                                
-                                               local features = {};
+                                               local features = st.stanza("stream:features");
                                                modulemanager.fire_event("stream-features", session, features);
                                                
-                                               -- FIXME: Need to send() this all at once
-                                               send("<stream:features>");
+                                               send(features);
                                                
-                                               for _, feature in ipairs(features) do
-                                                       send(tostring(feature));
-                                               end
-                                               send("</stream:features>");
-                                               log("info", "Stream opened successfully");
+                                               (session.log or log)("info", "Sent reply <stream:stream> to client");
                                                session.notopen = nil;
 end
 
index 6ceb0be31fa2dd20198c3e3ae0e7b18ff29b9bdc..7ca4308b6224d7f2c33fe65d8c84c884ff7a9d80 100644 (file)
@@ -83,19 +83,21 @@ add_handler("c2s_unauthed", "auth", xmlns_sasl, sasl_handler);
 add_handler("c2s_unauthed", "abort", xmlns_sasl, sasl_handler);
 add_handler("c2s_unauthed", "response", xmlns_sasl, sasl_handler);
 
+local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' };
+local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' };
+local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' };
 add_event_hook("stream-features", 
                                        function (session, features)                                                                                            
                                                if not session.username then
-                                                       t_insert(features, "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>");
+                                                       features:tag("mechanisms", mechanisms_attr);
                                                        -- TODO: Provide PLAIN only if TLS is active, this is a SHOULD from the introduction of RFC 4616. This behavior could be overridden via configuration but will issuing a warning or so.
-                                                               t_insert(features, "<mechanism>PLAIN</mechanism>");
-                                                               t_insert(features, "<mechanism>DIGEST-MD5</mechanism>");
-                                                       t_insert(features, "</mechanisms>");
+                                                               features:tag("mechanism"):text("PLAIN"):up();
+                                                               features:tag("mechanism"):text("DIGEST-MD5"):up();
+                                                       features:up();
                                                else
-                                                       t_insert(features, "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><required/></bind>");
-                                                       t_insert(features, "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>");
+                                                       features:tag("bind", bind_attr):tag("required"):up():up();
+                                                       features:tag("session", xmpp_session_attr):up();
                                                end
-                                               --send [[<register xmlns="http://jabber.org/features/iq-register"/> ]]
                                        end);
                                        
 add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", 
index b5ca5015fe23162599b5379ccf5d6449827bcac5..cc46d55613187e79c1cf30d4fb7eab1f27848c2c 100644 (file)
@@ -24,9 +24,10 @@ add_handler("c2s_unauthed", "starttls", xmlns_starttls,
                        end
                end);
                
+local starttls_attr = { xmlns = xmlns_starttls };
 add_event_hook("stream-features", 
                                        function (session, features)                                                                                            
                                                if session.conn.starttls then
-                                                       t_insert(features, "<starttls xmlns='"..xmlns_starttls.."'/>");
+                                                       features:tag("starttls", starttls_attr):up();
                                                end
                                        end);
index fb7382c20762665052aca0e58ef91fe684f281ee..d2f2c7ba2873dd062774d3a099abecbcf80ba06b 100644 (file)
@@ -43,9 +43,10 @@ add_iq_handler({"c2s", "s2sin"}, "vcard-temp",
                        end
                end);
 
+local feature_vcard_attr = { var='vcard-temp' };
 add_event_hook("stream-features", 
                                        function (session, features)                                                                                            
                                                if session.type == "c2s" then
-                                                       t_insert(features, "<feature var='vcard-temp'/>");
+                                                       features:tag("feature", feature_vcard_attr):up();
                                                end
                                        end);