-- OUT OF BAND DATA (XEP-0066)
-- library
local lm = require 'lm'
local iq = require 'lm.iq'
--
local O = {
handler =
function ( from, url, desc, success, fail )
fail ()
end,
}
local F = { }
function F.send ( conn, to, url, success, fail, desc )
if desc then
desc = { desc }
end
iq.send ( conn, to, 'set',
{
query = { xmlns = 'jabber:iq:oob',
url = { url },
desc = desc,
},
}, success, fail )
end
function F.handler ( handler )
O.handler = handler
end
function F.iq_handler ( conn, mess )
local mtype, smtype = mess:type ()
if smtype == 'set' then
local query = mess:child ( 'query' )
if query and query:attribute ( 'xmlns' ) == 'jabber:iq:oob' then
local from = mess:attribute ( 'from' )
local url = query:child( 'url' ):value ()
local desc = query:child( 'desc' )
if desc then
desc = desc:value ()
end
O.handler ( from, url, desc,
function ()
conn:send ( lm.message.create { mtype = 'iq-result', to = from, id = mess:attribute ( 'id' ) } )
end,
function () -- XXX distinguish download error and reject
conn:send (
lm.message.create { mype = 'iq-error', to = from, id = mess:attribute ( 'id' ),
-- XXX must we include query here?
error = { code = '406', type = 'modify',
['not-acceptable'] = { xmlns = 'urn:ietf:params:xml:ns:xmpp-stanzas' },
},
} )
end )
return true
end
end
return false
end
function F.message_handler ( conn, mess )
local x = mess:child ( 'x' )
if x and x:attribute ( 'xmlns' ) == 'jabber:x:oob' then
local from = mess:attribute ( 'from' )
local url = x:child( 'url' ):value ()
local desc = x:child( 'desc' )
if desc then
desc = desc:value ()
end
O.handler ( from, url, desc,
function ()
end,
function ()
end )
end
return false
end
return F
-- vim: se ts=4: --