From d2b45506b55764632a8f02ad9c3fe0650ade7c8a Mon Sep 17 00:00:00 2001 From: fritzy Date: Mon, 7 Jul 2008 06:56:15 +0000 Subject: [PATCH] * added XMPP_Old git-svn-id: svn://netflint.net/xmpphp@46 ef36c318-a008-4979-b6e8-6b496270793b --- XMPPHP/XMPP_Old.php | 112 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 XMPPHP/XMPP_Old.php diff --git a/XMPPHP/XMPP_Old.php b/XMPPHP/XMPP_Old.php new file mode 100644 index 0000000..e1be4c7 --- /dev/null +++ b/XMPPHP/XMPP_Old.php @@ -0,0 +1,112 @@ + + * @author Stephan Wentz + * @copyright 2008 Nathanael C. Fritz + */ + +/** XMPPHP_XMPP + * + * This file is unnecessary unless you need to connect to older, non-XMPP-compliant servers like Dreamhost's. + * In this case, use instead of XMPPHP_XMPP, otherwise feel free to delete it. + * The old Jabber protocol wasn't standardized, so use at your own risk. + * + */ +require_once "XMPP.php"; + + class XMPPHP_XMPPOld extends XMPPHP_XMPP { + /** + * + * @var string + */ + protected $session_id; + + public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) { + parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel); + + } + + /** + * Override XMLStream's startXML + * + * @param parser $parser + * @param string $name + * @param array $attr + */ + protected function startXML($parser, $name, $attr) { + if($this->xml_depth == 0 and $attr['version'] != '1.0') { + print_r($attr); + $this->session_id = $attr['ID']; + $this->authenticate(); + } + parent::startXML($parser, $name, $attr); + } + + /** + * Send Authenticate Info Request + * + */ + public function authenticate() { + $id = $this->getId(); + $this->addidhandler($id, 'authfieldshandler'); + $this->send("{$this->user}"); + } + + /** + * Retrieve auth fields and send auth attempt + * + * @param XMLObj $xml + */ + public function authFieldsHandler($xml) { + $id = $this->getId(); + $this->addidhandler($id, 'oldAuthResultHandler'); + if($xml->sub('query')->hasSub('digest')) { + $hash = sha1($this->session_id . $this->password); + print "{$this->session_id} {$this->password}\n"; + $out = "{$this->user}{$hash}{$this->resource}"; + } else { + $out = "{$this->user}{$this->password}{$this->resource}"; + } + $this->send($out); + + } + + /** + * Determine authenticated or failure + * + * @param XMLObj $xml + */ + public function oldAuthResultHandler($xml) { + if($xml->attrs['type'] != 'result') { + $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR); + $this->disconnect(); + throw new XMPPHP_Exception('Auth failed!'); + } else { + $this->log->log("Session started"); + $this->event('session_start'); + } + } + } + + +?>