Annotate

plugins/mod_pep.lua @ 1136:506012db54e8

mod_pep: Initial commit (extremely basic implementation)
author Waqas Hussain <waqas20@gmail.com>
date Fri, 08 May 2009 01:07:35 +0500
child 1323:e1bfe7816761
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
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
10 local function publish(session, node, item)
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
11 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
12 :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
13 :tag('items', {node=node})
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
14 :add_child(item)
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
15 :up()
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
16 :up();
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
17
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
18 -- broadcast to resources
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
19 stanza.attr.to = session.username..'@'..session.host;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
20 core_route_stanza(session, stanza);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
21
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
22 -- broadcast to contacts
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
23 for jid, item in pairs(session.roster) do
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
24 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
25 stanza.attr.to = jid;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
26 core_route_stanza(session, stanza);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
27 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
28 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
29 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
30
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
31 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
32 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
33 local payload = stanza.tags[1];
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
34 if payload.name == 'pubsub' then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
35 payload = payload.tags[1];
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
36 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
37 local node = payload.attr.node;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
38 payload = payload.tags[1];
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
39 if payload then
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
40 publish(session, node, payload);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
41 return true;
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
42 end -- TODO else error
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
43 end -- TODO else error
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
44 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
45 end
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
46 origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
47 end);
506012db54e8 mod_pep: Initial commit (extremely basic implementation)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
48