queuedxmpp.php 3.7 KB

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