Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions lib/XmppPrebind.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,29 @@ public function connect($username, $password, $route = false) {

$this->debug($this->sid, 'sid');

if(empty($body->firstChild) || empty($body->firstChild->firstChild)) {
throw new XmppPrebindConnectionException("Child not found in response from server.");
$mechanisms = null;
if(empty($body->firstChild) || empty($body->firstChild->firstChild)) {
// this is not good
} else {
$mechanisms = $body->getElementsByTagName('mechanism');
}

if(empty($mechanisms)) {
// Accorrding to https://xmpp.org/extensions/xep-0206.html
// If no <stream:features/> element is included in the connection manager's session creation response,
// then the client SHOULD send empty request elements until it receives a response containing a <stream:features/> element.
$response2 = $this->sendInitialConnection($route);
$body2 = self::getBodyFromXml($response2);
if(empty($body2->firstChild) || empty($body2->firstChild->firstChild)) {
throw new XmppPrebindConnectionException("Child not found in second response from server.");
} else {
$mechanisms = $body2->getElementsByTagName('mechanism');
}
}

if(empty($mechanisms)) {
throw new XmppPrebindConnectionException("Tag mechanism not found in response from server.");
}
$mechanisms = $body->getElementsByTagName('mechanism');

foreach ($mechanisms as $value) {
$this->mechanisms[] = $value->nodeValue;
Expand Down