queuedxmpp.php 3.9 KB

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