]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/XMPPHP/XMPP_Old.php
e5649effe348a0c985247670c75564d901b22df9
[quix0rs-gnu-social.git] / extlib / XMPPHP / XMPP_Old.php
1 <?php
2 /**
3  * XMPPHP: The PHP XMPP Library
4  * Copyright (C) 2008  Nathanael C. Fritz
5  * This file is part of SleekXMPP.
6  * 
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.
11  * 
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.
16  * 
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
20  *
21  * @category   xmpphp 
22  * @package     XMPPHP
23  * @author       Nathanael C. Fritz <JID: fritzy@netflint.net>
24  * @author       Stephan Wentz <JID: stephan@jabber.wentz.it>
25  * @copyright  2008 Nathanael C. Fritz
26  */
27
28 /** XMPPHP_XMPP 
29  *
30  * This file is unnecessary unless you need to connect to older, non-XMPP-compliant servers like Dreamhost's.
31  * In this case, use instead of XMPPHP_XMPP, otherwise feel free to delete it.
32  * The old Jabber protocol wasn't standardized, so use at your own risk.
33  *
34  */
35 require_once "XMPP.php";
36
37         class XMPPHP_XMPPOld extends XMPPHP_XMPP {
38                 /**
39                  *
40                  * @var string
41                  */
42                 protected $session_id;
43
44                 public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
45                         parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
46                         if(!$server) $server = $host;
47                         $this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">';
48                         $this->fulljid = "{$user}@{$server}/{$resource}";
49                 }
50         
51                 /**
52                  * Override XMLStream's startXML
53                  *
54                  * @param parser $parser
55                  * @param string $name
56                  * @param array $attr
57                  */
58                 public function startXML($parser, $name, $attr) {
59                         if($this->xml_depth == 0) {
60                                 $this->session_id = $attr['ID'];
61                                 $this->authenticate();
62                         }
63                         parent::startXML($parser, $name, $attr);
64                 }
65
66                 /**
67                  * Send Authenticate Info Request
68                  *
69                  */
70                 public function authenticate() {
71                         $id = $this->getId();
72                         $this->addidhandler($id, 'authfieldshandler');
73                         $this->send("<iq type='get' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username></query></iq>");
74                 }
75
76                 /**
77                  * Retrieve auth fields and send auth attempt
78                  *
79                  * @param XMLObj $xml
80                  */
81                 public function authFieldsHandler($xml) {
82                         $id = $this->getId();
83                         $this->addidhandler($id, 'oldAuthResultHandler');
84                         if($xml->sub('query')->hasSub('digest')) {
85                                 $hash = sha1($this->session_id . $this->password);
86                                 print "{$this->session_id} {$this->password}\n";
87                                 $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>";
88                         } else {
89                                 $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>";
90                         }
91                         $this->send($out);
92
93                 }
94                 
95                 /**
96                  * Determine authenticated or failure
97                  *
98                  * @param XMLObj $xml
99                  */
100                 public function oldAuthResultHandler($xml) {
101                         if($xml->attrs['type'] != 'result') {
102                                 $this->log->log("Auth failed!",  XMPPHP_Log::LEVEL_ERROR);
103                                 $this->disconnect();
104                                 throw new XMPPHP_Exception('Auth failed!');
105                         } else {
106                                 $this->log->log("Session started");
107                                 $this->event('session_start');
108                         }
109                 }
110         }
111
112
113 ?>