ZP-1093 Add service unavailable exception. Released under the Affero GNU...

ZP-1093 Add service unavailable exception. Released under the Affero GNU General Public License (AGPL) version 3.
parent b8be1f7a
......@@ -272,6 +272,13 @@
define('SYNC_TIMEOUT_MEDIUM_DEVICETYPES', "SAMSUNGGTI");
define('SYNC_TIMEOUT_LONG_DEVICETYPES', "iPod, iPad, iPhone, WP, WindowsOutlook");
// The delay in second the device should wait whenever the service is unavailable
// A service is unavailable whenever z-push sends a 503 http code. This can be accomplished
// by throwing the ServiceUnavailableException.
// It is up to the device to respect or not this directive so even if this option is set,
// the device might not wait the time.
define('RETRY_AFTER_DELAY', 300);
/**********************************************************************************
* Backend settings
*/
......
......@@ -344,6 +344,13 @@ class ZPush {
throw new FatalMisconfigurationException("The PING_HIGHER_BOUND_LIFETIME value must be greater or equal to PING_LOWER_BOUND_LIFETIME.");
}
if (!defined('RETRY_AFTER_DELAY')) {
define('RETRY_AFTER_DELAY', 300);
}
elseif (RETRY_AFTER_DELAY !== false && !is_int(RETRY_AFTER_DELAY) || RETRY_AFTER_DELAY < 0) {
throw new FatalMisconfigurationException("The RETRY_AFTER_DELAY value must be 'false' or a number greater than 0.");
}
// Check KOE flags
if (!defined('KOE_CAPABILITY_GAB')) {
define('KOE_CAPABILITY_GAB', false);
......
......@@ -1002,6 +1002,7 @@ define("HTTP_CODE_200", 200);
define("HTTP_CODE_401", 401);
define("HTTP_CODE_449", 449);
define("HTTP_CODE_500", 500);
define("HTTP_CODE_503", 503);
define("WINDOW_SIZE_MAX", 512);
......
<?php
/***********************************************
* File : serviceunavailableexception.php
* Project : Z-Push
* Descr : Exception sending a '503 Service Unavailable' to the mobile
*
* Created : 09.08.2016
*
* Copyright 2007 - 2016 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation with the following additional
* term according to sec. 7:
*
* According to sec. 7 of the GNU Affero General Public License, version 3,
* the terms of the AGPL are supplemented with the following terms:
*
* "Zarafa" is a registered trademark of Zarafa B.V.
* "Z-Push" is a registered trademark of Zarafa Deutschland GmbH
* The licensing of the Program under the AGPL does not imply a trademark license.
* Therefore any rights, title and interest in our trademarks remain entirely with us.
*
* However, if you propagate an unmodified version of the Program you are
* allowed to use the term "Z-Push" to indicate that you distribute the Program.
* Furthermore you may use our trademarks where it is necessary to indicate
* the intended purpose of a product or service provided you use it in accordance
* with honest practices in industrial or commercial matters.
* If you want to propagate modified versions of the Program under the name "Z-Push",
* you may only do so if you have a written permission by Zarafa Deutschland GmbH
* (to acquire a permission please contact Zarafa at trademark@zarafa.com).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Consult LICENSE file for details
************************************************/
class ServiceUnavailableException extends HTTPReturnCodeException {
protected $defaultLogLevel = LOGLEVEL_INFO;
protected $httpReturnCode = HTTP_CODE_503;
protected $httpReturnMessage = "Service Unavailable";
protected $httpHeaders = array();
protected $showLegal = true;
public function __construct($message = "", $code = 0, $previous = NULL, $logLevel = false) {
parent::__construct($message, $code, $previous, $logLevel);
if (RETRY_AFTER_DELAY !== false) {
$this->httpHeaders[] = 'Retry-After: ' . RETRY_AFTER_DELAY;
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment