How to use getChild method of data class

Best Atoum code snippet using data.getChild

MessageHandler.php

Source:MessageHandler.php Github

copy

Full Screen

...30 31 if ($this->node->hasChild('x') && $this->parent->getLastId() == $this->node->getAttribute('id')) { 32 $this->parent->sendNextMessage(); 33 } 34 if ($this->parent->getNewMsgBind() && ($this->node->getChild('body') || $this->node->getChild('media'))) { 35 $this->parent->getNewMsgBind()->process($this->node); 36 } 37 if ($this->node->getAttribute('type') == 'text' && ($this->node->getChild('body') != null || $this->node->getChild('enc') != null)) { 38 $this->processMessageNode($this->node); 39 } 40 if ($this->node->getAttribute('type') == 'media' && ($this->node->getChild('media') != null || $this->node->getChild('enc') != null)) { 41 $file_data = ''; 42 if ($this->node->getChild('enc') != null && $this->node->getAttribute('participant') == null) { // for now only private messages 43 44 $dec_node = null; 45 if (extension_loaded('curve25519') && extension_loaded('protobuf')) { 46 $dec_node = $this->processEncryptedNode($this->node); 47 } 48 if ($dec_node) { 49 $this->node = $dec_node; 50 if ($dec_node->getChild('media') != null) { 51 $file_data = $dec_node->getChild('media')->getAttribute('file'); 52 } 53 } 54 } elseif (($this->node->getChild('enc') == null) && ($this->node->getChild('media')->getAttribute('url') != null)) { 55 $file_data = file_get_contents($this->node->getChild('media')->getAttribute('url')); 56 } 57 58 if ($this->node->getChild('enc') != null && $this->node->getChild('enc')->getAttribute('mediatype') == 'url') { 59 $this->parent->eventManager()->fire('onGetMessage', 60 [ 61 $this->phoneNumber, 62 $this->node->getAttribute('from'), 63 $this->node->getAttribute('id'), 64 $this->node->getAttribute('type'), 65 $this->node->getAttribute('t'), 66 $this->node->getAttribute('notify'), 67 $this->node->getChild('body')->getData(), 68 ]); 69 } 70 71 if ($this->node->getChild('media') != null) { 72 if ($this->node->getChild('media')->getAttribute('type') == 'image') { 73 if ($this->node->getAttribute('participant') == null) { 74 $this->parent->eventManager()->fire('onGetImage', 75 [ 76 $this->phoneNumber, 77 $this->node->getAttribute('from'), 78 $this->node->getAttribute('id'), 79 $this->node->getAttribute('type'), 80 $this->node->getAttribute('t'), 81 $this->node->getAttribute('notify'), 82 $this->node->getChild('media')->getAttribute('size'), 83 $this->node->getChild('media')->getAttribute('url'), 84 $file_data, 85 $this->node->getChild('media')->getAttribute('mimetype'), 86 $this->node->getChild('media')->getAttribute('filehash'), 87 $this->node->getChild('media')->getAttribute('width'), 88 $this->node->getChild('media')->getAttribute('height'), 89 $this->node->getChild('media')->getData(), 90 $this->node->getChild('media')->getAttribute('caption'), 91 ]); 92 } else { 93 $this->parent->eventManager()->fire('onGetGroupImage', 94 [ 95 $this->phoneNumber, 96 $this->node->getAttribute('from'), 97 $this->node->getAttribute('participant'), 98 $this->node->getAttribute('id'), 99 $this->node->getAttribute('type'), 100 $this->node->getAttribute('t'), 101 $this->node->getAttribute('notify'), 102 $this->node->getChild('media')->getAttribute('size'), 103 $this->node->getChild('media')->getAttribute('url'), 104 $this->node->getChild('media')->getAttribute('file'), 105 $this->node->getChild('media')->getAttribute('mimetype'), 106 $this->node->getChild('media')->getAttribute('filehash'), 107 $this->node->getChild('media')->getAttribute('width'), 108 $this->node->getChild('media')->getAttribute('height'), 109 $this->node->getChild('media')->getData(), 110 $this->node->getChild('media')->getAttribute('caption'), 111 ]); 112 } 113 114 $msgId = $this->parent->createIqId(); 115 $ackNode = new ProtocolNode('ack', 116 [ 117 'url' => $this->node->getChild('media')->getAttribute('url'), 118 ], null, null); 119 120 $iqNode = new ProtocolNode('iq', 121 [ 122 'id' => $msgId, 123 'xmlns' => 'w:m', 124 'type' => 'set', 125 'to' => Constants::WHATSAPP_SERVER, 126 ], [$ackNode], null); 127 128 $this->parent->sendNode($iqNode); 129 } elseif ($this->node->getChild('media')->getAttribute('type') == 'video') { 130 if ($this->node->getAttribute('participant') == null) { 131 $this->parent->eventManager()->fire('onGetVideo', 132 [ 133 $this->phoneNumber, 134 $this->node->getAttribute('from'), 135 $this->node->getAttribute('id'), 136 $this->node->getAttribute('type'), 137 $this->node->getAttribute('t'), 138 $this->node->getAttribute('notify'), 139 $this->node->getChild('media')->getAttribute('url'), 140 $this->node->getChild('media')->getAttribute('file'), 141 $this->node->getChild('media')->getAttribute('size'), 142 $this->node->getChild('media')->getAttribute('mimetype'), 143 $this->node->getChild('media')->getAttribute('filehash'), 144 $this->node->getChild('media')->getAttribute('duration'), 145 $this->node->getChild('media')->getAttribute('vcodec'), 146 $this->node->getChild('media')->getAttribute('acodec'), 147 $this->node->getChild('media')->getData(), 148 $this->node->getChild('media')->getAttribute('caption'), 149 $this->node->getChild('media')->getAttribute('width'), 150 $this->node->getChild('media')->getAttribute('height'), 151 $this->node->getChild('media')->getAttribute('fps'), 152 $this->node->getChild('media')->getAttribute('vbitrate'), 153 $this->node->getChild('media')->getAttribute('asampfreq'), 154 $this->node->getChild('media')->getAttribute('asampfmt'), 155 $this->node->getChild('media')->getAttribute('abitrate'), 156 ]); 157 } else { 158 $this->parent->eventManager()->fire('onGetGroupVideo', 159 [ 160 $this->phoneNumber, 161 $this->node->getAttribute('from'), 162 $this->node->getAttribute('participant'), 163 $this->node->getAttribute('id'), 164 $this->node->getAttribute('type'), 165 $this->node->getAttribute('t'), 166 $this->node->getAttribute('notify'), 167 $this->node->getChild('media')->getAttribute('url'), 168 $this->node->getChild('media')->getAttribute('file'), 169 $this->node->getChild('media')->getAttribute('size'), 170 $this->node->getChild('media')->getAttribute('mimetype'), 171 $this->node->getChild('media')->getAttribute('filehash'), 172 $this->node->getChild('media')->getAttribute('duration'), 173 $this->node->getChild('media')->getAttribute('vcodec'), 174 $this->node->getChild('media')->getAttribute('acodec'), 175 $this->node->getChild('media')->getData(), 176 $this->node->getChild('media')->getAttribute('caption'), 177 $this->node->getChild('media')->getAttribute('width'), 178 $this->node->getChild('media')->getAttribute('height'), 179 $this->node->getChild('media')->getAttribute('fps'), 180 $this->node->getChild('media')->getAttribute('vbitrate'), 181 $this->node->getChild('media')->getAttribute('asampfreq'), 182 $this->node->getChild('media')->getAttribute('asampfmt'), 183 $this->node->getChild('media')->getAttribute('abitrate'), 184 ]); 185 } 186 } elseif ($this->node->getChild('media')->getAttribute('type') == 'audio') { 187 if ($this->node->getAttribute('participant') == null) { 188 $this->parent->eventManager()->fire('onGetAudio', 189 [ 190 $this->phoneNumber, 191 $this->node->getAttribute('from'), 192 $this->node->getAttribute('id'), 193 $this->node->getAttribute('type'), 194 $this->node->getAttribute('t'), 195 $this->node->getAttribute('notify'), 196 $this->node->getChild('media')->getAttribute('size'), 197 $this->node->getChild('media')->getAttribute('url'), 198 $this->node->getChild('media')->getAttribute('file'), 199 $this->node->getChild('media')->getAttribute('mimetype'), 200 $this->node->getChild('media')->getAttribute('filehash'), 201 $this->node->getChild('media')->getAttribute('seconds'), 202 $this->node->getChild('media')->getAttribute('acodec'), 203 ]); 204 } else { 205 $this->parent->eventManager()->fire('onGetGroupAudio', 206 [ 207 $this->phoneNumber, 208 $this->node->getAttribute('from'), 209 $this->node->getAttribute('participant'), 210 $this->node->getAttribute('id'), 211 $this->node->getAttribute('type'), 212 $this->node->getAttribute('t'), 213 $this->node->getAttribute('notify'), 214 $this->node->getChild('media')->getAttribute('size'), 215 $this->node->getChild('media')->getAttribute('url'), 216 $this->node->getChild('media')->getAttribute('file'), 217 $this->node->getChild('media')->getAttribute('mimetype'), 218 $this->node->getChild('media')->getAttribute('filehash'), 219 $this->node->getChild('media')->getAttribute('seconds'), 220 $this->node->getChild('media')->getAttribute('acodec'), 221 ]); 222 } 223 } elseif ($this->node->getChild('media')->getAttribute('type') == 'vcard') { 224 if ($this->node->getChild('media')->hasChild('vcard')) { 225 $name = $this->node->getChild('media')->getChild('vcard')->getAttribute('name'); 226 $data = $this->node->getChild('media')->getChild('vcard')->getData(); 227 } else { 228 $name = 'NO_NAME'; 229 $data = $this->node->getChild('media')->getData(); 230 } 231 232 if ($this->node->getAttribute('participant') == null) { 233 $this->parent->eventManager()->fire('onGetvCard', 234 [ 235 $this->phoneNumber, 236 $this->node->getAttribute('from'), 237 $this->node->getAttribute('id'), 238 $this->node->getAttribute('type'), 239 $this->node->getAttribute('t'), 240 $this->node->getAttribute('notify'), 241 $name, 242 $data, 243 ]); 244 } else { 245 $this->parent->eventManager()->fire('onGetGroupvCard', 246 [ 247 $this->phoneNumber, 248 $this->node->getAttribute('from'), 249 $this->node->getAttribute('participant'), 250 $this->node->getAttribute('id'), 251 $this->node->getAttribute('type'), 252 $this->node->getAttribute('t'), 253 $this->node->getAttribute('notify'), 254 $name, 255 $data, 256 ]); 257 } 258 } elseif ($this->node->getChild('media')->getAttribute('type') == 'location') { 259 $url = $this->node->getChild('media')->getAttribute('url'); 260 $name = $this->node->getChild('media')->getAttribute('name'); 261 if ($this->node->getAttribute('participant') == null) { 262 $this->parent->eventManager()->fire('onGetLocation', 263 [ 264 $this->phoneNumber, 265 $this->node->getAttribute('from'), 266 $this->node->getAttribute('id'), 267 $this->node->getAttribute('type'), 268 $this->node->getAttribute('t'), 269 $this->node->getAttribute('notify'), 270 $name, 271 $this->node->getChild('media')->getAttribute('longitude'), 272 $this->node->getChild('media')->getAttribute('latitude'), 273 $url, 274 $this->node->getChild('media')->getData(), 275 ]); 276 } else { 277 $this->parent->eventManager()->fire('onGetGroupLocation', 278 [ 279 $this->phoneNumber, 280 $this->node->getAttribute('from'), 281 $this->node->getAttribute('participant'), 282 $this->node->getAttribute('id'), 283 $this->node->getAttribute('type'), 284 $this->node->getAttribute('t'), 285 $this->node->getAttribute('notify'), 286 $name, 287 $this->node->getChild('media')->getAttribute('longitude'), 288 $this->node->getChild('media')->getAttribute('latitude'), 289 $url, 290 $this->node->getChild('media')->getData(), 291 ]); 292 } 293 } 294 } 295 296 //Read receipt for media messages 297 if ($this->parent->getReadReceipt()) { 298 $this->parent->sendReceipt($this->node, 'read', $this->node->getAttribute('participant')); 299 } else { 300 $this->parent->sendReceipt($this->node, 'receipt', $this->node->getAttribute('participant')); 301 } 302 } 303 if ($this->node->getChild('received') != null) { 304 $this->parent->eventManager()->fire('onMessageReceivedClient', 305 [ 306 $this->phoneNumber, 307 $this->node->getAttribute('from'), 308 $this->node->getAttribute('id'), 309 $this->node->getAttribute('type'), 310 $this->node->getAttribute('t'), 311 $this->node->getAttribute('participant'), 312 ]); 313 } 314 } 315 316 protected function processMessageNode(ProtocolNode $node) 317 { 318 //encrypted node 319 if ($node->getChild('enc') != null) { 320 if (extension_loaded('curve25519') && extension_loaded('protobuf')) { 321 $ack = new ProtocolNode('ack', ['to' => $node->getAttribute('from'), 'class' => 'message', 'id' => $node->getAttribute('id'), 't' => $node->getAttribute('t')], null, null); 322 $this->parent->sendNode($ack); 323 $dec_node = $this->processEncryptedNode($node); 324 if ($dec_node instanceof ProtocolNode) { 325 $node = $dec_node; 326 } 327 } 328 } 329 if ($node) { 330 $author = $node->getAttribute('participant'); 331 if ($author == '') { 332 // Single chats 333 if ($node->hasChild('body')) { 334 if ($this->parent->getReadReceipt()) { 335 $this->parent->sendReceipt($node, 'read', $author); 336 } else { 337 $this->parent->sendReceipt($this->node, 'receipt', $author); 338 } 339 340 $this->parent->eventManager()->fire('onGetMessage', 341 [ 342 $this->phoneNumber, 343 $node->getAttribute('from'), 344 $node->getAttribute('id'), 345 $node->getAttribute('type'), 346 $node->getAttribute('t'), 347 $node->getAttribute('notify'), 348 $node->getChild('body')->getData(), 349 ]); 350 351 if ($this->parent->getMessageStore() !== null) { 352 $this->parent->getMessageStore()->saveMessage(ExtractNumber($node->getAttribute('from')), $this->phoneNumber, $node->getChild('body')->getData(), $node->getAttribute('id'), $node->getAttribute('t')); 353 } 354 } 355 } else { 356 //group chat message 357 if ($node->hasChild('body')) { 358 if ($this->parent->getReadReceipt()) { 359 $this->parent->sendReceipt($node, 'read', $author); 360 } else { 361 $this->parent->sendReceipt($this->node, 'receipt', $this->node->getAttribute('participant')); 362 } 363 364 $this->parent->eventManager()->fire('onGetGroupMessage', 365 [ 366 $this->phoneNumber, 367 $node->getAttribute('from'), 368 $author, 369 $node->getAttribute('id'), 370 $node->getAttribute('type'), 371 $node->getAttribute('t'), 372 $node->getAttribute('notify'), 373 $node->getChild('body')->getData(), 374 ]); 375 if ($this->parent->getMessageStore() !== null) { 376 $this->parent->getMessageStore()->saveMessage($author, $node->getAttribute('from'), $node->getChild('body')->getData(), $node->getAttribute('id'), $node->getAttribute('t')); 377 } 378 } 379 } 380 } 381 } 382 383 /** 384 * @param ProtocolNode $node 385 * 386 * @return null|ProtocolNode 387 */ 388 protected function processEncryptedNode(ProtocolNode $node) 389 { 390 if ($this->parent->getAxolotlStore() == null) { 391 return; 392 } 393 //is a chat encrypted message 394 $from = $node->getAttribute('from'); 395 if (strpos($from, Constants::WHATSAPP_SERVER) !== false) { 396 $author = ExtractNumber($node->getAttribute('from')); 397 398 $version = $node->getChild(0)->getAttribute('v'); 399 $encType = $node->getChild(0)->getAttribute('type'); 400 $encMsg = $node->getChild('enc')->getData(); 401 if (!$this->parent->getAxolotlStore()->containsSession($author, 1)) { 402 //we don't have the session to decrypt, save it in pending and process it later 403 $this->parent->addPendingNode($node); 404 $this->parent->logFile('info', 'Requesting cipher keys from {from}', ['from' => $author]); 405 $this->parent->sendGetCipherKeysFromUser($author); 406 } else { 407 //decrypt the message with the session 408 if ($node->getChild('enc')->getAttribute('count') == '') { 409 $this->parent->setRetryCounter($node->getAttribute('id'), 1); 410 } 411 412 if ($version == '2') { 413 if (!in_array($author, $this->parent->getv2Jids())) { 414 $this->parent->setv2Jids($author); 415 } 416 } 417 418 $plaintext = $this->decryptMessage($from, $encMsg, $encType, $node->getAttribute('id'), $node->getAttribute('t')); 419 420 //$plaintext ="A"; 421 if ($plaintext === false) { 422 $this->parent->sendRetry($this->node, $from, $node->getAttribute('id'), $node->getAttribute('t')); 423 $this->parent->logFile('info', 'Couldn\'t decrypt message with {id} id from {from}. Retrying...', ['id' => $node->getAttribute('id'), 'from' => ExtractNumber($from)]); 424 425 return $node; // could not decrypt 426 } 427 if (isset($this->parent->retryNodes[$node->getAttribute('id')])) { 428 unset($this->parent->retryNodes[$node->getAttribute('id')]); 429 } 430 if (isset($this->parent->retryCounters[$node->getAttribute('id')])) { 431 unset($this->parent->retryCounters[$node->getAttribute('id')]); 432 } 433 switch ($node->getAttribute('type')) { 434 case 'text': 435 $node->addChild(new ProtocolNode('body', null, null, $plaintext)); 436 break; 437 case 'media': 438 439 switch ($node->getChild('enc')->getAttribute('mediatype')) { 440 case 'image': 441 $image = new ImageMessage(); 442 $image->parseFromString($plaintext); 443 $keys = (new HKDFv3())->deriveSecrets($image->getRefKey(), hex2bin('576861747341707020496d616765204b657973'), 112); 444 $iv = substr($keys, 0, 16); 445 $keys = substr($keys, 16); 446 $parts = str_split($keys, 32); 447 $key = $parts[0]; 448 $macKey = $parts[1]; 449 $refKey = $parts[2]; 450 451 //should be changed to nice curl, no extra headers :D 452 $file_enc = file_get_contents($image->getUrl()); 453 //requires mac check , last 10 chars 454 $mac = substr($file_enc, -10); 455 $cipherImage = substr($file_enc, 0, strlen($file_enc) - 10); 456 $decrypted_image = pkcs5_unpad(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cipherImage, MCRYPT_MODE_CBC, $iv)); 457 //$save_file = tempnam(sys_get_temp_dir(),"WAIMG_"); 458 //file_put_contents($save_file,$decrypted_image); 459 $child = new ProtocolNode('media', 460 [ 461 'size' => $image->getLength(), 462 'caption' => $image->getCaption(), 463 'url' => $image->getUrl(), 464 'mimetype' => $image->getMimeType(), 465 'filehash' => bin2hex($image->getSha256()), 466 'width' => 0, 467 'height' => 0, 468 'file' => $decrypted_image ?: $file_enc, 469 'type' => 'image', 470 ], null, $image->getThumbnail()); 471 $node->addChild($child); 472 break; 473 case 'location': 474 $location = new Location(); 475 $data = $node->getChild('enc')->getData(); 476 $location->parseFromString($plaintext); 477 $child = new ProtocolNode('media', 478 [ 479 'type' => 'location', 480 'encoding' => 'raw', 481 'latitude' => $location->getLatitude(), 482 'longitude' => $location->getLongitude(), 483 'name' => $location->getName(), 484 'url' => $location->getUrl(), 485 ], null, $location->getThumbnail()); 486 $node->addChild($child); 487 break; 488 case 'url': 489 $mediaUrl = new MediaUrl(); 490 $mediaUrl->parseFromString($plaintext); 491 $node->addChild(new ProtocolNode('body', null, null, $mediaUrl->getMessage())); 492 break; 493 case 'document': 494 $document = new DocumentMessage(); 495 $a = ord($plaintext[0]); 496 //prepad? 497 if (substr($plaintext, 0, $a) == str_repeat($plaintext[0], $a)) { 498 $plaintext = substr($plaintext, $a); 499 } 500 $document->parseFromString($plaintext); 501 502 $keys = (new HKDFv3())->deriveSecrets($document->getRefKey(), hex2bin('576861747341707020446f63756d656e74204b657973'), 112); 503 $iv = substr($keys, 0, 16); 504 $keys = substr($keys, 16); 505 $parts = str_split($keys, 32); 506 $key = $parts[0]; 507 $macKey = $parts[1]; 508 $refKey = $parts[2]; 509 //should be changed to nice curl, no extra headers :D 510 $file_enc = file_get_contents($document->getUrl()); 511 //requires mac check , last 10 chars 512 $mac = substr($file_enc, -10); 513 $cipherDocument = substr($file_enc, 0, strlen($file_enc) - 10); 514 $uncrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cipherDocument, MCRYPT_MODE_CBC, $iv); 515 $decrypted_document = pkcs5_unpad($uncrypted); 516 file_put_contents('/tmp/'.$document->getFilename(), $decrypted_document); 517 if (strlen($document->getThumbnail() > 0)) { 518 //is posible to not have thumbnail 519 file_put_contents('/tmp/'.$document->getName(), $document->getThumbnail()); 520 } 521 break; 522 } 523 break; 524 525 } 526 $this->parent->logFile('info', 'Decrypted message with {id} from {from}', ['id' => $node->getAttribute('id'), 'from' => ExtractNumber($from)]); 527 528 return $node; 529 } 530 } 531 //is a group encrypted message 532 else { 533 $author = ExtractNumber($node->getAttribute('participant')); 534 $group_number = ExtractNumber($node->getAttribute('from')); 535 $childs = $node->getChildren(); 536 foreach ($childs as $child) { 537 if ($child->getAttribute('type') == 'pkmsg' || $child->getAttribute('type') == 'msg') { 538 if (!$this->parent->getAxolotlStore()->containsSession($author, 1)) { 539 $this->parent->addPendingNode($node); 540 541 $this->parent->sendGetCipherKeysFromUser($author); 542 break; 543 } else { 544 545 //decrypt senderKey and save it 546 $encType = $child->getAttribute('type'); 547 $encMsg = $child->getData(); 548 $from = $node->getAttribute('participant'); 549 $version = $child->getAttribute('v'); 550 if ($node->getChild('enc')->getAttribute('count') == '') { 551 $this->parent->setRetryCounter($node->getAttribute('id'), 1); 552 } 553 554 if ($version == '2') { 555 if (!in_array($author, $this->parent->getv2Jids())) { 556 $this->parent->setv2Jids($author); 557 } 558 } 559 $skip_unpad = $node->getChild('enc', ['type' => 'skmsg']) == null; 560 $senderKeyBytes = $this->decryptMessage($from, $encMsg, $encType, $node->getAttribute('id'), $node->getAttribute('t'), $node->getAttribute('from'), $skip_unpad); 561 if ($senderKeyBytes) { 562 if (!$skip_unpad) { 563 $senderKeyGroupMessage = new SenderKeyGroupMessage(); 564 $senderKeyGroupMessage->parseFromString($senderKeyBytes); 565 } else { 566 $senderKeyGroupMessage = new SenderKeyGroupData(); 567 try { 568 $senderKeyGroupMessage->parseFromString($senderKeyBytes); 569 } catch (Exception $ex) { 570 try { 571 $senderKeyGroupMessage->parseFromString(substr($senderKeyBytes, 0, -1)); 572 } catch (Exception $ex) { 573 return $node; ...

Full Screen

Full Screen

IqHandler.php

Source:IqHandler.php Github

copy

Full Screen

...24 } 25 26 public function Process() 27 { 28 if ($this->node->getChild('query') != null) { 29 if (isset($this->parent->getNodeId()['privacy']) && ($this->parent->getNodeId()['privacy'] == $this->node->getAttribute('id'))) { 30 $listChild = $this->node->getChild(0)->getChild(0); 31 $blockedJids = []; 32 foreach ($listChild->getChildren() as $child) { 33 $blockedJids[] = $child->getAttribute('value'); 34 } 35 $this->parent->eventManager()->fire('onGetPrivacyBlockedList', 36 [ 37 $this->phoneNumber, 38 $blockedJids, 39 ]); 40 41 return; 42 } 43 } 44 45 if ($this->node->getAttribute('type') == 'get' 46 && $this->node->getAttribute('xmlns') == 'urn:xmpp:ping') { 47 $this->parent->eventManager()->fire('onPing', 48 [ 49 $this->phoneNumber, 50 $this->node->getAttribute('id'), 51 ]); 52 $this->parent->sendPong($this->node->getAttribute('id')); 53 } 54 55 if ($this->node->getChild('sync') != null) { 56 57 //sync result 58 $sync = $this->node->getChild('sync'); 59 $existing = $sync->getChild('in'); 60 $nonexisting = $sync->getChild('out'); 61 62 //process existing first 63 $existingUsers = []; 64 if (!empty($existing)) { 65 foreach ($existing->getChildren() as $child) { 66 $existingUsers[$child->getData()] = $child->getAttribute('jid'); 67 } 68 } 69 70 //now process failed numbers 71 $failedNumbers = []; 72 if (!empty($nonexisting)) { 73 foreach ($nonexisting->getChildren() as $child) { 74 $failedNumbers[] = str_replace('+', '', $child->getData()); 75 } 76 } 77 78 $index = $sync->getAttribute('index'); 79 80 $result = new SyncResult($index, $sync->getAttribute('sid'), $existingUsers, $failedNumbers); 81 82 $this->parent->eventManager()->fire('onGetSyncResult', 83 [ 84 $result, 85 ]); 86 } 87 88 if ($this->node->getChild('props') != null) { 89 //server properties 90 $props = []; 91 foreach ($this->node->getChild(0)->getChildren() as $child) { 92 $props[$child->getAttribute('name')] = $child->getAttribute('value'); 93 } 94 $this->parent->eventManager()->fire('onGetServerProperties', 95 [ 96 $this->phoneNumber, 97 $this->node->getChild(0)->getAttribute('version'), 98 $props, 99 ]); 100 } 101 if ($this->node->getChild('picture') != null) { 102 $this->parent->eventManager()->fire('onGetProfilePicture', 103 [ 104 $this->phoneNumber, 105 $this->node->getAttribute('from'), 106 $this->node->getChild('picture')->getAttribute('type'), 107 $this->node->getChild('picture')->getData(), 108 ]); 109 } 110 if ($this->node->getChild('media') != null || $this->node->getChild('duplicate') != null) { 111 $this->parent->processUploadResponse($this->node); 112 } 113 if (strpos($this->node->getAttribute('from'), Constants::WHATSAPP_GROUP_SERVER) !== false) { 114 //There are multiple types of Group reponses. Also a valid group response can have NO children. 115 //Events fired depend on text in the ID field. 116 $groupList = []; 117 $groupNodes = []; 118 if ($this->node->getChild(0) != null && $this->node->getChild(0)->getChildren() != null) { 119 foreach ($this->node->getChild(0)->getChildren() as $child) { 120 $groupList[] = $child->getAttributes(); 121 $groupNodes[] = $child; 122 } 123 } 124 if (isset($this->parent->getNodeId()['groupcreate']) && ($this->parent->getNodeId()['groupcreate'] == $this->node->getAttribute('id'))) { 125 $this->parent->setGroupId($this->node->getChild(0)->getAttribute('id')); 126 $this->parent->eventManager()->fire('onGroupsChatCreate', 127 [ 128 $this->phoneNumber, 129 $this->node->getChild(0)->getAttribute('id'), 130 ]); 131 } 132 if (isset($this->parent->getNodeId()['leavegroup']) && ($this->parent->getNodeId()['leavegroup'] == $this->node->getAttribute('id'))) { 133 $this->parent->setGroupId($this->node->getChild(0)->getChild(0)->getAttribute('id')); 134 $this->parent->eventManager()->fire('onGroupsChatEnd', 135 [ 136 $this->phoneNumber, 137 $this->node->getChild(0)->getChild(0)->getAttribute('id'), 138 ]); 139 } 140 if (isset($this->parent->getNodeId()['getgroups']) && ($this->parent->getNodeId()['getgroups'] == $this->node->getAttribute('id'))) { 141 $this->parent->eventManager()->fire('onGetGroups', 142 [ 143 $this->phoneNumber, 144 $groupList, 145 ]); 146 //getGroups returns a array of nodes which are exactly the same as from getGroupV2Info 147 //so lets call this event, we have all data at hand, no need to call getGroupV2Info for every 148 //group we are interested 149 foreach ($groupNodes as $groupNode) { 150 $this->handleGroupV2InfoResponse($groupNode, true); 151 } 152 } 153 if (isset($this->parent->getNodeId()['get_groupv2_info']) && ($this->parent->getNodeId()['get_groupv2_info'] == $this->node->getAttribute('id'))) { 154 $groupChild = $this->node->getChild(0); 155 if ($groupChild != null) { 156 $this->handleGroupV2InfoResponse($groupChild); 157 } 158 } 159 } 160 if (isset($this->parent->getNodeId()['get_lists']) && ($this->parent->getNodeId()['get_lists'] == $this->node->getAttribute('id'))) { 161 $broadcastLists = []; 162 if ($this->node->getChild(0) != null) { 163 $childArray = $this->node->getChildren(); 164 foreach ($childArray as $list) { 165 if ($list->getChildren() != null) { 166 foreach ($list->getChildren() as $sublist) { 167 $id = $sublist->getAttribute('id'); 168 $name = $sublist->getAttribute('name'); 169 $broadcastLists[$id]['name'] = $name; 170 $recipients = []; 171 foreach ($sublist->getChildren() as $recipient) { 172 array_push($recipients, $recipient->getAttribute('jid')); 173 } 174 $broadcastLists[$id]['recipients'] = $recipients; 175 } 176 } 177 } 178 } 179 $this->parent->eventManager()->fire('onGetBroadcastLists', 180 [ 181 $this->phoneNumber, 182 $broadcastLists, 183 ]); 184 } 185 if ($this->node->getChild('pricing') != null) { 186 $this->parent->eventManager()->fire('onGetServicePricing', 187 [ 188 $this->phoneNumber, 189 $this->node->getChild(0)->getAttribute('price'), 190 $this->node->getChild(0)->getAttribute('cost'), 191 $this->node->getChild(0)->getAttribute('currency'), 192 $this->node->getChild(0)->getAttribute('expiration'), 193 ]); 194 } 195 if ($this->node->getChild('extend') != null) { 196 $this->parent->eventManager()->fire('onGetExtendAccount', 197 [ 198 $this->phoneNumber, 199 $this->node->getChild('account')->getAttribute('kind'), 200 $this->node->getChild('account')->getAttribute('status'), 201 $this->node->getChild('account')->getAttribute('creation'), 202 $this->node->getChild('account')->getAttribute('expiration'), 203 ]); 204 } 205 if ($this->node->getChild('normalize') != null) { 206 $this->parent->eventManager()->fire('onGetNormalizedJid', 207 [ 208 $this->phoneNumber, 209 $this->node->getChild(0)->getAttribute('result'), 210 ]); 211 } 212 if ($this->node->getChild('status') != null) { 213 $child = $this->node->getChild('status'); 214 $childs = $child->getChildren(); 215 if (isset($childs) && !is_null($childs)) { 216 foreach ($childs as $status) { 217 $this->parent->eventManager()->fire('onGetStatus', 218 [ 219 $this->phoneNumber, 220 $status->getAttribute('jid'), 221 'requested', 222 $this->node->getAttribute('id'), 223 $status->getAttribute('t'), 224 $status->getData(), 225 ]); 226 } 227 } 228 } 229 230 if (($this->node->getAttribute('type') == 'error') && ($this->node->getChild('error') != null)) { 231 $errorType = null; 232 $this->parent->logFile('error', 'Iq error with {id} id', ['id' => $this->node->getAttribute('id')]); 233 foreach ($this->parent->getNodeId() as $type => $nodeID) { 234 if ($nodeID == $this->node->getAttribute('id')) { 235 $errorType = $type; 236 break; 237 } 238 } 239 $nodeIds = $this->parent->getNodeId(); 240 if (isset($nodeIds['sendcipherKeys']) && (isset($nodeIds['sendcipherKeys']) == $this->node->getAttribute('id')) && $this->node->getChild('error')->getAttribute('code') == '406') { 241 $this->parent->sendSetPreKeys(); 242 } elseif ($this->node->getAttribute('id') == '2') { 243 $this->parent->sendSetGCM(); 244 } 245 246 $this->parent->eventManager()->fire('onGetError', 247 [ 248 $this->phoneNumber, 249 $this->node->getAttribute('from'), 250 $this->node->getAttribute('id'), 251 $this->node->getChild(0), 252 $errorType, 253 ]); 254 } 255 256 if (isset($this->parent->getNodeId()['cipherKeys']) && ($this->parent->getNodeId()['cipherKeys'] == $this->node->getAttribute('id'))) { 257 $users = $this->node->getChild(0)->getChildren(); 258 foreach ($users as $user) { 259 $jid = $user->getAttribute('jid'); 260 $registrationId = deAdjustId($user->getChild('registration')->getData()); 261 $identityKey = new IdentityKey(new DjbECPublicKey($user->getChild('identity')->getData())); 262 $signedPreKeyId = deAdjustId($user->getChild('skey')->getChild('id')->getData()); 263 $signedPreKeyPub = new DjbECPublicKey($user->getChild('skey')->getChild('value')->getData()); 264 $signedPreKeySig = $user->getChild('skey')->getChild('signature')->getData(); 265 $preKeyId = deAdjustId($user->getChild('key')->getChild('id')->getData()); 266 $preKeyPublic = new DjbECPublicKey($user->getChild('key')->getChild('value')->getData()); 267 268 $preKeyBundle = new PreKeyBundle($registrationId, 1, $preKeyId, $preKeyPublic, $signedPreKeyId, $signedPreKeyPub, $signedPreKeySig, $identityKey); 269 $sessionBuilder = new SessionBuilder($this->parent->getAxolotlStore(), $this->parent->getAxolotlStore(), $this->parent->getAxolotlStore(), $this->parent->getAxolotlStore(), ExtractNumber($jid), 1); 270 271 $sessionBuilder->processPreKeyBundle($preKeyBundle); 272 if (isset($this->parent->getPendingNodes()[ExtractNumber($jid)])) { 273 foreach ($this->parent->getPendingNodes()[ExtractNumber($jid)] as $pendingNode) { 274 $msgHandler = new MessageHandler($this->parent, $pendingNode); 275 $msgHandler->Process(); 276 } 277 $this->parent->unsetPendingNode($jid); 278 } 279 $this->parent->sendPendingMessages($jid); 280 } 281 } 282 } 283 284 /** 285 * @param ProtocolNode $groupNode 286 * @param mixed $fromGetGroups 287 */ 288 protected function handleGroupV2InfoResponse(ProtocolNode $groupNode, $fromGetGroups = false) 289 { 290 $creator = $groupNode->getAttribute('creator'); 291 $creation = $groupNode->getAttribute('creation'); 292 $subject = $groupNode->getAttribute('subject'); 293 $groupID = $groupNode->getAttribute('id'); 294 $participants = []; 295 $admins = []; 296 if ($groupNode->getChild(0) != null) { 297 foreach ($groupNode->getChildren() as $child) { 298 $participants[] = $child->getAttribute('jid'); 299 if ($child->getAttribute('type') == 'admin') { 300 $admins[] = $child->getAttribute('jid'); 301 } 302 } 303 } 304 $this->parent->eventManager()->fire('onGetGroupV2Info', 305 [ 306 $this->phoneNumber, 307 $groupID, 308 $creator, 309 $creation, 310 $subject, 311 $participants, ...

Full Screen

Full Screen

NotificationHandler.php

Source:NotificationHandler.php Github

copy

Full Screen

...24 $this->parent->eventManager()->fire('onGetStatus', 25 [ 26 $this->phoneNumber, //my number 27 $this->node->getAttribute('from'), 28 $this->node->getChild(0)->getTag(), 29 $this->node->getAttribute('id'), 30 $this->node->getAttribute('t'), 31 $this->node->getChild(0)->getData(), 32 ]); 33 break; 34 case 'picture': 35 if ($this->node->hasChild('set')) { 36 $this->parent->eventManager()->fire('onProfilePictureChanged', 37 [ 38 $this->phoneNumber, 39 $this->node->getAttribute('from'), 40 $this->node->getAttribute('id'), 41 $this->node->getAttribute('t'), 42 ]); 43 } elseif ($this->node->hasChild('delete')) { 44 $this->parent->eventManager()->fire('onProfilePictureDeleted', 45 [ 46 $this->phoneNumber, 47 $this->node->getAttribute('from'), 48 $this->node->getAttribute('id'), 49 $this->node->getAttribute('t'), 50 ]); 51 } 52 //TODO 53 break; 54 case 'contacts': 55 $notification = $this->node->getChild(0)->getTag(); 56 if ($notification == 'add') { 57 $this->parent->eventManager()->fire('onNumberWasAdded', 58 [ 59 $this->phoneNumber, 60 $this->node->getChild(0)->getAttribute('jid'), 61 ]); 62 } elseif ($notification == 'remove') { 63 $this->parent->eventManager()->fire('onNumberWasRemoved', 64 [ 65 $this->phoneNumber, 66 $this->node->getChild(0)->getAttribute('jid'), 67 ]); 68 } elseif ($notification == 'update') { 69 $this->parent->eventManager()->fire('onNumberWasUpdated', 70 [ 71 $this->phoneNumber, 72 $this->node->getChild(0)->getAttribute('jid'), 73 ]); 74 } 75 break; 76 case 'encrypt': 77 if (extension_loaded('curve25519') && extension_loaded('protobuf')) { 78 $value = $this->node->getChild(0)->getAttribute('value'); 79 if (is_numeric($value)) { 80 $this->parent->getAxolotlStore()->removeAllPrekeys(); 81 $this->parent->sendSetPreKeys(true); 82 } else { 83 echo 'Corrupt Stream: value '.$value.'is not numeric'; 84 } 85 } 86 break; 87 case 'w:gp2': 88 if ($this->node->hasChild('remove')) { 89 if ($this->node->getChild(0)->hasChild('participant')) { 90 $this->parent->eventManager()->fire('onGroupsParticipantsRemove', 91 [ 92 $this->phoneNumber, 93 $this->node->getAttribute('from'), 94 $this->node->getChild(0)->getChild(0)->getAttribute('jid'), 95 ]); 96 } 97 } elseif ($this->node->hasChild('add')) { 98 $this->parent->eventManager()->fire('onGroupsParticipantsAdd', 99 [ 100 $this->phoneNumber, 101 $this->node->getAttribute('from'), 102 $this->node->getChild(0)->getChild(0)->getAttribute('jid'), 103 ]); 104 } elseif ($this->node->hasChild('create')) { 105 $groupMembers = []; 106 foreach ($this->node->getChild(0)->getChild(0)->getChildren() as $cn) { 107 $groupMembers[] = $cn->getAttribute('jid'); 108 } 109 $this->parent->eventManager()->fire('onGroupisCreated', 110 [ 111 $this->phoneNumber, 112 $this->node->getChild(0)->getChild(0)->getAttribute('creator'), 113 $this->node->getChild(0)->getChild(0)->getAttribute('id'), 114 $this->node->getChild(0)->getChild(0)->getAttribute('subject'), 115 $this->node->getAttribute('participant'), 116 $this->node->getChild(0)->getChild(0)->getAttribute('creation'), 117 $groupMembers, 118 ]); 119 } elseif ($this->node->hasChild('subject')) { 120 $this->parent->eventManager()->fire('onGetGroupsSubject', 121 [ 122 $this->phoneNumber, 123 $this->node->getAttribute('from'), 124 $this->node->getAttribute('t'), 125 $this->node->getAttribute('participant'), 126 $this->node->getAttribute('notify'), 127 $this->node->getChild(0)->getAttribute('subject'), 128 ]); 129 } elseif ($this->node->hasChild('promote')) { 130 $promotedJIDs = []; 131 foreach ($this->node->getChild(0)->getChildren() as $cn) { 132 $promotedJIDs[] = $cn->getAttribute('jid'); 133 } 134 $this->parent->eventManager()->fire('onGroupsParticipantsPromote', 135 [ 136 $this->phoneNumber, 137 $this->node->getAttribute('from'), //Group-JID 138 $this->node->getAttribute('t'), //Time 139 $this->node->getAttribute('participant'), //Issuer-JID 140 $this->node->getAttribute('notify'), //Issuer-Name 141 $promotedJIDs, 142 ] 143 ); 144 } elseif ($this->node->hasChild('modify')) { 145 $this->parent->eventManager()->fire('onGroupsParticipantChangedNumber', 146 [ 147 $this->phoneNumber, 148 $this->node->getAttribute('from'), 149 $this->node->getAttribute('t'), 150 $this->node->getAttribute('participant'), 151 $this->node->getAttribute('notify'), 152 $this->node->getChild(0)->getChild(0)->getAttribute('jid'), 153 ] 154 ); 155 } 156 break; 157 case 'account': 158 if (($this->node->getChild(0)->getAttribute('author')) == '') { 159 $author = 'Paypal'; 160 } else { 161 $author = $this->node->getChild(0)->getAttribute('author'); 162 } 163 $this->parent->eventManager()->fire('onPaidAccount', 164 [ 165 $this->phoneNumber, 166 $author, 167 $this->node->getChild(0)->getChild(0)->getAttribute('kind'), 168 $this->node->getChild(0)->getChild(0)->getAttribute('status'), 169 $this->node->getChild(0)->getChild(0)->getAttribute('creation'), 170 $this->node->getChild(0)->getChild(0)->getAttribute('expiration'), 171 ]); 172 break; 173 case 'features': 174 if ($this->node->getChild(0)->getChild(0) == 'encrypt') { 175 $this->parent->eventManager()->fire('onGetFeature', 176 [ 177 $this->phoneNumber, 178 $this->node->getAttribute('from'), 179 $this->node->getChild(0)->getChild(0)->getAttribute('value'), 180 ]); 181 } 182 break; 183 case 'web': 184 if (($this->node->getChild(0)->getTag() == 'action') && ($this->node->getChild(0)->getAttribute('type') == 'sync')) { 185 $data = $this->node->getChild(0)->getChildren(); 186 $this->parent->eventManager()->fire('onWebSync', 187 [ 188 $this->phoneNumber, 189 $this->node->getAttribute('from'), 190 $this->node->getAttribute('id'), 191 $data[0]->getData(), 192 $data[1]->getData(), 193 $data[2]->getData(), 194 ]); 195 } 196 break; 197 default: 198 throw new Exception("Method $this->type not implemented"); 199 } ...

Full Screen

Full Screen

getChild

Using AI Code Generation

copy

Full Screen

1$data = new Data();2$child = $data->getChild($id);3$data = new Data();4$child = $data->getChild($id);5$data = new Data();6$child = $data->getChild($id);7$data = new Data();8$child = $data->getChild($id);9$data = new Data();10$child = $data->getChild($id);11$data = new Data();12$child = $data->getChild($id);13$data = new Data();14$child = $data->getChild($id);15$data = new Data();16$child = $data->getChild($id);17$data = new Data();18$child = $data->getChild($id);19$data = new Data();20$child = $data->getChild($id);21$data = new Data();22$child = $data->getChild($id);23$data = new Data();24$child = $data->getChild($id);25$data = new Data();26$child = $data->getChild($id);27$data = new Data();28$child = $data->getChild($id);29$data = new Data();30$child = $data->getChild($id);31$data = new Data();32$child = $data->getChild($id);

Full Screen

Full Screen

getChild

Using AI Code Generation

copy

Full Screen

1$obj = new Data();2$obj->getChild(1);3$obj = new Data();4$obj->getParent(1);5$obj = new Data();6$obj->getChild(2);7$obj = new Data();8$obj->getParent(2);9$obj = new Data();10$obj->getChild(3);11$obj = new Data();12$obj->getParent(3);13$obj = new Data();14$obj->getChild(4);15$obj = new Data();16$obj->getParent(4);17$obj = new Data();18$obj->getChild(5);19$obj = new Data();20$obj->getParent(5);21$obj = new Data();22$obj->getChild(6);23$obj = new Data();24$obj->getParent(6);25$obj = new Data();26$obj->getChild(7);27$obj = new Data();28$obj->getParent(7);29$obj = new Data();30$obj->getChild(8);31$obj = new Data();32$obj->getParent(8);33$obj = new Data();34$obj->getChild(9);35$obj = new Data();36$obj->getParent(9);37$obj = new Data();38$obj->getChild(10);39$obj = new Data();40$obj->getParent(10);41$obj = new Data();

Full Screen

Full Screen

getChild

Using AI Code Generation

copy

Full Screen

1$child = $data->getChild('data', 'child');2var_dump($child);3$child = $data->getChild('data', 'child');4var_dump($child);5$child = $data->getChild('data', 'child', 'path/to/2.php');6var_dump($child);7$child = $data->getChild('data', 'child', 'path/to/1.php');8var_dump($child);9$child = $data->getChild('data', 'child', 'path/to/2.php');10var_dump($child);11$child = $data->getChild('data', 'child', 'path/to/1.php');12var_dump($child);13$child = $data->getChild('data', 'child', 'path/to/2.php');14var_dump($child);15$child = $data->getChild('data', 'child

Full Screen

Full Screen

getChild

Using AI Code Generation

copy

Full Screen

1$node = $data->getChild($id);2$node = $data->getChildren($id);3$node = $data->getChildrenCount($id);4$node = $data->getRoot();5$node = $data->getRootCount();6$node = $data->getParent($id);7$node = $data->getParents($id);8$node = $data->getParentsCount($id);9$node = $data->getDescendant($id);10$node = $data->getDescendants($id);11$node = $data->getDescendantsCount($id);12$node = $data->getAncestors($id);13$node = $data->getAncestorsCount($id);

Full Screen

Full Screen

getChild

Using AI Code Generation

copy

Full Screen

1include_once 'data.php';2$data = new Data();3$root = $data->getRoot();4$children = $data->getChild($root);5foreach ($children as $child) {6";7}8include_once 'data.php';9$data = new Data();10$root = $data->getRoot();11$children = $data->getChild($root);12foreach ($children as $child) {13";14}15include_once 'data.php';16$data = new Data();17$root = $data->getRoot();18$children = $data->getChild($root);19foreach ($children as $child) {20";21}22{23 private $xml;24 public function __construct()25 {26 $this->xml = simplexml_load_file('data.xml');27 }28 public function getRoot()29 {30 return $this->xml;31 }32 public function getChild($parent)33 {34 return $parent->children();35 }36}

Full Screen

Full Screen

getChild

Using AI Code Generation

copy

Full Screen

1$child = $data->getChild(1, 'id');2$child = $data->getChild('John', 'name');3$child = $data->getChild(1, 'id', 'name', 'John');4$child = $data->getChild(1, 'id', 'name', 'John', 'type', 1);5$children = $data->getChildren(1, 'id');6$children = $data->getChildren('John', 'name');7$children = $data->getChildren(1, 'id', 'name', 'John');8$children = $data->getChildren(1, 'id', 'name', 'John', 'type', 1);9$parent = $data->getParent(1, 'id');10$parent = $data->getParent('John', 'name');11$parent = $data->getParent(1, 'id', 'name', 'John');12$parent = $data->getParent(1, 'id', 'name', 'John', 'type', 1);13$parents = $data->getParents(1, 'id');14$parents = $data->getParents('John', 'name');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger getChild code on LambdaTest Cloud Grid

Execute automation tests with getChild on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful