Beispiel #1
0
 public function ReceiveMessage($senderJId, array $arMessage, CXMPPClient $senderClient)
 {
     if (!$senderClient->IsAuthenticated()) {
         return false;
     }
     if (strlen($senderJId) <= 0) {
         return false;
     }
     if (!array_key_exists("iq", $arMessage)) {
         return false;
     }
     $to = "";
     if (array_key_exists("to", $arMessage["iq"]["."])) {
         $to = $arMessage["iq"]["."]["to"];
     }
     if (strlen($to) > 0 && strpos($to, "@") !== false) {
         $arResult = true;
         $arMessage["iq"]["."]["to"] = CXMPPUtility::GetJIdWithResource($arMessage["iq"]["."]["to"], "");
         $server = CXMPPServer::GetServer();
         $server->Send($to, $arMessage, $senderClient->GetClientDomain());
     } else {
         if ($arMessage["iq"]["."]["type"] == "get" && $arMessage["iq"]["query"]["."]["xmlns"] == "http://jabber.org/protocol/disco#items") {
             $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id']), "query" => array("." => array("xmlns" => "http://jabber.org/protocol/disco#items"))));
         } elseif ($arMessage["iq"]["."]["type"] == "set" && $arMessage["iq"]["session"]["."]["xmlns"] == "urn:ietf:params:xml:ns:xmpp-session") {
             $arResult = array("iq" => array("." => array("type" => "result", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id'])));
         } else {
             $arResult = array("iq" => array("." => array("type" => "error", "from" => $senderClient->GetClientDomain(), "id" => $arMessage['iq']['.']['id']), "error" => array("." => array("type" => "cancel"), "feature-not-implemented" => array("." => array("xmlns" => "urn:ietf:params:xml:ns:xmpp-stanzas")))));
         }
         //$arResult = CXMPPUtility::GetErrorArray($senderJId, "iq", "cancel", "feature-not-implemented", "", $arMessage['iq']['.']['id'], "");
     }
     return $arResult;
 }
Beispiel #2
0
 public function Send($arMessage)
 {
     if (!$this->connected) {
         return false;
     }
     if (count($arMessage) <= 0) {
         return false;
     }
     $arMessageKeys = array_keys($arMessage);
     if (count($arMessageKeys) <= 0) {
         return false;
     }
     $thisJId = $this->jid . (!empty($this->resource) ? "/" . $this->resource : "");
     foreach ($arMessageKeys as $key) {
         if ($arMessage[$key][0]) {
             $arMessageKeys1 = array_keys($arMessage[$key]);
             foreach ($arMessageKeys1 as $key1) {
                 $arMessage[$key][$key1]["."]["to"] = $thisJId;
                 if (isset($arMessage[$key][$key1]["."]["from"]) && !isset($arMessage[$key][$key1]["vCard"])) {
                     $arMessage[$key][$key1]["."]["from"] = CXMPPUtility::GetJIdWithResource($arMessage[$key][$key1]["."]["from"], $this->clientDomain);
                 }
             }
         } else {
             $arMessage[$key]["."]["to"] = $thisJId;
             if (isset($arMessage[$key]["."]["from"]) && !isset($arMessage[$key]["vCard"])) {
                 $arMessage[$key]["."]["from"] = CXMPPUtility::GetJIdWithResource($arMessage[$key]["."]["from"], $this->clientDomain);
             }
         }
     }
     $message = CXMPPParser::ToXml($arMessage);
     return $this->__Send($message);
 }
Beispiel #3
0
 public function SendPresenceMessages2($receiverJId, $clientDomain = "")
 {
     if (empty($clientDomain)) {
         $clientDomain = CXMPPServer::GetDomain();
     }
     $receiverJIdWithResource = CXMPPUtility::GetJIdWithResource($receiverJId, $clientDomain);
     if (array_key_exists($clientDomain, $this->arOnlineOnSite)) {
         foreach ($this->arOnlineOnSite[$clientDomain] as $jid) {
             $this->Send($jid, array("presence" => array("." => array("from" => $receiverJIdWithResource, "to" => CXMPPUtility::GetJIdWithResource($jid, $clientDomain)))), $clientDomain);
         }
     }
     if (array_key_exists($clientDomain, $this->arClientsIndex)) {
         foreach ($this->arClientsIndex[$clientDomain] as $jid => $arId) {
             if (count($arId) <= 0) {
                 continue;
             }
             if (!is_array($this->arOnlineOnSite[$clientDomain]) || !in_array($jid, $this->arOnlineOnSite[$clientDomain])) {
                 $this->Send($jid, array("presence" => array("." => array("from" => $receiverJIdWithResource, "to" => CXMPPUtility::GetJIdWithResource($jid, $clientDomain)))), $clientDomain);
             }
         }
     }
 }
Beispiel #4
0
 static function GetMessageArray($senderJId, $receiverJId, $messageType, $body, $domain = "")
 {
     if (strlen($receiverJId) <= 0) {
         return false;
     }
     if (empty($domain)) {
         $domain = CXMPPServer::GetDomain();
     }
     // chat - The message is sent in the context of a one-to-one chat conversation.
     // error - An error has occurred related to a previous message sent by the sender.
     // groupchat - The message is sent in the context of a multi-user chat environment.
     // headline - The message is probably generated by an automated service that delivers or broadcasts content.
     // normal - The message is a single message that is sent outside the context of a one-to-one conversation or
     //			groupchat, and to which it is expected that the recipient will reply.
     $arAllowableMessageTypes = array("chat", "groupchat", "headline", "normal");
     if (!in_array($messageType, $arAllowableMessageTypes)) {
         return false;
     }
     $arResult = array("message" => array("." => array("from" => CXMPPUtility::GetJIdWithResource($senderJId, $domain), "to" => CXMPPUtility::GetJIdWithResource($receiverJId, $domain), "type" => $messageType, "id" => "u" . rand(1000, 9999)), "body" => array("#" => $body)));
     return $arResult;
 }