--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/mc_oob.lua Fri Mar 27 12:06:19 2009 +0200
@@ -0,0 +1,59 @@
+
+local lm = require 'lm'
+local oob = require 'oob'
+
+oob.handler (
+ function ( from, url, desc, success, fail )
+ if desc then
+ main.print_info ( from, 'Buddy wants you to download link: ' .. url .. ' (' .. desc .. ')' )
+ else
+ main.print_info ( from, 'Buddy wants you to download link: ' .. url )
+ end
+ success ()
+ end )
+
+main.command ( 'oob',
+ function ( args )
+ local who
+ if args.t then
+ who = args.t
+ else
+ who = main.full_jid ()
+ end
+ -- here we can run something external to put file on server and obtain link to it
+ oob.send ( lm.connection.bless ( main.connection () ), who, args[1],
+ function ()
+ main.print_info ( who, 'OOB link accepted' )
+ end,
+ function ( mesg )
+ main.print_info ( who, 'OOB link refused: ' .. mesg )
+ end, args[2] )
+ end, true )
+
+local oob_iq_handler = lm.message_handler.new ( oob.iq_handler )
+local oob_message_handler = lm.message_handler.new ( oob.message_handler )
+local oob_handler_registered = false
+
+hooks_d['hook-post-connect'].oob =
+ function ( args )
+ local conn = lm.connection.bless ( main.connection () )
+ conn:handler ( oob_iq_handler, 'iq', 'normal' )
+ conn:handler ( oob_message_handler, 'message', 'normal' )
+ conn:handler ( oob_message_handler, 'presence', 'normal' )
+ oob_handler_registered = true
+ hooks_d['hook-post-connect'].oob = nil
+ hooks_d['hook-quit'].oob =
+ function ( args )
+ if oob_handler_registered then
+ local conn = lm.connection.bless ( main.connection () )
+ conn:handler ( oob_iq_handler, 'iq' )
+ conn:handler ( oob_message_handler, 'message' )
+ conn:handler ( oob_message_handler, 'presence' )
+ end
+ end
+ end
+
+main.add_feature ( 'jabber:iq:oob' )
+main.add_feature ( 'jabber:x:oob' )
+
+-- vim: se ts=4: --