From 2dae99da75a98d6f6dccd6983ec5f79dd52ae9d4 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Fri, 2 Dec 2011 19:24:54 +0100 Subject: util.dataforms: Fix form verification --- util/dataforms.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index e4d24cf6..b69df819 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -120,12 +120,18 @@ function form_t.data(layout, stanza) end end - local reader = field_readers[field.type]; - local verifier = field.verifier or field_verifiers[field.type]; - if reader then - data[field.name] = reader(tag); - if verifier then - errors[field.name] = verifier(data[field.name], tag, field.required); + if not tag then + if field.required then + errors[field.name] = "Required value missing"; + end + else + local reader = field_readers[field.type]; + local verifier = field.verifier or field_verifiers[field.type]; + if reader then + data[field.name] = reader(tag); + if verifier then + errors[field.name] = verifier(data[field.name], tag, field.required); + end end end end @@ -161,7 +167,7 @@ field_readers["jid-single"] = field_verifiers["jid-single"] = function (data, field_tag, required) - if #data == 0 and required then + if ((not data) or (#data == 0)) and required then return "Required value missing"; end if not jid_prep(data) then -- cgit v1.2.3 From df36a9727516426670630b618f3c3320fd0336a7 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sat, 3 Dec 2011 17:10:48 +0100 Subject: util.dataforms: Fix verfication for booleans --- util/dataforms.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index b69df819..d4a1865c 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -252,7 +252,7 @@ field_readers["boolean"] = field_verifiers["boolean"] = function (data, field_tag, required) data = field_readers["text-single"](field_tag); - if #data == 0 and required then + if ((not data) or (#data == 0)) and required then return "Required value missing"; end if data ~= "1" and data ~= "true" and data ~= "0" and data ~= "false" then -- cgit v1.2.3 From d59d8e6325a4a1cb3c4762d96697fcfbbbdd37df Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 18 Jan 2012 08:54:26 +0500 Subject: util.json: Added function encode_ordered(object). --- util/json.lua | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/util/json.lua b/util/json.lua index 5d0b0876..efc602f0 100644 --- a/util/json.lua +++ b/util/json.lua @@ -1,6 +1,6 @@ local type = type; -local t_insert, t_concat, t_remove = table.insert, table.concat, table.remove; +local t_insert, t_concat, t_remove, t_sort = table.insert, table.concat, table.remove, table.sort; local s_char = string.char; local tostring, tonumber = tostring, tonumber; local pairs, ipairs = pairs, ipairs; @@ -79,11 +79,25 @@ function tablesave(o, buffer) if next(__hash) ~= nil or next(hash) ~= nil or next(__array) == nil then t_insert(buffer, "{"); local mark = #buffer; - for k,v in pairs(hash) do - stringsave(k, buffer); - t_insert(buffer, ":"); - simplesave(v, buffer); - t_insert(buffer, ","); + if buffer.ordered then + local keys = {}; + for k in pairs(hash) do + t_insert(keys, k); + end + t_sort(keys); + for _,k in ipairs(keys) do + stringsave(k, buffer); + t_insert(buffer, ":"); + simplesave(hash[k], buffer); + t_insert(buffer, ","); + end + else + for k,v in pairs(hash) do + stringsave(k, buffer); + t_insert(buffer, ":"); + simplesave(v, buffer); + t_insert(buffer, ","); + end end if next(__hash) ~= nil then t_insert(buffer, "\"__hash\":["); @@ -129,6 +143,11 @@ function json.encode(obj) simplesave(obj, t); return t_concat(t); end +function json.encode_ordered(obj) + local t = { ordered = true }; + simplesave(obj, t); + return t_concat(t); +end ----------------------------------- -- cgit v1.2.3 From 03efdf7669e72be49b919adfa0085545182e7811 Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Tue, 24 Jan 2012 14:57:53 -0800 Subject: mod_saslauth: "" ~= nil (thanks, Zash!) --- plugins/mod_saslauth.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 9c62e5ec..58655a24 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -191,8 +191,10 @@ local function s2s_external_auth(session, stanza) session.from_host = text; end session.sends2s(build_reply("success")) - module:log("info", "Accepting SASL EXTERNAL identity from %s", text or session.from_host); - s2s_make_authenticated(session, text or session.from_host) + + local domain = text ~= "" and text or session.from_host; + module:log("info", "Accepting SASL EXTERNAL identity from %s", domain); + s2s_make_authenticated(session, domain); session:reset_stream(); return true end -- cgit v1.2.3 From fdd51ac3ffa99de906d63f9b45897c0c95ce8e2a Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Tue, 24 Jan 2012 14:58:54 -0800 Subject: s2smanager: Log the host when marking it authenticated --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 974b2f4f..97cc3e6d 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -557,7 +557,7 @@ function make_authenticated(session, host) else return false; end - session.log("debug", "connection %s->%s is now authenticated", session.from_host or "(unknown)", session.to_host or "(unknown)"); + session.log("debug", "connection %s->%s is now authenticated for %s", session.from_host or "(unknown)", session.to_host or "(unknown)", host); mark_connected(session); -- cgit v1.2.3