3 * XMPPHP: The PHP XMPP Library
4 * Copyright (C) 2008 Nathanael C. Fritz
5 * This file is part of SleekXMPP.
7 * XMPPHP is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * XMPPHP is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XMPPHP; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
24 * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
25 * @author Michael Garvin <JID: gar@netflint.net>
26 * @copyright 2008 Nathanael C. Fritz
31 * This file is unnecessary unless you need to connect to older, non-XMPP-compliant servers like Dreamhost's.
32 * In this case, use instead of XMPPHP_XMPP, otherwise feel free to delete it.
33 * The old Jabber protocol wasn't standardized, so use at your own risk.
36 require_once "XMPP.php";
38 class XMPPHP_XMPPOld extends XMPPHP_XMPP {
43 protected $session_id;
45 public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
46 parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
47 if(!$server) $server = $host;
48 $this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">';
49 $this->fulljid = "{$user}@{$server}/{$resource}";
53 * Override XMLStream's startXML
55 * @param parser $parser
59 public function startXML($parser, $name, $attr) {
60 if($this->xml_depth == 0) {
61 $this->session_id = $attr['ID'];
62 $this->authenticate();
64 parent::startXML($parser, $name, $attr);
68 * Send Authenticate Info Request
71 public function authenticate() {
73 $this->addidhandler($id, 'authfieldshandler');
74 $this->send("<iq type='get' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username></query></iq>");
78 * Retrieve auth fields and send auth attempt
82 public function authFieldsHandler($xml) {
84 $this->addidhandler($id, 'oldAuthResultHandler');
85 if($xml->sub('query')->hasSub('digest')) {
86 $hash = sha1($this->session_id . $this->password);
87 print "{$this->session_id} {$this->password}\n";
88 $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>";
90 $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>";
97 * Determine authenticated or failure
101 public function oldAuthResultHandler($xml) {
102 if($xml->attrs['type'] != 'result') {
103 $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
105 throw new XMPPHP_Exception('Auth failed!');
107 $this->log->log("Session started");
108 $this->event('session_start');