Software /
code /
prosody
Annotate
plugins/mod_private.lua @ 258:a93ccd84db83
Yep, s2s definitely works now. This is just a small fix for logging...
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 14 Nov 2008 02:38:41 +0000 |
parent | 185:a67c88ce1c6a |
child | 310:b28b51746fe7 |
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 local send = require "core.sessionmanager".send_to_session |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 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
|
6 local datamanager = require "util.datamanager" |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 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
|
9 function (session, stanza) |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local type = stanza.attr.type; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local query = stanza.tags[1]; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 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
|
13 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
|
14 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
|
15 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
|
16 if #query.tags == 1 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 local tag = query.tags[1]; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 if data and data[key] then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 send(session, st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key]))); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 send(session, st.reply(stanza):add_child(stanza.tags[1])); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 else -- set |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 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
|
28 if #tag == 0 then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 data[key] = nil; |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 data[key] = st.preserialize(tag); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 end |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 -- TODO delete datastore if empty |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 if datamanager.store(node, host, "private", data) then |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 send(session, st.reply(stanza)); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 send(session, st.error_reply(stanza, "wait", "internal-server-error")); |
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 end |
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 send(session, st.error_reply(stanza, "modify", "bad-format")); |
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 else |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 send(session, st.error_reply(stanza, "cancel", "forbidden")); |
a67c88ce1c6a
Added support for XEP-0049: Private XML Storage (mod_private)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 end |
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 end); |