config/main.inc.php.dist lib/ext lib/kolab_sync.php

Aleksander Machniak machniak at kolabsys.com
Mon Aug 25 10:48:05 CEST 2014


 config/main.inc.php.dist                              |    3 +++
 lib/ext/Syncroton/Command/Ping.php                    |   15 +++++++++++----
 lib/ext/Syncroton/Registry.php                        |   15 +++++++++++++++
 lib/ext/Syncroton/Wbxml/Dtd/ActiveSync/CodePage13.php |   11 +++++------
 lib/kolab_sync.php                                    |    3 ++-
 5 files changed, 36 insertions(+), 11 deletions(-)

New commits:
commit 9be6b26bc8967daa2256aab5a09abb11d51c8dce
Author: Aleksander Machniak <machniak at kolabsys.com>
Date:   Mon Aug 25 10:47:09 2014 +0200

    Fix Ping interval handling, add option to define max. HeartbeatInterval value

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);




More information about the commits mailing list