* @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/component/jabberd2.php'); /** * XMPP Jabberd2 Logger * -------------------- * Basic logging-sink for jabberd2 * * @class tiggerXMPP_Component_Jabberd2 * @extends tiggerXMPP_Component * @author Bernd Holzmueller **/ class tiggerXMPP_Component_Jabberd2_Logger extends tiggerXMPP_Component_Jabberd2 { /* Direction of a packet */ const DIRECTION_IN = 'IN'; const DIRECTION_OUT = 'OUT'; // {{{ authenticate /** * Authenticate with server * * @param string $Password Passwort to authenticate with * @param string $Username (optional) * @param int $Options (optional) * * @access public * @return bool */ public function authenticate ($Password, $Username = 'jabberd', $Options = self::COMPONENT_OPTIONS_LOG) { return parent::authenticate ($Password, $Username, $Options); } // }}} // {{{ handleRouterPacket /** * Handle an incoming packet from the jabberd2-router * * @param object $Tag * @param object $Response * * @access protected * @return mixed **/ protected function handleRouterPacket ($Tag, $Response) { // Check for directed packet if ($this->boundDomain ($Tag->getAttribute ('to'))) return parent::handleRouterPacket ($Tag, $Response); // Ignore packets from ourself if ($this->boundDomain ($Tag->getAttribute ('from'))) return null; // Ignore non-log-packets here if ($Tag->getAttribute ('type') != 'log') return null; // Forward payloads to logger-targets foreach ($Tag->getSubtags () as $Type=>$Tags) foreach ($Tags as $Subtag) { // Check the sender again if ($this->boundDomain ($Subtag->getAttribute ('from'))) continue; switch ($Subtag->getName ()) { case 'message': $this->logMessage ($Subtag); break; case 'iq': $this->logIQ ($Subtag); break; case 'presence': $this->logPresence ($Subtag); break; default: $this->__debug (self::DEBUG_ERROR, 'Unknown packet: ' . $Subtag->getName (), __FUNCTION__, __LINE__, __CLASS__, __FILE__, false); } } return null; } // }}} // {{{ getDirection /** * Retrive the direction of a logged packet * * @param object $Tag * * @access protected * @return enum **/ protected function getDirection ($Tag) { // Retrive the route-packet if (!is_object ($P =$Tag->getParent ())) return false; if ($P->getName () != 'route') return false; // Get the address-labels $rFromDomain = $this->getJID (false, true, false, $P->getAttribute ('from')); $rToDomain = $this->getJID (false, true, false, $P->getAttribute ('to')); $pFromDomain = $this->getJID (false, true, false, $Tag->getAttribute ('from')); $pToDomain = $this->getJID (false, true, false, $Tag->getAttribute ('to')); // Packets withour from-Domain likely come from c2s-links and are ignored here if (strlen ($pFromDomain) == 0) return false; // Determine Direction if ($pFromDomain == $pToDomain) { return ($rFromDomain == $rToDomain ? self::DIRECTION_OUT : self::DIRECTION_IN); } elseif ($rFromDomain == $pFromDomain) return self::DIRECTION_OUT; elseif ($rFromDomain == $pToDomain) return self::DIRECTION_IN; return $this->__debug (self::DEBUG_DEBUG, 'DIRERR ' . $rFromDomain . ' -> ' . $rToDomain . ' / ' . $pFromDomain . ' -> ' . $pToDomain, __FUNCTION__, __LINE__, __CLASS__, __FILE__, false); } // }}} // {{{ getOwner /** * Retrive JID of the owner of a packet * * @param object $Tag * @param enum $Direction (optional) * * @access protected * @return string **/ protected function getOwner ($Tag, $Direction = null) { if ($Direction === null) $Direction = $this->getDirection ($Tag); if ($Direction == self::DIRECTION_OUT) return $Tag->getAttribute ('from'); if ($Direction == self::DIRECTION_IN) return $Tag->getAttribute ('to'); return false; } // }}} // {{{ getOpponent /** * Retrive JID of the opponent from a packet * * @param object $Tag * @param enum $Direction (optional) * * @remark This is like getOwner(), but just in reverse * @access protected * @return string **/ protected function getOpponent ($Tag, $Direction = null) { if ($Direction === null) $Direction = $this->getDirection ($Tag); if ($Direction == self::DIRECTION_OUT) return $Tag->getAttribute ('to'); if ($Direction == self::DIRECTION_IN) return $Tag->getAttribute ('from'); return false; } // }}} // {{{ logMessage /** * Log an incoming message * * @param object $Tag * * @access protected * @return void **/ protected function logMessage ($Tag) { # Unused here } // }}} // {{{ logPresence /** * Log an incoming presence-packet * * @param object $Tag * * @access protected * @return void **/ protected function logPresence ($Tag) { # Unused here } // }}} // {{{ logIQ /** * Log an incoming IQ-Stanza * * @param object $Tag * * @access protected * @return void **/ protected function logIQ ($Tag) { # Unused here } // }}} } ?>