Annotate

plugins/mod_storage_xep0227.lua @ 6698:95a8aeca1fc9

mod_storage_xep0227: Close file handle after reading
author Kim Alvefur <zash@zash.se>
date Fri, 15 May 2015 15:17:27 +0200
parent 6697:3d27f5855f4b
child 6699:ccdd0b615106
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 local ipairs, pairs = ipairs, pairs;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local setmetatable = setmetatable;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 local tostring = tostring;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local next = next;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 local t_remove = table.remove;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 local os_remove = os.remove;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 local io_open = io.open;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
6697
3d27f5855f4b mod_storage_xep0227: Use configured storage path
Kim Alvefur <zash@zash.se>
parents: 6696
diff changeset
10 local paths = require"util.paths";
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 local st = require "util.stanza";
5219
060d7fc6caf4 plugins/storage/mod_xep0227: Use util.xml.
Waqas Hussain <waqas20@gmail.com>
parents: 5121
diff changeset
12 local parse_xml_real = require "util.xml".parse;
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 local function getXml(user, host)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 local jid = user.."@"..host;
6697
3d27f5855f4b mod_storage_xep0227: Use configured storage path
Kim Alvefur <zash@zash.se>
parents: 6696
diff changeset
16 local path = paths.join(prosody.paths.data, jid..".xml");
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 local f = io_open(path);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 if not f then return; end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 local s = f:read("*a");
6698
95a8aeca1fc9 mod_storage_xep0227: Close file handle after reading
Kim Alvefur <zash@zash.se>
parents: 6697
diff changeset
20 f:close();
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21 return parse_xml_real(s);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 local function setXml(user, host, xml)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 local jid = user.."@"..host;
6697
3d27f5855f4b mod_storage_xep0227: Use configured storage path
Kim Alvefur <zash@zash.se>
parents: 6696
diff changeset
25 local path = paths.join(prosody.paths.data, jid..".xml");
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 if xml then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 local f = io_open(path, "w");
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 if not f then return; end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 local s = tostring(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 f:write(s);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 f:close();
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 else
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 return os_remove(path);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 local function getUserElement(xml)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 if xml and xml.name == "server-data" then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 local host = xml.tags[1];
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 if host and host.name == "host" then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 local user = host.tags[1];
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 if user and user.name == "user" then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 return user;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 local function createOuterXml(user, host)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 return st.stanza("server-data", {xmlns='http://www.xmpp.org/extensions/xep-0227.html#ns'})
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 :tag("host", {jid=host})
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 :tag("user", {name = user});
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 local function removeFromArray(array, value)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 for i,item in ipairs(array) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 if item == value then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 t_remove(array, i);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 return;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
59 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
60 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
61 local function removeStanzaChild(s, child)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 removeFromArray(s.tags, child);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 removeFromArray(s, child);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66 local handlers = {};
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68 handlers.accounts = {
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 get = function(self, user)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 local user = getUserElement(getXml(user, self.host));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 if user and user.attr.password then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 return { password = user.attr.password };
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
74 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
75 set = function(self, user, data)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 if data and data.password then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 local xml = getXml(user, self.host);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 if not xml then xml = createOuterXml(user, self.host); end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 local usere = getUserElement(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 usere.attr.password = data.password;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 return setXml(user, self.host, xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 else
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 return setXml(user, self.host, nil);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
85 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
86 };
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 handlers.vcard = {
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 get = function(self, user)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 local user = getUserElement(getXml(user, self.host));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 if user then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 local vcard = user:get_child("vCard", 'vcard-temp');
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 if vcard then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 return st.preserialize(vcard);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
95 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
96 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
97 set = function(self, user, data)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 local xml = getXml(user, self.host);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 local usere = xml and getUserElement(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 if usere then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 local vcard = usere:get_child("vCard", 'vcard-temp');
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 if vcard then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 removeStanzaChild(usere, vcard);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 elseif not data then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 if data then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 vcard = st.deserialize(data);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 usere:add_child(vcard);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 return setXml(user, self.host, xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115 };
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
116 handlers.private = {
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 get = function(self, user)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 local user = getUserElement(getXml(user, self.host));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
119 if user then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 local private = user:get_child("query", "jabber:iq:private");
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
121 if private then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122 local r = {};
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 for _, tag in ipairs(private.tags) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 r[tag.name..":"..tag.attr.xmlns] = st.preserialize(tag);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126 return r;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
128 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
129 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
130 set = function(self, user, data)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131 local xml = getXml(user, self.host);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 local usere = xml and getUserElement(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
133 if usere then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
134 local private = usere:get_child("query", 'jabber:iq:private');
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 if private then removeStanzaChild(usere, private); end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 if data and next(data) ~= nil then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
137 private = st.stanza("query", {xmlns='jabber:iq:private'});
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 for _,tag in pairs(data) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139 private:add_child(st.deserialize(tag));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 usere:add_child(private);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143 return setXml(user, self.host, xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 };
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
148
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
149 -----------------------------
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
150 local driver = {};
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
152 function driver:open(host, datastore, typ)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
153 local instance = setmetatable({}, self);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
154 instance.host = host;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
155 instance.datastore = datastore;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
156 local handler = handlers[datastore];
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157 if not handler then return nil; end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158 for key,val in pairs(handler) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159 instance[key] = val;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
160 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
161 if instance.init then instance:init(); end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
162 return instance;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
163 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
164
5121
b5a5643f8572 core.storagemanager, mod_storage_*: "data-driver" -> "storage-provider", to allow using module:provides().
Waqas Hussain <waqas20@gmail.com>
parents: 3414
diff changeset
165 module:provides("storage", driver);