diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:05:14 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2012-12-17 12:05:14 +0100 |
commit | eaad37485fe59d0306c37cc038dda6d210052910 (patch) | |
tree | 072c4b0e33d442528555b82c415f5e7a1712b2b0 /misc/freeswitch/scripts/common/node.lua | |
parent | 3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff) | |
parent | b80bd744ad873f6fc43018bc4bfb90677de167bd (diff) |
Merge branch 'develop'
Diffstat (limited to 'misc/freeswitch/scripts/common/node.lua')
-rw-r--r-- | misc/freeswitch/scripts/common/node.lua | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/common/node.lua b/misc/freeswitch/scripts/common/node.lua new file mode 100644 index 0000000..544ede9 --- /dev/null +++ b/misc/freeswitch/scripts/common/node.lua @@ -0,0 +1,73 @@ +-- CommonModule: Node +-- +module(...,package.seeall) + +Node = {} + +-- Create Node object +function Node.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self) + self.__index = self + self.log = arg.log + self.database = arg.database + self.record = arg.record + self.session = arg.session + return object +end + +-- Find Node account by name +function Node.find_by_id(self, node_id) + + if not tonumber(node_id) then + return nil + end + + local sql_query = 'SELECT * FROM `gs_nodes` WHERE `id`= ' .. node_id .. ' LIMIT 1'; + local record = nil + + self.database:query(sql_query, function(node_entry) + record = node_entry + end) + + if record then + local node_object = Node:new(self); + node_object.record = record + + return node_object + end + + return nil +end + +-- Find Node account by name +function Node.find_by_address(self, address) + local sql_query = 'SELECT * FROM `gs_nodes` WHERE `ip_address`= "' .. tostring(address):gsub('[^A-F0-9%.%:]', '') .. '" LIMIT 1'; + local record = nil + + self.database:query(sql_query, function(node_entry) + record = node_entry + end) + + if record then + local node_object = Node:new(self); + node_object.record = record + + return node_object + end + + return nil +end + +-- List Nodes +function Node.all(self) + local sql_query = 'SELECT * FROM `gs_nodes`'; + nodes = {}; + + self.database:query(sql_query, function(node_entry) + nodes[tonumber(node_entry.id)] = node_entry; + end) + + return nodes +end
\ No newline at end of file |