summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-08-25 08:47:09 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-08-25 08:47:09 (GMT)
commit9be6b26bc8967daa2256aab5a09abb11d51c8dce (patch)
tree17e12671be27c5ec6c58b9075e333621f6dc06a1
parent05facb6dce339b4dca008db4b38d1aba194ef851 (diff)
downloadkolab-syncroton-9be6b26bc8967daa2256aab5a09abb11d51c8dce.tar.gz
Fix Ping interval handling, add option to define max. HeartbeatInterval value
-rw-r--r--config/main.inc.php.dist3
-rw-r--r--lib/ext/Syncroton/Command/Ping.php15
-rw-r--r--lib/ext/Syncroton/Registry.php15
-rw-r--r--lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage13.php11
-rw-r--r--lib/kolab_sync.php3
5 files changed, 36 insertions, 11 deletions
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index c792377..5f0a7c2 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -60,6 +60,9 @@ $config['activesync_plugins'] = array();
// action for detecting changes in folders. Default: 60
$config['activesync_ping_timeout'] = 60;
+// Defines maximum Ping interval in seconds. Default: 900 (15 minutes)
+$config['activesync_ping_interval'] = 900;
+
// We start detecting changes n seconds since the last sync of a folder
// Default: 180
$config['activesync_quiet_time'] = 180;
diff --git a/lib/ext/Syncroton/Command/Ping.php b/lib/ext/Syncroton/Command/Ping.php
index d2e5c83..a2bd926 100644
--- a/lib/ext/Syncroton/Command/Ping.php
+++ b/lib/ext/Syncroton/Command/Ping.php
@@ -57,8 +57,8 @@ class Syncroton_Command_Ping extends Syncroton_Command_Wbxml
$xml = simplexml_import_dom($this->_requestBody);
$xml->registerXPathNamespace('Ping', 'Ping');
- if(isset($xml->HeartBeatInterval)) {
- $this->_device->pinglifetime = (int)$xml->HeartBeatInterval;
+ if(isset($xml->HeartbeatInterval)) {
+ $this->_device->pinglifetime = (int)$xml->HeartbeatInterval;
}
if (isset($xml->Folders->Folder)) {
@@ -86,8 +86,15 @@ class Syncroton_Command_Ping extends Syncroton_Command_Wbxml
$this->_device = $this->_deviceBackend->update($this->_device);
}
- $lifeTime = $this->_device->pinglifetime;
- #Tinebase_Core::setExecutionLifeTime($lifeTime);
+ $lifeTime = $this->_device->pinglifetime;
+ $maxLifeTime = Syncroton_Registry::getPingInterval();
+
+ if ($maxLifeTime > 0 && $lifeTime > $maxLifeTime) {
+ $ping = $this->_outputDom->documentElement;
+ $ping->appendChild($this->_outputDom->createElementNS('uri:Ping', 'Status', self::STATUS_INTERVAL_TO_GREAT_OR_SMALL));
+ $ping->appendChild($this->_outputDom->createElementNS('uri:Ping', 'HeartbeatInterval', $maxLifeTime));
+ return;
+ }
$intervalEnd = $intervalStart + $lifeTime;
$secondsLeft = $intervalEnd;
diff --git a/lib/ext/Syncroton/Registry.php b/lib/ext/Syncroton/Registry.php
index 5460f96..f67e2d3 100644
--- a/lib/ext/Syncroton/Registry.php
+++ b/lib/ext/Syncroton/Registry.php
@@ -36,6 +36,7 @@ class Syncroton_Registry extends ArrayObject
const DEFAULT_POLICY = 'default_policy';
const PING_TIMEOUT = 'ping_timeout';
+ const PING_INTERVAL = 'ping_interval';
const QUIET_TIME = 'quiet_time';
const DATABASE = 'database';
@@ -242,6 +243,20 @@ class Syncroton_Registry extends ArrayObject
}
/**
+ * Return maximum ping interval (HeartbeatInterval) value (in seconds)
+ *
+ * @return int
+ */
+ public static function getPingInterval()
+ {
+ if (!self::isRegistered(self::PING_INTERVAL)) {
+ return 3540; // 59 minutes limit defined in Activesync protocol spec.
+ }
+
+ return self::get(self::PING_INTERVAL);
+ }
+
+ /**
* return ping timeout
*
* sleep "ping timeout" seconds between folder checks in Ping and Sync command
diff --git a/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage13.php b/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage13.php
index f670f75..6b909f3 100644
--- a/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage13.php
+++ b/lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage13.php
@@ -15,22 +15,21 @@
* @package Wbxml
* @subpackage ActiveSync
*/
-
class Syncroton_Wbxml_Dtd_ActiveSync_CodePage13 extends Syncroton_Wbxml_Dtd_ActiveSync_Abstract
{
protected $_codePageNumber = 13;
-
+
protected $_codePageName = 'Ping';
-
- protected $_tags = array(
+
+ protected $_tags = array(
'Ping' => 0x05,
'AutdState' => 0x06, //unused
'Status' => 0x07,
- 'HeartBeatInterval' => 0x08,
+ 'HeartbeatInterval' => 0x08,
'Folders' => 0x09,
'Folder' => 0x0a,
'Id' => 0x0b,
'Class' => 0x0c,
'MaxFolders' => 0x0d
);
-} \ No newline at end of file
+}
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index 3ae473c..d2867b8 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -155,7 +155,8 @@ class kolab_sync extends rcube
// Configuration
Syncroton_Registry::set(Syncroton_Registry::PING_TIMEOUT, $this->config->get('activesync_ping_timeout', 60));
- Syncroton_Registry::set(Syncroton_Registry::QUIET_TIME, $this->config->get('activesync_quiet_time', 180));
+ Syncroton_Registry::set(Syncroton_Registry::PING_INTERVAL, $this->config->get('activesync_ping_interval', 15 * 60));
+ Syncroton_Registry::set(Syncroton_Registry::QUIET_TIME, $this->config->get('activesync_quiet_time', 3 * 60));
// Run Syncroton
$syncroton = new Syncroton_Server($userid);