From 21abba87b27433cebf09e19b32eefcb575647d02 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Mon, 21 Oct 2013 19:45:00 +0000 Subject: [PATCH] throw an exception when server doesn't give us list of mechanisms (otherwise we get a fatal error) --- lib/XmppPrebind.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/XmppPrebind.php b/lib/XmppPrebind.php index 8110ba7..f9323c1 100644 --- a/lib/XmppPrebind.php +++ b/lib/XmppPrebind.php @@ -133,7 +133,12 @@ public function connect($username, $password) { $this->sid = $body->getAttribute('sid'); $this->debug($this->sid, 'sid'); - $mechanisms = $body->firstChild->firstChild->getElementsByTagName('mechanism'); + $child = $body->firstChild->firstChild; + if (is_object($child)) { + $mechanisms = $child->getElementsByTagName('mechanism'); + } else { + throw new Exception('Invalid response'); + } foreach ($mechanisms as $value) { $this->mechanisms[] = $value->nodeValue; @@ -617,4 +622,4 @@ protected function getAndIncrementRid() { */ class XmppPrebindException extends Exception{} -class XmppPrebindConnectionException extends XmppPrebindException {} \ No newline at end of file +class XmppPrebindConnectionException extends XmppPrebindException {}