]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Xmpp/Fake_XMPP.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / plugins / Xmpp / Fake_XMPP.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Instead of sending XMPP messages, retrieve the raw XML that would be sent
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Network
23  * @package   StatusNet
24  * @author    Brion Vibber <brion@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 class Fake_XMPP extends XMPPHP_XMPP
35 {
36     public $would_be_sent = null;
37
38         /**
39          * Constructor
40          *
41          * @param string  $host
42          * @param integer $port
43          * @param string  $user
44          * @param string  $password
45          * @param string  $resource
46          * @param string  $server
47          * @param boolean $printlog
48          * @param string  $loglevel
49          */
50         public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null)
51         {
52         parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
53
54         // We use $host to connect, but $server to build JIDs if specified.
55         // This seems to fix an upstream bug where $host was used to build
56         // $this->basejid, never seen since it isn't actually used in the base
57         // classes.
58         if (!$server) {
59             $server = $this->host;
60         }
61         $this->basejid = $this->user . '@' . $server;
62
63         // Normally the fulljid is filled out by the server at resource binding
64         // time, but we need to do it since we're not talking to a real server.
65         $this->fulljid = "{$this->basejid}/{$this->resource}";
66     }
67
68     /**
69      * Send a formatted message to the outgoing queue for later forwarding
70      * to a real XMPP connection.
71      *
72      * @param string $msg
73      */
74     public function send($msg, $timeout=NULL)
75     {
76         $this->would_be_sent = $msg;
77     }
78
79     //@{
80     /**
81      * Stream i/o functions disabled; only do output
82      */
83     public function connect($timeout = 30, $persistent = false, $sendinit = true)
84     {
85         throw new Exception("Can't connect to server from fake XMPP.");
86     }
87
88     public function disconnect()
89     {
90         throw new Exception("Can't connect to server from fake XMPP.");
91     }
92
93     public function process()
94     {
95         throw new Exception("Can't read stream from fake XMPP.");
96     }
97
98     public function processUntil($event, $timeout=-1)
99     {
100         throw new Exception("Can't read stream from fake XMPP.");
101     }
102
103     public function read()
104     {
105         throw new Exception("Can't read stream from fake XMPP.");
106     }
107
108     public function readyToProcess()
109     {
110         throw new Exception("Can't read stream from fake XMPP.");
111     }
112     //@}
113 }
114