* @revision 01 * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons Attribution-Share Alike 3.0 Germany * @homepage http://oss.tiggerswelt.net/xmpp * @copyright Copyright © 2011 tiggersWelt.net **/ require_once ('tiggerXMPP/extension.php'); /** * Ad-Hoc Commands (XEP-0050) * * @package tiggerXMPP * @class tiggerXMPP_XEP_0050 * @extends tiggerXMPP_Extension * @revision 01 * @author Bernd Holzmueller **/ class tiggerXMPP_XEP_0050 extends tiggerXMPP_Extension { const XEP_NAMESPACE = 'http://jabber.org/protocol/commands'; private $commandHandler = null; // {{{ getTags /** * Retrive the tags handle by this extension * * @param string $NS (optional) * * @access public * @return array **/ public function getTags ($NS = null) { return array ('command'); } // }}} // {{{ handle /** * Handle an incoming packet for us * * @param object $Tag Incoming packet data * * @access public * @return object */ public function handle ($Tag) { // Handle Command-Tag if ($Tag->getName () == 'command') { if (!is_object ($P = $Tag->getParent ())) return false; switch ($Tag->getAttribute ('action', 'execute')) { case 'execute': return $this->executeCommand ($Tag, $P->getAttribute ('to'), $Tag->getAttribute ('node'), $P->getAttribute ('from')); } } return false; } // }}} // {{{ executeCommand /** * Start execution of a command * * @param object $Tag * @param string $JID * @param string $Command * @param string $Receipient (optional) * * @access protected * @return object **/ protected function executeCommand ($Tag, $JID, $Cmd, $Receipient = null) { // Set inital result $rc = false; // Forward to generic command handler if ($this->commandHandler !== null) $rc = call_user_func ($this->commandHandler, $this, $Tag, $JID, $Cmd, $Receipient); $Command = new tiggerXMPP_Packet ('command'); $Command->setNamespace (self::XEP_NAMESPACE); $Command->setAttribute ('node', $Cmd); if ($rc === true) $Command->setAttribute ('status', 'completed'); elseif (($rc === null) && false) $Command->setAttribute ('status', 'executing'); else $Command->setAttribute ('status', 'canceled'); return $Command; } // }}} // {{{ setCommandHandler /** * Define generic callback-function * * @access public * @return bool **/ public function setCommandHandler ($Callback) { if (!is_callable ($Callback)) return false; $this->commandHandler = $Callback; return true; } // }}} } ?>