Annotate

plugins/mod_pep.lua @ 1324:dc64a841f0c2

mod_pep: Fix undefined global access
author Waqas Hussain <waqas20@gmail.com>
date Sun, 07 Jun 2009 17:39:34 +0500
parent 1323:e1bfe7816761
child 1325:b58645973d7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
1
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
2 local jid_bare = require "util.jid".bare;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
3 local jid_split = require "util.jid".split;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
4 local st = require "util.stanza";
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
5 local hosts = hosts;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
6 local user_exists = require "core.usermanager".user_exists;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
8 local pairs, ipairs = pairs, ipairs;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
9
1323
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
10 local data = {};
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
11
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
12 local function publish(session, node, item)
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
13 local stanza = st.message({from=session.full_jid, type='headline'})
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'})
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 :tag('items', {node=node})
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 :add_child(item)
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17 :up()
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 :up();
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19
1323
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
20 local bare = session.username..'@'..session.host;
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
21 -- store for the future
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
22 local user_data = data[bare];
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
23 if not user_data then user_data = {}; data[bare] = user_data; end
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
24 user_data[node] = stanza;
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
25
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 -- broadcast to resources
1323
e1bfe7816761 mod_pep: Maintain user nodes for delayed delivery
Waqas Hussain <waqas20@gmail.com>
parents: 1136
diff changeset
27 stanza.attr.to = bare;
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 core_route_stanza(session, stanza);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30 -- broadcast to contacts
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 for jid, item in pairs(session.roster) do
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
32 if jid and jid ~= "pending" and (item.subscription == 'from' or item.subscription == 'both') then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
33 stanza.attr.to = jid;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 core_route_stanza(session, stanza);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
37 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 module:add_iq_handler("c2s", "http://jabber.org/protocol/pubsub", function (session, stanza)
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 local payload = stanza.tags[1];
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 if payload.name == 'pubsub' then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 payload = payload.tags[1];
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 if payload and payload.name == 'publish' and payload.attr.node then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 local node = payload.attr.node;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 payload = payload.tags[1];
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 if payload then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48 publish(session, node, payload);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
49 return true;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
50 end -- TODO else error
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
51 end -- TODO else error
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
52 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
53 end
1324
dc64a841f0c2 mod_pep: Fix undefined global access
Waqas Hussain <waqas20@gmail.com>
parents: 1323
diff changeset
54 session.send(st.error_reply(stanza, "cancel", "service-unavailable"));
1136
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
55 end);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
56