author | Myhailo Danylenko <isbear@ukrpost.net> |
Mon, 23 Mar 2009 05:06:15 +0200 | |
changeset 61 | 5182f466da7d |
parent 59 | 4660c4f10ef1 |
child 64 | bf7521ed96eb |
permissions | -rw-r--r-- |
46 | 1 |
|
2 |
-- PERSONAL EVENTING PROTOCOL (XEP-0163) |
|
3 |
||
4 |
-- library |
|
5 |
||
6 |
require 'lm' |
|
7 |
require 'iq' |
|
8 |
||
9 |
-- public |
|
10 |
||
11 |
pep = { |
|
12 |
handlers = {}, |
|
13 |
} |
|
14 |
||
56
8561e55e0662
Pep updates for avatar
Myhailo Danylenko <isbear@ukrpost.net>
parents:
46
diff
changeset
|
15 |
function pep.publish ( conn, node, item, success, fail ) |
46 | 16 |
-- local bjid = conn:jid():gsub ( '/.*', '' ) |
56
8561e55e0662
Pep updates for avatar
Myhailo Danylenko <isbear@ukrpost.net>
parents:
46
diff
changeset
|
17 |
-- item.id = 'current' |
46 | 18 |
iq.send ( conn, nil, 'set', |
19 |
{ |
|
20 |
pubsub = { xmlns = 'http://jabber.org/protocol/pubsub', |
|
56
8561e55e0662
Pep updates for avatar
Myhailo Danylenko <isbear@ukrpost.net>
parents:
46
diff
changeset
|
21 |
publish = { node = node, |
8561e55e0662
Pep updates for avatar
Myhailo Danylenko <isbear@ukrpost.net>
parents:
46
diff
changeset
|
22 |
item = item, |
46 | 23 |
}, |
24 |
}, |
|
25 |
--[[ |
|
26 |
configure = { |
|
27 |
x = { |
|
28 |
field = {{ type = "hidden", var = 'FORM_TYPE', |
|
29 |
value = { 'http://jabber.org/protocol/pubsub#node_config' }, |
|
30 |
},{ var = "pubsub#access_model", |
|
31 |
value = { 'presence' }, |
|
32 |
}}, |
|
33 |
}, |
|
34 |
}, |
|
35 |
--]] |
|
36 |
}, success, fail ) |
|
37 |
end |
|
38 |
||
39 |
-- private |
|
40 |
||
41 |
-- XXX in fact, it is not a pep handler, it is pubsub handler. |
|
42 |
-- should it go there? |
|
43 |
local pep_incoming_message_handler = lm.message_handler.new ( |
|
44 |
function ( conn, mess ) |
|
45 |
local e = mess:child ( 'event' ) |
|
46 |
if e and e:attribute ( 'xmlns' ) == 'http://jabber.org/protocol/pubsub#event' then |
|
47 |
local is = e:child ( 'items' ) |
|
48 |
if is then |
|
49 |
local from = mess:attribute ( 'from' ) |
|
50 |
local node = is:attribute ( 'node' ) |
|
51 |
local item = is:child ( 'item' ) |
|
52 |
if item then |
|
53 |
local handled = true -- XXX should we do this? well, if it becomes general pubsub handler - then no. |
|
54 |
local n = item:children () |
|
55 |
while n do |
|
56 |
local xmlns = n:attribute ( 'xmlns' ) |
|
57 |
if pep.handlers[xmlns] then |
|
58 |
if not pep.handlers[xmlns] ( from, node, n ) then |
|
59 |
handled = false |
|
60 |
end |
|
61 |
else |
|
62 |
handled = false |
|
63 |
end |
|
64 |
n = n:next () |
|
65 |
end |
|
66 |
return handled |
|
67 |
end |
|
68 |
end |
|
69 |
end |
|
70 |
return false |
|
71 |
end ) |
|
72 |
||
73 |
-- mcabber |
|
74 |
||
59 | 75 |
local pep_handler_registered = false |
46 | 76 |
|
77 |
hooks_d['hook-post-connect'].pep = |
|
78 |
function ( args ) |
|
79 |
lm.connection.bless( main.connection () ):handler ( pep_incoming_message_handler, 'message', 'normal' ) |
|
80 |
pep_handler_registered = true |
|
59 | 81 |
hooks_d['hook-post-connect'].pep = nil |
46 | 82 |
hooks_d['hook-quit'].pep = |
83 |
function ( args ) |
|
84 |
if pep_handler_registered then |
|
85 |
lm.connection.bless( main.connection () ):handler ( pep_incoming_message_handler, 'message' ) |
|
86 |
pep_handler_registered = false |
|
87 |
end |
|
88 |
end |
|
89 |
end |
|
90 |
||
91 |
-- vim: se ts=4: -- |