From 780ceb290e0b798ca392251ef13271eed044b6c9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 20 Nov 2008 01:33:25 +0000 Subject: [PATCH] Use a stanza for c2s stream features instead of an array of strings. Removes a FIXME. --- core/sessionmanager.lua | 12 +++--------- plugins/mod_saslauth.lua | 16 +++++++++------- plugins/mod_tls.lua | 3 ++- plugins/mod_vcard.lua | 3 ++- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 8be7bdec..e83b7c23 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -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(""); + send(features); - for _, feature in ipairs(features) do - send(tostring(feature)); - end - - send(""); - log("info", "Stream opened successfully"); + (session.log or log)("info", "Sent reply to client"); session.notopen = nil; end diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 6ceb0be3..7ca4308b 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -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, ""); + 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, "PLAIN"); - t_insert(features, "DIGEST-MD5"); - t_insert(features, ""); + features:tag("mechanism"):text("PLAIN"):up(); + features:tag("mechanism"):text("DIGEST-MD5"):up(); + features:up(); else - t_insert(features, ""); - t_insert(features, ""); + features:tag("bind", bind_attr):tag("required"):up():up(); + features:tag("session", xmpp_session_attr):up(); end - --send [[ ]] end); add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index b5ca5015..cc46d556 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -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, ""); + features:tag("starttls", starttls_attr):up(); end end); diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua index fb7382c2..d2f2c7ba 100644 --- a/plugins/mod_vcard.lua +++ b/plugins/mod_vcard.lua @@ -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, ""); + features:tag("feature", feature_vcard_attr):up(); end end); -- 2.30.2