Annotate

plugins/mod_storage_xep0227.lua @ 6702:6a5c6c95cf78

mod_storage_xep0227: Use the registered namespace
author Kim Alvefur <zash@zash.se>
date Fri, 15 May 2015 15:30:38 +0200
parent 6701:88a25c364a14
child 6703:353a7d4dfdc2
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");
6700
0103dc8fa179 mod_storage_xep0227: Return error from io.open if unable to open file for writing
Kim Alvefur <zash@zash.se>
parents: 6699
diff changeset
26 local f, err = io_open(path, "w");
0103dc8fa179 mod_storage_xep0227: Return error from io.open if unable to open file for writing
Kim Alvefur <zash@zash.se>
parents: 6699
diff changeset
27 if not f then return f, err; end
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 if xml then
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
6699
ccdd0b615106 mod_storage_xep0227: Open file for writing even if removing so os.remove has a file to delete
Kim Alvefur <zash@zash.se>
parents: 6698
diff changeset
34 f:close();
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 return os_remove(path);
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 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 local function getUserElement(xml)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 if xml and xml.name == "server-data" then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 local host = xml.tags[1];
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 if host and host.name == "host" then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 local user = host.tags[1];
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 if user and user.name == "user" then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 return user;
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 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 local function createOuterXml(user, host)
6702
6a5c6c95cf78 mod_storage_xep0227: Use the registered namespace
Kim Alvefur <zash@zash.se>
parents: 6701
diff changeset
50 return st.stanza("server-data", {xmlns='urn:xmpp:pie:0'})
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 :tag("host", {jid=host})
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 :tag("user", {name = user});
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
54 local function removeFromArray(array, value)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 for i,item in ipairs(array) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56 if item == value then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
57 t_remove(array, i);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
58 return;
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 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
62 local function removeStanzaChild(s, child)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
63 removeFromArray(s.tags, child);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
64 removeFromArray(s, child);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
65 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
66
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
67 local handlers = {};
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
68
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
69 handlers.accounts = {
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
70 get = function(self, user)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
71 local user = getUserElement(getXml(user, self.host));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
72 if user and user.attr.password then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
73 return { password = user.attr.password };
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 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
76 set = function(self, user, data)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
77 if data and data.password then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
78 local xml = getXml(user, self.host);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
79 if not xml then xml = createOuterXml(user, self.host); end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
80 local usere = getUserElement(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
81 usere.attr.password = data.password;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
82 return setXml(user, self.host, xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
83 else
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
84 return setXml(user, self.host, nil);
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 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
87 };
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
88 handlers.vcard = {
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
89 get = function(self, user)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
90 local user = getUserElement(getXml(user, self.host));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
91 if user then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
92 local vcard = user:get_child("vCard", 'vcard-temp');
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
93 if vcard then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
94 return st.preserialize(vcard);
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 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
98 set = function(self, user, data)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
99 local xml = getXml(user, self.host);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
100 local usere = xml and getUserElement(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
101 if usere then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
102 local vcard = usere:get_child("vCard", 'vcard-temp');
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
103 if vcard then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
104 removeStanzaChild(usere, vcard);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
105 elseif not data then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
106 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
107 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
108 if data then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
109 vcard = st.deserialize(data);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
110 usere:add_child(vcard);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
111 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
112 return setXml(user, self.host, xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
113 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
114 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
115 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
116 };
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
117 handlers.private = {
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
118 get = function(self, user)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
119 local user = getUserElement(getXml(user, self.host));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
120 if user then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
121 local private = user:get_child("query", "jabber:iq:private");
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
122 if private then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
123 local r = {};
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
124 for _, tag in ipairs(private.tags) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
125 r[tag.name..":"..tag.attr.xmlns] = st.preserialize(tag);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
126 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
127 return r;
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 end;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
131 set = function(self, user, data)
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
132 local xml = getXml(user, self.host);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
133 local usere = xml and getUserElement(xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
134 if usere then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
135 local private = usere:get_child("query", 'jabber:iq:private');
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
136 if private then removeStanzaChild(usere, private); end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
137 if data and next(data) ~= nil then
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
138 private = st.stanza("query", {xmlns='jabber:iq:private'});
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
139 for _,tag in pairs(data) do
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
140 private:add_child(st.deserialize(tag));
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
141 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
142 usere:add_child(private);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
143 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
144 return setXml(user, self.host, xml);
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
145 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
146 return true;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
147 end;
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 -----------------------------
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
151 local driver = {};
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
152
6701
88a25c364a14 mod_storage_xep0227: Update open method for current API
Kim Alvefur <zash@zash.se>
parents: 6700
diff changeset
153 function driver:open(datastore, typ)
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
154 local handler = handlers[datastore];
6701
88a25c364a14 mod_storage_xep0227: Update open method for current API
Kim Alvefur <zash@zash.se>
parents: 6700
diff changeset
155 if not handler then return nil, "unsupported-datastore"; end
88a25c364a14 mod_storage_xep0227: Update open method for current API
Kim Alvefur <zash@zash.se>
parents: 6700
diff changeset
156 local instance = setmetatable({ host = module.host; datastore = datastore; }, { __index = handler });
3414
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
157 if instance.init then instance:init(); end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
158 return instance;
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
159 end
9a1f6239b63c storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
160
5121
b5a5643f8572 core.storagemanager, mod_storage_*: "data-driver" -> "storage-provider", to allow using module:provides().
Waqas Hussain <waqas20@gmail.com>
parents: 3414
diff changeset
161 module:provides("storage", driver);