XMPP_Old.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * XMPPHP: The PHP XMPP Library
  4. * Copyright (C) 2008 Nathanael C. Fritz
  5. * This file is part of SleekXMPP.
  6. *
  7. * XMPPHP is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * XMPPHP is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with XMPPHP; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category xmpphp
  22. * @package XMPPHP
  23. * @author Nathanael C. Fritz <JID: fritzy@netflint.net>
  24. * @author Stephan Wentz <JID: stephan@jabber.wentz.it>
  25. * @author Michael Garvin <JID: gar@netflint.net>
  26. * @copyright 2008 Nathanael C. Fritz
  27. */
  28. /** XMPPHP_XMPP
  29. *
  30. * This file is unnecessary unless you need to connect to older, non-XMPP-compliant servers like Dreamhost's.
  31. * In this case, use instead of XMPPHP_XMPP, otherwise feel free to delete it.
  32. * The old Jabber protocol wasn't standardized, so use at your own risk.
  33. *
  34. */
  35. require_once "XMPP.php";
  36. class XMPPHP_XMPPOld extends XMPPHP_XMPP {
  37. /**
  38. *
  39. * @var string
  40. */
  41. protected $session_id;
  42. public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
  43. parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
  44. if(!$server) $server = $host;
  45. $this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">';
  46. $this->fulljid = "{$user}@{$server}/{$resource}";
  47. }
  48. /**
  49. * Override XMLStream's startXML
  50. *
  51. * @param parser $parser
  52. * @param string $name
  53. * @param array $attr
  54. */
  55. public function startXML($parser, $name, $attr) {
  56. if($this->xml_depth == 0) {
  57. $this->session_id = $attr['ID'];
  58. $this->authenticate();
  59. }
  60. parent::startXML($parser, $name, $attr);
  61. }
  62. /**
  63. * Send Authenticate Info Request
  64. *
  65. */
  66. public function authenticate() {
  67. $id = $this->getId();
  68. $this->addidhandler($id, 'authfieldshandler');
  69. $this->send("<iq type='get' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username></query></iq>");
  70. }
  71. /**
  72. * Retrieve auth fields and send auth attempt
  73. *
  74. * @param XMLObj $xml
  75. */
  76. public function authFieldsHandler($xml) {
  77. $id = $this->getId();
  78. $this->addidhandler($id, 'oldAuthResultHandler');
  79. if($xml->sub('query')->hasSub('digest')) {
  80. $hash = sha1($this->session_id . $this->password);
  81. print "{$this->session_id} {$this->password}\n";
  82. $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>";
  83. } else {
  84. $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>";
  85. }
  86. $this->send($out);
  87. }
  88. /**
  89. * Determine authenticated or failure
  90. *
  91. * @param XMLObj $xml
  92. */
  93. public function oldAuthResultHandler($xml) {
  94. if($xml->attrs['type'] != 'result') {
  95. $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
  96. $this->disconnect();
  97. throw new XMPPHP_Exception('Auth failed!');
  98. } else {
  99. $this->log->log("Session started");
  100. $this->event('session_start');
  101. }
  102. }
  103. }
  104. ?>