- Модуль: xmpp
- Путь к файлу: ~/bitrix/modules/xmpp/classes/util.php
- Класс: CXMPPUtility
- Вызов: CXMPPUtility::GetErrorArray
static function GetErrorArray($receiverJId, $stanzaKind, $errorType, $condition, $senderJId = "", $id = "", $text = "", $domain = "")
{
if ($receiverJId == '')
return false;
$arAllowableStanzaKinds = array("message", "presence", "iq");
if (!in_array($stanzaKind, $arAllowableStanzaKinds))
return false;
// cancel - do not retry (the error is unrecoverable)
// continue - proceed (the condition was only a warning)
// modify - retry after changing the data sent
// auth - retry after providing credentials
// wait - retry after waiting (the error is temporary)
$arAllowableErrorTypes = array("cancel", "continue", "modify", "auth", "wait");
if (!in_array($errorType, $arAllowableErrorTypes))
return false;
switch ($condition)
{
// the sender has sent XML that is malformed or that cannot be processed (e.g., an IQ stanza that includes an
// unrecognized value of the 'type' attribute); the associated error type SHOULD be "modify".
case "bad-request":
$errorType = "modify";
break;
// access cannot be granted because an existing resource or session exists with the same name or address; the
// associated error type SHOULD be "cancel".
case "conflict":
$errorType = "cancel";
break;
// the feature requested is not implemented by the recipient or server and therefore cannot be
// processed; the associated error type SHOULD be "cancel".
case "feature-not-implemented":
$errorType = "cancel";
break;
// the requesting entity does not possess the required permissions to perform the action; the associated
// error type SHOULD be "auth".
case "forbidden":
$errorType = "auth";
break;
// the recipient or server can no longer be contacted at this address (the error stanza MAY contain a new address in the
// XML character data of the element); the associated error type SHOULD be "modify".
case "gone":
$errorType = "modify";
break;
// the server could not process the stanza because of a misconfiguration or an otherwise-undefined
// internal server error; the associated error type SHOULD be "wait".
case "internal-server-error":
$errorType = "wait";
break;
// the addressed JID or item requested cannot be found; the associated error type SHOULD be "cancel".
case "item-not-found":
$errorType = "cancel";
break;
// the sending entity has provided or communicated an XMPP address (e.g., a value of the 'to' attribute)
// or aspect thereof (e.g., a resource identifier) that does not adhere to the syntax defined in
// Addressing Scheme; the associated error type SHOULD be "modify".
case "jid-malformed":
$errorType = "modify";
break;
// the recipient or server understands the request but is refusing to process it because it does not meet
// criteria defined by the recipient or server (e.g., a local policy regarding acceptable words in
// messages); the associated error type SHOULD be "modify".
case "not-acceptable":
$errorType = "modify";
break;
// the recipient or server does not allow any entity to perform the action; the associated
// error type SHOULD be "cancel".
case "not-allowed":
$errorType = "cancel";
break;
// the sender must provide proper credentials before being allowed to perform the action,
// or has provided improper credentials; the associated error type SHOULD be "auth".
case "not-authorized":
$errorType = "auth";
break;
// the requesting entity is not authorized to access the requested service because payment is
// required; the associated error type SHOULD be "auth".
case "payment-required":
$errorType = "auth";
break;
// the intended recipient is temporarily unavailable; the associated error type SHOULD
// be "wait" (note: an application MUST NOT return this error if doing so would provide
// information about the intended recipient's network availability to
// an entity that is not authorized to know such information).
case "recipient-unavailable":
$errorType = "wait";
break;
// the recipient or server is redirecting requests for this information to another entity,
// usually temporarily (the error stanza SHOULD contain the alternate address, which MUST be
// a valid JID, in the XML character data of the element); the
// associated error type SHOULD be "modify".
case "redirect":
$errorType = "modify";
break;
// the requesting entity is not authorized to access the requested service because registration
// is required; the associated error type SHOULD be "auth".
case "registration-required":
$errorType = "auth";
break;
// a remote server or service specified as part or all of the JID of the intended recipient
// does not exist; the associated error type SHOULD be "cancel".
case "remote-server-not-found":
$errorType = "cancel";
break;
// a remote server or service specified as part or all of the JID of the intended recipient
// (or required to fulfill a request) could not be contacted within a reasonable
// amount of time; the associated error type SHOULD be "wait".
case "remote-server-timeout":
$errorType = "wait";
break;
// the server or recipient lacks the system resources necessary to service the request; the
// associated error type SHOULD be "wait".
case "resource-constraint":
$errorType = "wait";
break;
// the server or recipient does not currently provide the requested service; the associated
// error type SHOULD be "cancel".
case "service-unavailable":
$errorType = "cancel";
break;
// the requesting entity is not authorized to access the requested service because a subscription
// is required; the associated error type SHOULD be "auth".
case "subscription-required":
$errorType = "auth";
break;
// the error condition is not one of those defined by the other conditions in this list;
// any error type may be associated with this condition, and it SHOULD be used only in
// conjunction with an application-specific condition.
case "undefined-condition":
break;
// the recipient or server understood the request but was not expecting it at this
// time (e.g., the request was out of order); the associated error type SHOULD be "wait".
case "unexpected-request":
$errorType = "wait";
break;
default:
return false;
break;
}
$arResult = array(
$stanzaKind => array(
"." => array(
"to" => self::GetJIdWithResource($receiverJId, $domain),
"type" => "error",
),
"error" => array(
"." => array(
"type" => $errorType,
),
$condition => array(
"." => array(
"xmlns" => "urn:ietf:params:xml:ns:xmpp-stanzas",
),
),
),
),
);
if ($senderJId <> '')
$arResult[$stanzaKind]["."]["from"] = self::GetJIdWithResource($senderJId, $domain);
if ($id <> '')
$arResult[$stanzaKind]["."]["id"] = $id;
if ($text <> '')
{
$arResult[$stanzaKind]["error"]["text"] = array(
"." => array(
"xmlns" => "urn:ietf:params:xml:ns:xmpp-stanzas",
"xml:lang" => "en",
),
"#" => $text,
);
}
return $arResult;
}