Software /
code /
prosody
Annotate
plugins/mod_private.lua @ 3366:a2a242321901
util.sasl, util.sasl_cyrus: Use method:mechanisms() in method:select(), instead of using the mechanisms list directly (fixes a traceback).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 14 Jul 2010 20:21:51 +0500 |
parent | 3114:75ea1aff69da |
child | 3522:4646b5b039ca |
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; |
3114
75ea1aff69da
mod_private: Detect datamanager read errors, and respond with 'internal-server-error'.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
29 local data, err = datamanager.load(node, host, "private"); |
75ea1aff69da
mod_private: Detect datamanager read errors, and respond with 'internal-server-error'.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
30 if err then |
75ea1aff69da
mod_private: Detect datamanager read errors, and respond with 'internal-server-error'.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
31 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
75ea1aff69da
mod_private: Detect datamanager read errors, and respond with 'internal-server-error'.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
32 return true; |
75ea1aff69da
mod_private: Detect datamanager read errors, and respond with 'internal-server-error'.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
33 end |
185
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
38 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
|
39 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 else -- set |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 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
|
42 if #tag == 0 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 data[key] = nil; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 data[key] = st.preserialize(tag); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 -- TODO delete datastore if empty |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 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
|
49 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
|
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, "wait", "internal-server-error")); |
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 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
55 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
|
56 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 else |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
58 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
|
59 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 end |
310
b28b51746fe7
Fixed mod_private to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
185
diff
changeset
|
61 end); |