Software /
code /
prosody
Annotate
plugins/mod_storage_xep0227.lua @ 6697:3d27f5855f4b
mod_storage_xep0227: Use configured storage path
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 15 May 2015 15:16:03 +0200 |
parent | 6696:6d717795708a |
child | 6698:95a8aeca1fc9 |
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"); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 return parse_xml_real(s); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 local function setXml(user, host, xml) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local jid = user.."@"..host; |
6697
3d27f5855f4b
mod_storage_xep0227: Use configured storage path
Kim Alvefur <zash@zash.se>
parents:
6696
diff
changeset
|
24 local path = paths.join(prosody.paths.data, jid..".xml"); |
3414
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 if xml then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 local f = io_open(path, "w"); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 if not f then return; end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 local s = tostring(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 f:write(s); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 f:close(); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 return true; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 else |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 return os_remove(path); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 end |
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 local function getUserElement(xml) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 if xml and xml.name == "server-data" then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 local host = xml.tags[1]; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 if host and host.name == "host" then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 local user = host.tags[1]; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 if user and user.name == "user" then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 return user; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 end |
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 local function createOuterXml(user, host) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 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
|
49 :tag("host", {jid=host}) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 :tag("user", {name = user}); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 local function removeFromArray(array, value) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 for i,item in ipairs(array) do |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 if item == value then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 t_remove(array, i); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 return; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 end |
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 local function removeStanzaChild(s, child) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 removeFromArray(s.tags, child); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 removeFromArray(s, child); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 local handlers = {}; |
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 handlers.accounts = { |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 get = function(self, user) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 local user = getUserElement(getXml(user, self.host)); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 if user and user.attr.password then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 return { password = user.attr.password }; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 end |
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 set = function(self, user, data) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 if data and data.password then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 local xml = getXml(user, self.host); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 if not xml then xml = createOuterXml(user, self.host); end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 local usere = getUserElement(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 usere.attr.password = data.password; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 return setXml(user, self.host, xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 else |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 return setXml(user, self.host, nil); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 end |
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 }; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 handlers.vcard = { |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 get = function(self, user) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 local user = getUserElement(getXml(user, self.host)); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 if user then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 local vcard = user:get_child("vCard", 'vcard-temp'); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 if vcard then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 return st.preserialize(vcard); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 end |
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 set = function(self, user, data) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 local xml = getXml(user, self.host); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 local usere = xml and getUserElement(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 if usere then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 local vcard = usere:get_child("vCard", 'vcard-temp'); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 if vcard then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 removeStanzaChild(usere, vcard); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 elseif not data then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 return true; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 if data then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 vcard = st.deserialize(data); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 usere:add_child(vcard); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 return setXml(user, self.host, xml); |
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 true; |
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 }; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 handlers.private = { |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 get = function(self, user) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 local user = getUserElement(getXml(user, self.host)); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 if user then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 local private = user:get_child("query", "jabber:iq:private"); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 if private then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 local r = {}; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 for _, tag in ipairs(private.tags) do |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 r[tag.name..":"..tag.attr.xmlns] = st.preserialize(tag); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 return r; |
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 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 set = function(self, user, data) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 local xml = getXml(user, self.host); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 local usere = xml and getUserElement(xml); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 if usere then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 local private = usere:get_child("query", 'jabber:iq:private'); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 if private then removeStanzaChild(usere, private); end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 if data and next(data) ~= nil then |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 private = st.stanza("query", {xmlns='jabber:iq:private'}); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 for _,tag in pairs(data) do |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 private:add_child(st.deserialize(tag)); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 usere:add_child(private); |
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 return setXml(user, self.host, xml); |
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 true; |
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 }; |
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 local driver = {}; |
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 function driver:open(host, datastore, typ) |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 local instance = setmetatable({}, self); |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 instance.host = host; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 instance.datastore = datastore; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 local handler = handlers[datastore]; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 if not handler then return nil; end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 for key,val in pairs(handler) do |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 instance[key] = val; |
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 if instance.init then instance:init(); end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 return instance; |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 end |
9a1f6239b63c
storage/mod_xep0227: Initial commit.
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 |
5121
b5a5643f8572
core.storagemanager, mod_storage_*: "data-driver" -> "storage-provider", to allow using module:provides().
Waqas Hussain <waqas20@gmail.com>
parents:
3414
diff
changeset
|
164 module:provides("storage", driver); |