From 537f4aed20318392845881a31f27e30c03e75873 Mon Sep 17 00:00:00 2001 From: arthursc Date: Sun, 16 Sep 2012 21:20:35 +0300 Subject: [PATCH 1/2] Update src/php/whatsprot.class.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added Pong function (to respond on Whatsapp's PING request): http://xmpp.org/extensions/xep-0199.html#c2s server to client ping Added if statement to handle incoming PING requests in processInboundData --- src/php/whatsprot.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/php/whatsprot.class.php b/src/php/whatsprot.class.php index ba0f44fe..75a92633 100644 --- a/src/php/whatsprot.class.php +++ b/src/php/whatsprot.class.php @@ -202,6 +202,11 @@ protected function processInboundData($data) array_push($this->_messageQueue, $node); $this->sendMessageReceived($node); } + if (strcmp($node->_tag, "iq") == 0 AND strcmp($node->_attributeHash['type'], "get") == 0 AND strcmp($node->_children[0]->_tag, "ping") == 0) + { + $this->Pong($node->_attributeHash['id']); + } + $node = $this->_reader->nextTree(); } } @@ -295,6 +300,19 @@ public function MessageImage($msgid, $to, $url, $file, $size, $icon) $mediaNode = new ProtocolNode("media", $mediaAttribs, null, $icon); $this->SendMessageNode($msgid, $to, $mediaNode); } + + public function Pong($msgid) + { + $whatsAppServer = $this->_whatsAppServer; + + $messageHash = array(); + $messageHash["to"] = $whatsAppServer; + $messageHash["id"] = $msgid; + $messageHash["type"] = "result"; + + $messsageNode = new ProtocolNode("iq", $messageHash, null, ""); + $this->sendNode($messsageNode); + } protected function DebugPrint($debugMsg) { From 35de006daf9f29de56ed72daf1384f936544b717 Mon Sep 17 00:00:00 2001 From: arthursc Date: Sun, 16 Sep 2012 21:21:07 +0300 Subject: [PATCH 2/2] Update src/php/whatsprot.class.php --- src/php/whatsprot.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php/whatsprot.class.php b/src/php/whatsprot.class.php index 75a92633..cee7c8c8 100644 --- a/src/php/whatsprot.class.php +++ b/src/php/whatsprot.class.php @@ -204,7 +204,7 @@ protected function processInboundData($data) } if (strcmp($node->_tag, "iq") == 0 AND strcmp($node->_attributeHash['type'], "get") == 0 AND strcmp($node->_children[0]->_tag, "ping") == 0) { - $this->Pong($node->_attributeHash['id']); + $this->Pong($node->_attributeHash['id']); } $node = $this->_reader->nextTree();