]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/queued_xmpp.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / lib / queued_xmpp.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Queue-mediated proxy class for outgoing XMPP messages.
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 require_once INSTALLDIR . '/lib/jabber.php';
35
36 class Queued_XMPP extends XMPPHP_XMPP
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                 // Normally the fulljid isn't filled out until resource binding time;
54                 // we need to save it here since we're not talking to a real server.
55                 $this->fulljid = "{$this->basejid}/{$this->resource}";
56     }
57
58     /**
59      * Send a formatted message to the outgoing queue for later forwarding
60      * to a real XMPP connection.
61      *
62      * @param string $msg
63      */
64     public function send($msg, $timeout=NULL)
65     {
66         $qm = QueueManager::get();
67         $qm->enqueue(strval($msg), 'xmppout');
68     }
69
70     /**
71      * Since we'll be getting input through a queue system's run loop,
72      * we'll process one standalone message at a time rather than our
73      * own XMPP message pump.
74      *
75      * @param string $message
76      */
77     public function processMessage($message) {
78        $frame = array_shift($this->frames);
79        xml_parse($this->parser, $frame->body, false);
80     }
81
82     //@{
83     /**
84      * Stream i/o functions disabled; push input through processMessage()
85      */
86     public function connect($timeout = 30, $persistent = false, $sendinit = true)
87     {
88         throw new Exception("Can't connect to server from XMPP queue proxy.");
89     }
90
91     public function disconnect()
92     {
93         throw new Exception("Can't connect to server from XMPP queue proxy.");
94     }
95
96     public function process()
97     {
98         throw new Exception("Can't read stream from XMPP queue proxy.");
99     }
100
101     public function processUntil($event, $timeout=-1)
102     {
103         throw new Exception("Can't read stream from XMPP queue proxy.");
104     }
105
106     public function read()
107     {
108         throw new Exception("Can't read stream from XMPP queue proxy.");
109     }
110
111     public function readyToProcess()
112     {
113         throw new Exception("Can't read stream from XMPP queue proxy.");
114     }
115     //@}
116 }
117