summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ext/Syncroton/Command/Ping.php10
-rw-r--r--lib/ext/Syncroton/Command/Sync.php19
-rw-r--r--lib/ext/Syncroton/Server.php1
3 files changed, 24 insertions, 6 deletions
diff --git a/lib/ext/Syncroton/Command/Ping.php b/lib/ext/Syncroton/Command/Ping.php
index a2bd926..2e71fd2 100644
--- a/lib/ext/Syncroton/Command/Ping.php
+++ b/lib/ext/Syncroton/Command/Ping.php
@@ -87,12 +87,16 @@ class Syncroton_Command_Ping extends Syncroton_Command_Wbxml
}
$lifeTime = $this->_device->pinglifetime;
- $maxLifeTime = Syncroton_Registry::getPingInterval();
+ $maxInterval = Syncroton_Registry::getPingInterval();
- if ($maxLifeTime > 0 && $lifeTime > $maxLifeTime) {
+ if ($maxInterval <= 0 || $maxInterval > Syncroton_Server::MAX_HEARTBEAT_INTERVAL) {
+ $maxInterval = Syncroton_Server::MAX_HEARTBEAT_INTERVAL;
+ }
+
+ if ($lifeTime > $maxInterval) {
$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));
+ $ping->appendChild($this->_outputDom->createElementNS('uri:Ping', 'HeartbeatInterval', $maxInterval));
return;
}
diff --git a/lib/ext/Syncroton/Command/Sync.php b/lib/ext/Syncroton/Command/Sync.php
index 3a3bc26..e528999 100644
--- a/lib/ext/Syncroton/Command/Sync.php
+++ b/lib/ext/Syncroton/Command/Sync.php
@@ -123,11 +123,24 @@ class Syncroton_Command_Sync extends Syncroton_Command_Wbxml
return $this->_outputDom;
}
-
if (isset($requestXML->HeartbeatInterval)) {
+ $intervalDiv = 1;
$this->_heartbeatInterval = (int)$requestXML->HeartbeatInterval;
- } elseif (isset($requestXML->Wait)) {
- $this->_heartbeatInterval = (int)$requestXML->Wait * 60;
+ } else if (isset($requestXML->Wait)) {
+ $intervalDiv = 60;
+ $this->_heartbeatInterval = (int)$requestXML->Wait * $intervalDiv;
+ }
+
+ $maxInterval = Syncroton_Registry::getPingInterval();
+ if ($maxInterval <= 0 || $maxInterval > Syncroton_Server::MAX_HEARTBEAT_INTERVAL) {
+ $maxInterval = Syncroton_Server::MAX_HEARTBEAT_INTERVAL;
+ }
+
+ if ($this->_heartbeatInterval && $this->_heartbeatInterval > $maxInterval) {
+ $sync = $this->_outputDom->documentElement;
+ $sync->appendChild($this->_outputDom->createElementNS('uri:Sync', 'Status', self::STATUS_WAIT_INTERVAL_OUT_OF_RANGE));
+ $sync->appendChild($this->_outputDom->createElementNS('uri:Sync', 'Limit', floor($maxInterval/$intervalDiv)));
+ $this->_heartbeatInterval = null;
}
$this->_globalWindowSize = isset($requestXML->WindowSize) ? (int)$requestXML->WindowSize : 100;
diff --git a/lib/ext/Syncroton/Server.php b/lib/ext/Syncroton/Server.php
index e89b0fe..0fa4855 100644
--- a/lib/ext/Syncroton/Server.php
+++ b/lib/ext/Syncroton/Server.php
@@ -19,6 +19,7 @@ class Syncroton_Server
const PARAMETER_COLLECTIONID = 1;
const PARAMETER_ITEMID = 3;
const PARAMETER_OPTIONS = 7;
+ const MAX_HEARTBEAT_INTERVAL = 3540; // 59 minutes
protected $_body;