--- a/TODO Mon Mar 16 18:54:16 2009 +0200
+++ b/TODO Mon Mar 16 19:57:51 2009 +0200
@@ -16,4 +16,5 @@
common pubsub infrastructure, in particular, xmlns-based event handlers?
forms abandoning hook to inform server
eliminate main.parse_args?
+common disco routines should get connection object from outer space - no mcabber dependency, the same for forms parsing, pep sending (though it anyway needs to be converted to pubsub)...
--- a/examples/xep0030.lua Mon Mar 16 18:54:16 2009 +0200
+++ b/examples/xep0030.lua Mon Mar 16 19:57:51 2009 +0200
@@ -1,5 +1,5 @@
-function disco_items ( callback, what, node )
+function disco_items ( connection, callback, what, node )
local request =
lm.message.create { to = what, mtype = 'iq-get',
query = { xmlns = 'http://jabber.org/protocol/disco#items' }
@@ -7,7 +7,7 @@
if node then
request:child( 'query' ):attribute ( 'node', node )
end
- return lm.connection.bless( main.connection () ):send ( request,
+ return connection:send ( request,
function ( conn, message )
if message:child ( 'error' ) then
callback ( message:child( 'error' ):children():name () )
@@ -26,8 +26,8 @@
end )
end
-function disco_info ( callback, what )
- return lm.connection.bless( main.connection () ):send (
+function disco_info ( connection, callback, what )
+ return connection:send (
lm.message.create { to = what, mtype = 'iq-get',
query = { xmlns='http://jabber.org/protocol/disco#info' }
},
@@ -56,6 +56,7 @@
main.command ( 'disco',
function ( args )
local who
+ local conn = lm.connection.bless ( main.connection () )
if args.t then
who = args.t
else
@@ -63,7 +64,7 @@
end
if args[1] == 'items' then
local node = args[2]
- disco_items (
+ disco_items ( conn,
function ( items )
if type ( items ) == 'string' then
main.print_info ( who, ("Items service discovery for %s (%s) failed: %s"):format ( who, node or '', items ) )
@@ -80,7 +81,7 @@
end
end, who, node )
else
- disco_info (
+ disco_info ( conn,
function ( identities, features )
if type ( identities ) == 'string' then
main.print_info ( who, ("Info service discovery for %s failed: %s"):format ( who, identities ) )
@@ -109,6 +110,6 @@
end
end, true, 'jid' )
-commands_help['disco'] = "[-t target_jid] [info | items] [node]\n\nService discovery request.\nInfo is sent if omitted.\nIf info reveals, that buddy can do items, items request also will be sent."
+commands_help['disco'] = "[-t target_jid] [info | items] [node]\n\nService discovery request.\nInfo is sent if omitted."
-- vim: se ts=4: --
--- a/examples/xep0146.lua Mon Mar 16 18:54:16 2009 +0200
+++ b/examples/xep0146.lua Mon Mar 16 19:57:51 2009 +0200
@@ -49,7 +49,7 @@
end
local action = args[1]
if not action then
- disco_items (
+ disco_items ( lm.connection.bless ( main.connection (),
function ( items )
if type ( items ) == 'string' then
main.print_info ( who, string.format ( "Service items discovery for %s (http://jabber.org/protocol/commands) failed: %s", who, items ) )
--- a/examples/xep0163.lua Mon Mar 16 18:54:16 2009 +0200
+++ b/examples/xep0163.lua Mon Mar 16 19:57:51 2009 +0200
@@ -72,8 +72,15 @@
end
end
-function pep_publish ( node, data )
- local conn = lm.connection.bless ( main.connection () )
+function pep_publish ( conn, callback, node, data )
+ if not callback then
+ callback =
+ function ( mesg )
+ if mesg then
+ print ( mesg ) -- FIXME
+ end
+ end
+ end
data.xmlns = 'http://jabber.org/protocol/' .. node -- this may modify original data? imo it does not matter.
if conn:status () == 'authenticated' then
-- local bjid = conn:jid():gsub ( '/.*', '' )
@@ -101,12 +108,13 @@
function ( conn, mess )
local mtype, smtype = mess:type ()
if smtype == 'result' then
+ callback ()
return true
elseif smtype == 'error' then
- print ( 'Error publishing to ' .. node .. ': ' .. mess:xml () ) -- FIXME
+ callback ( message:child( 'error' ):children():name () )
return true
else
- print ( 'Weird ansver to publishing request: ' .. mess:xml () )
+ callback ( 'Weird ansver to publishing request: ' .. mess:xml () )
return false
end
end )
@@ -226,7 +234,7 @@
function mpd_callback ()
local sdata = mpd_getstatus ()
if sdata then
- pep_publish ( 'tune', sdata )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'tune', sdata )
end
if tune_enabled then
return true
@@ -277,7 +285,7 @@
if mood then
data[mood] = { }
end
- pep_publish ( 'mood', data )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'mood', data )
end, true )
main.command ( 'activity',
function ( args )
@@ -296,7 +304,7 @@
data[act][subact] = { }
end
end
- pep_publish ( 'activity', data )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'activity', data )
end, true )
main.command ( 'location',
function ( args )
@@ -304,7 +312,7 @@
for key, val in pairs ( args ) do
data[key] = { val }
end
- pep_publish ( 'geoloc', data )
+ pep_publish ( lm.connection.bless ( main.connection () ), nil, 'geoloc', data )
end, true )
commands_help['tune'] = "[enable|disable|on|off|yes|no|true|false]\n\nEnables or disables publishing of notifications about playing music in your player (currently only mpd is supported)."