diff options
Diffstat (limited to 'misc/freeswitch')
-rw-r--r-- | misc/freeswitch/scripts/common/configuration_table.lua | 39 |
1 files changed, 39 insertions, 0 deletions
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 |