Software /
code /
prosody
Annotate
plugins/mod_private.lua @ 310:b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 16 Nov 2008 04:39:48 +0500 |
parent | 185:a67c88ce1c6a |
child | 421:63be85693710 |
rev | line source |
---|---|
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local st = require "util.stanza" |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 local jid_split = require "util.jid".split; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 local datamanager = require "util.datamanager" |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 add_iq_handler("c2s", "jabber:iq:private", |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 function (session, stanza) |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 local type = stanza.attr.type; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local query = stanza.tags[1]; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 if (type == "get" or type == "set") and query.name == "query" then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local node, host = jid_split(stanza.attr.to); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 if not(node or host) or (node == session.username and host == session.host) then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 node, host = session.username, session.host; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 if #query.tags == 1 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 local tag = query.tags[1]; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local key = tag.name..":"..tag.attr.xmlns; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local data = datamanager.load(node, host, "private"); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 if stanza.attr.type == "get" then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 if data and data[key] then |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
21 session.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key]))); |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
23 session.send(st.reply(stanza):add_child(stanza.tags[1])); |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 else -- set |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 if not data then data = {}; end; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 if #tag == 0 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 data[key] = nil; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 data[key] = st.preserialize(tag); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 -- TODO delete datastore if empty |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 if datamanager.store(node, host, "private", data) then |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
34 session.send(st.reply(stanza)); |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
36 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
40 session.send(st.error_reply(stanza, "modify", "bad-format")); |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
43 session.send(st.error_reply(stanza, "cancel", "forbidden")); |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 end |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
46 end); |