From d968c1f9a6933c3e5d2b2f16d38d656edb6fe152 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 11:08:00 +0100 Subject: configuration_table added --- .../scripts/common/configuration_table.lua | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 misc/freeswitch/scripts/common/configuration_table.lua (limited to 'misc/freeswitch/scripts/common/configuration_table.lua') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua new file mode 100644 index 0000000..afb5b0e --- /dev/null +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -0,0 +1,39 @@ +-- Gemeinschaft 5 module: configuration table +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +-- retrieve configuration from database +function get(database, entity, section) + if not database or not entity then + return {}; + end + + require 'common.str' + + local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"'; + if section then + sql_query = sql_query .. ' AND `section` = "' .. section .. '"'; + end + + local root = {} + local parameter_class = ''; + + database:query(sql_query, function(parameters) + if not root[parameters.section] then + root[parameters.section] = {}; + end + parameter_class = tostring(parameters.class_type):lower(); + + if parameter_class == 'boolean' then + root[parameters.section][parameters.name] = common.str.to_b(parameters.value); + elseif parameter_class == 'integer' then + root[parameters.section][parameters.name] = common.str.to_i(parameters.value); + else + root[parameters.section][parameters.name] = tostring(parameters.value); + end + end) + + return root; +end -- cgit v1.2.3 From a1e1ad4fc578042613df891ea25971b8fc045edc Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 9 Jan 2013 13:37:13 +0100 Subject: remove parent --- misc/freeswitch/scripts/common/configuration_table.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'misc/freeswitch/scripts/common/configuration_table.lua') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua index afb5b0e..731bf2f 100644 --- a/misc/freeswitch/scripts/common/configuration_table.lua +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -35,5 +35,9 @@ function get(database, entity, section) end end) + if section then + return root[section]; + end + return root; end -- cgit v1.2.3 From 7326afdd65ae58c7158249c9ea73eaf0db16bbd3 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 10 Jan 2013 16:34:19 +0100 Subject: strip whitespace --- .../freeswitch/scripts/common/configuration_table.lua | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'misc/freeswitch/scripts/common/configuration_table.lua') diff --git a/misc/freeswitch/scripts/common/configuration_table.lua b/misc/freeswitch/scripts/common/configuration_table.lua index 731bf2f..85bc014 100644 --- a/misc/freeswitch/scripts/common/configuration_table.lua +++ b/misc/freeswitch/scripts/common/configuration_table.lua @@ -21,17 +21,20 @@ function get(database, entity, section) local parameter_class = ''; database:query(sql_query, function(parameters) - if not root[parameters.section] then - root[parameters.section] = {}; + local p_section = common.str.strip(parameters.section):lower(); + local p_class_type = common.str.strip(parameters.class_type):lower(); + local p_name = common.str.strip(parameters.name); + + if not root[p_section] then + root[p_section] = {}; end - parameter_class = tostring(parameters.class_type):lower(); - if parameter_class == 'boolean' then - root[parameters.section][parameters.name] = common.str.to_b(parameters.value); - elseif parameter_class == 'integer' then - root[parameters.section][parameters.name] = common.str.to_i(parameters.value); + if p_class_type == 'boolean' then + root[p_section][p_name] = common.str.to_b(parameters.value); + elseif p_class_type == 'integer' then + root[p_section][p_name] = common.str.to_i(parameters.value); else - root[parameters.section][parameters.name] = tostring(parameters.value); + root[p_section][p_name] = tostring(parameters.value); end end) -- cgit v1.2.3