Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
1135:355f9487ab38 | 1136:506012db54e8 |
---|---|
1 | |
2 local jid_bare = require "util.jid".bare; | |
3 local jid_split = require "util.jid".split; | |
4 local st = require "util.stanza"; | |
5 local hosts = hosts; | |
6 local user_exists = require "core.usermanager".user_exists; | |
7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | |
8 local pairs, ipairs = pairs, ipairs; | |
9 | |
10 local function publish(session, node, item) | |
11 local stanza = st.message({from=session.full_jid, type='headline'}) | |
12 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) | |
13 :tag('items', {node=node}) | |
14 :add_child(item) | |
15 :up() | |
16 :up(); | |
17 | |
18 -- broadcast to resources | |
19 stanza.attr.to = session.username..'@'..session.host; | |
20 core_route_stanza(session, stanza); | |
21 | |
22 -- broadcast to contacts | |
23 for jid, item in pairs(session.roster) do | |
24 if jid and jid ~= "pending" and (item.subscription == 'from' or item.subscription == 'both') then | |
25 stanza.attr.to = jid; | |
26 core_route_stanza(session, stanza); | |
27 end | |
28 end | |
29 end | |
30 | |
31 module:add_iq_handler("c2s", "http://jabber.org/protocol/pubsub", function (session, stanza) | |
32 if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then | |
33 local payload = stanza.tags[1]; | |
34 if payload.name == 'pubsub' then | |
35 payload = payload.tags[1]; | |
36 if payload and payload.name == 'publish' and payload.attr.node then | |
37 local node = payload.attr.node; | |
38 payload = payload.tags[1]; | |
39 if payload then | |
40 publish(session, node, payload); | |
41 return true; | |
42 end -- TODO else error | |
43 end -- TODO else error | |
44 end | |
45 end | |
46 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | |
47 end); | |
48 |