* @revision 05 * @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 © 2009 tiggersWelt.net */ require_once ('tiggerXMPP/stream.php'); require_once ('phpEvents/socket/stream/xml/tag.php'); class tiggerXMPP_Client extends tiggerXMPP_Stream { // {{{ __construct /** * Create a new XMPP Client * * @param string $Domain Domain to connect to * @param string $Server (optional) Manually specify server * @param int $Port (optional) Manually specify port on server * @param enum $Debug (optional) Set initial debug-value * * @access public * @return void * @see tiggerXMPP_Stream::__construct */ public function __construct ($Domain, $Server = "", $Port = null, $Debug = null) { parent::__construct ($Domain, $Server, $Port, self::STREAM_TYPE_CLIENT, $Debug); } // }}} // {{{ authenticate /** * Authenticate with server * * @param string $Username Username to authenticate with * @param stirng $Password Passwort to authenticate with * @param string $Ressource (optional) Ressource to bind to * * @access public * @return bool * @todo Implement SASL-Authentication */ public function authenticate ($Username, $Password, $Ressource = 'tiggerXMPP') { $this->setAuthenticator (array ($this, 'startAuthenticator'), $Username, $Password, $Ressource); } // }}} // {{{ startAuthenticator /** * Start the authentication-process for clients * * @param string $Password * @param string $Username * * @access protected * @return bool **/ protected function startAuthenticator ($Username, $Password, $Ressource) { self::__debug (self::DEBUG_DEBUG, 'called.', __FUNCTION__, __LINE__, __CLASS__, __FILE__); // TODO: Implement SASL-Auth here? // Do jabber:iq:auth (XEP-0078) $Resp = new phpEvents_Socket_Stream_XML_Tag ('iq'); $Resp->setDestination ($this->Domain); $Resp->setAttribute ('type', 'get'); $Resp->setAttribute ('id', 'auth1'); $tagQuery = new phpEvents_Socket_Stream_XML_Tag ('query', $Resp); $tagQuery->setNamespace ('jabber:iq:auth'); $tagUsername = new phpEvents_Socket_Stream_XML_Tag ('username', $tagQuery, $Username); self::sendXML ($Resp); $Resp = self::waitBlock (array (), 'auth1'); if (!is_object ($tagQuery = $Resp->getSubtagByName ('query'))) return self::__debug (self::DEBUG_ERROR, 'Invalid response received', __FUNCTION__, __LINE__, __CLASS__, __FILE__, false); if ($tagQuery->haveSubtags ('digest')) { $Tag = 'digest'; $Value = strtolower (sha1 ($this->ConnectionID . $Password)); } elseif ($tagQuery->haveSubtags ('password')) { $Tag = 'password'; $Value = $Password; } else return self::__debug (self::DEBUG_ERROR, 'No supported authentication-mechanisms', __FUNCTION__, __LINE__, __CLASS__, __FILE__, false); $Resp = new phpEvents_Socket_Stream_XML_Tag ('iq'); $Resp->setAttribute ('type', 'set'); $Resp->setAttribute ('id', 'auth2'); $tagQuery = new phpEvents_Socket_Stream_XML_Tag ('query', $Resp)); $tagQuery->setNamespace ('jabber:iq:auth'); $tagUsername = new phpEvents_Socket_Stream_XML_Tag ('username', $tagQuery, $Username); $tagAuth = new phpEvents_Socket_Stream_XML_Tag ($Tag, $tagQuery, $Value); $tagRessource = new phpEvents_Socket_Stream_XML_Tag ('resource', $tagQuery, $Ressource); self::sendXML ($Resp); $Resp = self::waitBlock (array (), 'auth2'); if ($Resp->getAttribute ('type') == 'result') { $this->Username = $Username; $this->Ressource = $Ressource; $this->authenticationSuccess (); return true; } $this->authenticationFailure (); return self::__debug (self::DEBUG_ERROR, 'Authentication failed', __FUNCTION__, __LINE__, __CLASS__, __FILE__, false); } // }}} } ?>