From a477d142f106d3e385f1ba38bbf5e04724bd9f44 Mon Sep 17 00:00:00 2001 From: ron Date: Fri, 24 Sep 2010 02:52:00 +0000 Subject: [PATCH] Updated stdnse.get_script_args() function to take arrays in addition to strings. If an array is passed, currently, the first name is considered 'valid' and the others are considered 'deprecated'. This behaviour is still under discussion. --- nselib/stdnse.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index 206de583a..4ef68183c 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -589,14 +589,29 @@ function get_script_args (...) local args, args_num = {}, select("#", ...) for i = 1, args_num do - local option = select(i, ...) + local options = select(i, ...) - if nmap.registry.args[option] then - args[i] = nmap.registry.args[option] - else - for _, v in ipairs(nmap.registry.args) do - if v == option then - args[i] = 1 + if(type(options) == 'string') then + options = {options} + end + + -- Save the first option (which will be the primary, non-deprecated one) + local first_option = options[1] + + for _, option in ipairs(options) do + if nmap.registry.args[option] then + if(option ~= first_option) then + print_debug(1, "WARNING: Option '%s' is deprecated; use '%s' instead.", option, first_option) + end + args[i] = nmap.registry.args[option] + else + for _, v in ipairs(nmap.registry.args) do + if v == option then + if(option ~= first_option) then + print_debug(1, "WARNING: Option '%s' is deprecated; use '%s' instead.", option, first_option) + end + args[i] = 1 + end end end end