* @revision 05 * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons Attribution-Share Alike 3.0 Germany * @homepage http://oss.tiggerswelt.net/xmpp * @copyright Copyright © 2008 tiggersWelt.net */ require_once ('phpEvents/socket/stream/xml/tag.php'); /** * XMPP Error Handling * * Respond to incoming packets with ugly errors :) * * @package tiggerXMPP * @class tiggerXMPP_Error */ class tiggerXMPP_Error { /* Our namespace */ const XEP_NAMESPACE = 'urn:ietf:params:xml:ns:xmpp-stanzas'; /* Error Types */ const ERROR_TYPE_MODIFY = 'modify'; const ERROR_TYPE_CANCEL = 'cancel'; const ERROR_TYPE_AUTH = 'auth'; const ERROR_TYPE_WAIT = 'wait'; /* Error Codes */ const ERROR_BAD_REQUEST = 'bad-request'; const ERROR_CONFLICT = 'conflict'; const ERROR_FEATURE_NOT_IMPLEMENTED = 'feature-not-implemented'; const ERROR_FORBIDDEN = 'forbidden'; const ERROR_GONE = 'gone'; const ERROR_INTERNAL_SERVER_ERROR = 'internal-server-error'; const ERROR_ITEM_NOT_FOUND = 'item-not-found'; const ERROR_JID_MALFORMED = 'jid-malformed'; const ERROR_NOT_ACCEPTABLE = 'not-acceptable'; const ERROR_NOT_ALLOWDED = 'not-allowed'; const ERROR_NOT_AUTHORIZED = 'not-authorized'; const ERROR_PAYMENT_REQUIRED = 'payment-required'; const ERROR_RECIPIENT_UNAVAILABLE = 'recipient-unavailable'; const ERROR_REDIRECT = 'redirect'; const ERROR_REGISTRATION_REQUIRED = 'registration-required'; const ERROR_REMOTE_SERVER_NOT_FOUND = 'remote-server-not-found'; const ERROR_REMOTE_SERVER_TIMEOUT = 'remote-server-timeout'; const ERROR_RESOURCE_CONSTRAINT = 'resource-constraint'; const ERROR_SERVICE_UNAVAILABLE = 'service-unavailable'; const ERROR_SUBSCRIPTION_REQUIRED = 'subscription-required'; const ERROR_UNDEFINED_CONDITION = 'undefined-condition'; const ERROR_UNEXPECTED_REQUEST = 'unexpected-request'; /* Error Description */ public $Text = ""; /* Internal Errorcode Storage */ private $Code = 0; // {{{ __construct /** * Generate a new error * * @param int $Error Which error should we handle? * @param string $Text (optional) Description of error * @param object $Tag (optional) Append to this tag * * @access public * @return void */ public function __construct ($Error, $Text = '', $Tag = null) { $this->Code = $Error; $this->Text = $Text; if (is_object ($Tag)) $this->generate ($Tag); } // }}} // {{{ generate /** * Generate an XML-Response from this object * * @param object $Response (optional) Response to use * @param object $Tag (optional) Tag to respond to * @param bool $Append (optional) Append to response-packet (default) * * @access public * @return object */ public function generate ($Response = null, $Tag = null, $Append = true) { if (is_object ($Response)) $Packet = $Response; else $Packet = new phpEvents_Socket_Stream_XML_Tag ('iq'); // Find ID of most top object if (is_object ($Parent = $Tag)) { while (is_object ($Parent->getParent ())) $Parent = $Parent->getParent (); if ($Parent->getAttribute ('id', false)) $Packet->setAttribute ('id', $Parent->getAttribute ('id')); } // Generate the error-packet $Packet->setAttribute ('type', 'error'); $Error = new phpEvents_Socket_Stream_XML_Tag ('error', $Packet); if ($Append) $Packet->setSubtag ($Error); switch ($this->Code) { case self::ERROR_BAD_REQUEST: case self::ERROR_GONE: case self::ERROR_JID_MALFORMED: case self::ERROR_NOT_ACCEPTABLE: case self::ERROR_REDIRECT: case self::ERROR_UNDEFINED_CONDITION: // This is only here per accident $Error->setAttribute ('type', self::ERROR_TYPE_MODIFY); break; case self::ERROR_CONFLICT: case self::ERROR_FEATURE_NOT_IMPLEMENTED: case self::ERROR_ITEM_NOT_FOUND: case self::ERROR_NOT_ALLOWDED: case self::ERROR_REMOTE_SERVER_NOT_FOUND: case self::ERROR_SERVICE_UNAVAILABLE: $Error->setAttribute ('type', self::ERROR_TYPE_CANCEL); break; case self::ERROR_FORBIDDEN: case self::ERROR_NOT_AUTHORIZED: case self::ERROR_PAYMENT_REQUIRED: case self::ERROR_REGISTRATION_REQUIRED: case self::ERROR_SUBSCRIPTION_REQUIRED: $Error->setAttribute ('type', self::ERROR_TYPE_AUTH); break; case self::ERROR_INTERNAL_SERVER_ERROR: case self::ERROR_RECIPIENT_UNAVAILABLE: case self::ERROR_REMOTE_SERVER_TIMEOUT: case self::ERROR_RESOURCE_CONSTRAINT: case self::ERROR_UNEXPECTED_REQUEST: $Error->setAttribute ('type', self::ERROR_TYPE_WAIT); break; default: return false; } $Subtag = new phpEvents_Socket_Stream_XML_Tag ($this->Code, $Error); $Subtag->setNamespace (self::XEP_NAMESPACE); if (is_object ($Response)) return $Error; return $Packet; } // }}} } /** * XMPP Exception Class * * Throw with errors :D * * @package tiggerXMPP * @class xmppException */ class xmppException extends Exception {} ?>