queuedxmpp.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 7
  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. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once dirname(__DIR__) . '/extlib/XMPPHP/XMPP.php';
  33. use XMPPHP\XMPP;
  34. class QueuedXMPP extends XMPP
  35. {
  36. /**
  37. * Reference to the XmppPlugin object we're hooked up to.
  38. */
  39. public $plugin;
  40. /**
  41. * Constructor
  42. *
  43. * @param XmppPlugin $plugin
  44. * @param string $host
  45. * @param integer $port
  46. * @param string $user
  47. * @param string $password
  48. * @param string $resource
  49. * @param string $server
  50. * @param boolean $printlog
  51. * @param string $loglevel
  52. */
  53. public function __construct($plugin, $host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null)
  54. {
  55. $this->plugin = $plugin;
  56. parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
  57. // We use $host to connect, but $server to build JIDs if specified.
  58. // This seems to fix an upstream bug where $host was used to build
  59. // $this->basejid, never seen since it isn't actually used in the base
  60. // classes.
  61. if (!$server) {
  62. $server = $this->host;
  63. }
  64. $this->basejid = $this->user . '@' . $server;
  65. // Normally the fulljid is filled out by the server at resource binding
  66. // time, but we need to do it since we're not talking to a real server.
  67. $this->fulljid = "{$this->basejid}/{$this->resource}";
  68. }
  69. /**
  70. * Send a formatted message to the outgoing queue for later forwarding
  71. * to a real XMPP connection.
  72. *
  73. * @param string $msg
  74. * @param null $timeout
  75. */
  76. public function send($msg, $timeout = NULL)
  77. {
  78. @$this->plugin->enqueueOutgoingRaw($msg);
  79. }
  80. //@{
  81. /**
  82. * Stream i/o functions disabled; only do output
  83. * @param int $timeout
  84. * @param bool $persistent
  85. * @param bool $sendinit
  86. * @throws Exception
  87. */
  88. public function connect($timeout = 30, $persistent = false, $sendinit = true)
  89. {
  90. // No i18n needed. Test message.
  91. throw new Exception('Cannot connect to server from fake XMPP.');
  92. }
  93. public function disconnect()
  94. {
  95. // No i18n needed. Test message.
  96. throw new Exception('Cannot connect to server from fake XMPP.');
  97. }
  98. public function process()
  99. {
  100. // No i18n needed. Test message.
  101. throw new Exception('Cannot read stream from fake XMPP.');
  102. }
  103. public function processUntil($event, $timeout = -1)
  104. {
  105. // No i18n needed. Test message.
  106. throw new Exception('Cannot read stream from fake XMPP.');
  107. }
  108. public function read()
  109. {
  110. // No i18n needed. Test message.
  111. throw new Exception('Cannot read stream from fake XMPP.');
  112. }
  113. public function readyToProcess()
  114. {
  115. // No i18n needed. Test message.
  116. throw new Exception('Cannot read stream from fake XMPP.');
  117. }
  118. //@}
  119. }