Software /
code /
prosody
Annotate
plugins/mod_private.lua @ 2923:b7049746bd29
Update copyright headers for 2010
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 22 Mar 2010 17:06:15 +0000 |
parent | 1523:841d61be198f |
child | 3114:75ea1aff69da |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local st = require "util.stanza" |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 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
|
14 local datamanager = require "util.datamanager" |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
16 module:add_feature("jabber:iq:private"); |
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
310
diff
changeset
|
17 |
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
421
diff
changeset
|
18 module:add_iq_handler("c2s", "jabber:iq:private", |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 function (session, stanza) |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local type = stanza.attr.type; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 local query = stanza.tags[1]; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 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
|
23 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
|
24 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
|
25 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
|
26 if #query.tags == 1 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 local tag = query.tags[1]; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 else |
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):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
|
35 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 else -- set |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 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
|
38 if #tag == 0 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 data[key] = nil; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 data[key] = st.preserialize(tag); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 -- TODO delete datastore if empty |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 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
|
45 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
|
46 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
47 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
|
48 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
51 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
|
52 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
54 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
|
55 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 end |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
57 end); |