public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient) { if (strlen($senderJId) <= 0) { return false; } if (!array_key_exists("iq", $arMessage) || !array_key_exists("bind", $arMessage["iq"]) || $arMessage['iq']['bind']['.']['xmlns'] != 'urn:ietf:params:xml:ns:xmpp-bind') { return false; } $type = ""; if (array_key_exists("type", $arMessage["iq"]["."])) { $type = $arMessage["iq"]["."]["type"]; } if ($type == "set") { $resource = $arMessage["iq"]["bind"]["resource"]["#"]; if (strlen($resource) <= 0) { $resource = "bx"; } $senderClient->SetResource($resource); $arMessageTmp = array("iq" => array("." => array("type" => "result", "to" => htmlspecialcharsbx($senderClient->GetClientDomain()) . "/" . $senderClient->GetStreamId(), "id" => $arMessage['iq']['.']['id']), "bind" => array("." => array("xmlns" => "urn:ietf:params:xml:ns:xmpp-bind"), "jid" => array("#" => $senderJId . "/" . $resource)))); $messageTmp = CXMPPParser::ToXml($arMessageTmp); $senderClient->__Send($messageTmp); } else { $arMessageTmp = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id']))); $messageTmp = CXMPPParser::ToXml($arMessageTmp); $senderClient->__Send($messageTmp); } return true; }
static function _SendToServer($arMessage, &$errorNo, &$errorStr, $domain = "") { if (empty($domain)) { $domain = CXMPPServer::GetDomain(); } if ($f = @fsockopen(CXMPPServer::GetDomain(), 5222, $errNo, $errStr, 10)) { $arMessage['server'] = array('.' => array('uniid' => CXMPPUtility::GetUniid($domain), "domain" => $domain), '#' => ''); $message = CXMPPParser::ToXml($arMessage); fwrite($f, $message); $responce = ""; while (!feof($f)) { $responce .= trim(fread($f, 8192)); } fclose($f); $arResponce = CXMPPParser::ToArray($responce); return $arResponce; } $errorNo = $errNo; $errorStr = $errStr; return false; }
function ToXml($ar) { $parser = new CXMPPParser(); $text = $parser->toString($ar); return $text; }
protected function __ParseBuffer() { $buffer = trim($this->readBuffer); if (strlen($buffer) <= 0) { return false; } if (strtolower(substr($buffer, 0, 5)) == '<?xml') { $buffer = trim(substr($buffer, strpos($buffer, ">") + 1)); } if (strtolower(substr($buffer, 0, 14)) == '<stream:stream') { $buffer .= "</stream:stream>"; stream_set_timeout($this->sock, 5); } $arRequest = CXMPPParser::ToArray($buffer); if (!$arRequest) { return false; } CXMPPUtility::Show("<<< " . $this->jid . " (" . $this->xmppId . ")\n" . $buffer, 0); $this->readBuffer = ""; $this->pingTime = time(); if ($arRequest['server']) { if (isset($arRequest['server']['.']['domain'])) { $clientDomain = $arRequest['server']['.']['domain']; } if (empty($clientDomain)) { $clientDomain = CXMPPServer::GetDomain(); } if (!CXMPPUtility::SelectDatabase($clientDomain)) { $this->Disconnect(); return false; } if ($arRequest['server']['.']['uniid'] != CXMPPUtility::GetUniid($clientDomain)) { $this->Disconnect(); return false; } unset($arRequest['server']); foreach ($arRequest as $key => $value) { if ($value[0]) { foreach ($value as $value0) { $this->__ProcessServerMessage(array($key => $value0), $clientDomain); } } else { $this->__ProcessServerMessage(array($key => $value), $clientDomain); } } $this->Disconnect(); return true; } foreach ($arRequest as $key => $value) { if ($value[0]) { foreach ($value as $value0) { $this->__ProcessMessage(array($key => $value0)); } } else { $this->__ProcessMessage(array($key => $value)); } } return true; }